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

Adding the user_agent when is creating the connection #96

Merged
merged 2 commits into from
Nov 30, 2017

Conversation

CharlleDaniel
Copy link
Member

@CharlleDaniel CharlleDaniel commented Oct 30, 2017

This PR is able to:

  • Add the User-Agent when is creating the connection.

screenshot from 2017-10-27 17-47-47

@CharlleDaniel CharlleDaniel force-pushed the add_agent_label branch 3 times, most recently from b02ea0d to 5f1df73 Compare October 30, 2017 13:37
@CharlleDaniel
Copy link
Member Author

CharlleDaniel commented Oct 30, 2017

@AndreyMenezes

@CharlleDaniel CharlleDaniel force-pushed the add_agent_label branch 3 times, most recently from 704290a to 680d30e Compare October 30, 2017 20:39
@CharlleDaniel CharlleDaniel changed the title Added the user_agent when is creating the connection Adding the user_agent when is creating the connection Oct 30, 2017
@CharlleDaniel CharlleDaniel force-pushed the add_agent_label branch 2 times, most recently from 0139819 to 3b3cbc3 Compare October 31, 2017 14:10
@@ -20,10 +20,11 @@ def connect(options = {})
host = options[:host] || address
port = options[:port] || self.port
auth_type = AUTH_TYPES[options[:auth_type]]
user_agent_label = "ManageIQ/#{MiqServer.first.version}"
Copy link
Member

Choose a reason for hiding this comment

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

@rodneyhbrown7 @ManasaRaoK using cloudforms MiqServer.first.version will show the version of the cloudforms? Doesn't make sense to me expose the branch in this label. Do you have any particular request for this?

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't make any sense for me...

Copy link
Contributor

Choose a reason for hiding this comment

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

The goal is to be able to identify what client was communicating with LXCA. The version is just a way to identify what version of the client was used.

Copy link
Member

Choose a reason for hiding this comment

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

Oooh, now it's clear for me! Thanks @rodneyhbrown7 :D

Copy link
Member Author

Choose a reason for hiding this comment

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

So, @AndreyMenezes, @walteraa and @rodneyhbrown7 Could you review this PR, please? 👍

Copy link
Member

Choose a reason for hiding this comment

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

@rodneyhbrown7 I understand this, but for ManageIQ this call will get fine-3, fine-4, etc, depends on the branch of manageIQ. In cloudforms this call will return 4.5, 4.6, etc? Just to understand the expectancy.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should change the user_agent_label to "CFME/#{MiqServer.first.version}"

@rodneyhbrown7
Copy link
Contributor

@miq-bot add_label gaprindashvili/yes

@@ -20,10 +20,11 @@ def connect(options = {})
host = options[:host] || address
port = options[:port] || self.port
auth_type = AUTH_TYPES[options[:auth_type]]
user_agent_label = "ManageIQ/#{MiqServer.first.version}"
Copy link
Member

Choose a reason for hiding this comment

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

Once it always will be the same value and it isn't defined through options, I recommend it should be a constant.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I can accept the constant. But it shouldn't be the first.version, because when the build change MIQ create another entry to this table. So, it should be last.version.

Copy link
Member

Choose a reason for hiding this comment

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

I disagree with you @AndreyMenezes. This value is coming from a file named VERSION which is in the ManageIQ root, the point is: how to know what ManageIQ is instantiating the client, it could be the first, the last or another between both of them.

It is coming from this stack:

manageiq/app/models/miq_server.rb

class MiqServer < ApplicationRecord
(...)
     self.version    = Vmdb::Appliance.VERSION
end
(...)

manageiq/lib/vmdb/appliance.rb

module Vmdb
  module Appliance
    def self.VERSION
      @EVM_VERSION ||= File.read(File.join(File.expand_path(Rails.root), "VERSION")).strip
    end
(...)
end
end

manageiq/lib/vmdb/appliance.rb

@rodneyhbrown7 @CharlleDaniel is there a way to know what server is instantiating the client and then perform a kind of MiqServer.find and then getting the .version variable?

Copy link
Member

Choose a reason for hiding this comment

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

@walteraa I got it! the find should be perfect! I'm thinking we only can have the last build server, but I'm wrong!

@@ -4,6 +4,7 @@
describe ManageIQ::Providers::Lenovo::PhysicalInfraManager do
before :all do
@auth = { :user => 'admin', :pass => 'smartvm', :host => 'localhost', :port => '3000' }
FactoryGirl.create(:miq_server, :version=>'master')
end

