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

Fix discovery of version 4 of oVirt #69

Merged
merged 2 commits into from
Nov 21, 2016
Merged

Fix discovery of version 4 of oVirt #69

merged 2 commits into from
Nov 21, 2016

Conversation

jhernand
Copy link
Contributor

@jhernand jhernand commented Oct 10, 2016

Currently this gem tests for the presence of the oVirt engine sending a
request to the following URL:

http://.../engine.ssh.key.txt

This doesn't work with version 4 of the engine, as that path was
removed. In order to support older and newer versions of the engine this
patch modifies the gem so that it checks first the path that works since
version 3.5 of the engine, and then, if that doesn't work, the old path.

https://bugzilla.redhat.com/1382732

# Do nothing, just try the next candidate.
end
end
nil
Copy link
Member

@Fryguy Fryguy Oct 18, 2016

Choose a reason for hiding this comment

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

It might be cleaner to use .detect

def engine_ssh_public_key
  CANDIDATE_SSH_PUBLIC_KEY_PATHS.detect do |path|
    begin
      key = RestClient::Resource.new("#{base_uri}#{path}", resource_options).get
      key.present?
    rescue RestClient::ResourceNotFound, NoMethodError
      false # Do nothing, just try the next candidate.
    end
  end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not 100% sure how detect works, but my understanding is that in this case it would return the first path that passes the test, and what we want to do here is to return the key retrieved from that path, not the path itself.

Copy link
Member

Choose a reason for hiding this comment

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

Ah fair enough...I misread and mixed up key and path. Carry on :)

Copy link
Member

Choose a reason for hiding this comment

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

Do you need the key? or is just the presence of it important?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the message spam, but what I mean is, if you don't actually need the key itself, then you can keep the detect above and maybe rename the method to engine_ssh_public_key?, then the ovirt? method can be

     def self.ovirt?(options)
        options[:username] = options[:password] = "_unused"
        new(options).engine_ssh_public_key?
     end

@jhernand
Copy link
Contributor Author

The key isn't needed here, except for the tests: they check that it starts with ssh. That could be changed. However the engine_ssh_public_key is an instance method and isn't marked as private, so I'd say that the original intention was to use the method from outside this class, maybe from the provider. I checked in the provider source code and didn't find any use, but I can't be 100% sure that this isn't used somewhere else. Do you know if this gem is used outside of the provider? I believe it isn't, but I'd appreciate if you can confirm.

@Fryguy
Copy link
Member

Fryguy commented Oct 25, 2016

I don't believe this gem is used outside of the provider, but I don't think there's any real way to know. So, yeah, for SemVer reasons, you'll have to leave it as is, unless you cut a major version.

@jhernand
Copy link
Contributor Author

jhernand commented Nov 16, 2016

I have just verified that this works as expected with oVirt 3.x and oVirt 4.x.

@bdunne, @Fryguy please review/merge, and consider including the change in a new release of the gem.

Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

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

Please address the remaining rubocop comments (I suggested a solution to one of the issues). Then we can merge and release a new version. Thanks @jhernand

expect_any_instance_of(described_class).to receive(:engine_ssh_public_key).and_raise(RestClient::ResourceNotFound)
expect(described_class.ovirt?(:server => "127.0.0.1")).to be false
context "#ssh_public_key" do
BASE_URI = "https://nobody.com"
Copy link
Member

Choose a reason for hiding this comment

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

You could use let to define these strings then refer to it like a method call in your tests.

let(:base_uri) { "https://nobody.com" }

@bdunne
Copy link
Member

bdunne commented Nov 18, 2016

@jhernand I'm okay with the unhandled exception rubocop issue since it is well documented.

Currently this gem tests for the presence of the oVirt engine sending a
request to the following URL:

  http://.../engine.ssh.key.txt

This doesn't work with version 4 of the engine, as that path was
removed. In order to support older and newer versions of the engine this
patch modifies the gem so that it checks first the path that works since
version 3.5 of the engine, and then, if that doesn't work, the old path.

Bug-Url: https://bugzilla.redhat.com/1382732
Signed-off-by: Juan Hernandez <juan.hernandez@redhat.com>
This patch changes ghe 'service_spec.rb' file so that it uses 'let'
instead of module constants, as otherwise Rubocop doesn't like that the
constants aren't frozen.

Signed-off-by: Juan Hernandez <juan.hernandez@redhat.com>
@jhernand
Copy link
Contributor Author

@bdunne I addressed your comments in the parts that are relevant for the patch, and introduced another patch in the pull request to address them in the parts that aren't relevant. Hopefully Rubocop will be satisfied now.

@miq-bot
Copy link
Member

miq-bot commented Nov 20, 2016

<github_pr_commenter_batch />Some comments on commits https://github.com/jhernand/ovirt/compare/3f438dea65f71dfa2ae389b73938947eb62e1a3d~...a170624ad8c2b631f29f1899fab426ee84455e67

spec/service_spec.rb

  • ⚠️ - 220 - Detected expect_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.

@miq-bot
Copy link
Member

miq-bot commented Nov 20, 2016

Checked commits https://github.com/jhernand/ovirt/compare/3f438dea65f71dfa2ae389b73938947eb62e1a3d~...a170624ad8c2b631f29f1899fab426ee84455e67 with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
2 files checked, 1 offense detected

lib/ovirt/service.rb

@jhernand
Copy link
Contributor Author

@bdunne bdunne merged commit 6eccd09 into ManageIQ:master Nov 21, 2016
bdunne added a commit that referenced this pull request Nov 21, 2016
- Fix discovery of oVirt v4 [#69]
- Allow passing params to Base#update, Update Vm#memory & Vm#guaranteed in one call to Vm#update_memory [#72]
- Update event map [#71]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants