diff --git a/devops-service/app/api2/routes/server.rb b/devops-service/app/api2/routes/server.rb index b2d5c17..5d1f594 100644 --- a/devops-service/app/api2/routes/server.rb +++ b/devops-service/app/api2/routes/server.rb @@ -196,6 +196,9 @@ module Devops # "groups": [], -> specify special security groups, 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 + # "project_info": { + # "deployers": ['user1'] -> currently it's used only in sandbox projects + # } # } # # * *Returns* : text stream diff --git a/devops-service/lib/executors/server_executor.rb b/devops-service/lib/executors/server_executor.rb index a31d471..57eb18b 100644 --- a/devops-service/lib/executors/server_executor.rb +++ b/devops-service/lib/executors/server_executor.rb @@ -119,9 +119,11 @@ module Devops schedule_expiration() unless options["without_bootstrap"] - bootstrap_options = { - bootstrap_template: i.bootstrap_template - } + bootstrap_options = { 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) else return 0 @@ -287,6 +289,7 @@ module Devops @out.flush knife_instance.set_run_list(@server.chef_node_name, run_list) 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) if deploy_status == 0 0 diff --git a/devops-service/spec/executors/server_executor_spec.rb b/devops-service/spec/executors/server_executor_spec.rb index d6f2500..ae5c99d 100644 --- a/devops-service/spec/executors/server_executor_spec.rb +++ b/devops-service/spec/executors/server_executor_spec.rb @@ -80,7 +80,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec describe '#create_server' do let(:image) { double('Image instance', remote_user: 'remote_user') } let(:create_server_options) { { - 'created_by' => 'user', + 'created_by' => 'me', 'run_list' => @run_list, 'name' => 'node_name', 'key' => @key, @@ -92,14 +92,16 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec allow(provider).to receive(:create_server) { true } allow(stubbed_connector).to receive(:image) { image } allow(stubbed_connector).to receive(:server_insert) - @without_bootstrap = true @run_list = %w(role[asd]) @key = 'key' + + allow(image).to receive(:bootstrap_template) { 'template' } + allow(executor).to receive(:two_phase_bootstrap) end it 'builds server model from given options' do 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.key).to eq @key expect(executor.server.run_list).to eq @run_list @@ -149,26 +151,25 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec create_server end - context 'without_bootstrap option is false or nil' do - it 'launches bootstrap' do - @without_bootstrap = false - allow(image).to receive(:bootstrap_template) { 'template' } - allow(executor).to receive(:two_phase_bootstrap) - expect(executor).to receive(:two_phase_bootstrap) + it 'launches bootstrap' do + @without_bootstrap = nil + expect(executor).to receive(:two_phase_bootstrap) + create_server + end + + 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 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 context 'without_bootstrap option is true' do @@ -332,6 +333,13 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec two_phase_bootstrap 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 it 'returns 0' do allow(executor).to receive(:deploy_server) { 0 }