This makes the Log function able to take multiple args for simplified
message construction, similar to the ToStdout one.
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
USAGE = ("\tburnin -o OS_NAME [options...] instance_name ...")
MAX_RETRIES = 3
USAGE = ("\tburnin -o OS_NAME [options...] instance_name ...")
MAX_RETRIES = 3
+LOG_HEADERS = {
+ 0: "- ",
+ 1: "* ",
+ 2: ""
+ }
class InstanceDown(Exception):
"""The checked instance was not up"""
class InstanceDown(Exception):
"""The checked instance was not up"""
+def Log(msg, *args, **kwargs):
"""Simple function that prints out its argument.
"""
"""Simple function that prints out its argument.
"""
- headers = {
- 0: "- ",
- 1: "* ",
- 2: ""
- }
+ if args:
+ msg = msg % args
+ indent = kwargs.get('indent', 0)
sys.stdout.write("%*s%s%s\n" % (2*indent, "",
sys.stdout.write("%*s%s%s\n" % (2*indent, "",
- headers.get(indent, " "), msg))
+ LOG_HEADERS.get(indent, " "), msg))
def Err(msg, exit_code=1):
"""Simple error logging that prints to stderr.
def Err(msg, exit_code=1):
"""Simple error logging that prints to stderr.
try:
val = fn(*args)
if retry_count > 0 and retry_count < MAX_RETRIES:
try:
val = fn(*args)
if retry_count > 0 and retry_count < MAX_RETRIES:
- Log("Idempotent %s succeeded after %d retries" %
- (msg, MAX_RETRIES - retry_count))
+ Log("Idempotent %s succeeded after %d retries",
+ msg, MAX_RETRIES - retry_count)
return val
except Exception, err: # pylint: disable-msg=W0703
if retry_count == 0:
return val
except Exception, err: # pylint: disable-msg=W0703
if retry_count == 0:
- Log("Non-idempotent %s failed, aborting" % (msg, ))
+ Log("Non-idempotent %s failed, aborting", msg)
raise
elif retry_count == 1:
raise
elif retry_count == 1:
- Log("Idempotent %s repeated failure, aborting" % (msg, ))
+ Log("Idempotent %s repeated failure, aborting", msg)
- Log("Idempotent %s failed, retry #%d/%d: %s" %
- (msg, MAX_RETRIES - retry_count + 1, MAX_RETRIES, err))
+ Log("Idempotent %s failed, retry #%d/%d: %s",
+ msg, MAX_RETRIES - retry_count + 1, MAX_RETRIES, err)
self.MaybeRetry(retry_count - 1, msg, fn, *args)
def _SetDebug(self, ops):
self.MaybeRetry(retry_count - 1, msg, fn, *args)
def _SetDebug(self, ops):
"""
self.ClearFeedbackBuf()
job_ids = [cli.SendJob(row[0], cl=self.cl) for row in jobs]
"""
self.ClearFeedbackBuf()
job_ids = [cli.SendJob(row[0], cl=self.cl) for row in jobs]
- Log("Submitted job ID(s) %s" % utils.CommaJoin(job_ids), indent=1)
+ Log("Submitted job ID(s) %s", utils.CommaJoin(job_ids), indent=1)
results = []
for jid, (_, iname) in zip(job_ids, jobs):
results = []
for jid, (_, iname) in zip(job_ids, jobs):
- Log("waiting for job %s for %s" % (jid, iname), indent=2)
+ Log("waiting for job %s for %s", jid, iname, indent=2)
try:
results.append(cli.PollJob(jid, cl=self.cl, feedback_fn=self.Feedback))
except Exception, err: # pylint: disable-msg=W0703
try:
results.append(cli.PollJob(jid, cl=self.cl, feedback_fn=self.Feedback))
except Exception, err: # pylint: disable-msg=W0703
- Log("Job for %s failed: %s" % (iname, err))
+ Log("Job for %s failed: %s", iname, err)
if len(results) != len(jobs):
raise BurninFailure()
return results
if len(results) != len(jobs):
raise BurninFailure()
return results
Log("Creating instances")
for pnode, snode, instance in mytor:
Log("Creating instances")
for pnode, snode, instance in mytor:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
if self.opts.iallocator:
pnode = snode = None
msg = "with iallocator %s" % self.opts.iallocator
if self.opts.iallocator:
pnode = snode = None
msg = "with iallocator %s" % self.opts.iallocator
"""Grow both the os and the swap disks by the requested amount, if any."""
Log("Growing disks")
for instance in self.instances:
"""Grow both the os and the swap disks by the requested amount, if any."""
Log("Growing disks")
for instance in self.instances:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
for idx, growth in enumerate(self.disk_growth):
if growth > 0:
op = opcodes.OpGrowDisk(instance_name=instance, disk=idx,
amount=growth, wait_for_sync=True)
for idx, growth in enumerate(self.disk_growth):
if growth > 0:
op = opcodes.OpGrowDisk(instance_name=instance, disk=idx,
amount=growth, wait_for_sync=True)
- Log("increase disk/%s by %s MB" % (idx, growth), indent=2)
+ Log("increase disk/%s by %s MB", idx, growth, indent=2)
self.ExecOrQueue(instance, op)
@_DoBatch(True)
self.ExecOrQueue(instance, op)
@_DoBatch(True)
"""Replace disks on primary and secondary for drbd8."""
Log("Replacing disks on the same nodes")
for instance in self.instances:
"""Replace disks on primary and secondary for drbd8."""
Log("Replacing disks on the same nodes")
for instance in self.instances:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
ops = []
for mode in constants.REPLACE_DISK_SEC, constants.REPLACE_DISK_PRI:
op = opcodes.OpReplaceDisks(instance_name=instance,
mode=mode,
disks=[i for i in range(self.disk_count)],
early_release=self.opts.early_release)
ops = []
for mode in constants.REPLACE_DISK_SEC, constants.REPLACE_DISK_PRI:
op = opcodes.OpReplaceDisks(instance_name=instance,
mode=mode,
disks=[i for i in range(self.disk_count)],
early_release=self.opts.early_release)
- Log("run %s" % mode, indent=2)
+ Log("run %s", mode, indent=2)
ops.append(op)
self.ExecOrQueue(instance, *ops) # pylint: disable-msg=W0142
ops.append(op)
self.ExecOrQueue(instance, *ops) # pylint: disable-msg=W0142
mytor = izip(islice(cycle(self.nodes), 2, None),
self.instances)
for tnode, instance in mytor:
mytor = izip(islice(cycle(self.nodes), 2, None),
self.instances)
for tnode, instance in mytor:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
if self.opts.iallocator:
tnode = None
msg = "with iallocator %s" % self.opts.iallocator
if self.opts.iallocator:
tnode = None
msg = "with iallocator %s" % self.opts.iallocator
iallocator=self.opts.iallocator,
disks=[],
early_release=self.opts.early_release)
iallocator=self.opts.iallocator,
disks=[],
early_release=self.opts.early_release)
- Log("run %s %s" % (mode, msg), indent=2)
+ Log("run %s %s", mode, msg, indent=2)
self.ExecOrQueue(instance, op)
@_DoCheckInstances
self.ExecOrQueue(instance, op)
@_DoCheckInstances
"""Failover the instances."""
Log("Failing over instances")
for instance in self.instances:
"""Failover the instances."""
Log("Failing over instances")
for instance in self.instances:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
op = opcodes.OpFailoverInstance(instance_name=instance,
ignore_consistency=False)
self.ExecOrQueue(instance, op)
op = opcodes.OpFailoverInstance(instance_name=instance,
ignore_consistency=False)
self.ExecOrQueue(instance, op)
mytor = izip(islice(cycle(self.nodes), 1, None),
self.instances)
for tnode, instance in mytor:
mytor = izip(islice(cycle(self.nodes), 1, None),
self.instances)
for tnode, instance in mytor:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
op = opcodes.OpMoveInstance(instance_name=instance,
target_node=tnode)
self.ExecOrQueue(instance, op)
op = opcodes.OpMoveInstance(instance_name=instance,
target_node=tnode)
self.ExecOrQueue(instance, op)
"""Migrate the instances."""
Log("Migrating instances")
for instance in self.instances:
"""Migrate the instances."""
Log("Migrating instances")
for instance in self.instances:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
op1 = opcodes.OpMigrateInstance(instance_name=instance, live=True,
cleanup=False)
op1 = opcodes.OpMigrateInstance(instance_name=instance, live=True,
cleanup=False)
self.instances)
for pnode, snode, enode, instance in mytor:
self.instances)
for pnode, snode, enode, instance in mytor:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
# read the full name of the instance
nam_op = opcodes.OpQueryInstances(output_fields=["name"],
names=[instance], use_locking=True)
# read the full name of the instance
nam_op = opcodes.OpQueryInstances(output_fields=["name"],
names=[instance], use_locking=True)
erem_op = opcodes.OpRemoveExport(instance_name=instance)
erem_op = opcodes.OpRemoveExport(instance_name=instance)
- Log("export to node %s" % enode, indent=2)
+ Log("export to node %s", enode, indent=2)
Log("remove instance", indent=2)
Log(import_log_msg, indent=2)
Log("remove export", indent=2)
Log("remove instance", indent=2)
Log(import_log_msg, indent=2)
Log("remove export", indent=2)
"""Stop/start the instances."""
Log("Stopping and starting instances")
for instance in self.instances:
"""Stop/start the instances."""
Log("Stopping and starting instances")
for instance in self.instances:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
op1 = self.StopInstanceOp(instance)
op2 = self.StartInstanceOp(instance)
self.ExecOrQueue(instance, op1, op2)
op1 = self.StopInstanceOp(instance)
op2 = self.StartInstanceOp(instance)
self.ExecOrQueue(instance, op1, op2)
"""Remove the instances."""
Log("Removing instances")
for instance in self.to_rem:
"""Remove the instances."""
Log("Removing instances")
for instance in self.to_rem:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
op = opcodes.OpRemoveInstance(instance_name=instance,
ignore_failures=True)
self.ExecOrQueue(instance, op)
op = opcodes.OpRemoveInstance(instance_name=instance,
ignore_failures=True)
self.ExecOrQueue(instance, op)
Log("Renaming instances")
rename = self.opts.rename
for instance in self.instances:
Log("Renaming instances")
rename = self.opts.rename
for instance in self.instances:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
op_stop1 = self.StopInstanceOp(instance)
op_stop2 = self.StopInstanceOp(rename)
op_rename1 = self.RenameInstanceOp(instance, rename)
op_stop1 = self.StopInstanceOp(instance)
op_stop2 = self.StopInstanceOp(rename)
op_rename1 = self.RenameInstanceOp(instance, rename)
"""Reinstall the instances."""
Log("Reinstalling instances")
for instance in self.instances:
"""Reinstall the instances."""
Log("Reinstalling instances")
for instance in self.instances:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
op1 = self.StopInstanceOp(instance)
op2 = opcodes.OpReinstallInstance(instance_name=instance)
Log("reinstall without passing the OS", indent=2)
op1 = self.StopInstanceOp(instance)
op2 = opcodes.OpReinstallInstance(instance_name=instance)
Log("reinstall without passing the OS", indent=2)
"""Reboot the instances."""
Log("Rebooting instances")
for instance in self.instances:
"""Reboot the instances."""
Log("Rebooting instances")
for instance in self.instances:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
ops = []
for reboot_type in constants.REBOOT_TYPES:
op = opcodes.OpRebootInstance(instance_name=instance,
reboot_type=reboot_type,
ignore_secondaries=False)
ops = []
for reboot_type in constants.REBOOT_TYPES:
op = opcodes.OpRebootInstance(instance_name=instance,
reboot_type=reboot_type,
ignore_secondaries=False)
- Log("reboot with type '%s'" % reboot_type, indent=2)
+ Log("reboot with type '%s'", reboot_type, indent=2)
ops.append(op)
self.ExecOrQueue(instance, *ops) # pylint: disable-msg=W0142
ops.append(op)
self.ExecOrQueue(instance, *ops) # pylint: disable-msg=W0142
"""Activate and deactivate disks of the instances."""
Log("Activating/deactivating disks")
for instance in self.instances:
"""Activate and deactivate disks of the instances."""
Log("Activating/deactivating disks")
for instance in self.instances:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
op_start = self.StartInstanceOp(instance)
op_act = opcodes.OpActivateInstanceDisks(instance_name=instance)
op_deact = opcodes.OpDeactivateInstanceDisks(instance_name=instance)
op_start = self.StartInstanceOp(instance)
op_act = opcodes.OpActivateInstanceDisks(instance_name=instance)
op_deact = opcodes.OpDeactivateInstanceDisks(instance_name=instance)
"""Add and remove an extra disk for the instances."""
Log("Adding and removing disks")
for instance in self.instances:
"""Add and remove an extra disk for the instances."""
Log("Adding and removing disks")
for instance in self.instances:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
op_add = opcodes.OpSetInstanceParams(\
instance_name=instance,
disks=[(constants.DDM_ADD, {"size": self.disk_size[0]})])
op_add = opcodes.OpSetInstanceParams(\
instance_name=instance,
disks=[(constants.DDM_ADD, {"size": self.disk_size[0]})])
"""Add and remove an extra NIC for the instances."""
Log("Adding and removing NICs")
for instance in self.instances:
"""Add and remove an extra NIC for the instances."""
Log("Adding and removing NICs")
for instance in self.instances:
- Log("instance %s" % instance, indent=1)
+ Log("instance %s", instance, indent=1)
op_add = opcodes.OpSetInstanceParams(\
instance_name=instance, nics=[(constants.DDM_ADD, {})])
op_rem = opcodes.OpSetInstanceParams(\
op_add = opcodes.OpSetInstanceParams(\
instance_name=instance, nics=[(constants.DDM_ADD, {})])
op_rem = opcodes.OpSetInstanceParams(\
except Exception, err: # pylint: disable-msg=W0703
if has_err: # already detected errors, so errors in removal
# are quite expected
except Exception, err: # pylint: disable-msg=W0703
if has_err: # already detected errors, so errors in removal
# are quite expected
- Log("Note: error detected during instance remove: %s" % str(err))
+ Log("Note: error detected during instance remove: %s", err)
else: # non-expected error
raise
else: # non-expected error
raise