From fae492324e4f4667d44be31893baa795ad7689d6 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Mon, 16 May 2016 14:11:15 +0200 Subject: [PATCH] Port the rest of the file to the 2.4/3 compatible syntax (#15873) Since the modules can use a paramiko transport (ergo python 2.4 syntax), we need to keep compat with 2.4 and python 3, so we need to use the get_exception trick, even if the various juniper libraries are not compatible with 2.4. --- lib/ansible/module_utils/junos.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/ansible/module_utils/junos.py b/lib/ansible/module_utils/junos.py index bf1a2f955d..5654816902 100644 --- a/lib/ansible/module_utils/junos.py +++ b/lib/ansible/module_utils/junos.py @@ -158,7 +158,8 @@ class Netconf(object): self.config = Config(self.device) - except Exception, exc: + except Exception: + exc = get_exception() self._fail('unable to connect to %s: %s' % (host, str(exc))) def run_commands(self, commands, **kwargs): @@ -169,9 +170,11 @@ class Netconf(object): try: resp = self.device.cli(command=cmd, format=fmt) response.append(resp) - except (ValueError, RpcError), exc: + except (ValueError, RpcError): + exc = get_exception() self._fail('Unable to get cli output: %s' % str(exc)) - except Exception, exc: + except Exception: + exc = get_exception() self._fail('Uncaught exception - please report: %s' % str(exc)) return response @@ -180,14 +183,16 @@ class Netconf(object): try: self.config.unlock() self._locked = False - except UnlockError, exc: + except UnlockError: + exc = get_exception() self.module.log('unable to unlock config: {0}'.format(str(exc))) def lock_config(self): try: self.config.lock() self._locked = True - except LockError, exc: + except LockError: + exc = get_exception() self.module.log('unable to lock config: {0}'.format(str(exc))) def check_config(self): @@ -200,7 +205,8 @@ class Netconf(object): if confirm and confirm > 0: kwargs['confirm'] = confirm return self.config.commit(**kwargs) - except CommitError, exc: + except CommitError: + exc = get_exception() msg = 'Unable to commit configuration: {0}'.format(str(exc)) self._fail(msg=msg) @@ -215,7 +221,8 @@ class Netconf(object): try: self.config.load(candidate, format=format, merge=merge, overwrite=overwrite) - except ConfigLoadError, exc: + except ConfigLoadError: + exc = get_exception() msg = 'Unable to load config: {0}'.format(str(exc)) self._fail(msg=msg) @@ -234,7 +241,8 @@ class Netconf(object): try: result = self.config.rollback(identifier) - except Exception, exc: + except Exception: + exc = get_exception() msg = 'Unable to rollback config: {0}'.format(str(exc)) self._fail(msg=msg)