diff options
author | Sam Doran <sdoran@redhat.com> | 2021-06-14 14:16:18 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-14 13:16:18 -0500 |
commit | fad56bd4e6aaba7fc9eadead97f1d5ff1f88193b (patch) | |
tree | e301bbb1f57a7e4cb1e5b1f4248c0b989fcc9ba0 | |
parent | f92f039ea7143ae348a1d253c150d18c10961ff7 (diff) | |
download | ansible-fad56bd4e6aaba7fc9eadead97f1d5ff1f88193b.tar.gz |
[stable-2.11] subversion - fix stack trace when getting repository information (#74405) (#74977)
* subversion - set LC_ALL for accurate command output parsing
When LC_ALL is not set, the output language of commands will differ based on locale. There
is a lot of history of trying to fix this. See the following pull requests:
https://github.com/ansible/ansible-modules-core/pull/4358
https://github.com/ansible/ansible-modules-core/pull/4358
This patch attempts to fix this my setting LC_ALL to a UTF-8 locale. Setting LC_ALL to C reintroduces this bug https://github.com/ansible/ansible-modules-core/issues/4178.
I'm sure there are some problems I am not seeing with setting this to en_US.UTF-8, but that is
the only way I could find to fix this bug without reintriducing the bug mentioned above.
* Rather than setting locale, just check for matches before trying to get groups
This is a pragmatic solution to avoid the stack trace since setting the locale correctly
to ensure message parsing is accurate is problematic.
* Improve regexps for finding revision and URL
(cherry picked from commit a8cf0196f7)
Co-authored-by: Sam Doran <sdoran@redhat.com>
-rw-r--r-- | changelogs/fragments/36498-subversion-fix-info-parsing.yml | 2 | ||||
-rw-r--r-- | lib/ansible/modules/subversion.py | 33 |
2 files changed, 31 insertions, 4 deletions
diff --git a/changelogs/fragments/36498-subversion-fix-info-parsing.yml b/changelogs/fragments/36498-subversion-fix-info-parsing.yml new file mode 100644 index 0000000000..d14605b6c0 --- /dev/null +++ b/changelogs/fragments/36498-subversion-fix-info-parsing.yml @@ -0,0 +1,2 @@ +bugfixes: + - subversion - fix stack trace when getting information about the repository (https://github.com/ansible/ansible/issues/36498) diff --git a/lib/ansible/modules/subversion.py b/lib/ansible/modules/subversion.py index c28471bf22..c62146af59 100644 --- a/lib/ansible/modules/subversion.py +++ b/lib/ansible/modules/subversion.py @@ -134,6 +134,13 @@ from ansible.module_utils.basic import AnsibleModule class Subversion(object): + + # Example text matched by the regexp: + # Révision : 1889134 + # 版本: 1889134 + # Revision: 1889134 + REVISION_RE = r'^\w+\s?:\s+\d+$' + def __init__(self, module, dest, repo, revision, username, password, svn_path, validate_certs): self.module = module self.dest = dest @@ -228,14 +235,28 @@ class Subversion(object): def get_revision(self): '''Revision and URL of subversion working directory.''' text = '\n'.join(self._exec(["info", self.dest])) - rev = re.search(r'^Revision:.*$', text, re.MULTILINE).group(0) - url = re.search(r'^URL:.*$', text, re.MULTILINE).group(0) + rev = re.search(self.REVISION_RE, text, re.MULTILINE) + if rev: + rev = rev.group(0) + else: + rev = 'Unable to get revision' + + url = re.search(r'^URL\s?:.*$', text, re.MULTILINE) + if url: + url = url.group(0) + else: + url = 'Unable to get URL' + return rev, url def get_remote_revision(self): '''Revision and URL of subversion working directory.''' text = '\n'.join(self._exec(["info", self.repo])) - rev = re.search(r'^Revision:.*$', text, re.MULTILINE).group(0) + rev = re.search(self.REVISION_RE, text, re.MULTILINE) + if rev: + rev = rev.group(0) + else: + rev = 'Unable to get remote revision' return rev def has_local_mods(self): @@ -250,7 +271,11 @@ class Subversion(object): def needs_update(self): curr, url = self.get_revision() out2 = '\n'.join(self._exec(["info", "-r", self.revision, self.dest])) - head = re.search(r'^Revision:.*$', out2, re.MULTILINE).group(0) + head = re.search(self.REVISION_RE, out2, re.MULTILINE) + if head: + head = head.group(0) + else: + head = 'Unable to get revision' rev1 = int(curr.split(':')[1].strip()) rev2 = int(head.split(':')[1].strip()) change = False |