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

Select datastore by its association with the provider #15245

Merged
merged 1 commit into from
Jun 8, 2017

Conversation

masayag
Copy link
Contributor

@masayag masayag commented May 29, 2017

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

@masayag
Copy link
Contributor Author

masayag commented May 29, 2017

@gmcculloug please review.

@masayag
Copy link
Contributor Author

masayag commented May 29, 2017

@@ -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])
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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] }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gmcculloug fixed.

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
Copy link
Member

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!

Copy link
Contributor Author

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.

@masayag masayag force-pushed the find_datastore_within_provider branch from af7d916 to 620d610 Compare June 7, 2017 04:11
Copy link
Contributor Author

@masayag masayag left a 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
Copy link
Contributor Author

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.

@masayag masayag force-pushed the find_datastore_within_provider branch from 620d610 to 24b0e25 Compare June 7, 2017 10:53
@masayag
Copy link
Contributor Author

masayag commented Jun 7, 2017

@gmcculloug added tests.

@masayag
Copy link
Contributor Author

masayag commented Jun 7, 2017

@agrare @gmcculloug I think this incorporates all of the comments.

verified the following scenarios:

  1. add disk via vm reconfigure
  2. add disk via an automation script (restapi)
  3. vm provision via UI
  4. vm provision via restapi where disks were specified as part of the request.

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
Copy link
Member

@gmcculloug gmcculloug Jun 7, 2017

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

Copy link
Contributor Author

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 ?

Copy link
Member

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?

Copy link
Contributor

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
@masayag masayag force-pushed the find_datastore_within_provider branch from 24b0e25 to e9c07df Compare June 8, 2017 04:15
@miq-bot
Copy link
Member

miq-bot commented Jun 8, 2017

Checked commit masayag@e9c07df with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 🍰

@gmcculloug gmcculloug merged commit ec5d106 into ManageIQ:master Jun 8, 2017
@gmcculloug gmcculloug added this to the Sprint 63 Ending Jun 19, 2017 milestone Jun 8, 2017
simaishi pushed a commit that referenced this pull request Jun 19, 2017
Select datastore by its association with the provider
(cherry picked from commit ec5d106)

https://bugzilla.redhat.com/show_bug.cgi?id=1462774
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit 44b7dfe9631e4a72a3234da5ce858e4266ab72bb
Author: Greg McCullough <gmccullo@redhat.com>
Date:   Thu Jun 8 10:51:54 2017 -0400

    Merge pull request #15245 from masayag/find_datastore_within_provider
    
    Select datastore by its association with the provider
    (cherry picked from commit ec5d10654285cab2f2e5461d098330cee0333048)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1462774

@masayag masayag deleted the find_datastore_within_provider branch June 27, 2018 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants