Change exceptions to python3 syntax.
This commit is contained in:
parent
62c08d96e5
commit
6747f82547
22 changed files with 38 additions and 38 deletions
|
@ -270,9 +270,9 @@ class Base:
|
||||||
# and assign the massaged value back to the attribute field
|
# and assign the massaged value back to the attribute field
|
||||||
setattr(self, name, value)
|
setattr(self, name, value)
|
||||||
|
|
||||||
except (TypeError, ValueError), e:
|
except (TypeError, ValueError) as e:
|
||||||
raise AnsibleParserError("the field '%s' has an invalid value (%s), and could not be converted to an %s. Error was: %s" % (name, value, attribute.isa, e), obj=self.get_ds())
|
raise AnsibleParserError("the field '%s' has an invalid value (%s), and could not be converted to an %s. Error was: %s" % (name, value, attribute.isa, e), obj=self.get_ds())
|
||||||
except UndefinedError, e:
|
except UndefinedError as e:
|
||||||
if fail_on_undefined:
|
if fail_on_undefined:
|
||||||
raise AnsibleParserError("the field '%s' has an invalid value, which appears to include a variable that is undefined. The error was: %s" % (name,e), obj=self.get_ds())
|
raise AnsibleParserError("the field '%s' has an invalid value, which appears to include a variable that is undefined. The error was: %s" % (name,e), obj=self.get_ds())
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ class PluginLoader:
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
try:
|
try:
|
||||||
full_paths = (os.path.join(path, f) for f in os.listdir(path))
|
full_paths = (os.path.join(path, f) for f in os.listdir(path))
|
||||||
except OSError,e:
|
except OSError as e:
|
||||||
d = Display()
|
d = Display()
|
||||||
d.warning("Error accessing plugin paths: %s" % str(e))
|
d.warning("Error accessing plugin paths: %s" % str(e))
|
||||||
for full_path in (f for f in full_paths if os.path.isfile(f)):
|
for full_path in (f for f in full_paths if os.path.isfile(f)):
|
||||||
|
|
|
@ -223,7 +223,7 @@ class ActionBase:
|
||||||
#else:
|
#else:
|
||||||
# data = data.encode('utf-8')
|
# data = data.encode('utf-8')
|
||||||
afo.write(data)
|
afo.write(data)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
#raise AnsibleError("failure encoding into utf-8: %s" % str(e))
|
#raise AnsibleError("failure encoding into utf-8: %s" % str(e))
|
||||||
raise AnsibleError("failure writing module data to temporary file for transfer: %s" % str(e))
|
raise AnsibleError("failure writing module data to temporary file for transfer: %s" % str(e))
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ class ActionModule(ActionBase):
|
||||||
else:
|
else:
|
||||||
content_tempfile = self._create_content_tempfile(content)
|
content_tempfile = self._create_content_tempfile(content)
|
||||||
source = content_tempfile
|
source = content_tempfile
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
return dict(failed=True, msg="could not write content temp file: %s" % err)
|
return dict(failed=True, msg="could not write content temp file: %s" % err)
|
||||||
|
|
||||||
###############################################################################################
|
###############################################################################################
|
||||||
|
@ -297,7 +297,7 @@ class ActionModule(ActionBase):
|
||||||
content = to_bytes(content)
|
content = to_bytes(content)
|
||||||
try:
|
try:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
os.remove(content_tempfile)
|
os.remove(content_tempfile)
|
||||||
raise Exception(err)
|
raise Exception(err)
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -68,7 +68,7 @@ class ActionModule(ActionBase):
|
||||||
seconds = int(self._task.args['seconds'])
|
seconds = int(self._task.args['seconds'])
|
||||||
duration_unit = 'seconds'
|
duration_unit = 'seconds'
|
||||||
|
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
return dict(failed=True, msg="non-integer value given for prompt duration:\n%s" % str(e))
|
return dict(failed=True, msg="non-integer value given for prompt duration:\n%s" % str(e))
|
||||||
|
|
||||||
# Is 'prompt' a key in 'args'?
|
# Is 'prompt' a key in 'args'?
|
||||||
|
|
|
@ -102,7 +102,7 @@ class ActionModule(ActionBase):
|
||||||
with open(source, 'r') as f:
|
with open(source, 'r') as f:
|
||||||
template_data = f.read()
|
template_data = f.read()
|
||||||
resultant = templar.template(template_data, preserve_trailing_newlines=True)
|
resultant = templar.template(template_data, preserve_trailing_newlines=True)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
return dict(failed=True, msg=type(e).__name__ + ": " + str(e))
|
return dict(failed=True, msg=type(e).__name__ + ": " + str(e))
|
||||||
|
|
||||||
local_checksum = checksum_s(resultant)
|
local_checksum = checksum_s(resultant)
|
||||||
|
|
|
@ -140,7 +140,7 @@ class Connection(object):
|
||||||
# shutdown, so we'll reconnect.
|
# shutdown, so we'll reconnect.
|
||||||
wrong_user = True
|
wrong_user = True
|
||||||
|
|
||||||
except AnsibleError, e:
|
except AnsibleError as e:
|
||||||
if allow_ssh:
|
if allow_ssh:
|
||||||
if "WRONG_USER" in e:
|
if "WRONG_USER" in e:
|
||||||
vvv("Switching users, waiting for the daemon on %s to shutdown completely..." % self.host)
|
vvv("Switching users, waiting for the daemon on %s to shutdown completely..." % self.host)
|
||||||
|
|
|
@ -170,7 +170,7 @@ class Connection(object):
|
||||||
key_filename=key_filename, password=self.password,
|
key_filename=key_filename, password=self.password,
|
||||||
timeout=self.runner.timeout, port=self.port)
|
timeout=self.runner.timeout, port=self.port)
|
||||||
|
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
|
|
||||||
msg = str(e)
|
msg = str(e)
|
||||||
if "PID check failed" in msg:
|
if "PID check failed" in msg:
|
||||||
|
@ -197,7 +197,7 @@ class Connection(object):
|
||||||
self.ssh.get_transport().set_keepalive(5)
|
self.ssh.get_transport().set_keepalive(5)
|
||||||
chan = self.ssh.get_transport().open_session()
|
chan = self.ssh.get_transport().open_session()
|
||||||
|
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
|
|
||||||
msg = "Failed to open session"
|
msg = "Failed to open session"
|
||||||
if len(str(e)) > 0:
|
if len(str(e)) > 0:
|
||||||
|
@ -284,7 +284,7 @@ class Connection(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.sftp = self.ssh.open_sftp()
|
self.sftp = self.ssh.open_sftp()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise errors.AnsibleError("failed to open a SFTP connection (%s)" % e)
|
raise errors.AnsibleError("failed to open a SFTP connection (%s)" % e)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -308,7 +308,7 @@ class Connection(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.sftp = self._connect_sftp()
|
self.sftp = self._connect_sftp()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise errors.AnsibleError("failed to open a SFTP connection (%s)", e)
|
raise errors.AnsibleError("failed to open a SFTP connection (%s)", e)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -147,7 +147,7 @@ class Connection(object):
|
||||||
cmd_parts = powershell._encode_script(script, as_list=True)
|
cmd_parts = powershell._encode_script(script, as_list=True)
|
||||||
try:
|
try:
|
||||||
result = self._winrm_exec(cmd_parts[0], cmd_parts[1:], from_exec=True)
|
result = self._winrm_exec(cmd_parts[0], cmd_parts[1:], from_exec=True)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise errors.AnsibleError("failed to exec cmd %s" % cmd)
|
raise errors.AnsibleError("failed to exec cmd %s" % cmd)
|
||||||
return (result.status_code, '', result.std_out.encode('utf-8'), result.std_err.encode('utf-8'))
|
return (result.status_code, '', result.std_out.encode('utf-8'), result.std_err.encode('utf-8'))
|
||||||
|
|
|
@ -33,7 +33,7 @@ class LookupModule(LookupBase):
|
||||||
for row in creader:
|
for row in creader:
|
||||||
if row[0] == key:
|
if row[0] == key:
|
||||||
return row[int(col)]
|
return row[int(col)]
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise AnsibleError("csvfile: %s" % str(e))
|
raise AnsibleError("csvfile: %s" % str(e))
|
||||||
|
|
||||||
return dflt
|
return dflt
|
||||||
|
@ -61,7 +61,7 @@ class LookupModule(LookupBase):
|
||||||
name, value = param.split('=')
|
name, value = param.split('=')
|
||||||
assert(name in paramvals)
|
assert(name in paramvals)
|
||||||
paramvals[name] = value
|
paramvals[name] = value
|
||||||
except (ValueError, AssertionError), e:
|
except (ValueError, AssertionError) as e:
|
||||||
raise AnsibleError(e)
|
raise AnsibleError(e)
|
||||||
|
|
||||||
if paramvals['delimiter'] == 'TAB':
|
if paramvals['delimiter'] == 'TAB':
|
||||||
|
|
|
@ -59,7 +59,7 @@ class LookupModule(LookupBase):
|
||||||
string = 'NXDOMAIN'
|
string = 'NXDOMAIN'
|
||||||
except dns.resolver.Timeout:
|
except dns.resolver.Timeout:
|
||||||
string = ''
|
string = ''
|
||||||
except dns.exception.DNSException, e:
|
except dns.exception.DNSException as e:
|
||||||
raise AnsibleError("dns.resolver unhandled exception", e)
|
raise AnsibleError("dns.resolver unhandled exception", e)
|
||||||
|
|
||||||
ret.append(''.join(string))
|
ret.append(''.join(string))
|
||||||
|
|
|
@ -177,7 +177,7 @@ class LookupModule(LookupBase):
|
||||||
for fn in total_search:
|
for fn in total_search:
|
||||||
try:
|
try:
|
||||||
fn = templar.template(fn)
|
fn = templar.template(fn)
|
||||||
except (AnsibleUndefinedVariable, UndefinedError), e:
|
except (AnsibleUndefinedVariable, UndefinedError) as e:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if os.path.isabs(fn) and os.path.exists(fn):
|
if os.path.isabs(fn) and os.path.exists(fn):
|
||||||
|
|
|
@ -85,7 +85,7 @@ class LookupModule(LookupBase):
|
||||||
paramvals['chars'] = use_chars
|
paramvals['chars'] = use_chars
|
||||||
else:
|
else:
|
||||||
paramvals[name] = value
|
paramvals[name] = value
|
||||||
except (ValueError, AssertionError), e:
|
except (ValueError, AssertionError) as e:
|
||||||
raise AnsibleError(e)
|
raise AnsibleError(e)
|
||||||
|
|
||||||
length = paramvals['length']
|
length = paramvals['length']
|
||||||
|
@ -99,7 +99,7 @@ class LookupModule(LookupBase):
|
||||||
if not os.path.isdir(pathdir):
|
if not os.path.isdir(pathdir):
|
||||||
try:
|
try:
|
||||||
os.makedirs(pathdir, mode=0700)
|
os.makedirs(pathdir, mode=0700)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
raise AnsibleError("cannot create the path for the password lookup: %s (error was %s)" % (pathdir, str(e)))
|
raise AnsibleError("cannot create the path for the password lookup: %s (error was %s)" % (pathdir, str(e)))
|
||||||
|
|
||||||
chars = "".join([getattr(string,c,c) for c in use_chars]).replace('"','').replace("'",'')
|
chars = "".join([getattr(string,c,c) for c in use_chars]).replace('"','').replace("'",'')
|
||||||
|
|
|
@ -31,10 +31,10 @@ class LookupModule(LookupBase):
|
||||||
try:
|
try:
|
||||||
r = urllib2.Request(term)
|
r = urllib2.Request(term)
|
||||||
response = urllib2.urlopen(r)
|
response = urllib2.urlopen(r)
|
||||||
except URLError, e:
|
except URLError as e:
|
||||||
utils.warnings("Failed lookup url for %s : %s" % (term, str(e)))
|
utils.warnings("Failed lookup url for %s : %s" % (term, str(e)))
|
||||||
continue
|
continue
|
||||||
except HTTPError, e:
|
except HTTPError as e:
|
||||||
utils.warnings("Recieved HTTP error for %s : %s" % (term, str(e)))
|
utils.warnings("Recieved HTTP error for %s : %s" % (term, str(e)))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ class StrategyBase:
|
||||||
|
|
||||||
self._pending_results += 1
|
self._pending_results += 1
|
||||||
main_q.put((host, task, self._loader.get_basedir(), task_vars, connection_info, module_loader), block=False)
|
main_q.put((host, task, self._loader.get_basedir(), task_vars, connection_info, module_loader), block=False)
|
||||||
except (EOFError, IOError, AssertionError), e:
|
except (EOFError, IOError, AssertionError) as e:
|
||||||
# most likely an abort
|
# most likely an abort
|
||||||
debug("got an error while queuing: %s" % e)
|
debug("got an error while queuing: %s" % e)
|
||||||
return
|
return
|
||||||
|
|
|
@ -139,7 +139,7 @@ class StrategyModule(StrategyBase):
|
||||||
try:
|
try:
|
||||||
results = self._wait_on_pending_results(iterator)
|
results = self._wait_on_pending_results(iterator)
|
||||||
host_results.extend(results)
|
host_results.extend(results)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
# FIXME: ctrl+c can cause some failures here, so catch them
|
# FIXME: ctrl+c can cause some failures here, so catch them
|
||||||
# with the appropriate error type
|
# with the appropriate error type
|
||||||
print("wtf: %s" % e)
|
print("wtf: %s" % e)
|
||||||
|
|
|
@ -105,13 +105,13 @@ def safe_eval(expr, locals={}, include_exceptions=False):
|
||||||
return (result, None)
|
return (result, None)
|
||||||
else:
|
else:
|
||||||
return result
|
return result
|
||||||
except SyntaxError, e:
|
except SyntaxError as e:
|
||||||
# special handling for syntax errors, we just return
|
# special handling for syntax errors, we just return
|
||||||
# the expression string back as-is
|
# the expression string back as-is
|
||||||
if include_exceptions:
|
if include_exceptions:
|
||||||
return (expr, None)
|
return (expr, None)
|
||||||
return expr
|
return expr
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if include_exceptions:
|
if include_exceptions:
|
||||||
return (expr, e)
|
return (expr, e)
|
||||||
return expr
|
return expr
|
||||||
|
|
|
@ -64,7 +64,7 @@ def secure_hash(filename, hash_func=sha1):
|
||||||
digest.update(block)
|
digest.update(block)
|
||||||
block = infile.read(blocksize)
|
block = infile.read(blocksize)
|
||||||
infile.close()
|
infile.close()
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
raise errors.AnsibleError("error while accessing the file %s, error was: %s" % (filename, e))
|
raise errors.AnsibleError("error while accessing the file %s, error was: %s" % (filename, e))
|
||||||
return digest.hexdigest()
|
return digest.hexdigest()
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ def read_vault_file(vault_password_file):
|
||||||
try:
|
try:
|
||||||
# STDERR not captured to make it easier for users to prompt for input in their scripts
|
# STDERR not captured to make it easier for users to prompt for input in their scripts
|
||||||
p = subprocess.Popen(this_path, stdout=subprocess.PIPE)
|
p = subprocess.Popen(this_path, stdout=subprocess.PIPE)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
raise AnsibleError("Problem running vault password script %s (%s). If this is not a script, remove the executable bit from the file." % (' '.join(this_path), e))
|
raise AnsibleError("Problem running vault password script %s (%s). If this is not a script, remove the executable bit from the file." % (' '.join(this_path), e))
|
||||||
stdout, stderr = p.communicate()
|
stdout, stderr = p.communicate()
|
||||||
vault_pass = stdout.strip('\r\n')
|
vault_pass = stdout.strip('\r\n')
|
||||||
|
@ -49,7 +49,7 @@ def read_vault_file(vault_password_file):
|
||||||
f = open(this_path, "rb")
|
f = open(this_path, "rb")
|
||||||
vault_pass=f.read().strip()
|
vault_pass=f.read().strip()
|
||||||
f.close()
|
f.close()
|
||||||
except (OSError, IOError), e:
|
except (OSError, IOError) as e:
|
||||||
raise AnsibleError("Could not read vault password file %s: %s" % (this_path, e))
|
raise AnsibleError("Could not read vault password file %s: %s" % (this_path, e))
|
||||||
|
|
||||||
return vault_pass
|
return vault_pass
|
||||||
|
|
|
@ -243,7 +243,7 @@ class VariableManager:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
names = loader.list_directory(path)
|
names = loader.list_directory(path)
|
||||||
except os.error, err:
|
except os.error as err:
|
||||||
raise AnsibleError("This folder cannot be listed: %s: %s." % (path, err.strerror))
|
raise AnsibleError("This folder cannot be listed: %s: %s." % (path, err.strerror))
|
||||||
|
|
||||||
# evaluate files in a stable order rather than whatever
|
# evaluate files in a stable order rather than whatever
|
||||||
|
|
|
@ -59,10 +59,10 @@ def results(pipe, workers):
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
continue
|
continue
|
||||||
pipe.send(result)
|
pipe.send(result)
|
||||||
except (IOError, EOFError, KeyboardInterrupt), e:
|
except (IOError, EOFError, KeyboardInterrupt) as e:
|
||||||
debug("got a breaking error: %s" % e)
|
debug("got a breaking error: %s" % e)
|
||||||
break
|
break
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
debug("EXCEPTION DURING RESULTS PROCESSING: %s" % e)
|
debug("EXCEPTION DURING RESULTS PROCESSING: %s" % e)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
break
|
break
|
||||||
|
|
|
@ -55,10 +55,10 @@ def results(final_q, workers):
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
continue
|
continue
|
||||||
final_q.put(result, block=False)
|
final_q.put(result, block=False)
|
||||||
except (IOError, EOFError, KeyboardInterrupt), e:
|
except (IOError, EOFError, KeyboardInterrupt) as e:
|
||||||
debug("got a breaking error: %s" % e)
|
debug("got a breaking error: %s" % e)
|
||||||
break
|
break
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
debug("EXCEPTION DURING RESULTS PROCESSING: %s" % e)
|
debug("EXCEPTION DURING RESULTS PROCESSING: %s" % e)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
break
|
break
|
||||||
|
@ -77,10 +77,10 @@ def worker(main_q, res_q, loader):
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
pass
|
pass
|
||||||
except (IOError, EOFError, KeyboardInterrupt), e:
|
except (IOError, EOFError, KeyboardInterrupt) as e:
|
||||||
debug("got a breaking error: %s" % e)
|
debug("got a breaking error: %s" % e)
|
||||||
break
|
break
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
debug("EXCEPTION DURING WORKER PROCESSING: %s" % e)
|
debug("EXCEPTION DURING WORKER PROCESSING: %s" % e)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue