diff --git a/devops-service/db/mongo/models/deploy_env/deploy_env_base.rb b/devops-service/db/mongo/models/deploy_env/deploy_env_base.rb index d95d71c..3c3bbf1 100644 --- a/devops-service/db/mongo/models/deploy_env/deploy_env_base.rb +++ b/devops-service/db/mongo/models/deploy_env/deploy_env_base.rb @@ -30,6 +30,10 @@ module Devops ::Validators::FieldValidator::FieldType::String, ::Validators::FieldValidator::Expires] + set_field_validators :chef_client_options, [::Validators::FieldValidator::Nil, + ::Validators::FieldValidator::FieldType::String, + ::Validators::FieldValidator::NotEmpty] + def initialize d={} self.identifier = d["identifier"] set_provider(d) @@ -38,6 +42,7 @@ module Devops self.expires = d["expires"] b = d["users"] || [] self.users = b.uniq + self.chef_client_options = d["chef_client_options"] end def to_hash @@ -45,7 +50,8 @@ module Devops "identifier" => self.identifier, "run_list" => self.run_list, "expires" => self.expires, - "users" => self.users + "users" => self.users, + "chef_client_options" => self.chef_client_options }.merge(provider_hash) end diff --git a/devops-service/lib/executors/server_executor.rb b/devops-service/lib/executors/server_executor.rb index f41e4c7..7cf84e8 100644 --- a/devops-service/lib/executors/server_executor.rb +++ b/devops-service/lib/executors/server_executor.rb @@ -394,7 +394,11 @@ module Devops @out.flush cmd << " -j http://#{DevopsConfig.config[:address]}:#{DevopsConfig.config[:port]}/#{DevopsConfig.config[:url_prefix]}/v2.0/deploy/data/#{file}" else - cmd << " -r #{deploy_info["run_list"].join(",")}" unless @server.stack.nil? + if @deploy_env.chef_client_options + cmd << " #{@deploy_env.chef_client_options}" + else + cmd << " -r #{deploy_info["run_list"].join(",")}" unless @server.stack.nil? + end end ip = if @server.public_ip.nil? @server.private_ip diff --git a/devops-service/spec/executors/server_executor_spec.rb b/devops-service/spec/executors/server_executor_spec.rb index 55fa016..db48152 100644 --- a/devops-service/spec/executors/server_executor_spec.rb +++ b/devops-service/spec/executors/server_executor_spec.rb @@ -575,6 +575,12 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec expect(stubbed_knife).to receive(:ssh_stream).with(anything, 'chef-client --no-color', any_args) deploy_server end + + it "uses deploy_env's chef_client_options if they are set" do + deploy_env.chef_client_options = '-r role' + expect(stubbed_knife).to receive(:ssh_stream).with(anything, 'chef-client --no-color -r role', any_args) + deploy_server + end end it "uses server's key" do diff --git a/devops-service/spec/models/deploy_env/shared_deploy_env_specs.rb b/devops-service/spec/models/deploy_env/shared_deploy_env_specs.rb index 538f838..e8e8b42 100644 --- a/devops-service/spec/models/deploy_env/shared_deploy_env_specs.rb +++ b/devops-service/spec/models/deploy_env/shared_deploy_env_specs.rb @@ -10,6 +10,7 @@ RSpec.shared_examples 'deploy env' do include_examples 'field type validation', :run_list, :not_nil, :maybe_empty_array, :run_list, :field_validator include_examples 'field type validation', :users, :not_nil, :maybe_empty_array, :field_validator include_examples 'field type validation', :expires, :maybe_nil, :non_empty_string, :field_validator + include_examples 'field type validation', :chef_client_options, :maybe_nil, :non_empty_string, :field_validator it 'should be valid only with all users available' do expect(build(validated_model_name, users: ['root'])).to be_valid