-
Notifications
You must be signed in to change notification settings - Fork 898
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
Change ConversionHost resource_type validation #18434
Change ConversionHost resource_type validation #18434
Conversation
…ith new validation.
👍 |
spec/models/conversion_host_spec.rb
Outdated
@@ -6,8 +6,8 @@ | |||
context "provider independent methods" do | |||
let(:host) { FactoryBot.create(:host) } | |||
let(:vm) { FactoryBot.create(:vm_or_template) } | |||
let(:conversion_host_1) { FactoryBot.create(:conversion_host, :resource => host) } | |||
let(:conversion_host_2) { FactoryBot.create(:conversion_host, :resource => vm) } | |||
let(:conversion_host_1) { FactoryBot.create(:conversion_host, :skip_validate, :resource => host) } |
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.
how about creating the following vm
factory and so that you don't need to skip_validate
?
factory(:vm_support_conversion, :parent => :vm) do
after(:build) do |vm|
vm.stub(:supports_conversion_host?).and_return true
end
end
and similarly to the host?
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.
@jameswnl Seems using rspec-mocks inside factories no longer works. Take a look at the comments for spec/factories/dialog.rb, for example.
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.
yeah, so this works
factory(:vm_support_conversion, :parent => :vm) do
after(:build) do |obj|
def obj.supports_conversion_host?; true; end
end
end
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 think this is frowned upon, though. The only other factories that do this are tagged with TODO comments to fix them.
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.
ok, we can do a simple re-arrangement. After moving up the factory lines outside of context, use allow
in before do
as in 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.
How about using a host_redhat
factory? That should already supports_conversion_host?
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 did that originally, but @jameswnl complained since it's supposed to be provider independent methods.
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 see vm_openstack
above and host_redhat
below so while I completely agree with that we don't need to solve that problem right here.
We should probably define a vm_supports_conversion_host
factory in the future to handle this.
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.
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.
Too late, I already switched them back. :)
Note that I also had to add an ems since the redhat provider demands a minimum api_version.
…e specs to meet minimum ems version for rhev.
|
||
validates :address, | ||
:uniqueness => true, | ||
:format => { :with => Resolv::AddressRegex }, | ||
:inclusion => { :in => ->(conversion_host) { conversion_host.resource.ipaddresses } }, | ||
:unless => ->(conversion_host) { conversion_host.resource.blank? || conversion_host.resource.ipaddresses.blank? } | ||
|
||
validate :resource_supports_conversion_host |
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.
It would be really cool if we could delegate :supports_conversion_host?, :to => :resource
then just validate supports_conversion_host?
but it looks like supports_feature_mixin can't do this type of validation yet....
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.
Reasonable idea. Let's investigate this in a separate, refactoring 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.
I noticed that Rails 5.1 has delegate_missing_to
, so perhaps we can point that to resource
once we're on 5.1+.
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.
👍 LGTM
@miq-bot add_label hammer/yes |
…_validation Change ConversionHost resource_type validation (cherry picked from commit 6ecc883) https://bugzilla.redhat.com/show_bug.cgi?id=1696437
Hammer backport details:
|
This is something of a followup to #18277 where I think I got confused about how
resource_type
should be validated, thinking that STI would automatically kick in. But no, that's not how it works. Instead, since we're dealing with strings, it will fail in practice because theresource_type
will be e.g. 'ManageIQ::Providers::Openstack::CloudManager::Vm' rather than just 'Vm'.This PR removes hard coded string checks and instead relies on the individual providers to tell us if the resource supports conversion hosts or not. With both ManageIQ/manageiq-providers-ovirt#315 and ManageIQ/manageiq-providers-openstack#407 now merged, which implemented
supports :conversion_host
using theSupportsFeature
mixin, we can now use this in practice for validations intead.https://bugzilla.redhat.com/show_bug.cgi?id=1622728https://bugzilla.redhat.com/show_bug.cgi?id=1695797