From 6169699b24c92fbcca10302d1e87b5641d42bae5 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 7 Jan 2026 20:50:56 +0100 Subject: [PATCH] [PR #11388/defd1560 backport][stable-12] pmem: remove redundant use of regexp (#11398) pmem: remove redundant use of regexp (#11388) * pmem: remove redundant use of regexp * add changelog frag * add bugfixes extry * Update plugins/modules/pmem.py * Update plugins/modules/pmem.py --------- (cherry picked from commit defd15609c45332c37bffb2df4dd94151fb62929) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Felix Fontein --- changelogs/fragments/11388-pmem-redundant-regexps.yml | 4 ++++ plugins/modules/pmem.py | 11 ++++------- 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/11388-pmem-redundant-regexps.yml diff --git a/changelogs/fragments/11388-pmem-redundant-regexps.yml b/changelogs/fragments/11388-pmem-redundant-regexps.yml new file mode 100644 index 0000000000..7f32bee927 --- /dev/null +++ b/changelogs/fragments/11388-pmem-redundant-regexps.yml @@ -0,0 +1,4 @@ +bugfixes: + - pmem - fix test for invalid data input (https://github.com/ansible-collections/community.general/pull/11388). +minor_changes: + - pmem - simplify text tests without using regular expression (https://github.com/ansible-collections/community.general/pull/11388). diff --git a/plugins/modules/pmem.py b/plugins/modules/pmem.py index 6ea0ee4a85..52e883b9ca 100644 --- a/plugins/modules/pmem.py +++ b/plugins/modules/pmem.py @@ -199,7 +199,6 @@ EXAMPLES = r""" """ import json -import re import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib, human_to_bytes @@ -493,19 +492,17 @@ class PersistentMemory: return ipmctl_opts def is_allocation_good(self, ipmctl_out, command): - warning = re.compile("WARNING") - error = re.compile(".*Error.*") - ignore_error = re.compile("Do you want to continue? [y/n] Error: Invalid data input.") + ignore_error = "Do you want to continue? [y/n] Error: Invalid data input." errmsg = "" rc = True for line in ipmctl_out.splitlines(): - if warning.match(line): + if line.startswith("WARNING"): errmsg = f"{line} (command: {command})" rc = False break - elif error.match(line): - if not ignore_error: + elif "Error" in line: + if not line.startswith(ignore_error): errmsg = f"{line} (command: {command})" rc = False break