chef-boneyard / minitest-chef-handler

Run minitest suites after your Chef recipes to check the status of your system.
Other
163 stars 44 forks source link

NameError: undefined local variable or method `node' for #<#<Class:0x7fb913ed18f8>:0x7fb913ebcca0> #33

Closed leifmadsen closed 12 years ago

leifmadsen commented 12 years ago

While testing with the latest minitest-chef-handler (and presumably latest minitest gem -- I'm not 100% sure where the change in behaviour has crept up from), I ran into the errors as shown in the subject.

The error is shown during minitest testing of the mysql opscode cookbook (1.3.0). I am using the latest minitest (3.0.1 I think) and minitest-chef-handler (0.6.1).

Error appears on both Chef 10.14.0.rc.1 and 10.12.0.

Additional information is shown on this ticket:

http://tickets.opscode.com/browse/CHEF-3405

leifmadsen commented 12 years ago

Oops, latests minitest is 3.3.0. Confirmed same issue on latest version of that. Also did some testing with minitest-chef-handler 0.5.4, and same issue there. Unfortunately having issues tracking down exactly "what" is causing the issue with access to a node attribute.

acrmp commented 12 years ago

Hi Leif,

I've left a comment against CHEF-3405. I think there are two issues here.

Cheers,

Andrew.

leifmadsen commented 12 years ago

Thanks for the quick response! I will certainly try the renaming thing which I think is related to the way the mysql cookbook is attempting to execute the tests. I'll see what I can come up with in testing over the next couple of days.

leifmadsen commented 12 years ago

I don't think the documentation update resolves this issue. As pointed out by @acrmp there is a change to the way the methods are accessed in Chef for node attributes. The change at https://github.com/opscode/chef/commit/3d76d1ea8961288809aaf867f00b632ec08d4297 shows that an action needs to be passed now to the provider.

@acrmp pointed out the line in minitest-chef-handler: https://github.com/calavera/minitest-chef-handler/blob/v0.6.1/lib/minitest-chef-handler/resources.rb#L17

An additional argument of 'action' needs to be passed in addition to the resource.

leifmadsen commented 12 years ago

One issue I see with that pull request I made, is that it doesn't take into account different Chef versions. I wasn't exactly sure how to handle that and I've run out of time today :(

(This only works for Chef 10.14.x and later)

calavera commented 12 years ago

Yeah, I feel like we should take into account other versions. I'm sitll using 0.10.8, the latest really stable version from my experience, and I'm pretty sure there are a bunch of people like me.

Btw, I like to keep information about that's inside every new release in History.txt, please feel free to edit it to add this patch.

leifmadsen commented 12 years ago

Sounds good, I can do that. Do you have a suggestion as to how best I should handle checking the chef-client version that is running? Do I have access to node attributes where I made the change?

leifmadsen commented 12 years ago

OK updated History.txt and added version checks

cgriego commented 12 years ago

Using Chef::VERSION would be easier node['chef_packages']['chef']['version'] and you can also use the Gem::Version class to do straight-forward version checks. if Gem::Version.new(Chef::VERSION) < Gem::Version.new("10.14.0")

leifmadsen commented 12 years ago

Thanks @cgriego !!! I'll make that change and test it out today.

leifmadsen commented 12 years ago

@cgriego You'll to bare with me here, but Chef::VERSION shows as uninitialized as shown in your example:

test_0005_has a config directory(mysql::server): NameError: uninitialized constant MiniTest::Chef::VERSION

Thoughts?

leifmadsen commented 12 years ago

Disregard, I figured it out :)

s/Chef::VERSION/::Chef::VERSION/

leifmadsen commented 12 years ago

I tested this change on Chef 10.12.0, 10.14.2 and 10.14.4.rc.0 -- works on all.

calavera commented 12 years ago

cool, thank you @leifmadsen. I'm going to release a new version then.