-
Notifications
You must be signed in to change notification settings - Fork 14
fixes #21 - add OS major/minor/name to yupana #333
fixes #21 - add OS major/minor/name to yupana #333
Conversation
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 suppose it would be easier to change the original regex and parse the OS name and major - minor parts from there directly.
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.
@patilsuraj767,
As @ShimShtein mentioned, you can make use of an existing os-release
regex.
Please verify & test below regex if that is helpful to you to add suggested changes related major/minor versions:
re.compile(r'(?P<name>[a-zA-Z\s]*)?\s*((?P<major>\d+)(\.(?P<minor>\d+)(\.(?P<patch>\d+))?)?)\s*(\((?P<code>\S*)\))?')
Codecov Report
@@ Coverage Diff @@
## master #333 +/- ##
==========================================
+ Coverage 94.04% 94.06% +0.02%
==========================================
Files 20 20
Lines 1393 1399 +6
Branches 158 160 +2
==========================================
+ Hits 1310 1316 +6
Misses 58 58
Partials 25 25
Continue to review full report at Codecov.
|
acb8d7b
to
56df138
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.
@patilsuraj767, added few inline comments.
@@ -254,7 +254,7 @@ def _transform_os_release(self, host: dict): | |||
return host | |||
|
|||
os_version = self._match_regex_and_find_version(os_release) |
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.
Would it be good to rename _match_regex_and_find_version
method as it is returning os
details?
@@ -229,22 +229,28 @@ def _remove_empty_mac_addresses(self, host: dict): | |||
)) | |||
return host | |||
|
|||
def _match_regex_and_find_version(self, os_release): | |||
def _match_regex_and_find_os_details(self, os_release): | |||
"""Match Regex with os_release and return os_version.""" |
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.
Could you update function description as well?
host['system_profile']['operating_system'] = {} | ||
host['system_profile']['operating_system']['major'] = os_details['major'] | ||
host['system_profile']['operating_system']['minor'] = os_details['minor'] | ||
|
||
if 'Red Hat' in os_details['name']: | ||
host['system_profile']['operating_system']['name'] = 'RHEL' | ||
else: | ||
host['system_profile']['operating_system']['name'] = os_details['name'].strip() |
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.
host['system_profile']['operating_system'] = {} | |
host['system_profile']['operating_system']['major'] = os_details['major'] | |
host['system_profile']['operating_system']['minor'] = os_details['minor'] | |
if 'Red Hat' in os_details['name']: | |
host['system_profile']['operating_system']['name'] = 'RHEL' | |
else: | |
host['system_profile']['operating_system']['name'] = os_details['name'].strip() | |
host['system_profile']['operating_system'] = { | |
'major': os_details['major'], | |
'minor': os_details['minor'], | |
'name': ('RHEL' if 'Red Hat' in os_details['name'] else os_details['name']).strip() } |
@@ -649,7 +653,8 @@ def test_transform_os_release_when_non_rhel_os(self): | |||
"""Test transform host os_release when non rhel.""" | |||
host = {'system_profile': {'os_release': 'CentOS Linux 7 (Core)'}} | |||
host = self.processor._transform_single_host(host) | |||
self.assertEqual(host, {'system_profile': {'os_release': '7'}}) | |||
self.assertEqual(host, {'system_profile': {'operating_system': { | |||
'major': '7', 'minor': '0', 'name': 'CentOS Linux'}, 'os_release': '7'}}) |
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 think according to the current schema this value of the name
field will not be accepted: https://github.com/RedHatInsights/inventory-schemas/blob/5b2fad998ca46b2a5f8e7e314d8cc0577487b581/schemas/system_profile/v1.yaml#L200
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.
Yes, you are right. maxLength
is 4.
Any suggestion regarding what should be the name
for Non-RHEL OS?
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.
Since it's defined an enum with a single value RHEL
, I think the field should be omitted, if it's a non-rhel host.
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.
@patilsuraj767,
In case of non-rhel hosts, could you just omit name
field from operating_system
and not the whole operating_system
key.
@ShimShtein, please correct me in case we will need to omit the operating_system
key itself.
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.
Agree with Kavita. I think omitting only name would be better in this case. As we discussed on IRC.
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.
Thank you @patilsuraj767.
Tested the changes. Works as expected.
LGTM 👍
@ShimShtein, do you have any additional comments?
In the schema major and minor defined as integers, after passing string values (example - "7", "8") for major/minor getting a result through host API. That's why as per offline discussion, merging this PR. |
Thank you @patilsuraj767 and @ShimShtein! |
No description provided.