-
Notifications
You must be signed in to change notification settings - Fork 900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create temporary inventory when execute a playbook #14008
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
describe(ServiceAnsiblePlaybook) do | ||
let(:tower_job) { FactoryGirl.create(:ansible_tower_job) } | ||
let(:tower_job_temp) { FactoryGirl.create(:ansible_configuration_script) } | ||
let(:basic_service) { FactoryGirl.create(:service_ansible_playbook, :options => dialog_options) } | ||
let(:basic_service) { FactoryGirl.create(:service_ansible_playbook, :options => config_info_options) } | ||
let(:service) { FactoryGirl.create(:service_ansible_playbook, :options => config_info_options.merge(dialog_options)) } | ||
let(:action) { ResourceAction::PROVISION } | ||
let(:credential_1) { FactoryGirl.create(:authentication, :manager_ref => 'a') } | ||
let(:credential_2) { FactoryGirl.create(:authentication, :manager_ref => 'b') } | ||
|
||
let(:loaded_service) do | ||
service_template = FactoryGirl.create(:service_template_ansible_playbook) | ||
|
@@ -12,40 +15,92 @@ | |
end | ||
|
||
let(:executed_service) do | ||
basic_service.tap do |service| | ||
FactoryGirl.create(:service_ansible_playbook, :options => provision_options).tap do |service| | ||
allow(service).to receive(:job).with(action).and_return(tower_job) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this build the relation rather than stubbing it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We cannot stub method for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then it sounds like it shouldn't be shared, but don't fix in this PR. |
||
end | ||
end | ||
|
||
let(:dialog_options) do | ||
{ | ||
:dialog => { | ||
'dialog_hosts' => 'host1,host2', | ||
'dialog_credential_id' => 1, | ||
'dialog_param_var1' => 'value1', | ||
'dialog_param_var2' => 'value2' | ||
'dialog_hosts' => 'host1,host2', | ||
'dialog_credential' => credential_1.id, | ||
'dialog_param_var1' => 'value1', | ||
'dialog_param_var2' => 'value2' | ||
} | ||
} | ||
end | ||
|
||
let(:config_info_options) do | ||
{ | ||
:config_info => { | ||
:provision => { | ||
:hosts => "default_host1,default_host2", | ||
:extra_vars => { | ||
"var1" => "default_val1", | ||
"var2" => "default_val2", | ||
"var3" => "default_val3" | ||
}, | ||
} | ||
} | ||
} | ||
end | ||
|
||
let(:override_options) do | ||
{ | ||
:hosts => 'host3', | ||
:extra_vars => { 'var1' => 'new_val1' } | ||
:credential_id => credential_2.id, | ||
:hosts => 'host3', | ||
:extra_vars => { 'var1' => 'new_val1' } | ||
} | ||
end | ||
|
||
let(:provision_options) { {:provision_job_options => override_options} } | ||
let(:provision_options) do | ||
{ | ||
:provision_job_options => { | ||
:credential => 1, | ||
:inventory => 2, | ||
:extra_vars => {'var1' => 'value1', 'var2' => 'value2'} | ||
} | ||
} | ||
end | ||
|
||
describe '#preprocess' do | ||
it 'prepares options for action' do | ||
basic_service.preprocess(action, override_options) | ||
basic_service.reload | ||
expect(basic_service.options[:provision_job_options]).to have_attributes( | ||
:hosts => 'host3', | ||
:credential_id => 1, | ||
:extra_vars => {'var1' => 'new_val1', 'var2' => 'value2'} | ||
) | ||
context 'basic service' do | ||
it 'prepares job options from service template' do | ||
hosts = config_info_options.fetch_path(:config_info, :provision, :hosts) | ||
expect(basic_service).to receive(:create_inventory_with_hosts).with(action, hosts).and_return(double(:id => 10)) | ||
basic_service.preprocess(action) | ||
service.reload | ||
expect(basic_service.options[:provision_job_options]).to have_attributes(:inventory => 10) | ||
end | ||
end | ||
|
||
context 'with dialog overrides' do | ||
it 'prepares job options combines from service template and dialog' do | ||
hosts = dialog_options[:dialog]['dialog_hosts'] | ||
expect(service).to receive(:create_inventory_with_hosts).with(action, hosts).and_return(double(:id => 20)) | ||
service.preprocess(action) | ||
service.reload | ||
expect(service.options[:provision_job_options]).to have_attributes( | ||
:inventory => 20, | ||
:credential => credential_1.manager_ref, | ||
:extra_vars => {'var1' => 'value1', 'var2' => 'value2', 'var3' => 'default_val3'} | ||
) | ||
end | ||
end | ||
|
||
context 'with runtime overrides' do | ||
it 'prepares job options combined from service template, dialog, and overrides' do | ||
hosts = override_options[:hosts] | ||
expect(service).to receive(:create_inventory_with_hosts).with(action, hosts).and_return(double(:id => 30)) | ||
service.preprocess(action, override_options) | ||
service.reload | ||
expect(service.options[:provision_job_options]).to have_attributes( | ||
:inventory => 30, | ||
:credential => credential_2.manager_ref, | ||
:extra_vars => {'var1' => 'new_val1', 'var2' => 'value2', 'var3' => 'default_val3'} | ||
) | ||
end | ||
end | ||
end | ||
|
||
|
@@ -90,4 +145,11 @@ | |
describe '#check_refreshed' do | ||
it { expect(executed_service.check_refreshed(action)).to eq([true, nil]) } | ||
end | ||
|
||
describe '#postprocess' do | ||
it 'deletes inventory' do | ||
expect(executed_service).to receive(:delete_inventory) | ||
executed_service.postprocess(action) | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inventory name should probably be a constant on the manager. It can then be reused by the setup scripting that we discussed with @gtanzillo @carbonin and @gmcculloug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure where should the constant be replaced. We can refactor once the solution is finalized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bzwei Agreed, please open a pivotal story to track this work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.pivotaltracker.com/story/show/140418429