Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dots in vSphere advanced settings break rspec-its #19

Closed
LandonThomas opened this issue Dec 20, 2017 · 1 comment
Closed

Dots in vSphere advanced settings break rspec-its #19

LandonThomas opened this issue Dec 20, 2017 · 1 comment

Comments

@LandonThomas
Copy link

Every advanced setting in vCenter for an ESX host contains a period. That means every key in the @params hash of vmhost_advancedsetting.rb contains a period and cannot be read:

[~/chef/inspec-vmware (master *)]$ cat controls/advanced_settings.rb 
dc = 'redacted'
esx_host = 'redacted'

describe vmhost_advancedsetting(datacenter: dc, host: esx_host) do
  its('Config.HostAgent.log.level') { should eq 'verbose' }
end
[~/chef/inspec-vmware (master *)]$ INSPEC_ESX_CONN='redacted' inspec exec .

Profile: VMware vSphere/ESXi Resource Pack (vsphere)
Version: 0.1.0
Target:  local://


  vmhost_advancedsetting Config.HostAgent.log.level
     ∅  undefined method `HostAgent' for nil:NilClass

Test Summary: 0 successful, 1 failure, 0 skipped

I think this is the same rspec-its issue as inspec/inspec#875. I can apply the fix from inspec/inspec#2160:

diff --git a/libraries/vmhost_advancedsetting.rb b/libraries/vmhost_advancedsetting.rb
index f577fa1..585bf52 100644
--- a/libraries/vmhost_advancedsetting.rb
+++ b/libraries/vmhost_advancedsetting.rb
@@ -19,8 +19,14 @@ class VmWareHostAdvancedSetting < Inspec.resource(1)
     @opts = opts
   end
 
-  def method_missing(name) # rubocop:disable Style/MethodMissing
-    advancedsetting[name.to_s]
+  def method_missing(*keys) # rubocop:disable Style/MethodMissing
+    if keys.is_a?(Array)
+       keys.shift if keys[0] == :[]
+       key = keys.first
+    else
+      key = keys
+    end
+    advancedsetting[key.to_s]
   end
 
   private

and bracket the key:

diff --git a/controls/advanced_settings.rb b/controls/advanced_settings.rb
index 0948b76..f5626c6 100644
--- a/controls/advanced_settings.rb
+++ b/controls/advanced_settings.rb
@@ -2,5 +2,5 @@ dc = 'redacted'
 esx_host = 'redacted'
 
 describe vmhost_advancedsetting(datacenter: dc, host: esx_host) do
-  its('Config.HostAgent.log.level') { should eq 'verbose' }
+  its(['Config.HostAgent.log.level']) { should eq 'verbose' }
 end

and it works:

[~/chef/inspec-vmware (master *)]$ INSPEC_ESX_CONN='redacted' inspec exec .

Profile: VMware vSphere/ESXi Resource Pack (vsphere)
Version: 0.1.0
Target:  local://


  vmhost_advancedsetting ["Config.HostAgent.log.level"]
     ∅  should eq "verbose"
     
     expected: "verbose"
          got: "info"
     
     (compared using ==)
     

Test Summary: 0 successful, 1 failure, 0 skipped
rndmh3ro pushed a commit to rndmh3ro/inspec-vmware that referenced this issue Jan 11, 2018
Signed-off-by: Sebastian Gumprich <[email protected]>
rndmh3ro pushed a commit to rndmh3ro/inspec-vmware that referenced this issue Jan 11, 2018
Signed-off-by: Sebastian Gumprich <[email protected]>
rndmh3ro pushed a commit to rndmh3ro/inspec-vmware that referenced this issue Jan 11, 2018
Signed-off-by: Sebastian Gumprich <[email protected]>
@chris-rock
Copy link
Collaborator

Thank you @LandonThomas As you've seen the old way had a lot of issues. Therefore we completely reworked our approach and base on powercli now. Please see inspec/inspec#3133 for further details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants