From 28b68d6b1b1caa64dc5b22549ca06b80354ce6f3 Mon Sep 17 00:00:00 2001 From: "John.Kerry" Date: Thu, 11 May 2017 20:42:45 -0400 Subject: [PATCH 1/3] not displaying the runlist when there are no entries Signed-off-by: John.Kerry --- lib/chef/azure/core/bootstrap_context.rb | 2 +- lib/chef/azure/core/windows_bootstrap_context.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/chef/azure/core/bootstrap_context.rb b/lib/chef/azure/core/bootstrap_context.rb index 92a54388..831aee24 100644 --- a/lib/chef/azure/core/bootstrap_context.rb +++ b/lib/chef/azure/core/bootstrap_context.rb @@ -18,7 +18,7 @@ def client_key end def first_boot - Hash(@config[:first_boot_attributes]).merge(:run_list => @run_list) + @run_list.empty? ? Hash(@config[:first_boot_attributes]) : Hash(@config[:first_boot_attributes]).merge(:run_list => @run_list) end def config_content diff --git a/lib/chef/azure/core/windows_bootstrap_context.rb b/lib/chef/azure/core/windows_bootstrap_context.rb index ea7bcb1a..159fc8f6 100644 --- a/lib/chef/azure/core/windows_bootstrap_context.rb +++ b/lib/chef/azure/core/windows_bootstrap_context.rb @@ -148,7 +148,8 @@ def bootstrap_directory end def first_boot - first_boot_attributes_and_run_list = (@config[:first_boot_attributes] || {}).merge(:run_list => @run_list) + attributes = (@config[:first_boot_attributes] || {}) + first_boot_attributes_and_run_list = @run_list.empty? ? attributes : attributes.merge(:run_list => @run_list) escape_and_echo(first_boot_attributes_and_run_list.to_json) end From 2036b1815f0209617e5d090a034c8bf0ef0b96fb Mon Sep 17 00:00:00 2001 From: NimishaS Date: Wed, 17 May 2017 15:42:47 +0530 Subject: [PATCH 2/3] Not setting default Chef::config[:environment] Signed-off-by: NimishaS --- lib/chef/azure/commands/enable.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/chef/azure/commands/enable.rb b/lib/chef/azure/commands/enable.rb index bac35e4a..ca4e0bec 100644 --- a/lib/chef/azure/commands/enable.rb +++ b/lib/chef/azure/commands/enable.rb @@ -203,7 +203,7 @@ def configure_chef_only_once bootstrap_options = value_from_json_file(handler_settings_file,'runtimeSettings','0','handlerSettings', 'publicSettings', 'bootstrap_options') bootstrap_options = eval(bootstrap_options) ? eval(bootstrap_options) : {} - config[:environment] = bootstrap_options['environment'] || "_default" + config[:environment] = bootstrap_options['environment'] config[:chef_node_name] = bootstrap_options['chef_node_name'] if bootstrap_options['chef_node_name'] config[:chef_extension_root] = @chef_extension_root config[:user_client_rb] = @client_rb @@ -255,7 +255,9 @@ def configure_chef_only_once end # Now the run chef-client with runlist in background, as we done want enable command to wait, else long running chef-client with runlist will timeout azure. puts "#{Time.now} Launching chef-client to register node with the runlist" - params = "-c #{bootstrap_directory}/client.rb -j #{bootstrap_directory}/first-boot.json -E #{config[:environment]} -L #{@azure_plugin_log_location}/chef-client.log --once " + params = "-c #{bootstrap_directory}/client.rb -j #{bootstrap_directory}/first-boot.json -L #{@azure_plugin_log_location}/chef-client.log --once " + params += " -E #{config[:environment]}" if config[:environment] + if @extended_logs == 'true' if windows? @chef_client_success_file = "c:\\chef_client_success" From bbfa0d76f78d0c70d4d7884914625af3070e2167 Mon Sep 17 00:00:00 2001 From: NimishaS Date: Wed, 17 May 2017 18:13:43 +0530 Subject: [PATCH 3/3] Fixed rspecs Signed-off-by: NimishaS --- spec/unit/azure_enable_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/unit/azure_enable_spec.rb b/spec/unit/azure_enable_spec.rb index 7f8f00f6..377f4b88 100644 --- a/spec/unit/azure_enable_spec.rb +++ b/spec/unit/azure_enable_spec.rb @@ -448,7 +448,7 @@ allow(IO).to receive_message_chain( :read, :chomp).and_return("template") allow(Process).to receive(:detach) - @sample_config = {:environment=>"_default", :chef_node_name=>"mynode3", :chef_extension_root=>"./", :user_client_rb=>"", :log_location=>nil, :chef_server_url=>"https://api.opscode.com/organizations/clochefacc", :validation_client_name=>"clochefacc-validator", :secret=>nil, :first_boot_attributes => {}} + @sample_config = {:environment=>nil, :chef_node_name=>"mynode3", :chef_extension_root=>"./", :user_client_rb=>"", :log_location=>nil, :chef_server_url=>"https://api.opscode.com/organizations/clochefacc", :validation_client_name=>"clochefacc-validator", :secret=>nil, :first_boot_attributes => {}} @sample_runlist = ["recipe[getting-started]", "recipe[apt]"] end @@ -463,7 +463,7 @@ expect(instance).to_not receive(:load_cloud_attributes_in_hints) expect(instance).to receive(:secret_key) expect(FileUtils).to receive(:rm) - expect(Process).to receive(:spawn).with("chef-client -c #{@bootstrap_directory}/client.rb -j #{@bootstrap_directory}/first-boot.json -E #{@sample_config[:environment]} -L #{@sample_config[:log_location]}/chef-client.log --once ").and_return(123) + expect(Process).to receive(:spawn).with("chef-client -c #{@bootstrap_directory}/client.rb -j #{@bootstrap_directory}/first-boot.json -L #{@sample_config[:log_location]}/chef-client.log --once ").and_return(123) instance.send(:configure_chef_only_once) expect(instance.instance_variable_get(:@child_pid)).to be == 123 expect(instance.instance_variable_get(:@chef_client_success_file)).to be nil @@ -480,7 +480,7 @@ expect(Erubis::Eruby.new).to receive(:evaluate) expect(instance).to receive(:shell_out).and_return( OpenStruct.new(:exitstatus => 0, :stdout => "")) - expect(Process).to receive(:spawn).with("chef-client -c #{@bootstrap_directory}/client.rb -j #{@bootstrap_directory}/first-boot.json -E #{@sample_config[:environment]} -L #{@sample_config[:log_location]}/chef-client.log --once ").and_return(456) + expect(Process).to receive(:spawn).with("chef-client -c #{@bootstrap_directory}/client.rb -j #{@bootstrap_directory}/first-boot.json -L #{@sample_config[:log_location]}/chef-client.log --once ").and_return(456) instance.send(:configure_chef_only_once) expect(instance.instance_variable_get(:@child_pid)).to be == 456 expect(instance.instance_variable_get(:@chef_client_success_file)).to be nil @@ -504,7 +504,7 @@ allow(IO).to receive_message_chain( :read, :chomp).and_return("template") allow(Process).to receive(:detach) - @sample_config = {:environment=>"_default", :chef_node_name=>"mynode3", :chef_extension_root=>"./", :user_client_rb=>"", :log_location=>nil, :chef_server_url=>"https://api.opscode.com/organizations/clochefacc", :validation_client_name=>"clochefacc-validator", :secret=>nil, :first_boot_attributes => {"container_service"=>{"chef-init-test"=>{"command"=>"C:\\opscode\\chef\\bin"}}} } + @sample_config = {:environment=>nil, :chef_node_name=>"mynode3", :chef_extension_root=>"./", :user_client_rb=>"", :log_location=>nil, :chef_server_url=>"https://api.opscode.com/organizations/clochefacc", :validation_client_name=>"clochefacc-validator", :secret=>nil, :first_boot_attributes => {"container_service"=>{"chef-init-test"=>{"command"=>"C:\\opscode\\chef\\bin"}}} } @sample_runlist = ["recipe[getting-started]", "recipe[apt]"] end @@ -519,7 +519,7 @@ expect(instance).to receive(:load_cloud_attributes_in_hints) expect(instance).to receive(:secret_key) expect(FileUtils).to receive(:rm) - expect(Process).to receive(:spawn).with("chef-client -c #{@bootstrap_directory}/client.rb -j #{@bootstrap_directory}/first-boot.json -E #{@sample_config[:environment]} -L #{@sample_config[:log_location]}/chef-client.log --once && touch c:\\chef_client_success").and_return(789) + expect(Process).to receive(:spawn).with("chef-client -c #{@bootstrap_directory}/client.rb -j #{@bootstrap_directory}/first-boot.json -L #{@sample_config[:log_location]}/chef-client.log --once && touch c:\\chef_client_success").and_return(789) instance.send(:configure_chef_only_once) expect(instance.instance_variable_get(:@child_pid)).to be == 789 expect(instance.instance_variable_get(:@chef_client_success_file)).to be == 'c:\\chef_client_success' @@ -536,7 +536,7 @@ expect(Erubis::Eruby.new).to receive(:evaluate) expect(instance).to receive(:shell_out).and_return( OpenStruct.new(:exitstatus => 0, :stdout => "")) - expect(Process).to receive(:spawn).with("chef-client -c #{@bootstrap_directory}/client.rb -j #{@bootstrap_directory}/first-boot.json -E #{@sample_config[:environment]} -L #{@sample_config[:log_location]}/chef-client.log --once && touch /tmp/chef_client_success").and_return(120) + expect(Process).to receive(:spawn).with("chef-client -c #{@bootstrap_directory}/client.rb -j #{@bootstrap_directory}/first-boot.json -L #{@sample_config[:log_location]}/chef-client.log --once && touch /tmp/chef_client_success").and_return(120) instance.send(:configure_chef_only_once) expect(instance.instance_variable_get(:@child_pid)).to be == 120 expect(instance.instance_variable_get(:@chef_client_success_file)).to be == '/tmp/chef_client_success'