Merge branch 'CID-418_chef_client_options_single_deploy' into features
This commit is contained in:
commit
e3b7a27976
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -31,8 +31,7 @@ module Devops
|
||||
::Validators::FieldValidator::Expires]
|
||||
|
||||
set_field_validators :chef_client_options, [::Validators::FieldValidator::Nil,
|
||||
::Validators::FieldValidator::FieldType::String,
|
||||
::Validators::FieldValidator::NotEmpty]
|
||||
::Validators::FieldValidator::FieldType::String]
|
||||
|
||||
def initialize d={}
|
||||
self.identifier = d["identifier"]
|
||||
|
||||
@ -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
|
||||
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
|
||||
|
||||
@ -576,11 +576,17 @@ 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 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
|
||||
|
||||
it "uses server's key" do
|
||||
|
||||
@ -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', :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
|
||||
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
|
||||
expect(build(validated_model_name, users: ['root'])).to be_valid
|
||||
|
||||
Loading…
Reference in New Issue
Block a user