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 a virtual column for supports_block_storage? and supports_cloud_object_store_container_create? #15600

Merged
merged 7 commits into from Jul 27, 2017

Conversation

AparnaKarve
Copy link
Contributor

The following API (that used to work before), returns an empty list currently since APIs do not support filtering on non-column methods anymore.

/api/providers?expand=resources&attributes=id,name&filter[]=supports_block_storage?=true

The solution is to add a new virtual column: v_supports_block_storage for supports_block_storage?.
And while at it, the ? was dropped from the original name to make it more friendly in the API-based URLs

https://bugzilla.redhat.com/show_bug.cgi?id=1471162
https://bugzilla.redhat.com/show_bug.cgi?id=1471110

@AparnaKarve
Copy link
Contributor Author

AparnaKarve commented Jul 19, 2017

@imtayadeway Please review. Thanks.

EDIT: Note that alias_method :v_supports_block_storage, :supports_block_storage? does not work hence I had to write a method for v_supports_block_storage

Once the review is done, I also need to make identical changes for supports_cloud_object_store_container_create?

Copy link
Contributor

@imtayadeway imtayadeway left a comment

Choose a reason for hiding this comment

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

Looks great! Just one request!

Was this the only column that needed to be added?

@@ -143,6 +143,7 @@ def hostname_uniqueness_valid?
virtual_column :total_vms_never, :type => :integer
virtual_column :total_vms_suspended, :type => :integer
virtual_total :total_subnets, :cloud_subnets
virtual_column :v_supports_block_storage, :type => :boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC, I think we were trying to prevent adding further v_ methods, so this could be :supports_block_storage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, not a problem. I can make it :supports_block_storage.

@AparnaKarve
Copy link
Contributor Author

Was this the only column that needed to be added?

@imtayadeway You are correct, there is one more column.
I wanted to get :supports_block_storage reviewed first and then apply identical changes for :supports_cloud_object_store_container_create.

@AparnaKarve AparnaKarve force-pushed the bz1471162 branch 2 times, most recently from 5a133dc to 42dce7e Compare July 19, 2017 18:11
@AparnaKarve AparnaKarve changed the title Add a virtual column for supports_block_storage? Add a virtual column for supports_block_storage? and supports_cloud_object_store_container_create? Jul 19, 2017
@@ -542,6 +544,14 @@ def total_vms_never; vm_count_by_state("never"); end

def total_vms_suspended; vm_count_by_state("suspended"); end

def supports_block_storage
Copy link
Contributor

Choose a reason for hiding this comment

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

@durandom any idea why alias would not work here? With alias supports_block_storage supports_block_storage?:

ems.supports_block_storage? # => true
ems.supports_block_storage # => false

Copy link
Member

Choose a reason for hiding this comment

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

maybe because you've added the alias before the block storage mixing got included?
the supports_feature_mixin defaults all features to unsupported. once it's supported it defines another method.

I tried to remove this in #11322 - but unfortunately that PR got stale

Copy link
Contributor

@imtayadeway imtayadeway left a comment

Choose a reason for hiding this comment

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

Thanks @AparnaKarve ! 🍰

Copy link
Member

@durandom durandom left a comment

Choose a reason for hiding this comment

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

is that the case for all other features in the supports feature mixin?
I mean, should they be queryable via the REST api?

If so, I would add those virtual columns in the supports_feature_mixin

@@ -542,6 +544,14 @@ def total_vms_never; vm_count_by_state("never"); end

def total_vms_suspended; vm_count_by_state("suspended"); end

def supports_block_storage
Copy link
Member

Choose a reason for hiding this comment

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

maybe because you've added the alias before the block storage mixing got included?
the supports_feature_mixin defaults all features to unsupported. once it's supported it defines another method.

I tried to remove this in #11322 - but unfortunately that PR got stale

@@ -234,6 +234,18 @@
provider_region "us-east-1"
end

factory :ems_amazon_storage_manager_ebs,
Copy link
Member

Choose a reason for hiding this comment

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

I would try not to add more provider specific factories. See below for another solution to test this


context "virtual column :supports_block_storage" do
it "returns true for Amazon EBS" do
ems_amz_ebs = FactoryGirl.create(:ems_amazon_storage_manager_ebs)
Copy link
Member

Choose a reason for hiding this comment

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

How about not using an amazon ems, but just a mock?

context "virtual column :supports_block_storage" do
  it "returns true if block storage is supported" do
    ems = FactoryGirl.build(:ems)
    allow(ems).to receive(:supports_block_storage?).and.return(true)
    expect(ems_amz_ebs.supports_block_storage).to eq(true)
  end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, if you recommend that.
I'm OK either ways - mock or not :-)

@miq-bot
Copy link
Member

miq-bot commented Jul 19, 2017

Checked commits AparnaKarve/manageiq@91b2e0f~...35a5f2c with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 🍰

@AparnaKarve
Copy link
Contributor Author

I would add those virtual columns in the supports_feature_mixin

@durandom That will not work. Getting this --

~/manageiq/app/models/mixins/supports_feature_mixin.rb:126:in `<module:SupportsFeatureMixin>': undefined method `virtual_column' for SupportsFeatureMixin:Module (NoMethodError)

If I'm not mistaken, you can use virtual_column only in the actual AR class.
(but I could be wrong)
Any suggestions on how to resolve the above error?

@durandom
Copy link
Member

I've created #15614 as a more generalized solution

@bronaghs
Copy link

@miq-bot assign @blomquisg

@miq-bot miq-bot assigned blomquisg and unassigned bronaghs Jul 24, 2017
@blomquisg
Copy link
Member

I'll merge this for the bug fixes. We can continue the conversation in #15614 as a possible refactoring effort.

@blomquisg blomquisg merged commit d7611ab into ManageIQ:master Jul 27, 2017
@blomquisg blomquisg added this to the Sprint 66 Ending Aug 7, 2017 milestone Jul 27, 2017
@simaishi
Copy link
Contributor

@AparnaKarve ManageIQ/manageiq-ui-classic#1711 depends on this PR and that's marked as fine/yes. I assume this PR should be fine/yes as well?

@AparnaKarve
Copy link
Contributor Author

@simaishi Yes. This needs to be fine/yes as well.

@AparnaKarve AparnaKarve deleted the bz1471162 branch July 28, 2017 14:27
simaishi pushed a commit that referenced this pull request Aug 9, 2017
Add a virtual column for `supports_block_storage?` and `supports_cloud_object_store_container_create?`
(cherry picked from commit d7611ab)

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

simaishi commented Aug 9, 2017

Fine backport details:

$ git log -1
commit ccbbe811bcce150e428ecb4a6d2999b40b171ba1
Author: Greg Blomquist <blomquisg@gmail.com>
Date:   Thu Jul 27 12:38:45 2017 -0400

    Merge pull request #15600 from AparnaKarve/bz1471162
    
    Add a virtual column for `supports_block_storage?` and `supports_cloud_object_store_container_create?`
    (cherry picked from commit d7611ab2ed3163ba7a89119d7ea17023aae784ec)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1478571
    https://bugzilla.redhat.com/show_bug.cgi?id=1479802

d-m-u pushed a commit to d-m-u/manageiq that referenced this pull request Jun 6, 2018
Add a virtual column for `supports_block_storage?` and `supports_cloud_object_store_container_create?`
(cherry picked from commit d7611ab)

https://bugzilla.redhat.com/show_bug.cgi?id=1478571
https://bugzilla.redhat.com/show_bug.cgi?id=1479802
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.

None yet

8 participants