CID-340: set deployers list for sandbox projects

This commit is contained in:
Anton Chuchkalov 2016-03-17 15:22:25 +02:00
parent 4144161089
commit fce9231acc
3 changed files with 38 additions and 24 deletions

View File

@ -196,6 +196,9 @@ module Devops
# "groups": [], -> specify special security groups, overrides value from project env # "groups": [], -> specify special security groups, overrides value from project env
# "key": "ssh key" -> specify ssh key for server, overrides value from project env # "key": "ssh key" -> specify ssh key for server, overrides value from project env
# "private_ip": null -> should be string like "172.31.31.203" if present # "private_ip": null -> should be string like "172.31.31.203" if present
# "project_info": {
# "deployers": ['user1'] -> currently it's used only in sandbox projects
# }
# } # }
# #
# * *Returns* : text stream # * *Returns* : text stream

View File

@ -119,9 +119,11 @@ module Devops
schedule_expiration() schedule_expiration()
unless options["without_bootstrap"] unless options["without_bootstrap"]
bootstrap_options = { bootstrap_options = { bootstrap_template: i.bootstrap_template }
bootstrap_template: i.bootstrap_template if @project.is_sandbox?
} bootstrap_options[:deployers] = [options['created_by']]
bootstrap_options[:deployers] += (options['project_info']['deployers'] || []) if options['project_info']
end
return two_phase_bootstrap(bootstrap_options) return two_phase_bootstrap(bootstrap_options)
else else
return 0 return 0
@ -287,6 +289,7 @@ module Devops
@out.flush @out.flush
knife_instance.set_run_list(@server.chef_node_name, run_list) knife_instance.set_run_list(@server.chef_node_name, run_list)
deploy_info = options[:deploy_info] || @project.deploy_info(@deploy_env) deploy_info = options[:deploy_info] || @project.deploy_info(@deploy_env)
deploy_info['project_info']['deployers'] = options[:deployers] if options[:deployers]
deploy_status = deploy_server(deploy_info) deploy_status = deploy_server(deploy_info)
if deploy_status == 0 if deploy_status == 0
0 0

View File

@ -80,7 +80,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
describe '#create_server' do describe '#create_server' do
let(:image) { double('Image instance', remote_user: 'remote_user') } let(:image) { double('Image instance', remote_user: 'remote_user') }
let(:create_server_options) { { let(:create_server_options) { {
'created_by' => 'user', 'created_by' => 'me',
'run_list' => @run_list, 'run_list' => @run_list,
'name' => 'node_name', 'name' => 'node_name',
'key' => @key, 'key' => @key,
@ -92,14 +92,16 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
allow(provider).to receive(:create_server) { true } allow(provider).to receive(:create_server) { true }
allow(stubbed_connector).to receive(:image) { image } allow(stubbed_connector).to receive(:image) { image }
allow(stubbed_connector).to receive(:server_insert) allow(stubbed_connector).to receive(:server_insert)
@without_bootstrap = true
@run_list = %w(role[asd]) @run_list = %w(role[asd])
@key = 'key' @key = 'key'
allow(image).to receive(:bootstrap_template) { 'template' }
allow(executor).to receive(:two_phase_bootstrap)
end end
it 'builds server model from given options' do it 'builds server model from given options' do
create_server create_server
expect(executor.server.created_by).to eq 'user' expect(executor.server.created_by).to eq 'me'
expect(executor.server.chef_node_name).to eq 'node_name' expect(executor.server.chef_node_name).to eq 'node_name'
expect(executor.server.key).to eq @key expect(executor.server.key).to eq @key
expect(executor.server.run_list).to eq @run_list expect(executor.server.run_list).to eq @run_list
@ -149,26 +151,25 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
create_server create_server
end end
context 'without_bootstrap option is false or nil' do it 'launches bootstrap' do
it 'launches bootstrap' do @without_bootstrap = nil
@without_bootstrap = false expect(executor).to receive(:two_phase_bootstrap)
allow(image).to receive(:bootstrap_template) { 'template' } create_server
allow(executor).to receive(:two_phase_bootstrap) end
expect(executor).to receive(:two_phase_bootstrap)
it 'launches bootstrap without_bootstrap option is false' do
@without_bootstrap = false
expect(executor).to receive(:two_phase_bootstrap)
create_server
end
context "when project is sandbox" do
it 'it sets deployers to owner and passed deployers' do
allow(project).to receive(:is_sandbox?) { true }
create_server_options['project_info'] = {'deployers' => %w(user1 user2)}
expect(executor).to receive(:two_phase_bootstrap).with(hash_including(deployers: %w(me user1 user2)))
create_server create_server
end end
it 'launches bootstrap' do
@without_bootstrap = nil
allow(image).to receive(:bootstrap_template) { 'template' }
allow(executor).to receive(:two_phase_bootstrap)
expect(executor).to receive(:two_phase_bootstrap)
create_server
end
# it 'passes additional deployers to bootstrap' do
# executor = described_class.new(server, output)
# end
end end
context 'without_bootstrap option is true' do context 'without_bootstrap option is true' do
@ -332,6 +333,13 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
two_phase_bootstrap two_phase_bootstrap
end end
it 'it sets deployers passed deployers if present' do
expect(executor).to receive(:deploy_server) do |param|
expect(param['project_info']['deployers']).to match_array %w(user1 user2)
end
executor.two_phase_bootstrap(deployers: %w(user1 user2))
end
context 'if deploy was successful' do context 'if deploy was successful' do
it 'returns 0' do it 'returns 0' do
allow(executor).to receive(:deploy_server) { 0 } allow(executor).to receive(:deploy_server) { 0 }