Skip to content

Commit

Permalink
Merge pull request #14697 from bzwei/extra_var_format
Browse files Browse the repository at this point in the history
extra_var to have metadata
(cherry picked from commit b84a4eb)
  • Loading branch information
gmcculloug authored and simaishi committed Apr 25, 2017
1 parent b8e052f commit 4f35996
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
3 changes: 3 additions & 0 deletions app/models/service_ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ 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).with_indifferent_access
job_options[:extra_vars].try(:transform_values!) do |val|
val.kind_of?(String) ? val : val[:default] # TODO: support Hash only
end
job_options.deep_merge!(parse_dialog_options) unless action == ResourceAction::RETIREMENT
job_options.deep_merge!(overrides)

Expand Down
6 changes: 5 additions & 1 deletion app/models/service_template_ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ def self.build_parameter_list(name, description, info)
:ask_inventory_on_launch => true,
:ask_credential_on_launch => true
}
params[:extra_vars] = info[:extra_vars].to_json if info[:extra_vars]
if info[:extra_vars]
params[:extra_vars] = info[:extra_vars].transform_values do |val|
val.kind_of?(String) ? val : val[:default] # TODO: support Hash only
end.to_json
end

[:credential, :cloud_credential, :network_credential].each do |credential|
cred_sym = "#{credential}_id".to_sym
Expand Down
6 changes: 3 additions & 3 deletions spec/models/service_ansible_playbook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
:credential_id => credential_0.id,
:playbook_id => 10,
:extra_vars => {
"var1" => "default_val1",
:var2 => "default_val2",
"var3" => "default_val3"
"var1" => {:default => "default_val1"},
:var2 => {:default => "default_val2"},
"var3" => {:default => "default_val3"}
},
}
}
Expand Down
12 changes: 6 additions & 6 deletions spec/models/service_template_ansible_playbook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
:config_info => {
:provision => {
:extra_vars => {
'key1' => 'val1',
'key2' => 'val2'
'key1' => {:default => 'val1'},
'key2' => {:default => 'val2'}
}
},
:retirement => {
Expand All @@ -63,8 +63,8 @@
:provision => {
:new_dialog_name => 'test_dialog_updated',
:extra_vars => {
'key1' => 'updated_val1',
'key2' => 'updated_val2'
'key1' => {:default => 'updated_val1'},
'key2' => {:default => 'updated_val2'}
}
}
}}
Expand Down Expand Up @@ -212,8 +212,8 @@
expect(service_template.name).to eq(catalog_item_options_three[:name])
expect(service_template.description).to eq(catalog_item_options_three[:description])
expect(service_template.options.fetch_path(:config_info, :provision, :extra_vars)).to have_attributes(
'key1' => 'updated_val1',
'key2' => 'updated_val2'
'key1' => {:default => 'updated_val1'},
'key2' => {:default => 'updated_val2'}
)
new_dialog_record = Dialog.where(:label => new_dialog_label).first
expect(new_dialog_record).to be_truthy
Expand Down

0 comments on commit 4f35996

Please sign in to comment.