diff --git a/devops-client/lib/devops-client/handler/deploy.rb b/devops-client/lib/devops-client/handler/deploy.rb index 7ab707c..9cfb34d 100644 --- a/devops-client/lib/devops-client/handler/deploy.rb +++ b/devops-client/lib/devops-client/handler/deploy.rb @@ -20,13 +20,12 @@ class Deploy < Handler end def deploy_handler args - tags = options[:tags] names = args[1..-1] if names.empty? @options_parser.invalid_deploy_command abort() end - job_ids = post("/deploy", :names => names, :tags => tags) + job_ids = post("/deploy", names: names, tags: options[:tags], chef_client_options: options[:chef_client_options]) reports_urls(job_ids) end diff --git a/devops-client/lib/devops-client/options/deploy_options.rb b/devops-client/lib/devops-client/options/deploy_options.rb index abb657d..a0f45c9 100644 --- a/devops-client/lib/devops-client/options/deploy_options.rb +++ b/devops-client/lib/devops-client/options/deploy_options.rb @@ -13,10 +13,12 @@ class DeployOptions < CommonOptions def deploy_options options do |parser, options| parser.banner << self.banner + parser.resource_name = :deploy - parser.recognize_option_value(:tag, resource_name: :deploy, variable_name: 'TAG1,TAG2...') do |tags| + parser.recognize_option_value(:tag, variable: 'TAG1,TAG2...') do |tags| options[:tags] = tags.split(",") end + parser.recognize_option_value(:chef_client_options) end end diff --git a/devops-client/locales/en.yml b/devops-client/locales/en.yml index a4a968b..51341fb 100644 --- a/devops-client/locales/en.yml +++ b/devops-client/locales/en.yml @@ -314,6 +314,7 @@ en: descriptions: deploy: tag: 'Tag names, comma separated list' + chef_client_options: 'String like "-o role[foo]"' image: provider: Image provider image_id: Image identifier diff --git a/devops-service/app/api2/handlers/deploy.rb b/devops-service/app/api2/handlers/deploy.rb index b0e3045..0af3ef3 100644 --- a/devops-service/app/api2/handlers/deploy.rb +++ b/devops-service/app/api2/handlers/deploy.rb @@ -19,6 +19,7 @@ module Devops names = body["names"] tags = body["tags"] || [] run_list = body["run_list"] + single_run_chef_client_options = body['chef_client_options'] files = [] jid = nil owner = parser.current_user @@ -33,6 +34,7 @@ module Devops begin deploy_info = create_deploy_info(s, project, body["build_number"]) deploy_info["run_list"] = run_list if run_list + set_chef_client_options(deploy_info, s, project, single_run_chef_client_options) jid = Worker.start_async(DeployWorker, server_attrs: s.to_hash, @@ -117,6 +119,17 @@ module Devops @deploy_info_buf[buf_key] = project.deploy_info(deploy_env_model, build_number) end end + + private + + # env's chef client options may be nil or empty string; it's OK. + def set_chef_client_options(deploy_info, server, project, single_run_options) + if single_run_options + deploy_info['chef_client_options'] = single_run_options + else + deploy_info['chef_client_options'] = project.deploy_env(server.deploy_env).chef_client_options + end + end end end end diff --git a/devops-service/app/api2/routes/deploy.rb b/devops-service/app/api2/routes/deploy.rb index 7a2a208..c42a69b 100644 --- a/devops-service/app/api2/routes/deploy.rb +++ b/devops-service/app/api2/routes/deploy.rb @@ -18,6 +18,7 @@ module Devops # "tags": [], -> array of tags to apply on each server before running chef-client # "build_number": "", -> string, build number to deploy # "run_list": [], -> array of strings to set run_list for chef-client + # "chef_client_options": "", String, optional. May be used to redefine run_list # } # # * *Returns* : text stream diff --git a/devops-service/lib/executors/server_executor.rb b/devops-service/lib/executors/server_executor.rb index 08e4dc3..0a6e657 100644 --- a/devops-service/lib/executors/server_executor.rb +++ b/devops-service/lib/executors/server_executor.rb @@ -394,8 +394,9 @@ module Devops @out.flush cmd << " -j http://#{DevopsConfig.config[:address]}:#{DevopsConfig.config[:port]}/#{DevopsConfig.config[:url_prefix]}/v2.0/deploy/data/#{file}" else - if @deploy_env.chef_client_options && !@deploy_env.chef_client_options.empty? - cmd << " #{@deploy_env.chef_client_options}" + chef_client_options = deploy_info['chef_client_options'] + if chef_client_options && !chef_client_options.empty? + cmd << " #{chef_client_options}" else cmd << " -r #{deploy_info["run_list"].join(",")}" unless @server.stack.nil? end diff --git a/devops-service/spec/executors/server_executor_spec.rb b/devops-service/spec/executors/server_executor_spec.rb index ce8135f..d9fd37f 100644 --- a/devops-service/spec/executors/server_executor_spec.rb +++ b/devops-service/spec/executors/server_executor_spec.rb @@ -576,14 +576,14 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec deploy_server end - it "uses deploy_env's chef_client_options if they are set" do - deploy_env.chef_client_options = '-r role' + it "uses chef_client_options from deploy_info if it is set" do + deploy_info['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 - it "doesn't use deploy_env's chef_client_options if it's blank string" do - deploy_env.chef_client_options = '' + it "doesn't use chef_client_options from deploy_info if it's blank string" do + deploy_info['chef_client_options'] = '' expect(stubbed_knife).to receive(:ssh_stream).with(anything, 'chef-client --no-color', any_args) deploy_server end