-
Notifications
You must be signed in to change notification settings - Fork 92
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
Conversation
@andyvesel Thanks for PR. Similar as for delete image PR, I'd suggest put there also non-raw method even keep it in same model to keep the consistency. (parent class is generic for all providers so it's not sure whether we want it also there) And it would be great if you coudl add some basic tests for these methods. |
f02a0de
to
02e8664
Compare
02e8664
to
41e91dc
Compare
@aufi tests added |
baae0c7
to
b151321
Compare
This pull request is not mergeable. Please rebase and repush. |
b151321
to
c4d845d
Compare
c4d845d
to
0444795
Compare
@@ -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 => 'Compute') do |service| | |||
service.images.create(create_options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think we usually use request methods (instead of fog model's one), search for image_create
at https://github.com/fog/fog-openstack/tree/master/lib/fog/compute/openstack/requests
before do | ||
allow(ExtManagementSystem).to receive(:find).with(ems.id).and_return(ems) | ||
allow(ems).to receive(:with_provider_connection).with(:service => 'Compute').and_yield(service) | ||
allow(service).to receive(:images).and_return(images) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these lines are not needed. E.g. ExtManagementSystem
exists in database so it can be found directly from model (created by line 2 and first usage of ems
variable). For example take a look at https://gist.github.com/aufi/16acd1f29086eeb211ceabd3bc98625e I don't want push you to rewrite your code much, just for information.
|
||
context 'with correct data' do | ||
it 'should create image' do | ||
expect(images).to receive(:create).with(image_attributes).and_return(template_openstack).once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using service (and its create_image
method) directly would be easier, no need to a "double mock" then.
Nit: I'm not sure if we care about returned template_openstack
data from Fog call, so we don't have to test it then.
@aufi thanks for review and comments. Will fix it asap |
0444795
to
c76ba5e
Compare
@aufi fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for update, could you address my few last comments?
@@ -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 => 'Compute') do |service| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, try use Image service instead of Compute.
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(ExtManagementSystem).to receive(:find).with(ems.id).and_return(ems) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is line is not needed, could you check it?
before do | ||
allow(ExtManagementSystem).to receive(:find).with(ems.id).and_return(ems) | ||
allow(ems).to receive(:with_provider_connection).with(:service => 'Compute').and_yield(service) | ||
allow(service).to receive(:images) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is line is not needed, could you check it?
allow(service).to receive(:images) | ||
end | ||
|
||
let(:images) { double } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is line is not needed, could you check it?
c76ba5e
to
e63642c
Compare
e63642c
to
71f29b3
Compare
Checked commits andyvesel/manageiq-providers-openstack@b6ec06b~...71f29b3 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
Looks good to me, merging. |
Added
create
method for Image