def testOpInstanceMultiAlloc(self): inst = dict([(name, []) for name in opcodes.OpInstanceCreate.GetAllSlots()]) inst_op = opcodes.OpInstanceCreate(**inst) inst_state = inst_op.__getstate__() multialloc = opcodes.OpInstanceMultiAlloc(instances=[inst_op]) state = multialloc.__getstate__() self.assertEquals(state["instances"], [inst_state]) loaded_multialloc = opcodes.OpCode.LoadOpCode(state) (loaded_inst, ) = loaded_multialloc.instances self.assertNotEquals(loaded_inst, inst_op) self.assertEquals(loaded_inst.__getstate__(), inst_state)
def testSecretParamsCheckWithError(self): op = opcodes.OpInstanceCreate( instance_name="plain.example.com", pnode="master.example.com", disk_template=constants.DT_PLAIN, mode=constants.INSTANCE_CREATE, nics=[{}], disks=[{ constants.IDISK_SIZE: 1024 }], osparams_secret= serializer.PrivateDict({"foo":"bar", "secret_param":"<redacted>"}), os_type="debian-image") self.assertRaises(errors.OpPrereqError, mcpu._CheckSecretParameters, op)
def BurnCreateInstances(self): """Create the given instances. """ self.to_rem = [] mytor = izip(cycle(self.nodes), islice(cycle(self.nodes), 1, None), self.instances) Log("Creating instances") for pnode, snode, instance in mytor: Log("instance %s", instance, indent=1) if self.opts.iallocator: pnode = snode = None msg = "with iallocator %s" % self.opts.iallocator elif self.opts.disk_template not in constants.DTS_INT_MIRROR: snode = None msg = "on %s" % pnode else: msg = "on %s, %s" % (pnode, snode) Log(msg, indent=2) op = opcodes.OpInstanceCreate( instance_name=instance, disks=[{ "size": size } for size in self.disk_size], disk_template=self.opts.disk_template, nics=self.opts.nics, mode=constants.INSTANCE_CREATE, os_type=self.opts.os, pnode=pnode, snode=snode, start=True, ip_check=self.opts.ip_check, name_check=self.opts.name_check, wait_for_sync=True, file_driver="loop", file_storage_dir=None, iallocator=self.opts.iallocator, beparams=self.bep, hvparams=self.hvp, hypervisor=self.hypervisor, osparams=self.opts.osparams, ) remove_instance = lambda name: lambda: self.to_rem.append(name) self.ExecOrQueue(instance, [op], post_process=remove_instance(instance))
def testSecretParamsCheckNoError(self): op = opcodes.OpInstanceCreate( instance_name="plain.example.com", pnode="master.example.com", disk_template=constants.DT_PLAIN, mode=constants.INSTANCE_CREATE, nics=[{}], disks=[{ constants.IDISK_SIZE: 1024 }], osparams_secret= serializer.PrivateDict({"foo":"bar", "foo2":"bar2"}), os_type="debian-image") try: mcpu._CheckSecretParameters(op) except errors.OpPrereqError: self.fail("OpPrereqError raised unexpectedly in _CheckSecretParameters")
def BurnImportExport(self): """Export the instance, delete it, and import it back. """ Log("Exporting and re-importing instances") mytor = izip(cycle(self.nodes), islice(cycle(self.nodes), 1, None), islice(cycle(self.nodes), 2, None), self.instances) qcl = GetClient(query=True) for pnode, snode, enode, instance in mytor: Log("instance %s", instance, indent=1) # read the full name of the instance ((full_name, ), ) = qcl.QueryInstances([instance], ["name"], False) if self.opts.iallocator: pnode = snode = None import_log_msg = ("import from %s" " with iallocator %s" % (enode, self.opts.iallocator)) elif self.opts.disk_template not in constants.DTS_INT_MIRROR: snode = None import_log_msg = ("import from %s to %s" % (enode, pnode)) else: import_log_msg = ("import from %s to %s, %s" % (enode, pnode, snode)) exp_op = opcodes.OpBackupExport(instance_name=instance, target_node=enode, mode=constants.EXPORT_MODE_LOCAL, shutdown=True) rem_op = opcodes.OpInstanceRemove(instance_name=instance, ignore_failures=True) imp_dir = utils.PathJoin(pathutils.EXPORT_DIR, full_name) imp_op = opcodes.OpInstanceCreate( instance_name=instance, disks=[{ "size": size } for size in self.disk_size], disk_template=self.opts.disk_template, nics=self.opts.nics, mode=constants.INSTANCE_IMPORT, src_node=enode, src_path=imp_dir, pnode=pnode, snode=snode, start=True, ip_check=self.opts.ip_check, name_check=self.opts.name_check, wait_for_sync=True, file_storage_dir=None, file_driver="loop", iallocator=self.opts.iallocator, beparams=self.bep, hvparams=self.hvp, osparams=self.opts.osparams, ) erem_op = opcodes.OpBackupRemove(instance_name=instance) Log("export to node %s", enode, indent=2) Log("remove instance", indent=2) Log(import_log_msg, indent=2) Log("remove export", indent=2) self.ExecOrQueue(instance, [exp_op, rem_op, imp_op, erem_op]) qcl.Close()