Open szymonpk opened 8 years ago
Hmm, I specifically accounted for that. Are you doing anything odd in your attributes file?
It's example we've talked yesterday on slack, if I change full method calls with just lazy
and run chef spec on cookbook (postgresql_server) which depends on this one (generic_server), it fails as described above, these attributes aren't even used in postgresql_wrapper.
default["generic_server"]["openssl"]["url"] = PoiseDerived::LazyAttribute.new(
node,
"https://www.openssl.org/source/openssl-%{generic_server.openssl.version}.tar.gz"
)
default["generic_server"]["openssl"]["checksum"] = "e7aff292be21c259c6af26469c7a9b3ba26e9abaaffd325e3dccc9785256c431"
default["generic_server"]["openssl"]["version"] = "1.0.2j"
default["generic_server"]["openssl"]["source_directory"] = PoiseDerived::LazyAttribute.new(
node,
"/usr/src/openssl-%{generic_server.openssl.version}"
)
Something smells fishy here. Using the class directly (or the internal form _lazy_attribute
instead of lazy
) should definitely work in this case. Check for recipe sync issues?
Sorry maybe my example wasn't clear PoiseDerived::LazyAttribute.new...
works - no exception, lazy
doesn't - exception is present.
What do you mean by recipe sync issues?
Never mind, if the class works then it isn't what I was thinking of. If you run with -l debug
, do you see a log line [poise-derived] Installing node DSL
? That is the point where it activates the override for lazy
. More generally, if you just grep the debug output for poise-derived
it would give us some info to work with.
Looks like something isn't loading when testing wrapper cookbook.
If I'm testing postgresql wrapper:
[2016-09-30T11:01:32+02:00] DEBUG: Cookbooks to compile: [:compat_resource, :apt, :"build-essential", :chef_handler, :windows, :seven_zip, :ark, :bsw_gpg, :"chef-sugar", :openssl, :postgresql, :database, :yum, :datadog, :ohai, :aws, :cron, :logrotate, :"chef-client", :"chef-vault", :"yum-epel", :fail2ban, :homebrew, :java, :dpkg_autostart, :ubuntu, :"monit-ng", :ntp, :omnibus_updater, :"poise-derived", :poise, :"poise-archive", :"poise-languages", :"poise-python", :postfix, :rsyslog, :"ssh-keys", :sudo, :sysctl, :hostsfile, :system, :ulimit, :generic_server, :postgresql_server]
[2016-09-30T11:01:32+02:00] DEBUG: Loading cookbook poise-derived's library file: /home/szymon/site-cookbooks/poise-derived/libraries/default.rb
When testing generic_server directly
[2016-09-30T11:05:19+02:00] DEBUG: Cookbooks to compile: [:compat_resource, :apt, :"build-essential", :chef_handler, :windows, :seven_zip, :ark, :ohai, :aws, :cron, :logrotate, :"chef-client", :"chef-sugar", :"chef-vault", :yum, :datadog, :"yum-epel", :fail2ban, :homebrew, :java, :dpkg_autostart, :ubuntu, :"monit-ng", :ntp, :omnibus_updater, :"poise-derived", :poise, :"poise-archive", :"poise-languages", :"poise-python", :postfix, :rsyslog, :"ssh-keys", :sudo, :sysctl, :hostsfile, :system, :ulimit, :generic_server]
[2016-09-30T11:05:19+02:00] DEBUG: Loading cookbook poise-derived's library file: /home/szymon/site-cookbooks/poise-derived/libraries/default.rb
[2016-09-30T11:05:19+02:00] DEBUG: [poise-derived] Installing event handler
[2016-09-30T11:05:19+02:00] DEBUG: [poise-derived] Installing node DSL
[2016-09-30T11:05:19+02:00] DEBUG: [poise-derived] Uninstalling node DSL
In metadata.rb only generic_server depends on poise-derived and postgresql_server wrapper depends on generic_server.
What kind of testing is this, ChefSpec or Test Kitchen?
ChefSpec with SoloRunner.
Does your postgresql_server cookbook work under Test Kitchen? That would at least narrow it to an interaction between ChefSpec and my code.
Yes, everything works fine when running TestKitchen.
Okay, so some kind of interaction with ChefSpec. I'll see if I can repro tomorrow. Not sure I see how it could be failing to at least install the handler, even if the handler doesn't activate but I'm sure it will be clearer with a repro I can poke at :)
I'm seeing the same in when trying to run chefspec with lazy attributes. Converges in test kitchen just fine.
Example attributes default['mta_mantis']['mantis']['version'] = '2.3.1' default['mta_mantis']['mantis']['name'] = lazy 'mantis-%{mta_mantis.mantis.version}'
Error:
1) mta_mantis::firewall When all attributes are set to default on a supported platform_family converges successfully
Failure/Error: chef_run.converge(described_recipe)
ArgumentError:
wrong number of arguments (given 1, expected 0)
# /tmp/chefspec20170426-4044-1istpmbfile_cache_path/cookbooks/mta_mantis/attributes/default.rb:7:in `from_file'
# ./spec/unit/firewall_spec.rb:12:in `block (3 levels) in <top (required)>'
Using _lazy_attribute works just fine.
I'm using chef 12.13.37, chefspec 4.7.0.
It's just an idea, today I've encountered strange issue, when I'm testing (using chefspec) cookbook which depends on cookbook where I'm using
lazy
in attributes, I'm gettingArgumentError
exception. Looks like upstream lazy method takes precedence over poise-derived. I wasn't able to isolate it to separate code yet, but maybe it would be good to use different method name - derived?