Fix various Python 2.x->3.x compat issues

Fix current git's Hacking H23x warnings via
mechanical translation to avoid the easy
Python 3.x compatibility issues.

Change-Id: Ic94ef537b0722c8b65fc3fecc093dc0cb25673cc
This commit is contained in:
Dirk Mueller 2013-06-23 15:06:32 +02:00
parent d4a4d1d4b2
commit 5f79373e1d
5 changed files with 7 additions and 7 deletions

View File

@ -202,7 +202,7 @@ def deploy(address, port, iqn, lun, image_path, pxe_config_path,
login_iscsi(address, port, iqn)
try:
root_uuid = work_on_disk(dev, root_mb, swap_mb, image_path)
except exception.ProcessExecutionError, err:
except exception.ProcessExecutionError as err:
# Log output if there was a error
LOG.error("Cmd : %s" % err.cmd)
LOG.error("StdOut : %s" % err.stdout)

View File

@ -80,7 +80,7 @@ def wrap_exception(notifier=None, publisher_id=None, event_type=None,
# contain confidential information.
try:
return f(self, context, *args, **kw)
except Exception, e:
except Exception as e:
with excutils.save_and_reraise_exception():
if notifier:
payload = dict(exception=e)

View File

@ -185,7 +185,7 @@ def trycmd(*args, **kwargs):
try:
out, err = execute(*args, **kwargs)
failed = False
except exception.ProcessExecutionError, exn:
except exception.ProcessExecutionError as exn:
out, err = '', str(exn)
failed = True
@ -490,7 +490,7 @@ def tempdir(**kwargs):
finally:
try:
shutil.rmtree(tmpdir)
except OSError, e:
except OSError as e:
LOG.error(_('Could not remove tmpdir: %s'), str(e))

View File

@ -53,7 +53,7 @@ class IPMIPrivateMethodTestCase(base.TestCase):
with ipmi._make_password_file(self.info.get('password')) as pw_file:
del_chk_pw_file = pw_file
self.assertTrue(os.path.isfile(pw_file))
self.assertEqual(os.stat(pw_file)[stat.ST_MODE] & 0777, 0600)
self.assertEqual(os.stat(pw_file)[stat.ST_MODE] & 0o777, 0o600)
with open(pw_file, "r") as f:
password = f.read()
self.assertEqual(password, self.info.get('password'))

View File

@ -104,7 +104,7 @@ echo $runs > "$1"
exit 1
''')
fp.close()
os.chmod(tmpfilename, 0755)
os.chmod(tmpfilename, 0o755)
self.assertRaises(exception.ProcessExecutionError,
utils.execute,
tmpfilename, tmpfilename2, attempts=10,
@ -149,7 +149,7 @@ echo foo > "$1"
grep foo
''')
fp.close()
os.chmod(tmpfilename, 0755)
os.chmod(tmpfilename, 0o755)
utils.execute(tmpfilename,
tmpfilename2,
process_input='foo',