add project metadata sync with chef on deploy
This commit is contained in:
parent
6419cbfe73
commit
a671083ae6
@ -359,6 +359,7 @@ module Devops
|
|||||||
end
|
end
|
||||||
|
|
||||||
def deploy_server deploy_info
|
def deploy_server deploy_info
|
||||||
|
sync_project_metadata_with_chef!(deploy_info)
|
||||||
@out << "\nBefore deploy hooks...\n"
|
@out << "\nBefore deploy hooks...\n"
|
||||||
res = self.run_hook(:before_deploy, @out, deploy_info)
|
res = self.run_hook(:before_deploy, @out, deploy_info)
|
||||||
@out << "Done\n"
|
@out << "Done\n"
|
||||||
@ -498,6 +499,25 @@ module Devops
|
|||||||
rlist.uniq
|
rlist.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sync_project_metadata_with_chef!(deploy_info)
|
||||||
|
version = deploy_info['project_info']['version']
|
||||||
|
deployers = deploy_info['project_info']['deployers']
|
||||||
|
api_cmd = %Q{
|
||||||
|
nodes.find(name: '#{@server.chef_node_name}') do |node|
|
||||||
|
node.set['project_info'] = {
|
||||||
|
'pinpromote' => { 'version'=> '#{version}' },
|
||||||
|
'deployers' => #{deployers}
|
||||||
|
}
|
||||||
|
node.save
|
||||||
|
end
|
||||||
|
}
|
||||||
|
knife_cmd = %Q{exec -E "#{api_cmd}"}
|
||||||
|
puts_and_flush "Going to execute knife command:\n#{knife_cmd}"
|
||||||
|
output, succeeded = knife_instance.knife(knife_cmd)
|
||||||
|
puts_and_flush "Command output: #{output}"
|
||||||
|
raise 'Failed to sync project metadata with chef' unless succeeded
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def schedule_expiration
|
def schedule_expiration
|
||||||
|
|||||||
@ -501,9 +501,15 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
|
|||||||
allow(executor).to receive(:run_hook).with(:before_deploy, any_args)
|
allow(executor).to receive(:run_hook).with(:before_deploy, any_args)
|
||||||
allow(executor).to receive(:run_hook).with(:after_deploy, any_args)
|
allow(executor).to receive(:run_hook).with(:after_deploy, any_args)
|
||||||
allow(stubbed_knife).to receive(:ssh_stream) { 'Chef Client finished'}
|
allow(stubbed_knife).to receive(:ssh_stream) { 'Chef Client finished'}
|
||||||
|
allow(stubbed_knife).to receive(:knife) { ['asd', true] }
|
||||||
allow(stubbed_connector).to receive(:key) { double('Key', path: 'path_to_key') }
|
allow(stubbed_connector).to receive(:key) { double('Key', path: 'path_to_key') }
|
||||||
allow(stubbed_connector).to receive(:server_update)
|
allow(stubbed_connector).to receive(:server_update)
|
||||||
@deploy_info = {}
|
@deploy_info = {
|
||||||
|
'project_info' => {
|
||||||
|
'version' => 'v1',
|
||||||
|
'deployers' => %w(root user)
|
||||||
|
}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -513,6 +519,16 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
|
|||||||
deploy_server
|
deploy_server
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'syncs project metadata with chef' do
|
||||||
|
expect(executor).to receive(:sync_project_metadata_with_chef!)
|
||||||
|
deploy_server
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'raises error if sync fails' do
|
||||||
|
allow(stubbed_knife).to receive(:knife) { ['asd', false] }
|
||||||
|
expect { deploy_server }.to raise_error(StandardError)
|
||||||
|
end
|
||||||
|
|
||||||
context 'when uses json file' do
|
context 'when uses json file' do
|
||||||
before(:all) do
|
before(:all) do
|
||||||
@tmp_files_at_start = Dir.entries(SpecSupport.tmp_dir)
|
@tmp_files_at_start = Dir.entries(SpecSupport.tmp_dir)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user