Skip to content
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

extra_var to have metadata #14697

Merged
merged 1 commit into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this belong in a migration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Since beta release every new service is having the new format. We don't need provide a migration for pre-beta versions.

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