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

Add create action for Image #89

Merged
merged 2 commits into from
Sep 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,29 @@ def requires_storage_for_scan?
false
end

def self.raw_create_image(ext_management_system, create_options)
ext_management_system.with_provider_connection(:service => 'Image') do |service|
service.create_image(create_options)
end
rescue => err
_log.error("image=[#{name}], error=[#{err}]")
raise MiqException::MiqOpenstackApiRequestError, err.to_s, err.backtrace
end

def self.validate_create_image(ext_management_system, _options = {})
if ext_management_system
{:available => true, :message => nil}
else
{:available => false,
:message => _("The Image is not connected to an active %{table}") %
{:table => ui_lookup(:table => "ext_management_system")}}
end
end

def self.create_image(ext_management_system, create_options)
raw_create_image(ext_management_system, create_options)
end

def raw_delete_image
ext_management_system.with_provider_connection(:service => 'Compute') do |service|
service.delete_image(ems_ref)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
describe ManageIQ::Providers::Openstack::CloudManager::Template do
let(:ems) { FactoryGirl.create(:ems_openstack_with_authentication) }
let(:image_attributes) { {:name => "image", :ram => "1"} }
let(:template_openstack) { FactoryGirl.create :template_openstack, :ext_management_system => ems, :ems_ref => 'one_id' }
let(:service) { double }

context 'when create_image' do
before do
allow(ems).to receive(:with_provider_connection).with(:service => 'Image').and_yield(service)
end

context 'with correct data' do
it 'should create image' do
expect(service).to receive(:create_image).with(image_attributes).once
subject.class.create_image(ems, image_attributes)
end

it 'should not raise error' do
allow(service).to receive(:create_image).with(image_attributes).once
expect do
subject.class.create_image(ems, image_attributes)
end.not_to raise_error
end
end

context 'with incorrect data' do
[Excon::Error::BadRequest, ArgumentError].map do |error|
it "should raise error when #{error}" do
allow(service).to receive(:create_image).with(image_attributes).and_raise(error)
expect do
subject.class.create_image(ems, image_attributes)
end.to raise_error(MiqException::MiqOpenstackApiRequestError)
end
end
end
end
context 'when raw_delete_image' do
before do
allow(ExtManagementSystem).to receive(:find).with(ems.id).and_return(ems)
Expand Down