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

Fixes #30627 - mac address is not required for virtual resources #7895

Merged
merged 1 commit into from
Aug 31, 2020

Conversation

domitea
Copy link
Contributor

@domitea domitea commented Aug 11, 2020

This fix is complementary to one of previous PR (#7366) where the field for enter MAC address in interface form of host detail is locked due to compute resource that is virtual resource (like AWS, Openstack... in that case MC address is provided).

So this PR only extends this behavior to API (and Hammer) related creation of host or interface. It add error where the mac address is set by request but it's not required due type of resource.

@domitea domitea changed the title Fixes #330627 - mac address is not required for virtual resources Fixes #30627 - mac address is not required for virtual resources Aug 11, 2020
@@ -45,6 +45,8 @@ class Base < ApplicationRecord
validates :subnet, :belongs_to_host_taxonomy => { :taxonomy => :organization }
validates :subnet6, :belongs_to_host_taxonomy => { :taxonomy => :organization }

before_create check_blank_mac_for_virtual_resources
Copy link
Member

Choose a reason for hiding this comment

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

I don't think adding validation error on before_create will work, alsow, you're running the method right away, instead of using the symbol.
Why dont you use following?

Suggested change
before_create check_blank_mac_for_virtual_resources
validate :check_blank_mac_for_virtual_resources

@@ -358,6 +360,12 @@ def interface_attribute_uniqueness(attr, base = Nic::Base.where(nil))
db_candidates = db_candidates.select { |c| c.id != id && in_memory_candidates.map(&:id).include?(c.id) }
errors.add(attr, :taken) if db_candidates.present?
end

def check_blank_mac_for_virtual_resources
if host.compute_provides?(:mac) && mac
Copy link
Member

@ezr-ondrej ezr-ondrej Aug 20, 2020

Choose a reason for hiding this comment

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

I'd prefer to be more verbose here:
EDIT: see Tomer's suggestion (I'd prefer his suggestion - present? over mine - !emtpy?)

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if host.compute_provides?(:mac) && mac
if host.compute_provides?(:mac) && mac.present?


def check_blank_mac_for_virtual_resources
if host.compute_provides?(:mac) && mac.present?
errors.add(:mac, _("can't be set for this compute resource because it's provided"))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
errors.add(:mac, _("can't be set for this compute resource because it's provided"))
errors.add(:mac, _("can't be set for this interface because it's provided by the compute resource"))

Copy link
Member

Choose a reason for hiding this comment

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

@domitea could you change this, please?

tbrisker
tbrisker previously approved these changes Aug 25, 2020
Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

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

LGTM, any other comments @ezr-ondrej ?

ezr-ondrej
ezr-ondrej previously approved these changes Aug 25, 2020
Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

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

LGTM as well, thanks @domitea ! 👍
Let's wait for tests?

@ezr-ondrej
Copy link
Member

Oh, the test failures are related, the factory host can't be built now, because the validation fails.

@domitea
Copy link
Contributor Author

domitea commented Aug 26, 2020

[test foreman]

@ezr-ondrej
Copy link
Member

ezr-ondrej commented Aug 26, 2020

tests are broken due to #7926 we need to wait for that and rebase on top of it.

@domitea domitea force-pushed the 30627_fix branch 3 times, most recently from 5bcfe18 to 53bdf53 Compare August 27, 2020 12:58
}
end


Choose a reason for hiding this comment

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

Layout/EmptyLines: Extra blank line detected.

@domitea
Copy link
Contributor Author

domitea commented Aug 27, 2020

@ezr-ondrej after struggling with tests I think that PR is ready to merge.

Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

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

Thanks @domitea ! 👍

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