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

Try both API versions in raw_connect #132

Merged
merged 1 commit into from
Nov 7, 2017
Merged

Try both API versions in raw_connect #132

merged 1 commit into from
Nov 7, 2017

Conversation

jhernand
Copy link
Contributor

@jhernand jhernand commented Nov 6, 2017

Currently the raw_connect method needs to receive the version of the
API in order to work correctly. If it doesn't receive it it fails
because the method that determines it just doesn't exist (it is an
instance method, but raw_connect is a class method). To avoid that
this patch changes the raw_connect method so that it tries with both
versions of the API.

This patch fixes partially the following bug:

Failed validation when adding RHV provider
https://bugzilla.redhat.com/1509432

@jhernand
Copy link
Contributor Author

jhernand commented Nov 6, 2017

@borod108 @masayag @pkliczewski @jntullo please review.

If/when this is merged we will be able to remove the scheme and version options from the call that the UI does to raw_connect.

v4_connection.test(raise_exception=true)
rescue Exception => exception
v4_error = exception
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not to have ensure here as for v3 below? Do we want to keep it open?

Copy link
Contributor

Choose a reason for hiding this comment

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

I saw the comment. Please ignore

@pkliczewski
Copy link
Contributor

@jhernand Can we fix codeclimate comments?

@borod108
Copy link
Contributor

borod108 commented Nov 6, 2017

@jhernand
Copy link
Contributor Author

jhernand commented Nov 6, 2017

@pkliczewski in the new version of the pull request I tried to address the style issues.

@borod108 probing via a queued request would mean two queued request, as the original call to raw_connect goes already via a queue. The result would be painfully slow.

@jhernand
Copy link
Contributor Author

jhernand commented Nov 6, 2017

@jhernand
Copy link
Contributor Author

jhernand commented Nov 6, 2017

@miq-bot add_label wip

I didn't test this with oVirt 3 yet, so please don't merge.

@jhernand jhernand changed the title Try both API versions in raw_connect [WIP] Try both API versions in raw_connect Nov 6, 2017
@miq-bot miq-bot added the wip label Nov 6, 2017
@pkliczewski
Copy link
Contributor

@jhernand Looks good to me, is it still WIP?

@jhernand
Copy link
Contributor Author

jhernand commented Nov 6, 2017

@pkliczewski yes, it is work in progress, I need to test that it works correctly with oVirt 3.6.

@jhernand jhernand changed the title [WIP] Try both API versions in raw_connect Try both API versions in raw_connect Nov 6, 2017
@jhernand
Copy link
Contributor Author

jhernand commented Nov 6, 2017

@miq-bot remove_label wip

Did some important changes to make this work with both versions of the API. I verified that it works correctly now for oVirt 4 and oVirt 3.

However, I also detected that the regression also affects the validation of the details of the C&U metrics endpoint. I am working on that. I'd suggest to merge this as a first step.

@miq-bot miq-bot removed the wip label Nov 6, 2017
@oourfali
Copy link
Contributor

oourfali commented Nov 6, 2017

@jhernand I'll merge once ci finishes.

@jhernand
Copy link
Contributor Author

jhernand commented Nov 6, 2017

