Bug 1223042 - Git based gems not available in CFME automate methods
Summary: Git based gems not available in CFME automate methods
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat CloudForms Management Engine
Classification: Red Hat
Component: Appliance
Version: 5.4.0
Hardware: x86_64
OS: Linux
high
high
Target Milestone: GA
: 5.4.0
Assignee: Joe Rafaniello
QA Contact: Milan Falešník
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-05-19 16:35 UTC by jritenou
Modified: 2015-06-16 13:02 UTC (History)
11 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-06-16 13:02:42 UTC
Category: ---
Cloudforms Team: ---
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2015:1100 0 normal SHIPPED_LIVE CFME 5.4.0 bug fixes, and enhancement update 2015-06-16 16:28:42 UTC

Description jritenou 2015-05-19 16:35:11 UTC
Description of problem:
Gems in /opt/rh/cfme-gemset are not available to automate methods.  In particular the rest-client gem is one of these, and in testing some automate code I have used in 5.2 & 5.3 that required the rest-client gem, they did not work out of the box in the current CFME beta build.  

In order to continue using these methods, I had to call the custom rest-client gem manaully with LOAD_PATH.
  
$LOAD_PATH.unshift "/opt/rh/cfme-gemset/bundler/gems/rest-client-08480eb86aef/lib/"


Version-Release number of selected component (if applicable):
5.4.0.0.19

How reproducible:
100%


Steps to Reproduce:
1. Create an automate method with a "require 'rest-api'" statement
2. Invoke automate method
3. Method will fail

