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
This commit is contained in:
parent
b292bf3441
commit
b9610fb0a3
@ -31,40 +31,39 @@ def run(cmd):
|
|||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def server_built(server_name, image_name, flavor=1, cleanup=True):
|
def server_built(server_name, image_name, flavor=1, cleanup=True):
|
||||||
run("nova boot --image=%(image_name)s --flavor=%(flavor)s"
|
run("nova boot --image=%s --flavor=%s"
|
||||||
" --poll %(server_name)s" % locals())
|
" --poll %s" % (image_name, flavor, server_name))
|
||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
if cleanup:
|
if cleanup:
|
||||||
run("nova delete %(server_name)s" % locals())
|
run("nova delete %s" % server_name)
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def snapshot_taken(server_name, snapshot_name, cleanup=True):
|
def snapshot_taken(server_name, snapshot_name, cleanup=True):
|
||||||
run("nova image-create %(server_name)s %(snapshot_name)s"
|
run("nova image-create %s %s"
|
||||||
" --poll" % locals())
|
" --poll" % (server_name, snapshot_name))
|
||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
if cleanup:
|
if cleanup:
|
||||||
run("nova image-delete %(snapshot_name)s" % locals())
|
run("nova image-delete %s" % snapshot_name)
|
||||||
|
|
||||||
|
|
||||||
def migrate_server(server_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)
|
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
|
||||||
stdout, stderr = proc.communicate()
|
stdout, stderr = proc.communicate()
|
||||||
status = stdout.strip()
|
status = stdout.strip()
|
||||||
if status.upper() != 'VERIFY_RESIZE':
|
if status.upper() != 'VERIFY_RESIZE':
|
||||||
sys.stderr.write("Server %(server_name)s failed to rebuild"\
|
sys.stderr.write("Server %s failed to rebuild" % server_name)
|
||||||
% locals())
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Confirm the resize
|
# Confirm the resize
|
||||||
run("nova resize-confirm %(server_name)s" % locals())
|
run("nova resize-confirm %s" % server_name)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -83,15 +82,14 @@ def test_migrate(context):
|
|||||||
|
|
||||||
|
|
||||||
def rebuild_server(server_name, snapshot_name):
|
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)
|
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
|
||||||
stdout, stderr = proc.communicate()
|
stdout, stderr = proc.communicate()
|
||||||
status = stdout.strip()
|
status = stdout.strip()
|
||||||
if status != 'ACTIVE':
|
if status != 'ACTIVE':
|
||||||
sys.stderr.write("Server %(server_name)s failed to rebuild"\
|
sys.stderr.write("Server %s failed to rebuild" % server_name)
|
||||||
% locals())
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -156,8 +154,7 @@ def main():
|
|||||||
finally:
|
finally:
|
||||||
if args.cleanup:
|
if args.cleanup:
|
||||||
for dom0_ip in dom0_ips:
|
for dom0_ip in dom0_ips:
|
||||||
run("ssh root@%(dom0_ip)s %(dom0_cleanup_script)s"
|
run("ssh root@%s %s" % (dom0_ip, dom0_cleanup_script))
|
||||||
% locals())
|
|
||||||
|
|
||||||
success = all(results)
|
success = all(results)
|
||||||
result = "SUCCESS" if success else "FAILED"
|
result = "SUCCESS" if success else "FAILED"
|
||||||
|
@ -130,7 +130,7 @@ def print_xen_object(obj_type, obj, indent_level=0, spaces_per_indent=4):
|
|||||||
name_label = obj["name_label"]
|
name_label = obj["name_label"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
name_label = ""
|
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
|
indent = " " * spaces_per_indent * indent_level
|
||||||
print("".join([indent, msg]))
|
print("".join([indent, msg]))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user