add specs for ServerExecutor#add_run_list_to_deploy_info and #compute_run_list
This commit is contained in:
parent
db1ccc2e33
commit
48572f6875
@ -37,7 +37,7 @@ module Devops
|
|||||||
define_hook :before_bootstrap
|
define_hook :before_bootstrap
|
||||||
define_hook :after_bootstrap
|
define_hook :after_bootstrap
|
||||||
|
|
||||||
before_deploy :create_run_list
|
before_deploy :add_run_list_to_deploy_info
|
||||||
|
|
||||||
|
|
||||||
attr_accessor :server, :deploy_env
|
attr_accessor :server, :deploy_env
|
||||||
@ -471,7 +471,7 @@ module Devops
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_run_list out, deploy_info
|
def add_run_list_to_deploy_info out, deploy_info
|
||||||
out << "\nGenerate run list hook...\n"
|
out << "\nGenerate run list hook...\n"
|
||||||
if deploy_info["run_list"]
|
if deploy_info["run_list"]
|
||||||
out << "Deploy info already contains 'run_list': #{deploy_info["run_list"].join(", ")}\n"
|
out << "Deploy info already contains 'run_list': #{deploy_info["run_list"].join(", ")}\n"
|
||||||
@ -480,14 +480,6 @@ module Devops
|
|||||||
out << "Project run list: #{@project.run_list.join(", ")}\n"
|
out << "Project run list: #{@project.run_list.join(", ")}\n"
|
||||||
out << "Deploy environment run list: #{@deploy_env.run_list.join(", ")}\n"
|
out << "Deploy environment run list: #{@deploy_env.run_list.join(", ")}\n"
|
||||||
out << "Server run list: #{@server.run_list.join(", ")}\n"
|
out << "Server run list: #{@server.run_list.join(", ")}\n"
|
||||||
=begin
|
|
||||||
rlist = Set.new.merge(@deploy_env.provider_instance.run_list).merge(@project.run_list).merge(@deploy_env.run_list).merge(@server.run_list)
|
|
||||||
if @server.stack
|
|
||||||
stack = Devops::Db.connector.stack(@server.stack)
|
|
||||||
out << "Stack run list: #{stack.run_list.join(", ")}\n"
|
|
||||||
rlist.merge(stack.run_list)
|
|
||||||
end
|
|
||||||
=end
|
|
||||||
deploy_info["run_list"] = compute_run_list
|
deploy_info["run_list"] = compute_run_list
|
||||||
out << "New deploy run list: #{deploy_info["run_list"].join(", ")}\nRun list has been generated\n\n"
|
out << "New deploy run list: #{deploy_info["run_list"].join(", ")}\nRun list has been generated\n\n"
|
||||||
end
|
end
|
||||||
@ -495,16 +487,14 @@ module Devops
|
|||||||
def compute_run_list
|
def compute_run_list
|
||||||
rlist = []
|
rlist = []
|
||||||
[@deploy_env.provider_instance.run_list, @project.run_list, @deploy_env.run_list, @server.run_list].each do |sub_run_list|
|
[@deploy_env.provider_instance.run_list, @project.run_list, @deploy_env.run_list, @server.run_list].each do |sub_run_list|
|
||||||
rlist += sub_run_list if sub_run_list.is_a?(Array)
|
rlist += sub_run_list if sub_run_list
|
||||||
end
|
end
|
||||||
rlist = Set.new(rlist)
|
|
||||||
if @server.stack
|
if @server.stack
|
||||||
stack = Devops::Db.connector.stack(@server.stack)
|
stack = Devops::Db.connector.stack(@server.stack)
|
||||||
# out << "Stack run list: #{stack.run_list.join(", ")}\n"
|
|
||||||
srl = stack.run_list
|
srl = stack.run_list
|
||||||
rlist.merge(srl) if srl.is_a?(Array)
|
rlist += srl if srl
|
||||||
end
|
end
|
||||||
rlist.to_a
|
rlist.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@ -698,4 +698,53 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
describe '#add_run_list_to_deploy_info' do
|
||||||
|
it "doesn't change deploy info if it already includes run list" do
|
||||||
|
deploy_info = {'run_list' => %w(foo)}
|
||||||
|
expect {
|
||||||
|
executor.add_run_list_to_deploy_info(output, deploy_info)
|
||||||
|
}.not_to change { deploy_info }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'computes and adds run_list to deploy_info' do
|
||||||
|
deploy_info = {}
|
||||||
|
allow(executor).to receive(:compute_run_list) { %w(foo) }
|
||||||
|
expect(executor).to receive(:compute_run_list)
|
||||||
|
executor.add_run_list_to_deploy_info(output, deploy_info)
|
||||||
|
expect(deploy_info['run_list']).to eq %w(foo)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#compute_run_list' do
|
||||||
|
before do
|
||||||
|
allow(deploy_env).to receive_message_chain('provider_instance.run_list') { %w(a) }
|
||||||
|
project.run_list = %w(b)
|
||||||
|
deploy_env.run_list = %w(c)
|
||||||
|
server.run_list = %w(d)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns array with run list merged from provider's, project's, env's and server's run lists" do
|
||||||
|
expect(executor.compute_run_list).to be_an(Array).and contain_exactly(*%w(a b c d))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "includes stack's run list if stack is set", stubbed_connector: true do
|
||||||
|
server.stack = 'stack'
|
||||||
|
allow(stubbed_connector).to receive(:stack) { instance_double(Devops::Model::StackEc2, run_list: %w(e)) }
|
||||||
|
expect(executor.compute_run_list).to be_an(Array).and contain_exactly(*%w(a b c d e))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't contain nils" do
|
||||||
|
server.run_list = nil
|
||||||
|
server.stack = 'stack'
|
||||||
|
allow(stubbed_connector).to receive(:stack) { instance_double(Devops::Model::StackEc2, run_list: nil) }
|
||||||
|
expect(executor.compute_run_list).to be_an(Array).and contain_exactly(*%w(a b c))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns uniq elements' do
|
||||||
|
project.run_list = %w(a)
|
||||||
|
deploy_env.run_list = %w(a)
|
||||||
|
expect(executor.compute_run_list).to be_an(Array).and contain_exactly(*%w(a d))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Loading…
Reference in New Issue
Block a user