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

Avoiding duplicated physical provider connection #16952

Closed

Conversation

douglasgabriel
Copy link
Member

This PR fix:
https://bugzilla.redhat.com/show_bug.cgi?id=1505610

This PR:

  • Disregards the slash at the end of hostname on the uniqueness validation;
  • Checks if hostname is an ipaddress, if true check if there isn't any discovered ipaddress on database with the same value;
  • If is a duplicated ipaddress, show the following message to user:
    image

@douglasgabriel
Copy link
Member Author

@miq-bot add_label gaprindashvili/yes

@douglasgabriel
Copy link
Member Author

@miq-bot add_label bug

@miq-bot miq-bot added the bug label Feb 5, 2018
@douglasgabriel
Copy link
Member Author

Hey @agrare, could you please take a look on this?

@agrare agrare self-assigned this Feb 7, 2018
@chargio
Copy link
Contributor

chargio commented Feb 12, 2018

Hi @agrare Did you have time to review this?

@agrare
Copy link
Member

agrare commented Feb 14, 2018

@douglasgabriel how is this related to #16714 ? Seems at least the trailing / shouldn't be possible.

Copy link
Member

@agrare agrare left a comment

Choose a reason for hiding this comment

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

Can you add some tests for the cases that you're trying to catch?

existing_hostnames = (self.class.all - [self]).map(&:hostname).compact.map(&:downcase)

errors.add(:hostname, N_("has to be unique per provider type")) if existing_hostnames.include?(hostname.downcase)
hostname_without_slash = hostname.downcase.gsub(/\/$/, '')
Copy link
Member

Choose a reason for hiding this comment

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

You're doing hostname.downcase.gsub() in a lot of places, can you add a normalized_hostname method that does this in one place?

if hostname.ipaddress?
existing_ipaddress = (self.class.all - [self]).map(&:ipaddress).compact.map { |ipaddress| ipaddress.gsub(/\/$/, '') }
errors.add(:ipaddress, N_("has to be unique per provider type")) if existing_ipaddress.include?(hostname_without_slash)
end
Copy link
Member

Choose a reason for hiding this comment

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

Under what circumstance would there be an EMS with an :ipaddress property that isn't equal to the :hostname?

Copy link
Member Author

Choose a reason for hiding this comment

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

You can bind a provider by the hostname or the ip address, and the ip address field always will be filled with the IP of the provider, in summary if the hostname is an ip address both hostname and ipaddress will be equals, else, will be differents. So when try to add a new provider by its ip address, the system must verify against hostname and ipaddress on the DB to ensure that will avoid duplicated providers.

Copy link
Member

Choose a reason for hiding this comment

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

and the ip address field always will be filled with the IP of the provider

Is this something the lenovo provider does? Because I don't think this is true across the board, I just tested with a VMware provider through the UI and the ipaddress wasn't filled in.

I also tested creating a provider with just an ipaddress (and no hostname) through a rails console and it threw an exception:
manageiq/app/models/ext_management_system.rb:99:in hostname_format_valid?': undefined method ipaddress?' for nil:NilClass (NoMethodError)

Copy link
Member Author

Choose a reason for hiding this comment

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

According with my tests, seems like that others providers doesn't fill the ipaddress field on the refresh routine, however all providers has this field, once that it is attached to an ExtManagementSystem and is shown on view through the "Discovered IP address" field on provider's table, as we can see on the image below:
image
In the particular case of Lenovo provider, the IP address is filled even the user regist the provider through its hostname, as we can see below:
image
So, without this verification added on this PR the user would be able to add the provider 10.243.9.123 (for example) again, if inform only its IP address on the hostname input.

@miq-bot
Copy link
Member

miq-bot commented Feb 15, 2018

Checked commit douglasgabriel@2033b2a with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 👍

@douglasgabriel
Copy link
Member Author

You are right @agrare, there's no need to treat the slash once that hostname_format_valid? doesn't allow the slash at the end of the hostname anymore.

@agrare
Copy link
Member

agrare commented Feb 22, 2018

I don't think that this is required, we've covered the majority of cases in your original PR.

If someone adds a provider by ipaddress then later by hostname should we nslookup the hostname to try to find if there is one matching the IP address? We can go crazy trying to prevent people from adding a duplicate provider but I don't think it is needed.

As long as they can remove the duplicate provider without any impacting the original provider then no harm is really done IMO.

@douglasgabriel
Copy link
Member Author

Yeah, I agree with you. And if @rodneyhbrown7 also agree, I can just close this PR

@rodneyhbrown7
Copy link

@douglasgabriel we can close this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants