-
Notifications
You must be signed in to change notification settings - Fork 897
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 validation for conversion hosts #18135
Conversation
@miq-bot add_label blocker |
@@ -15,6 +15,16 @@ def source_vms | |||
vm_resources.where(:status => [ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_FAILED]).pluck(:resource_id) | |||
end | |||
|
|||
def validate_conversion_hosts | |||
transformation_mapping.transformation_mapping_items.each do |item| | |||
next unless %w(EmsCluster CloudTenant).include?(item.source_type) |
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.
You can do transformation_mapping.transformation_mapping_items.reject { |item| %w(EmsCluster CloudTenant).include?(item.source_type).each ...
def validate_conversion_hosts | ||
transformation_mapping.transformation_mapping_items.each do |item| | ||
next unless %w(EmsCluster CloudTenant).include?(item.source_type) | ||
ems = item.destination_type.constantize.find(item.destination_id).ext_management_system |
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 can just be item.destination.ext_management_system
, :destination
is polymorphic so rails basically does _type.find(_id)
for you
transformation_mapping.transformation_mapping_items.each do |item| | ||
next unless %w(EmsCluster CloudTenant).include?(item.source_type) | ||
ems = item.destination_type.constantize.find(item.destination_id).ext_management_system | ||
conversion_hosts = ConversionHost.all.select { |ch| ch.ext_management_system == 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.
Hm this is unfortunate, something like ConversionHost.select { |ch| ch.ext_management_system == ems }
would be nicer but we should really add an ems_id to ConversionHost
if we need to do this sort of thing so we don't need to load every 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 think it'd be better to add associations to ext_management_system like:
has_many :host_conversion_hosts, :through => :hosts, :source => :conversion_host
has_many :vm_conversion_hosts, :through => :vms, :source => :conversion_host
def conversion_hosts
host_conversion_hosts + vm_conversion_hosts
end
Checked commits fabiendupont/manageiq@0868e07~...8342dbb with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@jameswnl can you review? |
@miq-bot add-reviewer jameswnl |
@@ -15,6 +15,13 @@ def source_vms | |||
vm_resources.where(:status => [ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_FAILED]).pluck(:resource_id) | |||
end | |||
|
|||
def validate_conversion_hosts | |||
transformation_mapping.transformation_mapping_items.select { |item| %w(EmsCluster CloudTenant).include?(item.source_type) }.each do |item| | |||
return false if item.destination.ext_management_system.conversion_hosts.empty? |
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
transformation_mapping.transformation_mapping_items.select do |item|
%w(EmsCluster CloudTenant).include?(item.source_type)
end.all? do |item|
item.destination.ext_management_system.conversion_hosts.present?
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.
Nice syntax. Will try to remember it.
let(:host) { FactoryGirl.create(:host, :ext_management_system => FactoryGirl.create(:ext_management_system, :zone => FactoryGirl.create(:zone))) } | ||
let(:conversion_host) { FactoryGirl.create(:conversion_host, :resource => host) } | ||
|
||
it { expect(request.validate_conversion_hosts).to eq(false) } |
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.
use be false
instead of eq(false)
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.
Done.
@@ -5,6 +5,32 @@ | |||
ServiceResource.new(:resource => vm, :status => status) | |||
end | |||
end | |||
|
|||
let(:dst_ems) { FactoryGirl.create(:ext_management_system) } |
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.
Any reason not to move these let
s to be inside Line57?
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.
Done.
@@ -15,6 +15,13 @@ def source_vms | |||
vm_resources.where(:status => [ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_FAILED]).pluck(:resource_id) | |||
end | |||
|
|||
def validate_conversion_hosts |
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.
Will valid_conversion_hosts?
be a more obvious method name?
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.
Name already validated in ManageIQ/manageiq-automation_engine#263. It would mean changing it again.
let(:host) { FactoryGirl.create(:host, :ext_management_system => dst_ems) } | ||
let(:conversion_host) { FactoryGirl.create(:conversion_host, :resource => host) } | ||
|
||
it { expect(request.validate_conversion_hosts).to eq(false) } |
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.
be false
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.
Done.
|
||
it { expect(request.validate_conversion_hosts).to eq(false) } | ||
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.
Can you add a test for using vm
as 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.
Done.
@@ -1,10 +1,13 @@ | |||
require 'byebug' |
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'd that sneak in ;)
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.
Don't know. Where have you seen it ? 😆
@fdupont-redhat just remove the byebug then I'm good with this, @jameswnl what do you think? |
end | ||
|
||
context 'conversion host exists in EMS and resource is a Host' do | ||
let(:dst_ems) { FactoryGirl.create(:ems_redhat) } |
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 these lets be shared with the previous context? You can still keep the :dst_ems local
let(:plan) { ServiceTemplateTransformationPlan.create_catalog_item(catalog_item_options) } | ||
let(:request) { FactoryGirl.create(:service_template_transformation_plan_request, :source => plan) } | ||
|
||
it 'returns true' do |
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.
nitpick: how about it 'passes' do
?
let(:plan) { ServiceTemplateTransformationPlan.create_catalog_item(catalog_item_options) } | ||
let(:request) { FactoryGirl.create(:service_template_transformation_plan_request, :source => plan) } | ||
|
||
it 'returns false' do |
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.
nitpick: how about it 'fails' do
?
end | ||
|
||
context 'conversion host exists in EMS and resource is a Vm' do | ||
let(:dst_ems) { FactoryGirl.create(:ems_openstack) } |
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.
Similarly with these lets, some of them can be shared with previous contexts
Just realized I didn't hit the |
Add a validation for conversion hosts (cherry picked from commit 8340f7c) https://bugzilla.redhat.com/show_bug.cgi?id=1640816
Hammer backport details:
|
When a no conversion host is configured in the destination EMS, the migration tasks will stall because the throttler won't be able to assign a conversion host. To avoid hanging requests, we should check that at least one conversion host is available in the destination EMS. This PR implements a validation method in ServiceTemplateTransformationPlanRequest, that will be exposed in Automate.
Associated RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1640816