require '<GEM>' in trema user controller giving LoadError

215 views
Skip to first unread message

skarr

unread,
Jun 27, 2012, 5:32:14 PM6/27/12
to trem...@googlegroups.com
Hi,

In Ubuntu 11.10 environment,  when I try to "require" a gem in the user-defined controller, I am getting a LoadError. This even happens with the "apps/learning_switch_memcached" example as follows:

user@ubuntu:~/work/trema$ ./trema run ../apps/learning_switch_memcached/learning-switch.rb
...
/home/user/work/trema/ruby/trema/command/run.rb:104:in `load_config': /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- memcache (LoadError)
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from ../apps/learning_switch_memcached/fdb.rb:30
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from (eval):29:in `load_config'
from /home/user/work/trema/ruby/trema/command/run.rb:67:in `run'
from ./trema:86:in `__send__'
from ./trema:86

The following is my ruby $LOAD_PATH and gem environment as well as location of "memcache" gem

user@ubuntu:~$ irb
irb(main):001:0> $LOAD_PATH
=> ["/usr/local/lib/site_ruby/1.8", "/usr/local/lib/site_ruby/1.8/i686-linux", "/usr/local/lib/site_ruby/1.8/i486-linux", "/usr/local/lib/site_ruby", "/usr/lib/ruby/vendor_ruby/1.8", "/usr/lib/ruby/vendor_ruby/1.8/i686-linux", "/usr/lib/ruby/vendor_ruby", "/usr/lib/ruby/1.8", "/usr/lib/ruby/1.8/i686-linux", "/usr/lib/ruby/1.8/i486-linux", "."]
irb(main):002:0> exit
user@ubuntu:~$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.24
  - RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/bin/ruby1.8
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.8
     - /home/user/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:

user@ubuntu:~$ gem which memcache
/usr/lib/ruby/gems/1.8/gems/memcache-client-1.8.5/lib/memcache.rb

I have tried various versions and installation mechanisms of "rubygems" including apt-get, RVM and manual installation with the same result. Am I missing some environment setting?

Thank You,
Regards
Karthik

Yasuhito Takamiya

unread,
Jun 28, 2012, 8:05:42 AM6/28/12
to trem...@googlegroups.com
Hi,

Thank you very much for the detailed report.

I am not sure but the root cause of this problem may come from the
fact that "trema run"
command uses eval() for loading controller's ".rb" files instead of
load(). Maybe using eval()
and require() at the same time causes such a problem, so replacing
"eval" with "load" may fix it.

We are investigating this problem and please hold on for a while.

Yasuhito

Kazuya Suzuki

unread,
Jun 29, 2012, 5:08:56 AM6/29/12
to trem...@googlegroups.com, karthi...@gmail.com
Hi,

If you must not require to use memcached, you can try an another version of
learning-switch without memcached.

user@ubuntu:~/work/trema$ ./trema run src/examples/learning_switch/learning-switch.rb

It is too difficult to execute a memcached-version of learning-switch.
I cannot succeed inexecuting it too.

Best regards,
Kazuya Suzuki
--
Kazuya Suzuki
kaz...@ax.jp.nec.com


karthik

unread,
Jun 29, 2012, 10:30:56 AM6/29/12
to trem...@googlegroups.com, karthi...@gmail.com
Hi,

The main reason for looking at the memcache example was to understand how to use gems within the trema user-defined controller.

In our application we are trying to use activerecord (active_record) gem to persist controller, switch, host and flow information into a database. But we were getting the same LoadError as the memcache example. On a side note, we were successful in getting the getting the memcache example to work by installing the debian package for memcache-client. 

But the real focus is how to use gem libraries within trema.

Thanks,
Best regards
Karthik

Yasuhito Takamiya

unread,
Jul 4, 2012, 1:05:06 AM7/4/12
to trem...@googlegroups.com
Hi,

Fixed in the current tree.
https://github.com/trema/trema/commit/c8178ae6f86ce1ed790178d7edccb77bd7578c13

Please git pull and try it.

Yasuhito


On Thu, Jun 28, 2012 at 6:32 AM, skarr <karthi...@gmail.com> wrote:

karthik

unread,
Jul 6, 2012, 4:28:44 PM7/6/12
to trem...@googlegroups.com
Thank you Takamiya San

The fix works great and we are now able to use active_record gem to persist controller, switch, host and flow information into a database. 

Best Regards
karthik

Yasuhito Takamiya

unread,
Jul 7, 2012, 11:04:26 AM7/7/12
to trem...@googlegroups.com
Hi,

BTW there is an active pull-request that adds a new Trema sample using AR.
https://github.com/trema/trema/pull/177

This sample receives Features Reply messages and stores switch and its
ports information into AR.
https://github.com/miyakz1192/trema/blob/f9676325add48dba6ad93e1ff92523b3a7f93a37/src/examples/active_record/active_record_app.rb

Hope this helps.

Yasuhito
Reply all
Reply to author
Forward
0 new messages