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

Default to resource name for conversion hosts #18516

Merged
merged 4 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/models/conversion_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ConversionHost < ApplicationRecord

validate :resource_supports_conversion_host

before_validation :name, :default_name, :on => :create

include_concern 'Configurations'

# To be eligible, a conversion host must have the following properties
Expand Down Expand Up @@ -202,4 +204,10 @@ def tag_resource_as_disabled
resource.tag_add('v2v_transformation_host/false')
resource.tag_remove('v2v_transformation_method/vddk')
end

# Set the default name to the name of the associated resource.
#
def default_name
self.name ||= resource&.name
end
end
11 changes: 11 additions & 0 deletions spec/models/conversion_host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,15 @@
expect(conversion_host.errors[:resource].first).to eql("can't be blank")
end
end

context "name validation" do
let(:ems) { FactoryBot.create(:ems_redhat, :zone => FactoryBot.create(:zone), :api_version => '4.2.4') }
let(:redhat_host) { FactoryBot.create(:host_redhat, :name => 'foo', :ext_management_system => ems) }

it "defaults to the associated resource name if no name is explicitly provided" do
Copy link

Choose a reason for hiding this comment

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

Don't you also test with an OpenStack VM as resource ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For purposes of a validation spec it's not really necessary. We mostly just want to make sure the name is set, regardless of the associated resource type.

Copy link

Choose a reason for hiding this comment

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

Ok. Then LGTM.

conversion_host = ConversionHost.new(:resource => redhat_host)
expect(conversion_host.valid?).to be(true)
expect(conversion_host.name).to eql(redhat_host.name)
end
end
end