-
Notifications
You must be signed in to change notification settings - Fork 683
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
Read Chef attributes within the tests ? #541
Comments
We will have all that data exposed to everyone who needs it (and much more), but with a cleaner attributes interface in the very near future. However, in the meantime, Matt's method will still work, with tiny adjustments. When test-kitchen does the converge step and all the data is written to the file, you can access it via inspec. Instead of reading via Using kitchen-inspec repo, in the ruby_block "Save node attributes" do
block do
File.write("/tmp/kitchen_chef_node.json", node.to_json)
end
end and then for the test in node = json("/tmp/kitchen_chef_node.json").params |
@mwrock your awesome trick still works 😄 |
👍 sweet! |
@mwrock @arlimus @andy-dufour Test-kitchen v1.10.x included in ChefDK 0.15.15 broke this work around. It used works under test-kitchen v1.8.0 included in ChefDK v0.14.25. I have posted a reproduce able minimal project at https://github.com/spuranam/hello. Any insight how best to solve would be greatly appreciated. My Chef Environment: |
@spuranam have you looked in |
@scalp42 i have posted the content of json file here. Below is error i am seeing: -----> Starting Kitchen (v1.10.0)
|
This can be accomplished via an inspec profile. See #813 |
I think this is fixed @spuranam . I just ran
I then altered my bundle to use the same versions packaged with 0.15.15:
This yielded the same failure as yours. Not sure what the exact fix was but I'd recommend updating those gems and they should be included in the soon to be released chefdk 0.16. |
@arlimus, you reference above (from March 16) about a 'cleaner attributes interface'...can you give an update on how that's coming, or a reference to the plan? |
Hi, I am not able to use this approach. Fixture cookbook (export_node) ruby_block "Save node attributes" do default_spec.rb: require 'json' describe file("#{Chef::Config[:file_cache_path]}/asset.json") do I am getting an error: "Detected alternative framework tests for Chef Development Kit Version: 1.1.16 Kindly help |
I'm excited for this. Any updates here? Would an inspec chef_node resource type be an option? |
Since I've just discovered your responses. Please open a new issue if the json loading is not working |
Does anyone know how to solve the encoding issue below? chef-client OS: windows 2016
Code used:
|
Hey @yangpeng-chn - great question! Unfortunately we do not track closed issues - could you file your question in a new issue? |
I'm curious if there's a way to parse a JSON (from test-kitchen) and be able to use it within inspec ?
See this blog post: http://www.hurryupandwait.io/blog/accessing-chef-node-attributes-from-kitchen-tests
TLDR: read test-kitchen data JSON, store it in a variable with Rspec and leverage it later, or pretty much can you use Rspec DSL I guess?
Thanks in advance!
The text was updated successfully, but these errors were encountered: