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

[V2V] Use authentication_check instead of verify credentials #18880

Merged
merged 5 commits into from
Jul 9, 2019
Merged

[V2V] Use authentication_check instead of verify credentials #18880

merged 5 commits into from
Jul 9, 2019

Conversation

djberg96
Copy link
Contributor

@djberg96 djberg96 commented Jun 14, 2019

This alters the ConversionHost#eligible? method so that it calls the authentication_check method instead of verify_credentials directly.

Internally the authentication_check method calls the verify_credentials method, and then updates the authentications object, including the last_valid_on field. We use that field to skip the ssh connection check if it was valid within the last 15 minutes. This will help reduce unnecessary ssh connections if the method happens to be called multiple times in a short period of time, e.g. InfraConversionThrottler.start_conversions. Plus it reduces the chance of unexpected timeout errors, etc.

Update: The 15 minute idea was dropped in favor of just using the authentication_status_ok? method that already exists in the Authentication mixin.

WIP until I can get some tests added.

Some other updates included in this PR:

  • I set the default auth_type to "v2v" in the verify_credentials method.

  • I changed the resources in the throttler specs to be provider-specific.

  • I added an "RSpec" to the outer describe for future rspec 4 compliance.

  • I added the "v2v" tag to the throttler specs.

  • I changed "Max Transformation Runners" to "MaxTransformationRunners" because it was causing a deprecation warning:

DEPRECATION WARNING: Invalid custom attribute: 'Max Transformation Runners'. A custom attribute name must begin with a letter (a-z, but also letters with diacritical marks and non-Latin letters) or an underscore (_). Subsequent characters can be letters, underscores, digits (0-9), or dollar signs ($) (called from block (3 levels) in <top (required)> at /Users/dberger/Dev/manageiq-djberg96/spec/lib/infra_conversion_throttler_spec.rb:31)

Not exactly related, but does obliquely help with #18880 a bit.

Addresses https://bugzilla.redhat.com/show_bug.cgi?id=1723420

@djberg96
Copy link
Contributor Author

@fdupont-redhat What do you think?

@miq-bot miq-bot added the wip label Jun 14, 2019
@djberg96 djberg96 changed the title [WIP] [V2V] Use authentication_check instead of verify credentials [V2V] Use authentication_check instead of verify credentials Jun 17, 2019
@miq-bot miq-bot removed the wip label Jun 17, 2019
@djberg96
Copy link
Contributor Author

@miq-bot add_labels transformation, changelog/yes, hammer/yes

@djberg96
Copy link
Contributor Author

@miq-bot remove_label wip

@djberg96
Copy link
Contributor Author

@miq-bot add_reviewers @agrare @kbrock

@miq-bot
Copy link
Member

miq-bot commented Jun 17, 2019

@djberg96 'agrare kbrock' is an invalid reviewer, ignoring...

@djberg96
Copy link
Contributor Author

@miq-bot add_reviewers @agrare, @kbrock

@miq-bot
Copy link
Member

miq-bot commented Jun 17, 2019

@djberg96 'agrare, kbrock' is an invalid reviewer, ignoring...

@ghost
Copy link

ghost commented Jun 17, 2019

@miq-bot add-reviewer @agree
@miq-bot add-reviewer @kbrock

@miq-bot
Copy link
Member

miq-bot commented Jun 17, 2019

@fdupont-redhat 'agree' is an invalid reviewer, ignoring...

@miq-bot miq-bot requested a review from kbrock June 17, 2019 17:30
@ghost
Copy link

ghost commented Jun 17, 2019

@miq-bot add-reviewer @agrare

@miq-bot miq-bot requested a review from agrare June 17, 2019 18:29
@ghost
Copy link

ghost commented Jun 17, 2019

@djberg96 shouldn't verify_credentials return false if authentication was not invalid within the last X minutes ? X could be 2, to not attempt connection too frequently, but also not leave the host as ineligible during too long.

Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

I sure am getting distracted a lot by this code.

verify_credentials: this looks like it is copy/pasted across the code. Encouraging us to have different implementations when we answer the question "Are these credentials are valid?". This seems like a support nightmare.

