Skip to content

Commit

Permalink
Merge pull request #14602 from bzwei/retirement_hosts
Browse files Browse the repository at this point in the history
Ansible Service: skip dialog options for retirement
(cherry picked from commit 961e29d)
  • Loading branch information
gmcculloug authored and simaishi committed Apr 3, 2017
1 parent c310f82 commit 6ff82bc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/service_ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_job_options(action)

def save_job_options(action, overrides)
job_options = options.fetch_path(:config_info, action.downcase.to_sym).slice(:hosts, :extra_vars)
job_options.deep_merge!(parse_dialog_options)
job_options.deep_merge!(parse_dialog_options) unless action == ResourceAction::RETIREMENT
job_options.deep_merge!(overrides)

credential_id = job_options.delete(:credential_id)
Expand Down
30 changes: 27 additions & 3 deletions spec/models/service_ansible_playbook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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_0) { FactoryGirl.create(:authentication, :manager_ref => '1') }
let(:credential_1) { FactoryGirl.create(:authentication, :manager_ref => 'a') }
let(:credential_2) { FactoryGirl.create(:authentication, :manager_ref => 'b') }

Expand Down Expand Up @@ -37,9 +38,10 @@
{
:config_info => {
:provision => {
:hosts => "default_host1,default_host2",
:playbook_id => 10,
:extra_vars => {
:hosts => "default_host1,default_host2",
:credential_id => credential_0.id,
:playbook_id => 10,
:extra_vars => {
"var1" => "default_val1",
"var2" => "default_val2",
"var3" => "default_val3"
Expand Down Expand Up @@ -91,6 +93,28 @@
:extra_vars => {'var1' => 'value1', 'var2' => 'value2', 'var3' => 'default_val3'}
)
end

context 'action is retirement' do
let(:action) { ResourceAction::RETIREMENT }

before do
service_options = service.options
service_options[:config_info][:retirement] = service_options[:config_info][:provision]
service.update_attributes(:options => service_options)
end

it 'ignores dialog options' do
hosts = service.options.fetch_path(:config_info, :retirement, :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[:retirement_job_options]).to have_attributes(
:inventory => 20,
:credential => nil,
:extra_vars => {'var1' => 'default_val1', 'var2' => 'default_val2', 'var3' => 'default_val3'}
)
end
end
end

context 'with runtime overrides' do
Expand Down

0 comments on commit 6ff82bc

Please sign in to comment.