Merge "Make print py3 compatible"

This commit is contained in:
Jenkins 2016-06-26 14:18:09 +00:00 committed by Gerrit Code Review
commit a074c661e4
6 changed files with 37 additions and 37 deletions

View File

@ -65,8 +65,8 @@ def main():
options, days_old = _parse_args() options, days_old = _parse_args()
if not os.path.exists(BASE): if not os.path.exists(BASE):
print >> sys.stderr, "error: '%s' doesn't exist. Make sure you're"\ sys.stderr.write("error: '%s' doesn't exist. Make sure you're"\
" running this on the dom0." % BASE " running this on the dom0." % BASE)
sys.exit(1) sys.exit(1)
lockpaths_removed = 0 lockpaths_removed = 0
@ -89,8 +89,8 @@ def main():
removed += 1 removed += 1
if options.verbose: if options.verbose:
print 'Removing old lock: %03d %s' % (lock_age_days, print('Removing old lock: %03d %s' % (lock_age_days,
lockpath) lockpath))
if not options.dry_run: if not options.dry_run:
os.unlink(lockpath) os.unlink(lockpath)
@ -100,23 +100,23 @@ def main():
nspaths_removed += 1 nspaths_removed += 1
if options.verbose: if options.verbose:
print 'Removing empty namespace: %s' % nspath print('Removing empty namespace: %s' % nspath)
if not options.dry_run: if not options.dry_run:
try: try:
os.rmdir(nspath) os.rmdir(nspath)
except OSError, e: except OSError, e:
if e.errno == errno.ENOTEMPTY: if e.errno == errno.ENOTEMPTY:
print >> sys.stderr, "warning: directory '%s'"\ sys.stderr.write("warning: directory '%s'"\
" not empty" % nspath " not empty" % nspath)
else: else:
raise raise
if options.dry_run: if options.dry_run:
print "** Dry Run **" print("** Dry Run **")
print "Total locks removed: ", lockpaths_removed print("Total locks removed: ", lockpaths_removed)
print "Total namespaces removed: ", nspaths_removed print("Total namespaces removed: ", nspaths_removed)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -60,9 +60,9 @@ def main():
dry_run=CONF.dry_run) dry_run=CONF.dry_run)
if '--verbose' in sys.argv: if '--verbose' in sys.argv:
print '\n'.join(destroyed) print('\n'.join(destroyed))
print "Destroyed %d cached VDIs" % len(destroyed) print("Destroyed %d cached VDIs" % len(destroyed))
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -79,7 +79,7 @@ def main():
# Parse out UUID # Parse out UUID
instance_uuid = name_label.replace('instance-', '')[:36] instance_uuid = name_label.replace('instance-', '')[:36]
if not uuidutils.is_uuid_like(instance_uuid): if not uuidutils.is_uuid_like(instance_uuid):
print "error: name label '%s' wasn't UUID-like" % name_label print("error: name label '%s' wasn't UUID-like" % name_label)
continue continue
vdi_type = vdi_rec['name_description'] vdi_type = vdi_rec['name_description']
@ -92,11 +92,11 @@ def main():
vdi_type, instance) vdi_type, instance)
if CONF.verbose: if CONF.verbose:
print "Setting other_config for instance_uuid=%s vdi_uuid=%s" % ( print("Setting other_config for instance_uuid=%s vdi_uuid=%s" % (
instance_uuid, vdi_rec['uuid']) instance_uuid, vdi_rec['uuid']))
if CONF.dry_run: if CONF.dry_run:
print "Dry run completed" print("Dry run completed")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -26,7 +26,7 @@ DOM0_CLEANUP_SCRIPT = "/tmp/destroy_cache_vdis"
def run(cmd): def run(cmd):
ret = subprocess.call(cmd, shell=True) ret = subprocess.call(cmd, shell=True)
if ret != 0: if ret != 0:
print >> sys.stderr, "Command exited non-zero: %s" % cmd sys.stderr.write("Command exited non-zero: %s" % cmd)
@contextlib.contextmanager @contextlib.contextmanager
@ -59,8 +59,8 @@ def migrate_server(server_name):
stdout, stderr = proc.communicate() stdout, stderr = proc.communicate()
status = stdout.strip() status = stdout.strip()
if status.upper() != 'VERIFY_RESIZE': if status.upper() != 'VERIFY_RESIZE':
print >> sys.stderr, "Server %(server_name)s failed to rebuild"\ sys.stderr.write("Server %(server_name)s failed to rebuild"\
% locals() % locals())
return False return False
# Confirm the resize # Confirm the resize
@ -90,8 +90,8 @@ def rebuild_server(server_name, snapshot_name):
stdout, stderr = proc.communicate() stdout, stderr = proc.communicate()
status = stdout.strip() status = stdout.strip()
if status != 'ACTIVE': if status != 'ACTIVE':
print >> sys.stderr, "Server %(server_name)s failed to rebuild"\ sys.stderr.write("Server %(server_name)s failed to rebuild"\
% locals() % locals())
return False return False
return True return True
@ -146,7 +146,7 @@ def main():
for test in args.tests: for test in args.tests:
test_func = globals().get("test_%s" % test) test_func = globals().get("test_%s" % test)
if not test_func: if not test_func:
print >> sys.stderr, "test '%s' not found" % test sys.stderr.write("test '%s' not found" % test)
sys.exit(1) sys.exit(1)
contexts = [(x, args) for x in range(args.num_runs)] contexts = [(x, args) for x in range(args.num_runs)]
@ -163,7 +163,7 @@ def main():
result = "SUCCESS" if success else "FAILED" result = "SUCCESS" if success else "FAILED"
duration = time.time() - start_time duration = time.time() - start_time
print "%s, finished in %.2f secs" % (result, duration) print("%s, finished in %.2f secs" % (result, duration))
sys.exit(0 if success else 1) sys.exit(0 if success else 1)

