From f759b5463b5814a07235dbed3c0c760b938968a3 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Wed, 23 Jan 2019 17:45:00 -0800 Subject: [PATCH] Backport #47219 fixes Python 3.7 bugs * Resolve invalid-unary-operand-type. * Resolve stop-iteration-return. (cherry-picked from c24c19594e4c4cddfda3226d49f8eeabacb18162) --- changelogs/fragments/py37_misc_module_backports.yaml | 6 ++++++ lib/ansible/modules/clustering/consul_kv.py | 2 +- lib/ansible/modules/network/cnos/cnos_backup.py | 2 +- lib/ansible/modules/network/cnos/cnos_image.py | 2 +- lib/ansible/modules/packaging/os/apt_repository.py | 1 - lib/ansible/modules/storage/netapp/netapp_e_storagepool.py | 5 ++++- 6 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/py37_misc_module_backports.yaml diff --git a/changelogs/fragments/py37_misc_module_backports.yaml b/changelogs/fragments/py37_misc_module_backports.yaml new file mode 100644 index 00000000000..2cf3d6c68d4 --- /dev/null +++ b/changelogs/fragments/py37_misc_module_backports.yaml @@ -0,0 +1,6 @@ +bugfixes: +- consul_kv - minor error-handling bugfix under Python 3.7 (https://github.com/ansible/ansible/pull/47219) +- cnos_backup - fixed syntax error (https://github.com/ansible/ansible/pull/47219) +- cnos_image - fixed syntax error (https://github.com/ansible/ansible/pull/47219) +- apt_repository - fixed failure under Python 3.7 (https://github.com/ansible/ansible/pull/47219) +- netapp_e_storagepool - fixed failure under Python 3.7 (https://github.com/ansible/ansible/pull/47219) diff --git a/lib/ansible/modules/clustering/consul_kv.py b/lib/ansible/modules/clustering/consul_kv.py index 7028c8ac5f4..16d0ae8f1eb 100644 --- a/lib/ansible/modules/clustering/consul_kv.py +++ b/lib/ansible/modules/clustering/consul_kv.py @@ -233,7 +233,7 @@ def set_value(module): value = module.params.get('value') if value is NOT_SET: - raise AssertionError('Cannot set value of "%s" to `NOT_SET`', (key, )) + raise AssertionError('Cannot set value of "%s" to `NOT_SET`' % key) index, changed = _has_value_changed(consul_api, key, value) diff --git a/lib/ansible/modules/network/cnos/cnos_backup.py b/lib/ansible/modules/network/cnos/cnos_backup.py index 6088ccd8767..a303cac9c0d 100644 --- a/lib/ansible/modules/network/cnos/cnos_backup.py +++ b/lib/ansible/modules/network/cnos/cnos_backup.py @@ -213,7 +213,7 @@ def doConfigBackUp(module, prompt, answer): elif(protocol == "tftp"): command = "copy " + configType + " " + protocol + " " + protocol command = command + "://" + server + "/" + confPath - command = command + + " vrf management\n" + command = command + " vrf management\n" # cnos.debugOutput(command) tftp_cmd = [{'command': command, 'prompt': None, 'answer': None}] cmd.extend(tftp_cmd) diff --git a/lib/ansible/modules/network/cnos/cnos_image.py b/lib/ansible/modules/network/cnos/cnos_image.py index d7da989cd80..fb17b150248 100644 --- a/lib/ansible/modules/network/cnos/cnos_image.py +++ b/lib/ansible/modules/network/cnos/cnos_image.py @@ -175,7 +175,7 @@ def doImageDownload(module, prompt, answer): elif(protocol == "tftp"): command = "copy " + protocol + " " + protocol + "://" + server command = command + "/" + imgPath + " system-image " + imgType - command = command + + " vrf management" + command = command + " vrf management" prompt = ['Confirm download operation', 'Do you want to change that to the standby image'] answer = ['y', 'y'] diff --git a/lib/ansible/modules/packaging/os/apt_repository.py b/lib/ansible/modules/packaging/os/apt_repository.py index 20b83ce108d..84972f40432 100644 --- a/lib/ansible/modules/packaging/os/apt_repository.py +++ b/lib/ansible/modules/packaging/os/apt_repository.py @@ -184,7 +184,6 @@ class SourcesList(object): for n, valid, enabled, source, comment in sources: if valid: yield file, n, enabled, source, comment - raise StopIteration def _expand_path(self, filename): if '/' in filename: diff --git a/lib/ansible/modules/storage/netapp/netapp_e_storagepool.py b/lib/ansible/modules/storage/netapp/netapp_e_storagepool.py index daa63084c41..d98cecbd2dc 100644 --- a/lib/ansible/modules/storage/netapp/netapp_e_storagepool.py +++ b/lib/ansible/modules/storage/netapp/netapp_e_storagepool.py @@ -145,7 +145,10 @@ class GroupBy(object): def _grouper(self, tgtkey): while self.currkey == tgtkey: yield self.currvalue - self.currvalue = next(self.it) # Exit on StopIteration + try: + self.currvalue = next(self.it) # Exit on StopIteration + except StopIteration: + return self.currkey = self.keyfunc(self.currvalue)