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 validation for conversion hosts #18135

Merged
merged 4 commits into from
Oct 31, 2018
Merged

Conversation

ghost
Copy link

@ghost ghost commented Oct 26, 2018

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

@ghost ghost closed this Oct 26, 2018
@ghost ghost reopened this Oct 26, 2018
@ghost
Copy link
Author

ghost commented Oct 26, 2018

@miq-bot add-label transformation, enhancement, hammer/yes
@miq-bot add-reviewer agrare

@JPrause
Copy link
Member

JPrause commented Oct 26, 2018

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

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

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

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.

Copy link
Member

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

@miq-bot
Copy link
Member

miq-bot commented Oct 30, 2018

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
3 files checked, 0 offenses detected
Everything looks fine. 🏆

@agrare
Copy link
Member

agrare commented Oct 30, 2018

@jameswnl can you review?

@ghost
Copy link
Author

ghost commented Oct 30, 2018

@miq-bot add-reviewer jameswnl

@miq-bot miq-bot requested a review from jameswnl October 30, 2018 15:46
@@ -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?
Copy link
Contributor

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

Copy link
Author

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) }
Copy link
Contributor

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)

Copy link
Author

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) }
Copy link
Contributor

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 lets to be inside Line57?

Copy link
Author

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

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?

Copy link
Author

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) }
Copy link
Contributor

Choose a reason for hiding this comment

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

be false

Copy link
Author

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

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?

Copy link
Author

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

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 ;)

Copy link
Author

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 ? 😆

@agrare
Copy link
Member

agrare commented Oct 31, 2018

@fdupont-redhat just remove the byebug then I'm good with this, @jameswnl what do you think?

@agrare agrare merged commit 8340f7c into ManageIQ:master Oct 31, 2018
@agrare agrare added this to the Sprint 98 Ending Nov 5, 2018 milestone Oct 31, 2018
end

context 'conversion host exists in EMS and resource is a Host' do
let(:dst_ems) { FactoryGirl.create(:ems_redhat) }
Copy link
Contributor

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

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

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) }
Copy link
Contributor

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

@jameswnl
Copy link
Contributor

Just realized I didn't hit the submit after adding these comments 😢

simaishi pushed a commit that referenced this pull request Nov 1, 2018
@simaishi
Copy link
Contributor

simaishi commented Nov 1, 2018

Hammer backport details:

$ git log -1
commit 898d25b81c271b2b35ac0969d577e93f06b33d3b
Author: Adam Grare <agrare@redhat.com>
Date:   Wed Oct 31 13:58:06 2018 -0400

    Merge pull request #18135 from fdupont-redhat/bz1640816
    
    Add a validation for conversion hosts
    
    (cherry picked from commit 8340f7c01af08acbcf76623ed562019b8bdb52d3)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1640816

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