View File

@ -62,7 +62,7 @@ def execute(cmd, ok_exit_codes=None):
def usage(): def usage():
print "usage: %s <SR PATH> <print|delete|move>" % sys.argv[0] print("usage: %s <SR PATH> <print|delete|move>" % sys.argv[0])
sys.exit(1) sys.exit(1)
@ -78,7 +78,7 @@ def main():
if action == 'move': if action == 'move':
if len(sys.argv) < 4: if len(sys.argv) < 4:
print "error: must specify where to move bad VHDs" print("error: must specify where to move bad VHDs")
sys.exit(1) sys.exit(1)
bad_vhd_path = sys.argv[3] bad_vhd_path = sys.argv[3]
@ -111,7 +111,7 @@ def main():
for bad_leaf in bad_leaves: for bad_leaf in bad_leaves:
for bad_vhd in walk_vhds(bad_leaf): for bad_vhd in walk_vhds(bad_leaf):
print bad_vhd print(bad_vhd)
if action == "print": if action == "print":
pass pass
elif action == "delete": elif action == "delete":

View File

@ -132,7 +132,7 @@ def print_xen_object(obj_type, obj, indent_level=0, spaces_per_indent=4):
name_label = "" name_label = ""
msg = "%(obj_type)s (%(uuid)s) '%(name_label)s'" % locals() msg = "%(obj_type)s (%(uuid)s) '%(name_label)s'" % locals()
indent = " " * spaces_per_indent * indent_level indent = " " * spaces_per_indent * indent_level
print "".join([indent, msg]) print("".join([indent, msg]))
def _find_vdis_connected_to_vm(xenapi, connected_vdi_uuids): def _find_vdis_connected_to_vm(xenapi, connected_vdi_uuids):
@ -247,38 +247,38 @@ def list_orphaned_vdis(vdi_uuids):
"""List orphaned VDIs.""" """List orphaned VDIs."""
for vdi_uuid in vdi_uuids: for vdi_uuid in vdi_uuids:
if CONF.verbose: if CONF.verbose:
print "ORPHANED VDI (%s)" % vdi_uuid print("ORPHANED VDI (%s)" % vdi_uuid)
else: else:
print vdi_uuid print(vdi_uuid)
def clean_orphaned_vdis(xenapi, vdi_uuids): def clean_orphaned_vdis(xenapi, vdi_uuids):
"""Clean orphaned VDIs.""" """Clean orphaned VDIs."""
for vdi_uuid in vdi_uuids: for vdi_uuid in vdi_uuids:
if CONF.verbose: if CONF.verbose:
print "CLEANING VDI (%s)" % vdi_uuid print("CLEANING VDI (%s)" % vdi_uuid)
vdi_ref = call_xenapi(xenapi, 'VDI.get_by_uuid', vdi_uuid) vdi_ref = call_xenapi(xenapi, 'VDI.get_by_uuid', vdi_uuid)
try: try:
call_xenapi(xenapi, 'VDI.destroy', vdi_ref) call_xenapi(xenapi, 'VDI.destroy', vdi_ref)
except XenAPI.Failure, exc: except XenAPI.Failure, exc:
print >> sys.stderr, "Skipping %s: %s" % (vdi_uuid, exc) sys.stderr.write("Skipping %s: %s" % (vdi_uuid, exc))
def list_orphaned_instances(orphaned_instances): def list_orphaned_instances(orphaned_instances):
"""List orphaned instances.""" """List orphaned instances."""
for vm_ref, vm_rec, orphaned_instance in orphaned_instances: for vm_ref, vm_rec, orphaned_instance in orphaned_instances:
if CONF.verbose: if CONF.verbose:
print "ORPHANED INSTANCE (%s)" % orphaned_instance.name print("ORPHANED INSTANCE (%s)" % orphaned_instance.name)
else: else:
print orphaned_instance.name print(orphaned_instance.name)
def clean_orphaned_instances(xenapi, orphaned_instances): def clean_orphaned_instances(xenapi, orphaned_instances):
"""Clean orphaned instances.""" """Clean orphaned instances."""
for vm_ref, vm_rec, instance in orphaned_instances: for vm_ref, vm_rec, instance in orphaned_instances:
if CONF.verbose: if CONF.verbose:
print "CLEANING INSTANCE (%s)" % instance.name print("CLEANING INSTANCE (%s)" % instance.name)
cleanup_instance(xenapi, instance, vm_ref, vm_rec) cleanup_instance(xenapi, instance, vm_ref, vm_rec)
@ -304,10 +304,10 @@ def main():
if command == "list-vdis": if command == "list-vdis":
if CONF.verbose: if CONF.verbose:
print "Connected VDIs:\n" print("Connected VDIs:\n")
orphaned_vdi_uuids = find_orphaned_vdi_uuids(xenapi) orphaned_vdi_uuids = find_orphaned_vdi_uuids(xenapi)
if CONF.verbose: if CONF.verbose:
print "\nOrphaned VDIs:\n" print("\nOrphaned VDIs:\n")
list_orphaned_vdis(orphaned_vdi_uuids) list_orphaned_vdis(orphaned_vdi_uuids)
elif command == "clean-vdis": elif command == "clean-vdis":
orphaned_vdi_uuids = find_orphaned_vdi_uuids(xenapi) orphaned_vdi_uuids = find_orphaned_vdi_uuids(xenapi)
@ -321,7 +321,7 @@ def main():
elif command == "test": elif command == "test":
doctest.testmod() doctest.testmod()
else: else:
print "Unknown command '%s'" % command print("Unknown command '%s'" % command)
sys.exit(1) sys.exit(1)