Actual results:
--] I, [2015-05-19T12:33:52.681321 #2278:35f7e24]  INFO -- : <AEMethod bigip_list_pools> BigIP_List_Pools - ================================= EVM Automate Method Started
[----] E, [2015-05-19T12:33:52.686118 #2278:35f7e24] ERROR -- : <AEMethod bigip_list_pools> The following error occurred during method evaluation:
[----] E, [2015-05-19T12:33:52.686490 #2278:35f7e24] ERROR -- : <AEMethod bigip_list_pools>   LoadError: cannot load such file -- rest-client
[----] E, [2015-05-19T12:33:52.687145 #2278:35f7e24] ERROR -- : <AEMethod bigip_list_pools>   /opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require'
/opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require'
[----] E, [2015-05-19T12:33:52.693031 #2278:63dea4] ERROR -- : Method STDERR: /opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require': cannot load such file -- rest-client (LoadError)
[----] E, [2015-05-19T12:33:52.693119 #2278:63dea4] ERROR -- : Method STDERR: from /opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require'
[----] E, [2015-05-19T12:33:52.693181 #2278:63dea4] ERROR -- : Method STDERR: from <code: require 'rest-client'>:38:in `<main>'
[----] I, [2015-05-19T12:33:52.693553 #2278:63dea4]  INFO -- : <AEMethod [/JMR/Integration/BigIP/BigIP_List_Pools]> Ending
[----] E, [2015-05-19T12:33:52.693908 #2278:63dea4] ERROR -- : Aborting instantiation (unknown method return code) because [Method exited with rc=Unknown RC: [1]]


Expected results:

Successful load of rest-client gem & connection invoked.  


Additional info:

Comment 3 Joe Rafaniello 2015-05-19 21:42:36 UTC
A really bad hack is to inject the lib paths for each of the bundler git based gems into the ruby automate method preamble:

diff --git a/vmdb/lib/miq_automation_engine/engine/miq_ae_method.rb b/vmdb/lib/miq_automation_engine/engine/miq_ae_method.rb
index 394c26c..d765392 100644
--- a/vmdb/lib/miq_automation_engine/engine/miq_ae_method.rb
+++ b/vmdb/lib/miq_automation_engine/engine/miq_ae_method.rb
@@ -140,6 +140,9 @@ begin
   Socket.do_not_reverse_lookup = true  # turn off reverse DNS resolution

   require 'drb'
+  # HACK: inject each of the bundler git based gem lib paths from the current
+  # process into the preamble executed in the ruby method subproces.
+  #{$LOAD_PATH.grep(/bundler\/gems/).each_with_object("") { |path, string| string << "$LOAD_PATH << '#{path}'\n  " } }

   MIQ_OK    = 0
   MIQ_WARN  = 4

Comment 4 Joe Rafaniello 2015-05-19 21:46:02 UTC
A better solution would be to symlink the gemset's bundler git gem directories so rubygems can find them.  

I was able to do this manually, just have to automate this as part of the gemset creation.


For each gem in the bundler/gems directory (/opt/rh/cfme-gemset/bundler/gems)

actionwebservice-fcb04f3fa857
handsoap-daec1277652f
jquery-rjs-33e0fc1c0b25
rails-4842a8377644
rest-client-08480eb86aef
rubyrep-fd866d906fcb
rubywbem-f2c18cbe14a4
ruport-3ba69305f42e
soap4r-514bdbe1d0bc
WinRM-f4fa33eba82d
ziya-597cc777c24f

Get the gem version for each git based gem
1) Load rails console on a cfme 5.4 appliance:

irb(main):014:0> Gem.loaded_specs.values.select { |s| s.full_gem_path.include?("bundler/gems") }
=> [#<Gem::Specification:0x1230ea0 activesupport-3.2.17>, #<Gem::Specification:0x1211e60 activemodel-3.2.17>, #<Gem::Specification:0x105a4f0 actionpack-3.2.17>, #<Gem::Specification:0x1267310 actionmailer-3.2.17>, #<Gem::Specification:0x10da844 activerecord-3.2.17>, #<Gem::Specification:0x12bce3c actionwebservice-3.1.0>, #<Gem::Specification:0x11f0698 activeresource-3.2.17>, #<Gem::Specification:0x15ed3cc rest-client-2.0.0.alpha>, #<Gem::Specification:0x112fb14 railties-3.2.17>, #<Gem::Specification:0x15fc2a0 handsoap-0.2.5>, #<Gem::Specification:0xf65b1c rails-3.2.17>, #<Gem::Specification:0x125cbcc jquery-rjs-0.1.1>, #<Gem::Specification:0x1246ee4 rubyrep-1.2.0>, #<Gem::Specification:0x1628b34 rubywbem-0.1.0>, #<Gem::Specification:0x163d250 ruport-1.7.0>, #<Gem::Specification:0x12002c8 soap4r-1.6.0>, #<Gem::Specification:0x15bd500 winrm-1.1.3>, #<Gem::Specification:0x1669954 ziya-2.3.0>]

2) Create the following symlinks for each gem using the above information.
Note, use the Gem::Specification's gem name and version number for the destination symlink.
For example, even though WinRM uses mixed case, the name of the gem is lowecase: #<Gem::Specification:0x15bd500 winrm-1.1.3>

So:
ln -s /opt/rh/cfme-gemset/bundler/gems/WinRM-f4fa33eba82d/ /opt/rh/cfme-gemset/gems/winrm-1.1.3
ln -s /opt/rh/cfme-gemset/bundler/gems/WinRM-f4fa33eba82d/winrm.gemspec /opt/rh/cfme-gemset/specifications/winrm-1.1.3.gemspec

Produces:
[root@10-16-6-93 vmdb]# ls -al /opt/rh/cfme-gemset/gems/winrm-1.1.3
lrwxrwxrwx. 1 root root 52 May 19 17:11 /opt/rh/cfme-gemset/gems/winrm-1.1.3 -> /opt/rh/cfme-gemset/bundler/gems/WinRM-f4fa33eba82d/

[root@10-16-6-93 vmdb]# ls -al /opt/rh/cfme-gemset/specifications/winrm-1.1.3.gemspec
lrwxrwxrwx. 1 root root 65 May 19 17:06 /opt/rh/cfme-gemset/specifications/winrm-1.1.3.gemspec -> /opt/rh/cfme-gemset/bundler/gems/WinRM-f4fa33eba82d/winrm.gemspec


ln -s /opt/rh/cfme-gemset/bundler/gems/rest-client-08480eb86aef/ /opt/rh/cfme-gemset/gems/rest-client-2.0.0.alpha
ln -s /opt/rh/cfme-gemset/bundler/gems/rest-client-08480eb86aef/rest-client.gemspec /opt/rh/cfme-gemset/specifications/rest-client-2.0.0.alpha.gemspec

[root@10-16-6-93 vmdb]# ls -al /opt/rh/cfme-gemset/gems/rest-client-2.0.0.alpha 
lrwxrwxrwx. 1 root root 58 May 19 16:38 /opt/rh/cfme-gemset/gems/rest-client-2.0.0.alpha -> /opt/rh/cfme-gemset/bundler/gems/rest-client-08480eb86aef/

[root@10-16-6-93 vmdb]# ls -al /opt/rh/cfme-gemset/specifications/rest-client-2.0.0.alpha.gemspec
lrwxrwxrwx. 1 root root 77 May 19 16:38 /opt/rh/cfme-gemset/specifications/rest-client-2.0.0.alpha.gemspec -> /opt/rh/cfme-gemset/bundler/gems/rest-client-08480eb86aef/rest-client.gemspec

Comment 5 Joe Rafaniello 2015-05-21 21:59:33 UTC
We had success rebuilding the old cfme-gemset-5.4.0.1 using a change in our gemset creation process to do symlinking and a commit on the cfme-gemset.spec to change the /opt/rh/cfme-gemset/enable script to no longer set GEM_HOME but instead set GEM_PATH and BUNDLE_PATH.


For testing:
1) gem install winrm should install to the default gem location, `gem env home`... not /opt/rh/cfme-gemset/gems

2) if you install a newer winrm (1.3.3), where we have 1.1.3 in our gemset, you should be able to write an automate method that does `require 'winrm'` and use the new 1.3.3 version.

3) if you install an older winrm (1.1.2), where we have 1.1.3 in our gemset, you can only use the older winrm, 1.1.2 by putting this in our automate method:
gem 'winrm', "=1.1.2"
require 'winrm' 

To test these, it was easiest to find the location of the gem by looking for it in the `gem env path` locations... then modify the winrm.rb file to `puts "hello 1.1.2"` at the top of the file, you should see the output in the log/automation.log file.

On my 5.4 appliance, these locations were here:

/opt/rh/ruby200/root/usr/local/share/gems/gems/winrm-1.1.2/lib/winrm.rb
/opt/rh/ruby200/root/usr/local/share/gems/gems/winrm-1.3.3/lib/winrm.rb
/opt/rh/cfme-gemset/bundler/gems/WinRM-f4fa33eba82d/lib/winrm.rb

Comment 6 Joe Rafaniello 2015-05-21 21:59:54 UTC
The next build of 5.4 will have the cfme-gemset rpm fixed.

Comment 9 Milan Falešník 2015-06-02 08:34:54 UTC
Verified in 5.4.0.4.

I created an instance and a method in the Request class in similar manner as InspectMe is done.

The instance had code like this:

$evm.log(:info, (require "rest-client"))


After running a simulation with executing the methods, the automation.log stated this:

[----] I, [2015-06-02T04:31:48.409972 #2752:403ea4]  INFO -- : Following Relationship [miqaedb:/System/Request/testit#create]
[----] I, [2015-06-02T04:31:48.424474 #2752:403ea4]  INFO -- : Updated namespace [miqaedb:/System/Request/testit#create  Default/System]
[----] I, [2015-06-02T04:31:48.444408 #2752:403ea4]  INFO -- : Updated namespace [System/Request/testitmeth  Default/System]
[----] I, [2015-06-02T04:31:48.451307 #2752:403ea4]  INFO -- : Invoking [inline] method [/Default/System/Request/testitmeth] with inputs [{}]
[----] I, [2015-06-02T04:31:48.452285 #2752:403ea4]  INFO -- : <AEMethod [/Default/System/Request/testitmeth]> Starting
[----] I, [2015-06-02T04:31:49.176876 #2752:80f726c]  INFO -- : <AEMethod testitmeth> true
[----] I, [2015-06-02T04:31:49.190384 #2752:403ea4]  INFO -- : <AEMethod [/Default/System/Request/testitmeth]> Ending
[----] I, [2015-06-02T04:31:49.190495 #2752:403ea4]  INFO -- : Method exited with rc=MIQ_OK
[----] I, [2015-06-02T04:31:49.191228 #2752:403ea4]  INFO -- : Followed  Relationship [miqaedb:/System/Request/testit#create]

Comment 11 errata-xmlrpc 2015-06-16 13:02:42 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-1100.html


Note You need to log in before you can comment on or make changes to this bug.