Skip to content

Commit

Permalink
Merge pull request #213 from MsysTechnologiesllc/nim/policy_runlist_c…
Browse files Browse the repository at this point in the history
…onflict

[MSYS-573] Runlist conflicts with policy_name and policy_group settings in first-boot.json
  • Loading branch information
Nimisha Sharad authored May 18, 2017
2 parents b301d98 + bbfa0d7 commit a10ac20
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
6 changes: 4 additions & 2 deletions lib/chef/azure/commands/enable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/chef/azure/core/bootstrap_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/chef/azure/core/windows_bootstrap_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions spec/unit/azure_enable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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'
Expand All @@ -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'
Expand Down

0 comments on commit a10ac20

Please sign in to comment.