chef-boneyard / chef-provisioning

A library for creating machines and infrastructures idempotently in Chef.
Apache License 2.0
524 stars 164 forks source link

attr normal tag is null not empty array #356

Open d-higuchi opened 9 years ago

d-higuchi commented 9 years ago

Here are chef-provisioning recipe (chef-prov-test.rb) and tagging-only recipe (test::default).

chef-prov-test.rb:

require 'chef/provisioning'

repo_dir = File.join(File.dirname(__FILE__), '../..')
with_chef_local_server(
  chef_repo_path: repo_dir,
  cookbook_path: File.join( repo_dir, 'cookbooks' ),
)

with_machine_options :vagrant_options => {
  'vm.box' => 'chef/ubuntu-14.04'
}

machine 'test' do
  recipe 'test' # XXX: include recipe
end

cookbooks/test/recipes/default.rb:

tag( 'test' )

Tagging-only recipe had been applied to node using chef-provisioning-vagrant and local-mode, I got NoMethodError. Because add normal.tags = nil, it is not empty array.

CHEF_DRIVER=vagrant chef-client -z chef-prov-test.rb
[2015-06-03T10:46:15+09:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.3.0
resolving cookbooks for run list: []
Synchronizing Cookbooks:
Compiling Cookbooks...
[2015-06-03T10:46:16+09:00] WARN: Node lilith has an empty run list.
Converging 1 resources
Recipe: @recipe_files::/tmp/chef-repo-test/cookbooks/test/chef-prov-test.rb
  * machine[test] action converge
    - create new directory /home/dai/.chef/vms
    - create new file /home/dai/.chef/vms/Vagrantfile
    - update content in file /home/dai/.chef/vms/Vagrantfile from none to 06b93d
    - --- /home/dai/.chef/vms/Vagrantfile   2015-06-03 10:46:16.707632279 +0900
    - +++ /home/dai/.chef/vms/.Vagrantfile20150603-11151-1iosh7c    2015-06-03 10:46:16.707632279 +0900
    - @@ -1 +1,4 @@
    - +Dir.glob('/home/dai/.chef/vms/*.vm') do |vm_file|
    - +  eval(IO.read(vm_file), nil, vm_file)
    - +end
    - create new file /home/dai/.chef/vms/test.vm
    - update content in file /home/dai/.chef/vms/test.vm from none to 341cfb
    - --- /home/dai/.chef/vms/test.vm   2015-06-03 10:46:16.711632312 +0900
    - +++ /home/dai/.chef/vms/.test.vm20150603-11151-rzirtp 2015-06-03 10:46:16.711632312 +0900
    - @@ -1 +1,7 @@
    - +Vagrant.configure('2') do |outer_config|
    - +  outer_config.vm.define "test" do |config|
    - +    config.vm.box = "chef/ubuntu-14.04"
    - +    config.vm.hostname = "test"
    - +  end
    - +end
    - create node test at http://127.0.0.1:8901
    -   add normal.tags = nil
    -   add normal.chef_provisioning = {"reference"=>{"driver_url"=>"vagrant:/home/dai/.chef/vms", "driver_version"=>"0.8.3", "vm_name"=>"test", "vm_file_path"=>"/home/dai/.chef/vms/test.vm", "allocated_at"=>"2015-06-03 01:46:16 UTC", "host_node"=>"chefzero://localhost:8889/nodes/", "needs_reload"=>true}}
    -   update run_list from [] to ["recipe[test]"]
    - run vagrant up test (status was 'not created')
    - update node test at http://127.0.0.1:8901
    -   update normal.chef_provisioning.reference.needs_reload from true to false
    -   add normal.chef_provisioning.reference.forwarded_ports = {}
SNIP SNIP SNIP
           ================================================================================
           Recipe Compile Error in /var/chef/cache/cookbooks/test/recipes/default.rb
           ================================================================================

           NoMethodError
           -------------
           undefined method `include?' for nil:NilClass

Here is node object. normal.tags is null, not [].

nodes/test.json:

{
  "name": "test",
  "normal": {
    "tags": null,
    "chef_provisioning": {

Then, writing just tags in machine instead of Tagging-only recipe.

chef-prov-test.rb:

require 'chef/provisioning'

repo_dir = File.join(File.dirname(__FILE__), '../..')
with_chef_local_server(
  chef_repo_path: repo_dir,
  cookbook_path: File.join( repo_dir, 'cookbooks' ),
)

with_machine_options :vagrant_options => {
  'vm.box' => 'chef/ubuntu-14.04'
}

machine 'test' do
  tag( 'test' ) # XXX: raw write tags
end

Using chef-provisioning-vagrant and local-mode, I got no error. Because add normal.tags = ["test"], it is already set.

% CHEF_DRIVER=vagrant chef-client -z chef-prov-test.rb
[2015-06-03T10:37:40+09:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.3.0
resolving cookbooks for run list: []
Synchronizing Cookbooks:
Compiling Cookbooks...
[2015-06-03T10:37:41+09:00] WARN: Node lilith has an empty run list.
Converging 1 resources
Recipe: @recipe_files::/tmp/chef-repo-test/cookbooks/test/chef-prov-test.rb
  * machine[test] action converge
    - create new directory /home/dai/.chef/vms
    - create new file /home/dai/.chef/vms/Vagrantfile
    - update content in file /home/dai/.chef/vms/Vagrantfile from none to 06b93d
    - --- /home/dai/.chef/vms/Vagrantfile   2015-06-03 10:37:42.055463931 +0900
    - +++ /home/dai/.chef/vms/.Vagrantfile20150603-6570-13iz39d 2015-06-03 10:37:42.055463931 +0900
    - @@ -1 +1,4 @@
    - +Dir.glob('/home/dai/.chef/vms/*.vm') do |vm_file|
    - +  eval(IO.read(vm_file), nil, vm_file)
    - +end
    - create new file /home/dai/.chef/vms/test.vm
    - update content in file /home/dai/.chef/vms/test.vm from none to 341cfb
    - --- /home/dai/.chef/vms/test.vm   2015-06-03 10:37:42.059463964 +0900
    - +++ /home/dai/.chef/vms/.test.vm20150603-6570-1s1mqhh 2015-06-03 10:37:42.059463964 +0900
    - @@ -1 +1,7 @@
    - +Vagrant.configure('2') do |outer_config|
    - +  outer_config.vm.define "test" do |config|
    - +    config.vm.box = "chef/ubuntu-14.04"
    - +    config.vm.hostname = "test"
    - +  end
    - +end
    - create node test at http://127.0.0.1:8901
    -   add normal.tags = ["test"]
    -   add normal.chef_provisioning = {"reference"=>{"driver_url"=>"vagrant:/home/dai/.chef/vms", "driver_version"=>"0.8.3", "vm_name"=>"test", "vm_file_path"=>"/home/dai/.chef/vms/test.vm", "allocated_at"=>"2015-06-03 01:37:42 UTC", "host_node"=>"chefzero://localhost:8889/nodes/", "needs_reload"=>true}}
    - run vagrant up test (status was 'not created')
    - update node test at http://127.0.0.1:8901
    -   update normal.chef_provisioning.reference.needs_reload from true to false
    -   add normal.chef_provisioning.reference.forwarded_ports = {}
SNIP SNIP SNIP
           Starting Chef Client, version 12.3.0
           resolving cookbooks for run list: []
           Synchronizing Cookbooks:
           Compiling Cookbooks...
           [2015-06-03T01:38:49+00:00] WARN: Node test has an empty run list.
           Converging 0 resources

           Running handlers:
           Running handlers complete
           Chef Client finished, 0/0 resources updated in 1.516613321 seconds
    - run 'chef-client -l auto' on test

Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 70.82122905 seconds

Here is node object. normal.tags is ["test"].

nodes/test.json:

{
  "name": "test",
  "normal": {
    "tags": [
      "test"

is it bug or limit?

related: chef/chef-zero#139

aaron-lane commented 9 years ago

:+1: