diff --git a/.travis.yml b/.travis.yml index 25396c56589..53bb90c7f77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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/ - - python3.5 -m compileall -fq system/ commands/ source_control/ inventory/ + - python3.4 -m compileall -fq system/ commands/ source_control/ inventory/ files/ + - python3.5 -m compileall -fq system/ commands/ source_control/ inventory/ files/ - 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 diff --git a/files/acl.py b/files/acl.py index d0de9c6d6b5..44ebedec42c 100644 --- a/files/acl.py +++ b/files/acl.py @@ -206,7 +206,8 @@ def run_acl(module, cmd, check_rc=True): try: (rc, out, err) = module.run_command(' '.join(cmd), check_rc=check_rc) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg=e.strerror) lines = out.splitlines() diff --git a/files/assemble.py b/files/assemble.py index 9f92e0209d3..aaed539644c 100644 --- a/files/assemble.py +++ b/files/assemble.py @@ -156,7 +156,8 @@ def cleanup(path, result=None): if os.path.exists(path): try: os.remove(path) - except (IOError, OSError), e: + except (IOError, OSError): + e = get_exception() # don't error on possible race conditions, but keep warning if result is not None: result['warnings'] = ['Unable to remove temp file (%s): %s' % (path, str(e))] @@ -203,7 +204,8 @@ def main(): if regexp != None: try: compiled_regexp = re.compile(regexp) - except re.error, e: + except re.error: + e = get_exception() module.fail_json(msg="Invalid Regexp (%s) in \"%s\"" % (e, regexp)) if validate and "%s" not in validate: diff --git a/files/copy.py b/files/copy.py index e80ea32ede2..5eacdd723ae 100644 --- a/files/copy.py +++ b/files/copy.py @@ -291,7 +291,8 @@ def main(): # the execute bit for the current user set, in # which case the stat() call will raise an OSError os.stat(os.path.dirname(dest)) - except OSError, e: + except OSError: + e = get_exception() if "permission denied" in str(e).lower(): module.fail_json(msg="Destination directory %s is not accessible" % (os.path.dirname(dest))) module.fail_json(msg="Destination directory %s does not exist" % (os.path.dirname(dest))) diff --git a/files/file.py b/files/file.py index 379418aa343..41deca0ce2e 100644 --- a/files/file.py +++ b/files/file.py @@ -250,12 +250,14 @@ def main(): if prev_state == 'directory': try: shutil.rmtree(path, ignore_errors=False) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="rmtree failed: %s" % str(e)) else: try: os.unlink(path) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(path=path, msg="unlinking failed: %s " % str(e)) module.exit_json(path=path, changed=True, diff=diff) else: @@ -301,7 +303,8 @@ def main(): if not os.path.exists(curpath): try: os.mkdir(curpath) - except OSError, ex: + except OSError: + ex = get_exception() # Possibly something else created the dir since the os.path.exists # check above. As long as it's a dir, we don't need to error out. if not (ex.errno == errno.EEXIST and os.path.isdir(curpath)): @@ -309,7 +312,8 @@ def main(): tmp_file_args = file_args.copy() tmp_file_args['path']=curpath changed = module.set_fs_attributes_if_different(tmp_file_args, changed, diff) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(path=path, msg='There was an issue creating %s as requested: %s' % (curpath, str(e))) # We already know prev_state is not 'absent', therefore it exists in some form. @@ -376,7 +380,8 @@ def main(): else: os.symlink(src, tmppath) os.rename(tmppath, path) - except OSError, e: + except OSError: + e = get_exception() if os.path.exists(tmppath): os.unlink(tmppath) module.fail_json(path=path, msg='Error while replacing: %s' % str(e)) @@ -386,7 +391,8 @@ def main(): os.link(src,path) else: os.symlink(src, path) - except OSError, e: + except OSError: + e = get_exception() module.fail_json(path=path, msg='Error while linking: %s' % str(e)) if module.check_mode and not os.path.exists(path): @@ -401,18 +407,21 @@ def main(): if prev_state == 'absent': try: open(path, 'w').close() - except OSError, e: + except OSError: + e = get_exception() module.fail_json(path=path, msg='Error, could not touch target: %s' % str(e)) elif prev_state in ['file', 'directory', 'hard']: try: os.utime(path, None) - except OSError, e: + except OSError: + e = get_exception() module.fail_json(path=path, msg='Error while touching existing target: %s' % str(e)) else: module.fail_json(msg='Cannot touch other than files, directories, and hardlinks (%s is %s)' % (path, prev_state)) try: module.set_fs_attributes_if_different(file_args, True, diff) - except SystemExit, e: + except SystemExit: + e = get_exception() if e.code: # We take this to mean that fail_json() was called from # somewhere in basic.py diff --git a/files/stat.py b/files/stat.py index f14717ca103..e2b534c4ec4 100644 --- a/files/stat.py +++ b/files/stat.py @@ -326,7 +326,8 @@ def main(): st = os.stat(path) else: st = os.lstat(path) - except OSError, e: + except OSError: + e = get_exception() if e.errno == errno.ENOENT: d = { 'exists' : False } module.exit_json(changed=False, stat=d) diff --git a/files/unarchive.py b/files/unarchive.py index 9377a5931f4..d2d7b97a52b 100644 --- a/files/unarchive.py +++ b/files/unarchive.py @@ -695,7 +695,8 @@ def main(): f.write(data) f.close() src = package - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="Failure downloading %s, %s" % (src, e)) else: module.fail_json(msg="Source '%s' does not exist" % src) @@ -706,7 +707,8 @@ def main(): try: if os.path.getsize(src) == 0: module.fail_json(msg="Invalid archive '%s', the file is 0 bytes" % src) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="Source '%s' not readable" % src) # is dest OK to receive tar file? @@ -746,7 +748,8 @@ def main(): file_args['path'] = os.path.join(dest, filename) try: res_args['changed'] = module.set_fs_attributes_if_different(file_args, res_args['changed']) - except (IOError, OSError), e: + except (IOError, OSError): + e = get_exception() module.fail_json(msg="Unexpected error when accessing exploded file: %s" % str(e)) if module.params['list_files']: diff --git a/files/xattr.py b/files/xattr.py index 519fb4d0f26..378665477cf 100644 --- a/files/xattr.py +++ b/files/xattr.py @@ -124,7 +124,8 @@ def _run_xattr(module,cmd,check_rc=True): try: (rc, out, err) = module.run_command(' '.join(cmd), check_rc=check_rc) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="%s!" % e.strerror) #result = {'raw': out}