diff --git a/lib/backend.py b/lib/backend.py index 99cb3984f9c63f1b32246ff8f474cddecfcedac7..1624c57a5d2ec6f2f97ac1db830683b70c5ce33f 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -1863,7 +1863,7 @@ def _TryOSFromDisk(name, base_dir=None): return False, ("File '%s' under path '%s' is not executable" % (filename, os_dir)) - variants = None + variants = [] if constants.OS_VARIANTS_FILE in os_files: variants_file = os_files[constants.OS_VARIANTS_FILE] try: diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 3b2dd3b403844596254ef14033aa9c63c2368288..30c431e0e845ff65720ed3d9718e23778f577bd4 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -2760,14 +2760,14 @@ class LUDiagnoseOS(NoHooksLU): for osl in os_data.values(): valid = valid and osl and osl[0][1] if not valid: - variants = None + variants = set() break if calc_variants: node_variants = osl[0][3] if variants is None: - variants = node_variants + variants = set(node_variants) else: - variants = [v for v in variants if v in node_variants] + variants.intersection_update(node_variants) for field in self.op.output_fields: if field == "name": @@ -2780,7 +2780,7 @@ class LUDiagnoseOS(NoHooksLU): for node_name, nos_list in os_data.items(): val[node_name] = nos_list elif field == "variants": - val = variants + val = list(variants) else: raise errors.ParameterError(field) row.append(val) @@ -4175,8 +4175,7 @@ class LUStartupInstance(LogicalUnit): # check hypervisor parameter syntax (locally) cluster = self.cfg.GetClusterInfo() utils.ForceDictType(self.hvparams, constants.HVS_PARAMETER_TYPES) - filled_hvp = objects.FillDict(cluster.hvparams[instance.hypervisor], - instance.hvparams) + filled_hvp = cluster.FillHV(instance) filled_hvp.update(self.hvparams) hv_type = hypervisor.GetHypervisor(instance.hypervisor) hv_type.CheckParameterSyntax(filled_hvp) @@ -5450,15 +5449,15 @@ class TLMigrateInstance(Tasklet): target_node = secondary_nodes[0] # check memory requirements on the secondary node - _CheckNodeFreeMemory(self, target_node, "migrating instance %s" % + _CheckNodeFreeMemory(self.lu, target_node, "migrating instance %s" % instance.name, i_be[constants.BE_MEMORY], instance.hypervisor) # check bridge existance - _CheckInstanceBridgesExist(self, instance, node=target_node) + _CheckInstanceBridgesExist(self.lu, instance, node=target_node) if not self.cleanup: - _CheckNodeNotDrained(self, target_node) + _CheckNodeNotDrained(self.lu, target_node) result = self.rpc.call_instance_migratable(instance.primary_node, instance) result.Raise("Can't migrate, please use failover", @@ -5647,7 +5646,7 @@ class TLMigrateInstance(Tasklet): self.feedback_fn("* checking disk consistency between source and target") for dev in instance.disks: - if not _CheckDiskConsistency(self, dev, target_node, False): + if not _CheckDiskConsistency(self.lu, dev, target_node, False): raise errors.OpExecError("Disk %s is degraded or not fully" " synchronized on target node," " aborting migrate." % dev.iv_name) @@ -6105,9 +6104,15 @@ class LUCreateInstance(LogicalUnit): # TODO: make the ip check more flexible and not depend on the name check raise errors.OpPrereqError("Cannot do ip checks without a name check", errors.ECODE_INVAL) - # check disk information: either all adopt, or no adopt + + # check nics' parameter names + for nic in self.op.nics: + utils.ForceDictType(nic, constants.INIC_PARAMS_TYPES) + + # check disks. parameter names and consistent adopt/no-adopt strategy has_adopt = has_no_adopt = False for disk in self.op.disks: + utils.ForceDictType(disk, constants.IDISK_PARAMS_TYPES) if "adopt" in disk: has_adopt = True else: @@ -8243,6 +8248,7 @@ class LUSetInstanceParams(LogicalUnit): # Disk validation disk_addremove = 0 for disk_op, disk_dict in self.op.disks: + utils.ForceDictType(disk_dict, constants.IDISK_PARAMS_TYPES) if disk_op == constants.DDM_REMOVE: disk_addremove += 1 continue @@ -8296,6 +8302,7 @@ class LUSetInstanceParams(LogicalUnit): # NIC validation nic_addremove = 0 for nic_op, nic_dict in self.op.nics: + utils.ForceDictType(nic_dict, constants.INIC_PARAMS_TYPES) if nic_op == constants.DDM_REMOVE: nic_addremove += 1 continue diff --git a/lib/constants.py b/lib/constants.py index 0a8f407cbe20282e6521aa7b04efc10345f72f84..f720fd535c10b1c169f498c2f11e58f6fe4a73d5 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -585,6 +585,18 @@ NICS_PARAMETER_TYPES = { NICS_PARAMETERS = frozenset(NICS_PARAMETER_TYPES.keys()) +IDISK_SIZE = "size" +IDISK_MODE = "mode" +IDISK_PARAMS = frozenset([IDISK_SIZE, IDISK_MODE]) +IDISK_PARAMS_TYPES = {IDISK_SIZE: VTYPE_SIZE, IDISK_MODE: VTYPE_STRING} +INIC_MAC = "mac" +INIC_IP = "ip" +INIC_MODE = "mode" +INIC_LINK = "link" +INIC_BRIDGE = "bridge" +INIC_PARAMS = frozenset([INIC_MAC, INIC_IP, INIC_MODE, INIC_LINK, INIC_BRIDGE]) +INIC_PARAMS_TYPES = dict([(name, VTYPE_STRING) for name in INIC_PARAMS]) + # Hypervisor constants HT_XEN_PVM = "xen-pvm" HT_FAKE = "fake" diff --git a/lib/hypervisor/hv_fake.py b/lib/hypervisor/hv_fake.py index c2990a3acd4c209e5cdc4a3258dcb54e0be8d142..2d386d2e3190c6bfa6aa896420c4013ad019f939 100644 --- a/lib/hypervisor/hv_fake.py +++ b/lib/hypervisor/hv_fake.py @@ -42,7 +42,7 @@ class FakeHypervisor(hv_base.BaseHypervisor): """ CAN_MIGRATE = True - _ROOT_DIR = constants.RUN_DIR + "/ganeti-fake-hypervisor" + _ROOT_DIR = constants.RUN_GANETI_DIR + "/fake-hypervisor" def __init__(self): hv_base.BaseHypervisor.__init__(self) diff --git a/lib/rpc.py b/lib/rpc.py index e099ddeb5287caa8799f3c0d8679e258a84e1cbb..c4a36c931a5c97582cfd0066ce29f894265bf7bf 100644 --- a/lib/rpc.py +++ b/lib/rpc.py @@ -193,7 +193,7 @@ class RpcResult(object): else: ec = errors.OpExecError if ecode is not None: - args = (msg, prereq) + args = (msg, ecode) else: args = (msg, ) raise ec(*args) # pylint: disable-msg=W0142