Please don't merge, checking the connection works, but using it doesn't :-( .

@chessbyte chessbyte requested a review from agrare November 6, 2017 19:34
@agrare
Copy link
Member

agrare commented Nov 6, 2017

@jhernand confirmed this works for validation but not for normal connections. Looks like just fallout from moving a number of methods to class methods, let me know if there is anything I can do to help.

@jhernand
Copy link
Contributor Author

jhernand commented Nov 6, 2017

@agrare would be nice if you can take a look and help find the right Ruby way to call the resolve_ip_address method from both instance and class methods. The typical self.resolve_ip_address doesn't work. I guess that is related to the fact that the methods are defined in a concern, and using the class_methods mechanism. I am trying now to call them with self.class.resolve_ip_address, but I have to admit that I am a bit lost.

@agrare
Copy link
Member

agrare commented Nov 6, 2017

@jhernand you're right about self.class.resolve_ip_address but it wasn't working because they're private class methods.

Try with this patch:

diff --git a/app/models/manageiq/providers/redhat/infra_manager/api_integration.rb b/app/models/manageiq/providers/redhat/infra_manager/api_integration.rb
index d917e43..5c7d6e0 100644
--- a/app/models/manageiq/providers/redhat/infra_manager/api_integration.rb
+++ b/app/models/manageiq/providers/redhat/infra_manager/api_integration.rb
@@ -41,8 +41,8 @@ module ManageIQ::Providers::Redhat::InfraManager::ApiIntegration
     # Starting with version 4 of oVirt authentication doesn't work when using directly the IP address, it requires
     # the fully qualified host name, so if we received an IP address we try to convert it into the corresponding
     # host name:
-    if resolve_ip_addresses?
-      resolved = resolve_ip_address(connect_options[:server])
+    if self.class.resolve_ip_addresses?
+      resolved = self.class.resolve_ip_address(connect_options[:server])
       if resolved != connect_options[:server]
         _log.info("IP address '#{connect_options[:server]}' has been resolved to host name '#{resolved}'.")
         default_endpoint.hostname = resolved
@@ -266,8 +266,8 @@ module ManageIQ::Providers::Redhat::InfraManager::ApiIntegration
       # the fully qualified host name, so if we received an IP address we try to convert it into the corresponding
       # host name:
       resolved = server
-      if resolve_ip_addresses?
-        resolved = resolve_ip_address(server)
+      if self.class.resolve_ip_addresses?
+        resolved = self.class.resolve_ip_address(server)
         if resolved != server
           _log.info("IP address '#{server}' has been resolved to host name '#{resolved}'.")
         end
@@ -391,8 +391,6 @@ module ManageIQ::Providers::Redhat::InfraManager::ApiIntegration
       href && href.split("/").last
     end
 
-    private
-
     #
     # Checks if IP address to host name resolving is enabled.
     #

@jhernand
Copy link
Contributor Author

jhernand commented Nov 6, 2017

@agrare self.class seems to work, even if I don't remove the private, and I really would like to preserve the private. Unit tests are still failing, but I am getting close. Thanks!

@agrare
Copy link
Member

agrare commented Nov 6, 2017

@jhernand I had an issue with them being private when calling #connect

>> ExtManagementSystem.first.connect
NoMethodError: private method `resolve_ip_addresses?' called for #<Class:0x0055ca75d2e5c0>
	from /var/lib/gems/2.3.0/gems/activerecord-5.0.6/lib/active_record/dynamic_matchers.rb:21:in `method_missing'
	from /home/agrare/workspace/redhat/manageiq/plugins/manageiq-providers-ovirt/app/models/manageiq/providers/redhat/infra_manager/api_integration.rb:44:in `connect'

Is this logic that we could move into the raw_connect_v4 method? The comment states it starts in version 4.

@jhernand
Copy link
Contributor Author

jhernand commented Nov 6, 2017

@agrare the name resolution logic can't be moved to the raw_connect_v4 method. The reason is that the name resolution is needed in order to work with version 4 of the the oVirt server, regardless of what version of the API is used. Version 4 of the server supports versions 3 and 4 of the API, version 3 of the server only supports version 3 of the API. But the name resolution has to be done before knowing the version of the server.

@jhernand
Copy link
Contributor Author

jhernand commented Nov 7, 2017

@agrare you were right about the need to remove the private, unfortunately. I didn't find other way to make this work than removing it and using self.class to call those methods. It is ugly, but works. I marked them with @api private, hopefully future readers will understand.

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.

This looks good to me, just need to get the tests passing.

Currently the `raw_connect` method needs to receive the version of the
API in order to work correctly. If it doesn't receive it it fails
because the method that determines it just doesn't exist (it is an
instance method, but `raw_connect` is a class method). To avoid that
this patch changes the `raw_connect` method so that it tries with both
versions of the API.

This patch fixes partially the following bug:

  Failed validation when adding RHV provider
  https://bugzilla.redhat.com/1509432
@miq-bot
Copy link
Member

miq-bot commented Nov 7, 2017

Checked commit https://github.com/jhernand/manageiq-providers-ovirt/commit/30bf6a128a42b11813f383abf04861900111f25e with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0
8 files checked, 0 offenses detected
Everything looks fine. 👍

@jhernand
Copy link
Contributor Author

jhernand commented Nov 7, 2017

Dear reviewers, this is now, to the best of my understanding, working with oVirt 3 and oVirt 4, and it passes the tests. Please re-review.

@agrare agrare added the bug label Nov 7, 2017
@agrare agrare self-assigned this Nov 7, 2017
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.

👍 thanks so much @jhernand !

@agrare agrare merged commit cb185fc into ManageIQ:master Nov 7, 2017
@agrare agrare modified the milestone: Sprint 73 Ending Nov 13, 2017 Nov 7, 2017
simaishi pushed a commit that referenced this pull request Nov 7, 2017
@simaishi
Copy link
Contributor

simaishi commented Nov 7, 2017

Gaprindashvili backport details:

$ git log -1
commit 3bc6ba4b1f11bf7c8574e9a378dec8cbbde362ea
Author: Adam Grare <[email protected]>
Date:   Tue Nov 7 09:32:13 2017 -0500

    Merge pull request #132 from jhernand/try_both_api_versions_in_raw_connect
    
    Try both API versions in `raw_connect`
    (cherry picked from commit cb185fc11567f66ad71d2287e0bc99e9507420a5)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1510504

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.

7 participants