From c7899e384a3427603bea58746615e7b24647c51f Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 24 May 2021 20:28:22 +0000 Subject: [PATCH] rhsm_release: Fix the issue that rhsm_release module considers 8, 7Client and 7Workstation as invalid releases (#2571) (#2605) * rhsm_release: Fix the issue that rhsm_release module considers 8, 7Client and 7Workstation as invalid releases. * Fix the unit test error: The new release_matcher could pass a wider range of patterns but that would not cause extra issue to the whole module. * Submit the changelog fragment. * Update changelogs/fragments/2571-rhsm_release-fix-release_matcher.yaml Co-authored-by: Amin Vakil Co-authored-by: Amin Vakil (cherry picked from commit 593d622438dd2a7aada0ccb762446df4ebb1a6ac) Co-authored-by: Tong He <68936428+unnecessary-username@users.noreply.github.com> --- .../fragments/2571-rhsm_release-fix-release_matcher.yaml | 2 ++ plugins/modules/packaging/os/rhsm_release.py | 6 +++--- .../unit/plugins/modules/packaging/os/test_rhsm_release.py | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/2571-rhsm_release-fix-release_matcher.yaml diff --git a/changelogs/fragments/2571-rhsm_release-fix-release_matcher.yaml b/changelogs/fragments/2571-rhsm_release-fix-release_matcher.yaml new file mode 100644 index 0000000000..764743303f --- /dev/null +++ b/changelogs/fragments/2571-rhsm_release-fix-release_matcher.yaml @@ -0,0 +1,2 @@ +bugfixes: + - rhsm_release - fix the issue that module considers 8, 7Client and 7Workstation as invalid releases (https://github.com/ansible-collections/community.general/pull/2571). diff --git a/plugins/modules/packaging/os/rhsm_release.py b/plugins/modules/packaging/os/rhsm_release.py index 22b280f1fc..a4d8f71197 100644 --- a/plugins/modules/packaging/os/rhsm_release.py +++ b/plugins/modules/packaging/os/rhsm_release.py @@ -56,9 +56,9 @@ from ansible.module_utils.basic import AnsibleModule import re -# Matches release-like values such as 7.2, 6.10, 10Server, -# but rejects unlikely values, like 100Server, 100.0, 1.100, etc. -release_matcher = re.compile(r'\b\d{1,2}(?:\.\d{1,2}|Server)\b') +# Matches release-like values such as 7.2, 5.10, 6Server, 8 +# but rejects unlikely values, like 100Server, 1.100, 7server etc. +release_matcher = re.compile(r'\b\d{1,2}(?:\.\d{1,2}|Server|Client|Workstation|)\b') def _sm_release(module, *args): diff --git a/tests/unit/plugins/modules/packaging/os/test_rhsm_release.py b/tests/unit/plugins/modules/packaging/os/test_rhsm_release.py index a75ec69448..98db6e2840 100644 --- a/tests/unit/plugins/modules/packaging/os/test_rhsm_release.py +++ b/tests/unit/plugins/modules/packaging/os/test_rhsm_release.py @@ -125,13 +125,12 @@ class RhsmRepositoryReleaseModuleTestCase(ModuleTestCase): def test_release_matcher(self): # throw a few values at the release matcher -- only sane_values should match - sane_values = ['1Server', '10Server', '1.10', '10.0'] + sane_values = ['1Server', '1Client', '10Server', '1.10', '10.0', '9'] insane_values = [ '6server', # lowercase 's' '100Server', # excessively long 'x' component - '100.0', # excessively long 'x' component - '6.100', # excessively long 'y' component '100.100', # excessively long 'x' and 'y' components + '+.-', # illegal characters ] matches = self.module.release_matcher.findall(' '.join(sane_values + insane_values))