-
Notifications
You must be signed in to change notification settings - Fork 982
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
Fixes #29110 - updated fact parser to handle v3 debian OS #7482
Fixes #29110 - updated fact parser to handle v3 debian OS #7482
Conversation
Issues: #29110 |
app/services/puppet_fact_parser.rb
Outdated
family = os.deduce_family || 'Operatingsystem' | ||
os.description = family.constantize.shorten_description facts[:lsbdistdescription] | ||
os.description = family.constantize.shorten_description(facts.dig(:os, :distro, :description).presence || facts[:lsbdistdescription]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here:
os.description = family.constantize.shorten_description(facts.dig(:os, :distro, :description).presence || facts[:lsbdistdescription]) | |
os.description = family.constantize.shorten_description(facts.dig(:os, :distro, :description) || facts[:lsbdistdescription]) |
test/test_helper.rb
Outdated
@@ -89,9 +89,20 @@ def after_teardown | |||
end | |||
end | |||
|
|||
module TestCaseNetworkStubExtensions | |||
def setup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Resolv.getaddress
and Resolv.getname
? Or are they covered because they just instantiate a Resolv::DNS
instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's how I understand the code however I haven't tested. Let me check.
test/test_helper.rb
Outdated
def setup | ||
Resolv::DNS.any_instance.stubs(:getname).returns("stubbed-host.example.com") | ||
Resolv::DNS.any_instance.stubs(:getnames).returns(["stubbed-host.example.com"]) | ||
Resolv::DNS.any_instance.stubs(:getaddress).returns("127.0.0.13") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As said on IRC, I think we should raise an exception and don't pretend it exists:
[4] pry(main)> Resolv.getaddress('doesnotexist.example.com')
Resolv::ResolvError: no address for doesnotexist.example.com
from /usr/share/ruby/resolv.rb:94:in `getaddress'
test/test_helper.rb
Outdated
Resolv::DNS.any_instance.stubs(:getname).returns("stubbed-host.example.com") | ||
Resolv::DNS.any_instance.stubs(:getnames).returns(["stubbed-host.example.com"]) | ||
Resolv::DNS.any_instance.stubs(:getaddress).returns("127.0.0.13") | ||
Resolv::DNS.any_instance.stubs(:getaddresses).returns(["127.0.0.13"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't pretend it exists:
[6] pry(main)> Resolv.getaddresses('doesnotexist.example.com')
=> []
Resolv::DNS.any_instance.stubs(:getaddresses).returns(["127.0.0.13"]) | |
Resolv::DNS.any_instance.stubs(:getaddresses).returns([]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok ok, I will do exceptions. I will do this in a separate PR tho, I want this one to be backported.
0d3652c
to
246fe36
Compare
Rebased, DNS stubs are out! |
Failure irrelevant? HostJSTest::hosts index multiple actions.test_0001_show action buttons |
A user on the discourse reports it worked for them. |
return "" if description.blank? | ||
s = description.dup | ||
s.gsub!('GNU/Linux', '') | ||
s.gsub!(/\(.+?\)/, '') | ||
s.squeeze! " " | ||
s.strip! | ||
s += '.' + minor unless s.include?('.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now it's hard to see what the benefit is. I assume you want to change Debian GNU/Linux 10 (buster)
into Debian 10.3
but I'm wondering if that's needed. Debian has dropped the use of minor versions since a few releases. Is there a reason we want to divert from the OS? Does the description column need to be unique?
Could you also add a test case for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description was previously "Debian 10", with the change it's gonna be "Debian 10.3".
Uniquness is a good question, I'd say yes we want it to be unique because that's the field we show in lists. You do not want to see this:
- Debian 10
- Debian 10
- Debian 10
- Debian 10
I vaguely remember that this field is preferred because users want to define their own naming convention e.g. RHEL 7.7 instead RedHat 7.7. So generally speaking, i'd rather keep them unique and do this patch than doing a big change on that.
We actually follow the same naming scheme for Red Hat systems and it makes sense to me. Every minor release of RHEL (I assume Debian too) has a installable tree (kickstart). To be able to install from different version trees, you actually need two OS entries otherwise you'd need to change minor version before every provisioning.
I will add a test case for this of couse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ekohl wait there is a test already, can you elaborate what you want me to do?
https://github.com/theforeman/foreman/pull/7482/files#diff-f6c009374a71e00e01084f53f35f47ba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering whether we should even store the minor for Debian since version 7 since it's more like a patch level. However, I think it may also influence boot media so from a fact handling perspective I think this is correct.
I'm having some doubts about making it a non-static method. Should we keep it static and pass the minor as an optional parameter. On the other hand, in many languages using static methods with class inheritance doesn't even work. The method is only used in the fact importer so the impact is minimal. Given my uncertainty on this area, I'd like someone more familiar with Ruby (on Rails) to take a look as well. @tbrisker perhaps?
For what it's worth, if I'd design this today, I'd move the shorten_description
into the PuppetFactParser
but that'd make this particular PR too big.
Passing attributes of an instance into method that is defined as static on the class is almost always a bad idea, no matter the language. What we had (static methods inheritance) is something that can only be used with some languages and IMHO is also generally a bad idea. This patch fixes it, I believe. I agree this would need an overhaul. If I had to pick, I'd rather work on the way we store reports, then facts :) |
@tbrisker mind having a look? |
I don't have a strong preference here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only thought regarding maybe keeping it as class method is that this is something we want to backport to stable releases, and the smaller the change the easier that will be.
Rebased conflicts. |
99a9198
to
1d9beab
Compare
@lzap ah, now i see you actually use an instance parameter in the debian one. I guess then it does make sense to make this into an instance method, although it is still a bit odd to me that it gets the description as a parameter and returns a new description rather than manipulating the instance's attributes directly. Still no idea regarding what makes sense from the debian install media pov |
1d9beab
to
51db133
Compare
It's been long, so I am rebasing. |
I've been assuming that @tbrisker would continue his review since he had comments. |
My only comment was that I don't know what makes sense regarding the install media path for debian, other than that i'm fine with this change. |
51db133
to
cffc41e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work just fine. The mediumpath doesn't contain the version, but the installer uses the distro code name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @lzap !
Please open CP PRs against stable branches, this does not cherry-pick cleanly. |
Done, they are associated to the ticket. Thanks! |
(cherry picked from commit 5d61c18)
(cherry picked from commit 5d61c18)
Added example JSON output from Facter v3 (VMWare, Debian 10.3) and
updated fact parser to handle LSB information from v3 "os" tree.
As part of this patch, I am adding stubbing of DNS calls as I noticed it
slows down fact tests 10x. Chances are there are other places in our
huge test codebase.