heck connecting to ssh in general looks like it is scattered across a number of classes. Sure feels like it should be in helper class. grep 'uname -a'. Implemented 2 totally different ways.

It feels like 15 minutes will need to be configurable. Don't want to deal with it here, but it sure feels like an obvious request right around the corner.

And to be fair, just looking at the verify_credentials method has me wanting to refactor out the count(*) up front, move the require ssh down a few lines. And also understand why the 2 uname calls seem to connect to ssh in different ways.

eligible? is too high level and low level at the same time. (total tangent: I sure wish the task count wasn't in that method.)

app/models/conversion_host.rb Outdated Show resolved Hide resolved
app/models/conversion_host.rb Show resolved Hide resolved
lib/infra_conversion_throttler.rb Show resolved Hide resolved
@@ -25,18 +25,20 @@
allow(ems).to receive(:conversion_hosts).and_return([conversion_host1, conversion_host2])
allow(conversion_host1).to receive(:check_ssh_connection).and_return(true)
allow(conversion_host2).to receive(:check_ssh_connection).and_return(true)
allow(conversion_host1).to receive(:authentication_check).and_return([true, 'passed'])
allow(conversion_host2).to receive(:authentication_check).and_return([true, 'passed'])
Copy link
Member

Choose a reason for hiding this comment

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

keep this

but this stubbing is skipping actually testing the code.
try and keep stubbing to a method that provides just an external interface (e.g.: connect to ssh - or maybe even connect to the database, though that is suspect)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those particular tests are just checking the throttling, not sure what you mean.

app/models/conversion_host.rb Show resolved Hide resolved
@djberg96
Copy link
Contributor Author

@fdupont-redhat Not sure I'm following. Do you want me to add logic that checks Authentication#last_invalid_on as well?

@ghost
Copy link

ghost commented Jun 20, 2019

@fdupont-redhat Not sure I'm following. Do you want me to add logic that checks Authentication#last_invalid_on as well?

Yes. Otherwise for a host with invalid authentication, we'll do SSH connections until it becomes valid. I think we should evince it for a period of time. Maybe we could have the same check interval for both, no ? What about 5 minutes ? That would still lower the number of SSH connections, while limiting the risk of assigning an invalid host to a task.

@djberg96
Copy link
Contributor Author

@fdupont-redhat I split the difference and changed it to 10 minutes. Is that ok? 5 minutes seems too short.

I also updated it so that if it was invalid in the last 10 minutes it will still retry, even if it was also valid within that time. I updated the specs, too.

@djberg96
Copy link
Contributor Author

@kbrock Are you ok with it now?

@agrare agrare self-assigned this Jun 25, 2019
@djberg96
Copy link
Contributor Author

@miq-bot remove_label hammer/yes

@djberg96
Copy link
Contributor Author

@miq-bot add_label hammer/no

@agrare
Copy link
Member

agrare commented Jun 27, 2019

This looks better, @kbrock you good with this?

… 15 minutes.

Update specs to reflect changes in eligible? method.

Add v2v tag to InfraConversionThrottler specs.

Update host and vm in specs to be provider-specific, change custom task name to avoid deprecation warnings.

Stub the authentication_check method.

Add more specs for verify_credentials to validate that ssh calls are not made if already valid within last 15 minutes.
…ith validation if invalid within last 10 minutes.
@miq-bot
Copy link
Member

miq-bot commented Jul 8, 2019

Checked commits https://github.com/djberg96/manageiq/compare/5cd804f742be40b7c4af6e050322a72b3ba29a2d~...51bca563276aed4824113d500d2dd8d61fc03a1a with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
4 files checked, 0 offenses detected
Everything looks fine. 👍

@kbrock kbrock assigned kbrock and unassigned agrare Jul 9, 2019
@kbrock kbrock added this to the Sprint 116 Ending Jul 22, 2019 milestone Jul 9, 2019
@kbrock kbrock merged commit bceab36 into ManageIQ:master Jul 9, 2019
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.

4 participants