Skip to content

Commit

Permalink
Merge pull request #18674 from d-m-u/fix_creating_service_template_wi…
Browse files Browse the repository at this point in the history
…th_picture

Handle picture correctly on service template update/create

(cherry picked from commit d26ae5a)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1702479
  • Loading branch information
jrafanie authored and simaishi committed Apr 23, 2019
1 parent 779877c commit 8174dc3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/models/service_template.rb
Expand Up @@ -378,7 +378,11 @@ def create_resource_actions(ae_endpoints)
end

def self.create_from_options(options)
create(options.except(:config_info).merge(:options => { :config_info => options[:config_info] }))
create(options.except(:config_info, :picture).merge(:options => { :config_info => options[:config_info] })).tap do |tmp|
if options[:picture]
tmp.update_attributes!(:picture => Picture.create(:content => options[:picture][:content], :extension => options[:picture][:extension]))
end
end
end
private_class_method :create_from_options

Expand Down Expand Up @@ -496,7 +500,10 @@ def resource_action_list

def update_from_options(params)
options[:config_info] = params[:config_info]
update_attributes!(params.except(:config_info))
if params[:picture]
update_attributes!(:picture => Picture.create(:content => params[:picture][:content], :extension => params[:picture][:extension]))
end
update_attributes!(params.except(:config_info, :picture))
end

def construct_config_info
Expand Down
18 changes: 18 additions & 0 deletions spec/models/service_template_spec.rb
Expand Up @@ -720,6 +720,20 @@
let(:ra1) { FactoryGirl.create(:resource_action, :action => 'Provision') }
let(:ra2) { FactoryGirl.create(:resource_action, :action => 'Retirement') }
let(:ems) { FactoryGirl.create(:ems_amazon) }
let(:content) do
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGP"\
"C/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3Cc"\
"ulE8AAAACXBIWXMAAAsTAAALEwEAmpwYAAABWWlUWHRYTUw6Y29tLmFkb2Jl"\
"LnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIg"\
"eDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpy"\
"ZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1u"\
"cyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAg"\
"ICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYv"\
"MS4wLyI+CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3Jp"\
"ZW50YXRpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpS"\
"REY+CjwveDp4bXBtZXRhPgpMwidZAAAADUlEQVQIHWNgYGCwBQAAQgA+3N0+"\
"xQAAAABJRU5ErkJggg=="
end
let(:vm) { FactoryGirl.create(:vm_amazon, :ext_management_system => ems) }
let(:flavor) { FactoryGirl.create(:flavor_amazon) }
let(:request_dialog) { FactoryGirl.create(:miq_dialog_provision) }
Expand All @@ -730,6 +744,7 @@
:service_type => 'atomic',
:prov_type => 'amazon',
:display => 'false',
:picture => { :content => content, :extension => 'jpg' },
:description => 'a description',
:config_info => {
:miq_request_dialog_name => request_dialog.name,
Expand Down Expand Up @@ -770,10 +785,12 @@

describe '#update_catalog_item' do
let(:new_vm) { FactoryGirl.create(:vm_amazon, :ext_management_system => ems) }
let(:new_picture_content) { "iVBORw0KGgoAAAAN" }
let(:updated_catalog_item_options) do
{
:name => 'Updated Template Name',
:display => 'false',
:picture => { :content => new_picture_content, :extension => 'jpg' },
:description => 'a description',
:config_info => {
:miq_request_dialog_name => request_dialog.name,
Expand Down Expand Up @@ -811,6 +828,7 @@
expect(updated.resource_actions.last.dialog).to eq(service_dialog)
expect(updated.resource_actions.last.fqname).to eq('/x1/y1/z1')
expect(updated.name).to eq('Updated Template Name')
expect(Base64.strict_encode64(updated.picture.content)).to eq('aVZCT1J3MEtHZ29BQUFBTg==')
expect(updated.service_resources.first.resource.source_id).to eq(new_vm.id) # Validate request update
expect(updated.config_info).to eq(updated_catalog_item_options[:config_info])
expect(updated.options.key?(:foo)).to be_truthy # Test that the options were merged
Expand Down

0 comments on commit 8174dc3

Please sign in to comment.