From b9610fb0a3938748a8efee3d43b29ddfac800330 Mon Sep 17 00:00:00 2001 From: Luong Anh Tuan Date: Mon, 22 Aug 2016 17:28:36 +0700 Subject: [PATCH] Remove locals() for formatting strings. Following OpenStack Style Guidelines: http://docs.openstack.org/developer/hacking/#dictionaries-lists Using locals() for formmatting strings is not clear as using explicit dictionaries and can hire errors during refactoring. Change-Id: If3930d62fea166760161eaa3bdf85efca95be121 --- tools/xenserver/stress_test.py | 31 ++++++++++++++----------------- tools/xenserver/vm_vdi_cleaner.py | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/tools/xenserver/stress_test.py b/tools/xenserver/stress_test.py index dc4b82948824..e82b3818acc5 100644 --- a/tools/xenserver/stress_test.py +++ b/tools/xenserver/stress_test.py @@ -31,40 +31,39 @@ def run(cmd): @contextlib.contextmanager def server_built(server_name, image_name, flavor=1, cleanup=True): - run("nova boot --image=%(image_name)s --flavor=%(flavor)s" - " --poll %(server_name)s" % locals()) + run("nova boot --image=%s --flavor=%s" + " --poll %s" % (image_name, flavor, server_name)) try: yield finally: if cleanup: - run("nova delete %(server_name)s" % locals()) + run("nova delete %s" % server_name) @contextlib.contextmanager def snapshot_taken(server_name, snapshot_name, cleanup=True): - run("nova image-create %(server_name)s %(snapshot_name)s" - " --poll" % locals()) + run("nova image-create %s %s" + " --poll" % (server_name, snapshot_name)) try: yield finally: if cleanup: - run("nova image-delete %(snapshot_name)s" % locals()) + run("nova image-delete %s" % snapshot_name) def migrate_server(server_name): - run("nova migrate %(server_name)s --poll" % locals()) + run("nova migrate %s --poll" % server_name) - cmd = "nova list | grep %(server_name)s | awk '{print $6}'" % locals() + cmd = "nova list | grep %s | awk '{print $6}'" % server_name proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) stdout, stderr = proc.communicate() status = stdout.strip() if status.upper() != 'VERIFY_RESIZE': - sys.stderr.write("Server %(server_name)s failed to rebuild"\ - % locals()) + sys.stderr.write("Server %s failed to rebuild" % server_name) return False # Confirm the resize - run("nova resize-confirm %(server_name)s" % locals()) + run("nova resize-confirm %s" % server_name) return True @@ -83,15 +82,14 @@ def test_migrate(context): def rebuild_server(server_name, snapshot_name): - run("nova rebuild %(server_name)s %(snapshot_name)s --poll" % locals()) + run("nova rebuild %s %s --poll" % (server_name, snapshot_name)) - cmd = "nova list | grep %(server_name)s | awk '{print $6}'" % locals() + cmd = "nova list | grep %s | awk '{print $6}'" % server_name proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) stdout, stderr = proc.communicate() status = stdout.strip() if status != 'ACTIVE': - sys.stderr.write("Server %(server_name)s failed to rebuild"\ - % locals()) + sys.stderr.write("Server %s failed to rebuild" % server_name) return False return True @@ -156,8 +154,7 @@ def main(): finally: if args.cleanup: for dom0_ip in dom0_ips: - run("ssh root@%(dom0_ip)s %(dom0_cleanup_script)s" - % locals()) + run("ssh root@%s %s" % (dom0_ip, dom0_cleanup_script)) success = all(results) result = "SUCCESS" if success else "FAILED" diff --git a/tools/xenserver/vm_vdi_cleaner.py b/tools/xenserver/vm_vdi_cleaner.py index 09b172e85e7d..0c8a5d013b69 100755 --- a/tools/xenserver/vm_vdi_cleaner.py +++ b/tools/xenserver/vm_vdi_cleaner.py @@ -130,7 +130,7 @@ def print_xen_object(obj_type, obj, indent_level=0, spaces_per_indent=4): name_label = obj["name_label"] except KeyError: name_label = "" - msg = "%(obj_type)s (%(uuid)s) '%(name_label)s'" % locals() + msg = "%s (%s) '%s'" % (obj_type, uuid, name_label) indent = " " * spaces_per_indent * indent_level print("".join([indent, msg]))