Skip to content

Commit a10ac20

Browse files
author
Nimisha Sharad
authored
Merge pull request #213 from MsysTechnologiesllc/nim/policy_runlist_conflict
[MSYS-573] Runlist conflicts with policy_name and policy_group settings in first-boot.json
2 parents b301d98 + bbfa0d7 commit a10ac20

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

lib/chef/azure/commands/enable.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def configure_chef_only_once
203203
bootstrap_options = value_from_json_file(handler_settings_file,'runtimeSettings','0','handlerSettings', 'publicSettings', 'bootstrap_options')
204204
bootstrap_options = eval(bootstrap_options) ? eval(bootstrap_options) : {}
205205

206-
config[:environment] = bootstrap_options['environment'] || "_default"
206+
config[:environment] = bootstrap_options['environment']
207207
config[:chef_node_name] = bootstrap_options['chef_node_name'] if bootstrap_options['chef_node_name']
208208
config[:chef_extension_root] = @chef_extension_root
209209
config[:user_client_rb] = @client_rb
@@ -255,7 +255,9 @@ def configure_chef_only_once
255255
end
256256
# 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.
257257
puts "#{Time.now} Launching chef-client to register node with the runlist"
258-
params = "-c #{bootstrap_directory}/client.rb -j #{bootstrap_directory}/first-boot.json -E #{config[:environment]} -L #{@azure_plugin_log_location}/chef-client.log --once "
258+
params = "-c #{bootstrap_directory}/client.rb -j #{bootstrap_directory}/first-boot.json -L #{@azure_plugin_log_location}/chef-client.log --once "
259+
params += " -E #{config[:environment]}" if config[:environment]
260+
259261
if @extended_logs == 'true'
260262
if windows?
261263
@chef_client_success_file = "c:\\chef_client_success"

lib/chef/azure/core/bootstrap_context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def client_key
1818
end
1919

2020
def first_boot
21-
Hash(@config[:first_boot_attributes]).merge(:run_list => @run_list)
21+
@run_list.empty? ? Hash(@config[:first_boot_attributes]) : Hash(@config[:first_boot_attributes]).merge(:run_list => @run_list)
2222
end
2323

2424
def config_content

lib/chef/azure/core/windows_bootstrap_context.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ def bootstrap_directory
148148
end
149149

150150
def first_boot
151-
first_boot_attributes_and_run_list = (@config[:first_boot_attributes] || {}).merge(:run_list => @run_list)
151+
attributes = (@config[:first_boot_attributes] || {})
152+
first_boot_attributes_and_run_list = @run_list.empty? ? attributes : attributes.merge(:run_list => @run_list)
152153
escape_and_echo(first_boot_attributes_and_run_list.to_json)
153154
end
154155

spec/unit/azure_enable_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@
448448
allow(IO).to receive_message_chain(
449449
:read, :chomp).and_return("template")
450450
allow(Process).to receive(:detach)
451-
@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 => {}}
451+
@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 => {}}
452452
@sample_runlist = ["recipe[getting-started]", "recipe[apt]"]
453453
end
454454

@@ -463,7 +463,7 @@
463463
expect(instance).to_not receive(:load_cloud_attributes_in_hints)
464464
expect(instance).to receive(:secret_key)
465465
expect(FileUtils).to receive(:rm)
466-
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)
466+
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)
467467
instance.send(:configure_chef_only_once)
468468
expect(instance.instance_variable_get(:@child_pid)).to be == 123
469469
expect(instance.instance_variable_get(:@chef_client_success_file)).to be nil
@@ -480,7 +480,7 @@
480480
expect(Erubis::Eruby.new).to receive(:evaluate)
481481
expect(instance).to receive(:shell_out).and_return(
482482
OpenStruct.new(:exitstatus => 0, :stdout => ""))
483-
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)
483+
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)
484484
instance.send(:configure_chef_only_once)
485485
expect(instance.instance_variable_get(:@child_pid)).to be == 456
486486
expect(instance.instance_variable_get(:@chef_client_success_file)).to be nil
@@ -504,7 +504,7 @@
504504
allow(IO).to receive_message_chain(
505505
:read, :chomp).and_return("template")
506506
allow(Process).to receive(:detach)
507-
@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"}}} }
507+
@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"}}} }
508508
@sample_runlist = ["recipe[getting-started]", "recipe[apt]"]
509509
end
510510

@@ -519,7 +519,7 @@
519519
expect(instance).to receive(:load_cloud_attributes_in_hints)
520520
expect(instance).to receive(:secret_key)
521521
expect(FileUtils).to receive(:rm)
522-
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)
522+
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)
523523
instance.send(:configure_chef_only_once)
524524
expect(instance.instance_variable_get(:@child_pid)).to be == 789
525525
expect(instance.instance_variable_get(:@chef_client_success_file)).to be == 'c:\\chef_client_success'
@@ -536,7 +536,7 @@
536536
expect(Erubis::Eruby.new).to receive(:evaluate)
537537
expect(instance).to receive(:shell_out).and_return(
538538
OpenStruct.new(:exitstatus => 0, :stdout => ""))
539-
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)
539+
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)
540540
instance.send(:configure_chef_only_once)
541541
expect(instance.instance_variable_get(:@child_pid)).to be == 120
542542
expect(instance.instance_variable_get(:@chef_client_success_file)).to be == '/tmp/chef_client_success'

0 commit comments

Comments
 (0)