Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

fixes #21 - add OS major/minor/name to yupana #333

Merged

Conversation

patilsuraj767
Copy link
Contributor

No description provided.

Copy link

@ShimShtein ShimShtein left a 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.

yupana/processor/report_slice_processor.py Outdated Show resolved Hide resolved
Copy link
Contributor

@kgaikwad kgaikwad left a 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-io
Copy link

codecov-io commented Dec 14, 2020

Codecov Report

Merging #333 (115b3f4) into master (6594011) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
yupana/processor/report_slice_processor.py 94.71% <100.00%> (+0.15%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6594011...115b3f4. Read the comment docs.

@patilsuraj767 patilsuraj767 force-pushed the YUPANA-21-add-OS-major-minor branch from acb8d7b to 56df138 Compare December 15, 2020 10:54
Copy link
Contributor

@kgaikwad kgaikwad left a 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.

yupana/processor/report_slice_processor.py Outdated Show resolved Hide resolved
@@ -254,7 +254,7 @@ def _transform_os_release(self, host: dict):
return host

os_version = self._match_regex_and_find_version(os_release)
Copy link
Contributor

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?

yupana/processor/report_slice_processor.py Outdated Show resolved Hide resolved
yupana/processor/report_slice_processor.py Outdated Show resolved Hide resolved
yupana/processor/report_slice_processor.py Outdated Show resolved Hide resolved
@@ -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."""
Copy link
Contributor

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?

Comment on lines 273 to 280
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()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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'}})

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

Copy link
Contributor Author

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?

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.

Copy link
Contributor

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.

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.

Copy link
Contributor

@kgaikwad kgaikwad left a 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?

@kgaikwad
Copy link
Contributor

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.

@kgaikwad kgaikwad merged commit 0104dd0 into quipucords:master Dec 29, 2020
@kgaikwad
Copy link
Contributor

Thank you @patilsuraj767 and @ShimShtein!

@kgaikwad kgaikwad mentioned this pull request Dec 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants