Convert the network subfolder to py3/py2.4 syntax (#3690)

This commit is contained in:
Michael Scherer 2016-05-18 18:08:30 +02:00 committed by Toshio Kuratomi
parent 368f8f0ac7
commit cc99fe24fc
21 changed files with 75 additions and 42 deletions

View file

@ -22,8 +22,8 @@ script:
- python2.4 -m compileall -fq cloud/amazon/_ec2_ami_search.py cloud/amazon/ec2_facts.py
- python2.6 -m compileall -fq .
- python2.7 -m compileall -fq .
- python3.4 -m compileall -fq system/ commands/ source_control/ inventory/ files/ databases/
- python3.5 -m compileall -fq system/ commands/ source_control/ inventory/ files/ databases/
- python3.4 -m compileall -fq system/ commands/ source_control/ inventory/ files/ databases/ network/
- python3.5 -m compileall -fq system/ commands/ source_control/ inventory/ files/ databases/ network/
- ansible-validate-modules --exclude 'utilities/' .
#- ansible-validate-modules --exclude 'cloud/amazon/ec2_lc\.py|cloud/amazon/ec2_scaling_policy\.py|cloud/amazon/ec2_scaling_policy\.py|cloud/amazon/ec2_asg\.py|cloud/azure/azure\.py|packaging/os/rhn_register\.py|network/openswitch/ops_template\.py|system/hostname\.py|utilities/' .
#- ./test-docs.sh core

View file

@ -226,7 +226,8 @@ def url_get(module, url, dest, use_proxy, last_mod_time, force, timeout=10, head
f = os.fdopen(fd, 'wb')
try:
shutil.copyfileobj(rsp, f)
except Exception, err:
except Exception:
err = get_exception()
os.remove(tempname)
module.fail_json(msg="failed to create temporary content file: %s" % str(err))
f.close()
@ -392,7 +393,8 @@ def main():
if os.path.exists(dest):
backup_file = module.backup_local(dest)
shutil.copyfile(tmpsrc, dest)
except Exception, err:
except Exception:
err = get_exception()
os.remove(tmpsrc)
module.fail_json(msg="failed to copy %s to %s: %s" % (tmpsrc, dest, str(err)))
changed = True

View file

@ -221,7 +221,8 @@ def write_file(module, url, dest, content):
f = open(tmpsrc, 'wb')
try:
f.write(content)
except Exception, err:
except Exception:
err = get_exception()
os.remove(tmpsrc)
module.fail_json(msg="failed to create temporary content file: %s" % str(err))
f.close()
@ -256,7 +257,8 @@ def write_file(module, url, dest, content):
if checksum_src != checksum_dest:
try:
shutil.copyfile(tmpsrc, dest)
except Exception, err:
except Exception:
err = get_exception()
os.remove(tmpsrc)
module.fail_json(msg="failed to copy %s to %s: %s" % (tmpsrc, dest, str(err)))

View file

@ -114,7 +114,8 @@ def check_url(module, url):
def run_cl_cmd(module, cmd, check_rc=True):
try:
(rc, out, err) = module.run_command(cmd, check_rc=check_rc)
except Exception, e:
except Exception:
e = get_exception()
module.fail_json(msg=e.strerror)
# trim last line as it is always empty
ret = out.splitlines()

View file

@ -84,7 +84,8 @@ def hash_existing_ports_conf(module):
try:
existing_ports_conf = open(PORTS_CONF).readlines()
except IOError, error_msg:
except IOError:
error_msg = get_exception()
_msg = "Failed to open %s: %s" % (PORTS_CONF, error_msg)
module.fail_json(msg=_msg)
return # for testing only should return on module.fail_json
@ -143,7 +144,8 @@ def make_copy_of_orig_ports_conf(module):
try:
shutil.copyfile(PORTS_CONF, PORTS_CONF + '.orig')
except IOError, error_msg:
except IOError:
error_msg = get_exception()
_msg = "Failed to save the original %s: %s" % (PORTS_CONF, error_msg)
module.fail_json(msg=_msg)
return # for testing only
@ -165,7 +167,8 @@ def write_to_ports_conf(module):
temp.write(_str)
temp.seek(0)
shutil.copyfile(temp.name, PORTS_CONF)
except IOError, error_msg:
except IOError:
error_msg = get_exception()
module.fail_json(
msg="Failed to write to %s: %s" % (PORTS_CONF, error_msg))
finally:

View file

@ -142,7 +142,8 @@ def main():
queue = set()
for entry in (module.params['waitfor'] or list()):
queue.add(Conditional(entry))
except AttributeError, exc:
except AttributeError:
exc = get_exception()
module.fail_json(msg=exc.message)
result = dict(changed=False)

View file

@ -135,7 +135,8 @@ def main():
queue = set()
for entry in (module.params['waitfor'] or list()):
queue.add(Conditional(entry))
except AttributeError, exc:
except AttributeError:
exc = get_exception()
module.fail_json(msg=exc.message)
result = dict(changed=False)

View file

@ -140,7 +140,8 @@ def main():
queue = set()
for entry in (module.params['waitfor'] or list()):
queue.add(Conditional(entry))
except AttributeError, exc:
except AttributeError:
exc = get_exception()
module.fail_json(msg=exc.message)

View file

@ -214,7 +214,8 @@ def main():
queue = set()
for entry in (module.params['waitfor'] or list()):
queue.add(Conditional(entry))
except AttributeError, exc:
except AttributeError:
exc = get_exception()
module.fail_json(msg=exc.message)
result = dict(changed=False)

View file

@ -147,7 +147,8 @@ def main():
queue = set()
for entry in (module.params['waitfor'] or list()):
queue.add(Conditional(entry))
except AttributeError, exc:
except AttributeError:
exc = get_exception()
module.fail_json(msg=exc.message)
result = dict(changed=False, result=list())
@ -164,7 +165,8 @@ def main():
if cmd.endswith('json'):
try:
response[index] = module.from_json(response[index])
except ValueError, exc:
except ValueError:
exc = get_exception()
module.fail_json(msg='failed to parse json response',
exc_message=str(exc), response=response[index],
cmd=cmd, response_dict=response)

View file

@ -66,7 +66,8 @@ def execute_show(cmds, module, command_type=None):
response = module.execute(cmds, command_type=command_type)
else:
response = module.execute(cmds)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending {0}'.format(command),
error=str(clie))
return response

View file

@ -89,7 +89,8 @@ feature:
def execute_config_command(commands, module):
try:
module.configure(commands)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending CLI commands',
error=str(clie), commands=commands)
@ -118,7 +119,8 @@ def execute_show(cmds, module, command_type=None):
response = module.execute(cmds, command_type=command_type)
else:
response = module.execute(cmds)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending {0}'.format(cmds),
error=str(clie))
return response

View file

@ -525,7 +525,8 @@ def smart_existing(module, intf_type, normalized_interface):
def execute_config_command(commands, module):
try:
module.configure(commands)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending CLI commands',
error=str(clie), commands=commands)
@ -556,7 +557,8 @@ def execute_show(cmds, module, command_type=None):
response = module.execute(cmds, command_type=command_type)
else:
response = module.execute(cmds)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending {0}'.format(command),
error=str(clie))
return response
@ -715,4 +717,4 @@ from ansible.module_utils.netcfg import *
from ansible.module_utils.nxos import *
if __name__ == '__main__':
main()
main()

View file

@ -102,7 +102,8 @@ changed:
def execute_config_command(commands, module):
try:
module.configure(commands)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending CLI commands',
error=str(clie), commands=commands)
@ -134,7 +135,8 @@ def execute_show(cmds, module, command_type=None):
response = module.execute(cmds, command_type=command_type)
else:
response = module.execute(cmds)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending {0}'.format(cmds),
error=str(clie))
return response
@ -523,4 +525,4 @@ from ansible.module_utils.shell import *
from ansible.module_utils.netcfg import *
from ansible.module_utils.nxos import *
if __name__ == '__main__':
main()
main()

View file

@ -150,7 +150,8 @@ def execute_show(cmds, module, command_type=None):
response = module.execute(cmds, command_type=command_type)
else:
response = module.execute(cmds)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending {0}'.format(cmds),
error=str(clie))
return response
@ -257,4 +258,4 @@ from ansible.module_utils.shell import *
from ansible.module_utils.netcfg import *
from ansible.module_utils.nxos import *
if __name__ == '__main__':
main()
main()

View file

@ -440,7 +440,8 @@ def apply_value_map(value_map, resource):
def execute_config_command(commands, module):
try:
module.configure(commands)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending CLI commands',
error=str(clie), commands=commands)
@ -469,7 +470,8 @@ def execute_show(cmds, module, command_type=None):
response = module.execute(cmds, command_type=command_type)
else:
response = module.execute(cmds)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending {0}'.format(command),
error=str(clie))
return response
@ -630,4 +632,4 @@ from ansible.module_utils.netcfg import *
from ansible.module_utils.nxos import *
if __name__ == '__main__':
main()
main()

View file

@ -280,7 +280,8 @@ def apply_value_map(value_map, resource):
def execute_config_command(commands, module):
try:
module.configure(commands)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending CLI commands',
error=str(clie), commands=commands)
@ -309,7 +310,8 @@ def execute_show(cmds, module, command_type=None):
response = module.execute(cmds, command_type=command_type)
else:
response = module.execute(cmds)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending {0}'.format(command),
error=str(clie))
return response
@ -427,4 +429,4 @@ from ansible.module_utils.netcfg import *
from ansible.module_utils.nxos import *
if __name__ == '__main__':
main()
main()

View file

@ -104,7 +104,8 @@ changed:
def execute_config_command(commands, module):
try:
module.configure(commands)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending CLI commands',
error=str(clie), commands=commands)
@ -133,7 +134,8 @@ def execute_show(cmds, module, command_type=None):
response = module.execute(cmds, command_type=command_type)
else:
response = module.execute(cmds)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending {0}'.format(cmds),
error=str(clie))
return response
@ -309,4 +311,4 @@ from ansible.module_utils.shell import *
from ansible.module_utils.netcfg import *
from ansible.module_utils.nxos import *
if __name__ == '__main__':
main()
main()

View file

@ -92,7 +92,8 @@ changed:
def execute_config_command(commands, module):
try:
module.configure(commands)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending CLI commands',
error=str(clie), commands=commands)
@ -118,7 +119,8 @@ def execute_show(cmds, module, command_type=None):
response = module.execute(cmds, command_type=command_type)
else:
response = module.execute(cmds)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending {0}'.format(command),
error=str(clie))
return response

View file

@ -116,7 +116,8 @@ changed:
def execute_config_command(commands, module):
try:
module.configure(commands)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending CLI commands',
error=str(clie), commands=commands)
@ -149,7 +150,8 @@ def execute_show(cmds, module, command_type=None):
response = module.execute(cmds, command_type=command_type)
else:
response = module.execute(cmds)
except ShellError, clie:
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending {0}'.format(command),
error=str(clie))
return response
@ -422,4 +424,4 @@ from ansible.module_utils.shell import *
from ansible.module_utils.netcfg import *
from ansible.module_utils.nxos import *
if __name__ == '__main__':
main()
main()

View file

@ -131,7 +131,8 @@ def main():
queue = set()
for entry in (module.params['waitfor'] or list()):
queue.add(Conditional(entry))
except AttributeError, exc:
except AttributeError:
exc = get_exception()
module.fail_json(msg=exc.message)
result = dict(changed=False)