Merge branch 'CID-418_chef_client_options_single_deploy' into features

This commit is contained in:
Anton Chuchkalov 2016-03-02 12:31:35 +03:00
commit e3b7a27976
9 changed files with 32 additions and 10 deletions

View File

@ -20,13 +20,12 @@ class Deploy < Handler
end end
def deploy_handler args def deploy_handler args
tags = options[:tags]
names = args[1..-1] names = args[1..-1]
if names.empty? if names.empty?
@options_parser.invalid_deploy_command @options_parser.invalid_deploy_command
abort() abort()
end 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) reports_urls(job_ids)
end end

View File

@ -13,10 +13,12 @@ class DeployOptions < CommonOptions
def deploy_options def deploy_options
options do |parser, options| options do |parser, options|
parser.banner << self.banner 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(",") options[:tags] = tags.split(",")
end end
parser.recognize_option_value(:chef_client_options)
end end
end end

View File

@ -314,6 +314,7 @@ en:
descriptions: descriptions:
deploy: deploy:
tag: 'Tag names, comma separated list' tag: 'Tag names, comma separated list'
chef_client_options: 'String like "-o role[foo]"'
image: image:
provider: Image provider provider: Image provider
image_id: Image identifier image_id: Image identifier

View File

@ -19,6 +19,7 @@ module Devops
names = body["names"] names = body["names"]
tags = body["tags"] || [] tags = body["tags"] || []
run_list = body["run_list"] run_list = body["run_list"]
single_run_chef_client_options = body['chef_client_options']
files = [] files = []
jid = nil jid = nil
owner = parser.current_user owner = parser.current_user
@ -33,6 +34,7 @@ module Devops
begin begin
deploy_info = create_deploy_info(s, project, body["build_number"]) deploy_info = create_deploy_info(s, project, body["build_number"])
deploy_info["run_list"] = run_list if run_list 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, jid = Worker.start_async(DeployWorker,
server_attrs: s.to_hash, server_attrs: s.to_hash,
@ -117,6 +119,17 @@ module Devops
@deploy_info_buf[buf_key] = project.deploy_info(deploy_env_model, build_number) @deploy_info_buf[buf_key] = project.deploy_info(deploy_env_model, build_number)
end end
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 end
end end

View File

@ -18,6 +18,7 @@ module Devops
# "tags": [], -> array of tags to apply on each server before running chef-client # "tags": [], -> array of tags to apply on each server before running chef-client
# "build_number": "", -> string, build number to deploy # "build_number": "", -> string, build number to deploy
# "run_list": [], -> array of strings to set run_list for chef-client # "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 # * *Returns* : text stream

View File

@ -31,8 +31,7 @@ module Devops
::Validators::FieldValidator::Expires] ::Validators::FieldValidator::Expires]
set_field_validators :chef_client_options, [::Validators::FieldValidator::Nil, set_field_validators :chef_client_options, [::Validators::FieldValidator::Nil,
::Validators::FieldValidator::FieldType::String, ::Validators::FieldValidator::FieldType::String]
::Validators::FieldValidator::NotEmpty]
def initialize d={} def initialize d={}
self.identifier = d["identifier"] self.identifier = d["identifier"]

View File

@ -394,8 +394,9 @@ module Devops
@out.flush @out.flush
cmd << " -j http://#{DevopsConfig.config[:address]}:#{DevopsConfig.config[:port]}/#{DevopsConfig.config[:url_prefix]}/v2.0/deploy/data/#{file}" cmd << " -j http://#{DevopsConfig.config[:address]}:#{DevopsConfig.config[:port]}/#{DevopsConfig.config[:url_prefix]}/v2.0/deploy/data/#{file}"
else else
if @deploy_env.chef_client_options chef_client_options = deploy_info['chef_client_options']
cmd << " #{@deploy_env.chef_client_options}" if chef_client_options && !chef_client_options.empty?
cmd << " #{chef_client_options}"
else else
cmd << " -r #{deploy_info["run_list"].join(",")}" unless @server.stack.nil? cmd << " -r #{deploy_info["run_list"].join(",")}" unless @server.stack.nil?
end end

View File

@ -576,11 +576,17 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
deploy_server deploy_server
end end
it "uses deploy_env's chef_client_options if they are set" do it "uses chef_client_options from deploy_info if it is set" do
deploy_env.chef_client_options = '-r role' deploy_info['chef_client_options'] = '-r role'
expect(stubbed_knife).to receive(:ssh_stream).with(anything, 'chef-client --no-color -r role', any_args) expect(stubbed_knife).to receive(:ssh_stream).with(anything, 'chef-client --no-color -r role', any_args)
deploy_server deploy_server
end end
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
end end
it "uses server's key" do it "uses server's key" do

View File

@ -10,7 +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', :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', :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', :expires, :maybe_nil, :non_empty_string, :field_validator
include_examples 'field type validation', :chef_client_options, :maybe_nil, :non_empty_string, :field_validator include_examples 'field type validation', :chef_client_options, :maybe_nil, :maybe_empty_string, :field_validator
it 'should be valid only with all users available' do it 'should be valid only with all users available' do
expect(build(validated_model_name, users: ['root'])).to be_valid expect(build(validated_model_name, users: ['root'])).to be_valid