Copy link
Member

Choose a reason for hiding this comment

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

Isn't interesting add a test to check the :user_agent_label, I mean, is it possible?

Copy link
Contributor

Choose a reason for hiding this comment

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

We should make sure that the :user_agent_label matches the :version added by FactoryGirl. Is that possible Charlle?

@walteraa
Copy link
Member

walteraa commented Nov 6, 2017

LGTM

@walteraa
Copy link
Member

walteraa commented Nov 6, 2017

@miq-bot assign @juliancheal

@miq-bot miq-bot assigned juliancheal and unassigned rodneyhbrown7 Nov 6, 2017
Copy link
Contributor

@rodneyhbrown7 rodneyhbrown7 left a comment

Choose a reason for hiding this comment

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

Charlle the spec test for this seems to have gone away? Is there anything we can do to do some spec testing here?

@@ -4,6 +4,7 @@
describe ManageIQ::Providers::Lenovo::PhysicalInfraManager do
before :all do
@auth = { :user => 'admin', :pass => 'smartvm', :host => 'localhost', :port => '3000' }
FactoryGirl.create(:miq_server, :version=>'master')
end

Copy link
Contributor

Choose a reason for hiding this comment

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

We should make sure that the :user_agent_label matches the :version added by FactoryGirl. Is that possible Charlle?

@@ -8,6 +8,8 @@ module ManageIQ::Providers::Lenovo::ManagerMixin
nil => 'basic_auth'
}.freeze

USER_AGENT = "CFME/#{MiqServer.last&.version}".freeze
Copy link
Member

Choose a reason for hiding this comment

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

Do not use the string "CFME" as part of the user agent string. CFME is a downstream Red Hat thing only, and upstream you should use ManageIQ. You can get the correct string by using I18n.t("product.name"). That being said, you probably should not access the i18n catalog at the class-level context, so I recommend putting this into a method instead. On that note, this seems like something that might be useful for every provider, so I would be OK with a class method in the core repo to get the user agent string.

Additionally, don't use MiqServer.last as you are technically then getting a random server object. Instead, if you are going for the version, prefer Vmdb::Appliance::VERSION or if you want the build number, Vmdb::Appliance::BUILD.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Fryguy and @juliancheal thanks for help me, I will work on this.

@juliancheal
Copy link
Member

juliancheal commented Nov 7, 2017

I've created two PRs that we could use (once they're merged)

It would be called by Vmdb::Appliance.USER_AGENT

@CharlleDaniel CharlleDaniel changed the title Adding the user_agent when is creating the connection [WIP]Adding the user_agent when is creating the connection Nov 7, 2017
@miq-bot miq-bot added the wip label Nov 7, 2017
@gberginc
Copy link

gberginc commented Nov 8, 2017

@juliancheal should you label them for the G-release because of this PR?

@miq-bot
Copy link
Member

miq-bot commented Nov 8, 2017

This pull request is not mergeable. Please rebase and repush.

@@ -8,6 +8,8 @@ module ManageIQ::Providers::Lenovo::ManagerMixin
nil => 'basic_auth'
}.freeze

USER_AGENT = "CFME/#{MiqServer.last&.version}".freeze
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be CFME, we should change this to a variable configurable from the settings. I think there might be something already like that.

maybe build would be ok to use?

I've posted a question in gitter.

@juliancheal
Copy link
Member

juliancheal commented Nov 27, 2017

ManageIQ/manageiq#16410 is merged now. You can use Vmdb::Appliance.USER_AGENT

@CharlleDaniel CharlleDaniel force-pushed the add_agent_label branch 2 times, most recently from b1f155a to 6557415 Compare November 27, 2017 20:57
@CharlleDaniel CharlleDaniel changed the title [WIP]Adding the user_agent when is creating the connection Adding the user_agent when is creating the connection Nov 27, 2017
@miq-bot miq-bot removed the wip label Nov 27, 2017
Vmdb::Appliance.USER_AGENT was called with ::USER_AGENT not .USER_AGENT
@miq-bot
Copy link
Member

miq-bot commented Nov 29, 2017

Checked commits CharlleDaniel/manageiq-providers-lenovo@940987a~...8f00e70 with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🍰

@juliancheal
Copy link
Member

My bad, waiting on ManageIQ/manageiq#16556 to be merged. THEN we'll be good to go.

@juliancheal juliancheal merged commit b3ab7f7 into ManageIQ:master Nov 30, 2017
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.

8 participants