-
Notifications
You must be signed in to change notification settings - Fork 896
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
Select datastore by its association with the provider #15245
Select datastore by its association with the provider #15245
Conversation
@gmcculloug please review. |
@@ -74,7 +74,7 @@ def disconnect_floppies | |||
def raw_add_disk(disk_name, disk_size_mb, options = {}) | |||
raise _("VM has no EMS, unable to add disk") unless ext_management_system | |||
if options[:datastore] | |||
datastore = Storage.find_by(:name => options[:datastore]) | |||
datastore = ext_management_system.storages.find_by(:name => options[:datastore]) |
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.
Can we use host.writable_storages
here? It could be possible to pick a datastore that exists but the VM's host doesn't have access to.
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.
@agrare hosts aren't available in this context. How would you suggest to do so ?
Also, the decision on which host to schedule the vm depends on auto-placement or not, in case of provision this is not in the context of this code.
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.
@masayag You would need to access hosts from the ext_management_system
and collect the writable_storages
.
Maybe something like this:
storages = ext_management_system.hosts.collect(&:writable_storages).uniq.compact
datastore = storages.detect { |storage| storage.name == options[:datastore] }
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.
@gmcculloug fixed.
5cb561d
to
af7d916
Compare
raise _("Data Store does not exist, unable to add disk") unless datastore | ||
datastore = ext_management_system.hosts.detect do |h| | ||
h.writable_storages.find_by(:name => options[:datastore]) | ||
end.uniq.compact.first |
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.
This is not going to do what you want. The detect
method will return a single Host
object or nil
and it looks like you are expecting a Storage
object array (I think) since you are calling uniq.compact.first
.
Which brings us to my second point: Test!
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.
@gmcculloug ofcourse - i thought i squashed a local change to the commit which did exactly that. The fix should have been similar to https://github.com/ManageIQ/manageiq-providers-ovirt/pull/42/files#diff-17198062ae8d3e8788a4f5db1eb17ccdR59 - I'll add a test as well.
af7d916
to
620d610
Compare
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.
@gmcculloug the funny (well...not that funny) thing about it that I caught that mistake by the test I added to the other PR https://github.com/ManageIQ/manageiq-providers-ovirt/pull/42/files#diff-ea68074c0f05c6eccff224929cd39fceR188 which confirms your second comment about test necessity.
raise _("Data Store does not exist, unable to add disk") unless datastore | ||
datastore = ext_management_system.hosts.detect do |h| | ||
h.writable_storages.find_by(:name => options[:datastore]) | ||
end.uniq.compact.first |
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.
@gmcculloug ofcourse - i thought i squashed a local change to the commit which did exactly that. The fix should have been similar to https://github.com/ManageIQ/manageiq-providers-ovirt/pull/42/files#diff-17198062ae8d3e8788a4f5db1eb17ccdR59 - I'll add a test as well.
620d610
to
24b0e25
Compare
@gmcculloug added tests. |
@agrare @gmcculloug I think this incorporates all of the comments. verified the following scenarios:
|
datastore = ext_management_system.hosts.collect do |h| | ||
h.writable_storages.find_by(:name => options[:datastore]) | ||
end.uniq.compact.first | ||
raise _("Data Store does not exist or cannot be accessed, unable to add disk") unless datastore |
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.
We should use Datastore
to match usage throughout the rest of the product.
https://github.com/ManageIQ/manageiq/blob/master/locale/en/manageiq.po#L801
Only place it differs is with the previous error string from the method: https://github.com/ManageIQ/manageiq/blob/master/locale/en/manageiq.po#L7491
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.
@gmcculloug fixed. I assume the translation itself isn't a concern of this PR ?
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.
@mzazrivec Can you confirm there is nothing extra we need to do here?
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.
Yep, wrt. translations nothing else is needed to be done here.
Datastores on the same setup may have the same name. However, there is an assumption that datastores names on the same provider are unique. The selection of datastore by its name should be narrow to the provider on which the vm is provisioned. https://bugzilla.redhat.com/show_bug.cgi?id=1427498
24b0e25
to
e9c07df
Compare
Checked commit masayag@e9c07df with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
Select datastore by its association with the provider (cherry picked from commit ec5d106) https://bugzilla.redhat.com/show_bug.cgi?id=1462774
Fine backport details:
|
Datastores on the same setup may have the same name.
However, there is an assumption that datastores names on the same
provider are unique. The selection of datastore by its name should be
narrow to the provider on which the vm is provisioned.
https://bugzilla.redhat.com/show_bug.cgi?id=1427498