Remove the parameter definitions and use those from the opcode classes instead. Small style changes are also made (empty lines, wrapping). --- lib/cmdlib.py | 453 +--------------------------------------- test/ganeti.cmdlib_unittest.py | 33 +--- 2 files changed, 15 insertions(+), 471 deletions(-)
diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 9a21301..88f21f8 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -60,38 +60,6 @@ from ganeti import qlang import ganeti.masterd.instance # pylint: disable-msg=W0611 -# Common opcode attributes - -#: output fields for a query operation -_POutputFields = ("output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)) - - -#: the shutdown timeout -_PShutdownTimeout = ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, - ht.TPositiveInt) - -#: the force parameter -_PForce = ("force", False, ht.TBool) - -#: a required instance name (for single-instance LUs) -_PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString) - -#: Whether to ignore offline nodes -_PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool) - -#: a required node name (for single-node LUs) -_PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString) - -#: a required node group name (for single-group LUs) -_PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString) - -#: the migration type (live/non-live) -_PMigrationMode = ("mode", None, - ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES))) - -#: the obsolete 'live' mode (boolean) -_PMigrationLive = ("live", None, ht.TMaybeBool) - def _SupportsOob(cfg, node): """Tells if node supports OOB. @@ -123,13 +91,10 @@ class LogicalUnit(object): @ivar dry_run_result: the value (if any) that will be returned to the caller in dry-run mode (signalled by opcode dry_run parameter) - @cvar _OP_PARAMS: a list of opcode attributes, the default values - they should get if not already defined, and types they must match """ HPATH = None HTYPE = None - _OP_PARAMS = [] REQ_BGL = True def __init__(self, processor, op, context, rpc): @@ -170,7 +135,7 @@ class LogicalUnit(object): # The new kind-of-type-system op_id = self.op.OP_ID - for attr_name, aval, test in self._OP_PARAMS: + for attr_name, aval, test in self.op.GetAllParams(): if not hasattr(op, attr_name): if aval == ht.NoDefault: raise errors.OpPrereqError("Required parameter '%s.%s' missing" % @@ -788,31 +753,6 @@ def _CheckNodeHasSecondaryIP(lu, node, secondary_ip, prereq): raise errors.OpExecError(msg) -def _CheckDiskTemplate(template): - """Ensure a given disk template is valid. - - """ - if template not in constants.DISK_TEMPLATES: - msg = ("Invalid disk template name '%s', valid templates are: %s" % - (template, utils.CommaJoin(constants.DISK_TEMPLATES))) - raise errors.OpPrereqError(msg, errors.ECODE_INVAL) - if template == constants.DT_FILE: - utils.RequireFileStorage() - return True - - -def _CheckStorageType(storage_type): - """Ensure a given storage type is valid. - - """ - if storage_type not in constants.VALID_STORAGE_TYPES: - raise errors.OpPrereqError("Unknown storage type: %s" % storage_type, - errors.ECODE_INVAL) - if storage_type == constants.ST_FILE: - utils.RequireFileStorage() - return True - - def _GetClusterDomainSecret(): """Reads the cluster domain secret. @@ -1289,13 +1229,6 @@ class LUVerifyCluster(LogicalUnit): """ HPATH = "cluster-verify" HTYPE = constants.HTYPE_CLUSTER - _OP_PARAMS = [ - ("skip_checks", ht.EmptyList, - ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS))), - ("verbose", False, ht.TBool), - ("error_codes", False, ht.TBool), - ("debug_simulate_errors", False, ht.TBool), - ] REQ_BGL = False TCLUSTER = "cluster" @@ -2496,7 +2429,6 @@ class LURepairDiskSizes(NoHooksLU): """Verifies the cluster disks sizes. """ - _OP_PARAMS = [("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString))] REQ_BGL = False def ExpandNames(self): @@ -2614,7 +2546,6 @@ class LURenameCluster(LogicalUnit): """ HPATH = "cluster-rename" HTYPE = constants.HTYPE_CLUSTER - _OP_PARAMS = [("name", ht.NoDefault, ht.TNonEmptyString)] def BuildHooksEnv(self): """Build hooks env. @@ -2693,41 +2624,6 @@ class LUSetClusterParams(LogicalUnit): """ HPATH = "cluster-modify" HTYPE = constants.HTYPE_CLUSTER - _OP_PARAMS = [ - ("vg_name", None, ht.TMaybeString), - ("enabled_hypervisors", None, - ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue), - ht.TNone)), - ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), - ht.TNone)), - ("beparams", None, ht.TOr(ht.TDict, ht.TNone)), - ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), - ht.TNone)), - ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), - ht.TNone)), - ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone)), - ("uid_pool", None, ht.NoType), - ("add_uids", None, ht.NoType), - ("remove_uids", None, ht.NoType), - ("maintain_node_health", None, ht.TMaybeBool), - ("prealloc_wipe_disks", None, ht.TMaybeBool), - ("nicparams", None, ht.TOr(ht.TDict, ht.TNone)), - ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)), - ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone)), - ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone)), - ("master_netdev", None, ht.TOr(ht.TString, ht.TNone)), - ("reserved_lvs", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone)), - ("hidden_os", None, ht.TOr(ht.TListOf(\ - ht.TAnd(ht.TList, - ht.TIsLength(2), - ht.TMap(lambda v: v[0], ht.TElemOf(constants.DDMS_VALUES)))), - ht.TNone)), - ("blacklisted_os", None, ht.TOr(ht.TListOf(\ - ht.TAnd(ht.TList, - ht.TIsLength(2), - ht.TMap(lambda v: v[0], ht.TElemOf(constants.DDMS_VALUES)))), - ht.TNone)), - ] REQ_BGL = False def CheckArguments(self): @@ -3252,11 +3148,6 @@ class LUOobCommand(NoHooksLU): """Logical unit for OOB handling. """ - _OP_PARAMS = [ - _PNodeName, - ("command", None, ht.TElemOf(constants.OOB_COMMANDS)), - ("timeout", constants.OOB_TIMEOUT, ht.TInt), - ] REG_BGL = False def CheckPrereq(self): @@ -3377,10 +3268,6 @@ class LUDiagnoseOS(NoHooksLU): """Logical unit for OS diagnose/query. """ - _OP_PARAMS = [ - _POutputFields, - ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)), - ] REQ_BGL = False _HID = "hidden" _BLK = "blacklisted" @@ -3517,9 +3404,6 @@ class LURemoveNode(LogicalUnit): """ HPATH = "node-remove" HTYPE = constants.HTYPE_NODE - _OP_PARAMS = [ - _PNodeName, - ] def BuildHooksEnv(self): """Build hooks env. @@ -3681,11 +3565,6 @@ class LUQueryNodes(NoHooksLU): """ # pylint: disable-msg=W0142 - _OP_PARAMS = [ - _POutputFields, - ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)), - ("use_locking", False, ht.TBool), - ] REQ_BGL = False def CheckArguments(self): @@ -3703,10 +3582,6 @@ class LUQueryNodeVolumes(NoHooksLU): """Logical unit for getting volumes on node(s). """ - _OP_PARAMS = [ - _POutputFields, - ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)), - ] REQ_BGL = False _FIELDS_DYNAMIC = utils.FieldSet("phys", "vg", "name", "size", "instance") _FIELDS_STATIC = utils.FieldSet("node") @@ -3786,12 +3661,6 @@ class LUQueryNodeStorage(NoHooksLU): """ _FIELDS_STATIC = utils.FieldSet(constants.SF_NODE) - _OP_PARAMS = [ - _POutputFields, - ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)), - ("storage_type", ht.NoDefault, _CheckStorageType), - ("name", None, ht.TMaybeString), - ] REQ_BGL = False def CheckArguments(self): @@ -3965,12 +3834,6 @@ class LUQuery(NoHooksLU): """ # pylint: disable-msg=W0142 - _OP_PARAMS = [ - ("what", ht.NoDefault, ht.TElemOf(constants.QR_OP_QUERY)), - ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)), - ("filter", None, ht.TOr(ht.TNone, - ht.TListOf(ht.TOr(ht.TNonEmptyString, ht.TList)))), - ] REQ_BGL = False def CheckArguments(self): @@ -3994,10 +3857,6 @@ class LUQueryFields(NoHooksLU): """ # pylint: disable-msg=W0142 - _OP_PARAMS = [ - ("what", ht.NoDefault, ht.TElemOf(constants.QR_OP_QUERY)), - ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString))), - ] REQ_BGL = False def CheckArguments(self): @@ -4014,12 +3873,6 @@ class LUModifyNodeStorage(NoHooksLU): """Logical unit for modifying a storage volume on a node. """ - _OP_PARAMS = [ - _PNodeName, - ("storage_type", ht.NoDefault, _CheckStorageType), - ("name", ht.NoDefault, ht.TNonEmptyString), - ("changes", ht.NoDefault, ht.TDict), - ] REQ_BGL = False def CheckArguments(self): @@ -4064,16 +3917,6 @@ class LUAddNode(LogicalUnit): """ HPATH = "node-add" HTYPE = constants.HTYPE_NODE - _OP_PARAMS = [ - _PNodeName, - ("primary_ip", None, ht.NoType), - ("secondary_ip", None, ht.TMaybeString), - ("readd", False, ht.TBool), - ("group", None, ht.TMaybeString), - ("master_capable", None, ht.TMaybeBool), - ("vm_capable", None, ht.TMaybeBool), - ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)), - ] _NFLAGS = ["master_capable", "vm_capable"] def CheckArguments(self): @@ -4341,19 +4184,6 @@ class LUSetNodeParams(LogicalUnit): """ HPATH = "node-modify" HTYPE = constants.HTYPE_NODE - _OP_PARAMS = [ - _PNodeName, - ("master_candidate", None, ht.TMaybeBool), - ("offline", None, ht.TMaybeBool), - ("drained", None, ht.TMaybeBool), - ("auto_promote", False, ht.TBool), - ("master_capable", None, ht.TMaybeBool), - ("vm_capable", None, ht.TMaybeBool), - ("secondary_ip", None, ht.TMaybeString), - ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)), - ("powered", None, ht.TMaybeBool), - _PForce, - ] REQ_BGL = False (_ROLE_CANDIDATE, _ROLE_DRAINED, _ROLE_OFFLINE, _ROLE_REGULAR) = range(4) _F2R = { @@ -4640,10 +4470,6 @@ class LUPowercycleNode(NoHooksLU): """Powercycles a node. """ - _OP_PARAMS = [ - _PNodeName, - _PForce, - ] REQ_BGL = False def CheckArguments(self): @@ -4741,7 +4567,6 @@ class LUQueryConfigValues(NoHooksLU): """Return configuration values. """ - _OP_PARAMS = [_POutputFields] REQ_BGL = False _FIELDS_DYNAMIC = utils.FieldSet() _FIELDS_STATIC = utils.FieldSet("cluster_name", "master_node", "drain_flag", @@ -4781,10 +4606,6 @@ class LUActivateInstanceDisks(NoHooksLU): """Bring up an instance's disks. """ - _OP_PARAMS = [ - _PInstanceName, - ("ignore_size", False, ht.TBool), - ] REQ_BGL = False def ExpandNames(self): @@ -4927,9 +4748,6 @@ class LUDeactivateInstanceDisks(NoHooksLU): """Shutdown an instance's disks. """ - _OP_PARAMS = [ - _PInstanceName, - ] REQ_BGL = False def ExpandNames(self): @@ -5118,13 +4936,6 @@ class LUStartupInstance(LogicalUnit): """ HPATH = "instance-start" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - _PForce, - _PIgnoreOfflineNodes, - ("hvparams", ht.EmptyDict, ht.TDict), - ("beparams", ht.EmptyDict, ht.TDict), - ] REQ_BGL = False def CheckArguments(self): @@ -5226,12 +5037,6 @@ class LURebootInstance(LogicalUnit): """ HPATH = "instance-reboot" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - ("ignore_secondaries", False, ht.TBool), - ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES)), - _PShutdownTimeout, - ] REQ_BGL = False def ExpandNames(self): @@ -5307,11 +5112,6 @@ class LUShutdownInstance(LogicalUnit): """ HPATH = "instance-stop" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - _PIgnoreOfflineNodes, - ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt), - ] REQ_BGL = False def ExpandNames(self): @@ -5374,12 +5174,6 @@ class LUReinstallInstance(LogicalUnit): """ HPATH = "instance-reinstall" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - ("os_type", None, ht.TMaybeString), - ("force_variant", False, ht.TBool), - ("osparams", None, ht.TOr(ht.TDict, ht.TNone)), - ] REQ_BGL = False def ExpandNames(self): @@ -5466,10 +5260,6 @@ class LURecreateInstanceDisks(LogicalUnit): """ HPATH = "instance-recreate-disks" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt)), - ] REQ_BGL = False def ExpandNames(self): @@ -5530,12 +5320,6 @@ class LURenameInstance(LogicalUnit): """ HPATH = "instance-rename" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - ("new_name", ht.NoDefault, ht.TNonEmptyString), - ("ip_check", False, ht.TBool), - ("name_check", True, ht.TBool), - ] def CheckArguments(self): """Check arguments. @@ -5641,11 +5425,6 @@ class LURemoveInstance(LogicalUnit): """ HPATH = "instance-remove" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - ("ignore_failures", False, ht.TBool), - _PShutdownTimeout, - ] REQ_BGL = False def ExpandNames(self): @@ -5728,11 +5507,6 @@ class LUQueryInstances(NoHooksLU): """ # pylint: disable-msg=W0142 - _OP_PARAMS = [ - _POutputFields, - ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)), - ("use_locking", False, ht.TBool), - ] REQ_BGL = False def CheckArguments(self): @@ -5755,11 +5529,6 @@ class LUFailoverInstance(LogicalUnit): """ HPATH = "instance-failover" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - ("ignore_consistency", False, ht.TBool), - _PShutdownTimeout, - ] REQ_BGL = False def ExpandNames(self): @@ -5910,13 +5679,6 @@ class LUMigrateInstance(LogicalUnit): """ HPATH = "instance-migrate" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - _PMigrationMode, - _PMigrationLive, - ("cleanup", False, ht.TBool), - ] - REQ_BGL = False def ExpandNames(self): @@ -5963,11 +5725,6 @@ class LUMoveInstance(LogicalUnit): """ HPATH = "instance-move" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - ("target_node", ht.NoDefault, ht.TNonEmptyString), - _PShutdownTimeout, - ] REQ_BGL = False def ExpandNames(self): @@ -6143,11 +5900,6 @@ class LUMigrateNode(LogicalUnit): """ HPATH = "node-migrate" HTYPE = constants.HTYPE_NODE - _OP_PARAMS = [ - _PNodeName, - _PMigrationMode, - _PMigrationLive, - ] REQ_BGL = False def ExpandNames(self): @@ -6991,37 +6743,6 @@ class LUCreateInstance(LogicalUnit): """ HPATH = "instance-add" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES)), - ("start", True, ht.TBool), - ("wait_for_sync", True, ht.TBool), - ("ip_check", True, ht.TBool), - ("name_check", True, ht.TBool), - ("disks", ht.NoDefault, ht.TListOf(ht.TDict)), - ("nics", ht.NoDefault, ht.TListOf(ht.TDict)), - ("hvparams", ht.EmptyDict, ht.TDict), - ("beparams", ht.EmptyDict, ht.TDict), - ("osparams", ht.EmptyDict, ht.TDict), - ("no_install", None, ht.TMaybeBool), - ("os_type", None, ht.TMaybeString), - ("force_variant", False, ht.TBool), - ("source_handshake", None, ht.TOr(ht.TList, ht.TNone)), - ("source_x509_ca", None, ht.TMaybeString), - ("source_instance_name", None, ht.TMaybeString), - ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, - ht.TPositiveInt), - ("src_node", None, ht.TMaybeString), - ("src_path", None, ht.TMaybeString), - ("pnode", None, ht.TMaybeString), - ("snode", None, ht.TMaybeString), - ("iallocator", None, ht.TMaybeString), - ("hypervisor", None, ht.TMaybeString), - ("disk_template", ht.NoDefault, _CheckDiskTemplate), - ("identify_defaults", False, ht.TBool), - ("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER))), - ("file_storage_dir", None, ht.TMaybeString), - ] REQ_BGL = False def CheckArguments(self): @@ -7445,8 +7166,6 @@ class LUCreateInstance(LogicalUnit): export_info = self._ReadExportInfo() self._ReadExportParams(export_info) - _CheckDiskTemplate(self.op.disk_template) - if (not self.cfg.GetVGName() and self.op.disk_template not in constants.DTS_NOT_LVM): raise errors.OpPrereqError("Cluster does not support lvm-based" @@ -7937,9 +7656,6 @@ class LUConnectConsole(NoHooksLU): console. """ - _OP_PARAMS = [ - _PInstanceName - ] REQ_BGL = False def ExpandNames(self): @@ -7995,14 +7711,6 @@ class LUReplaceDisks(LogicalUnit): """ HPATH = "mirrors-replace" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES)), - ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt)), - ("remote_node", None, ht.TMaybeString), - ("iallocator", None, ht.TMaybeString), - ("early_release", False, ht.TBool), - ] REQ_BGL = False def CheckArguments(self): @@ -8739,12 +8447,6 @@ class LURepairNodeStorage(NoHooksLU): """Repairs the volume group on a node. """ - _OP_PARAMS = [ - _PNodeName, - ("storage_type", ht.NoDefault, _CheckStorageType), - ("name", ht.NoDefault, ht.TNonEmptyString), - ("ignore_consistency", False, ht.TBool), - ] REQ_BGL = False def CheckArguments(self): @@ -8807,11 +8509,6 @@ class LUNodeEvacuationStrategy(NoHooksLU): """Computes the node evacuation strategy. """ - _OP_PARAMS = [ - ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)), - ("remote_node", None, ht.TMaybeString), - ("iallocator", None, ht.TMaybeString), - ] REQ_BGL = False def CheckArguments(self): @@ -8858,12 +8555,6 @@ class LUGrowDisk(LogicalUnit): """ HPATH = "disk-grow" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - ("disk", ht.NoDefault, ht.TInt), - ("amount", ht.NoDefault, ht.TInt), - ("wait_for_sync", True, ht.TBool), - ] REQ_BGL = False def ExpandNames(self): @@ -8958,10 +8649,6 @@ class LUQueryInstanceData(NoHooksLU): """Query runtime instance data. """ - _OP_PARAMS = [ - ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)), - ("static", False, ht.TBool), - ] REQ_BGL = False def ExpandNames(self): @@ -9118,19 +8805,6 @@ class LUSetInstanceParams(LogicalUnit): """ HPATH = "instance-modify" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - ("nics", ht.EmptyList, ht.TList), - ("disks", ht.EmptyList, ht.TList), - ("beparams", ht.EmptyDict, ht.TDict), - ("hvparams", ht.EmptyDict, ht.TDict), - ("disk_template", None, ht.TMaybeString), - ("remote_node", None, ht.TMaybeString), - ("os_name", None, ht.TMaybeString), - ("force_variant", False, ht.TBool), - ("osparams", None, ht.TOr(ht.TDict, ht.TNone)), - _PForce, - ] REQ_BGL = False def CheckArguments(self): @@ -9187,13 +8861,12 @@ class LUSetInstanceParams(LogicalUnit): " changes not supported at the same time", errors.ECODE_INVAL) - if self.op.disk_template: - _CheckDiskTemplate(self.op.disk_template) - if (self.op.disk_template in constants.DTS_NET_MIRROR and - self.op.remote_node is None): - raise errors.OpPrereqError("Changing the disk template to a mirrored" - " one requires specifying a secondary node", - errors.ECODE_INVAL) + if (self.op.disk_template and + self.op.disk_template in constants.DTS_NET_MIRROR and + self.op.remote_node is None): + raise errors.OpPrereqError("Changing the disk template to a mirrored" + " one requires specifying a secondary node", + errors.ECODE_INVAL) # NIC validation nic_addremove = 0 @@ -9785,10 +9458,6 @@ class LUQueryExports(NoHooksLU): """Query the exports list """ - _OP_PARAMS = [ - ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)), - ("use_locking", False, ht.TBool), - ] REQ_BGL = False def ExpandNames(self): @@ -9825,10 +9494,6 @@ class LUPrepareExport(NoHooksLU): """Prepares an instance for an export and returns useful information. """ - _OP_PARAMS = [ - _PInstanceName, - ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES)), - ] REQ_BGL = False def ExpandNames(self): @@ -9882,17 +9547,6 @@ class LUExportInstance(LogicalUnit): """ HPATH = "instance-export" HTYPE = constants.HTYPE_INSTANCE - _OP_PARAMS = [ - _PInstanceName, - ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList)), - ("shutdown", True, ht.TBool), - _PShutdownTimeout, - ("remove_instance", False, ht.TBool), - ("ignore_remove_failures", False, ht.TBool), - ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES)), - ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone)), - ("destination_x509_ca", None, ht.TMaybeString), - ] REQ_BGL = False def CheckArguments(self): @@ -10179,9 +9833,6 @@ class LURemoveExport(NoHooksLU): """Remove exports related to the named instance. """ - _OP_PARAMS = [ - _PInstanceName, - ] REQ_BGL = False def ExpandNames(self): @@ -10231,14 +9882,6 @@ class LUAddGroup(LogicalUnit): """ HPATH = "group-add" HTYPE = constants.HTYPE_GROUP - - _OP_PARAMS = [ - _PGroupName, - ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)), - ("alloc_policy", None, ht.TOr(ht.TNone, - ht.TElemOf(constants.VALID_ALLOC_POLICIES))), - ] - REQ_BGL = False def ExpandNames(self): @@ -10297,20 +9940,12 @@ class LUQueryGroups(NoHooksLU): """ # pylint: disable-msg=W0142 - _OP_PARAMS = [ - _POutputFields, - ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)), - ] - REQ_BGL = False - _FIELDS_DYNAMIC = utils.FieldSet() - _SIMPLE_FIELDS = ["name", "uuid", "alloc_policy", "ctime", "mtime", "serial_no"] - - _FIELDS_STATIC = utils.FieldSet( - "node_cnt", "node_list", "pinst_cnt", "pinst_list", *_SIMPLE_FIELDS) + _FIELDS_STATIC = utils.FieldSet("node_cnt", "node_list", "pinst_cnt", + "pinst_list", *_SIMPLE_FIELDS) def CheckArguments(self): _CheckOutputFields(static=self._FIELDS_STATIC, @@ -10407,14 +10042,6 @@ class LUSetGroupParams(LogicalUnit): """ HPATH = "group-modify" HTYPE = constants.HTYPE_GROUP - - _OP_PARAMS = [ - _PGroupName, - ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)), - ("alloc_policy", None, ht.TOr(ht.TNone, - ht.TElemOf(constants.VALID_ALLOC_POLICIES))), - ] - REQ_BGL = False def CheckArguments(self): @@ -10481,11 +10108,6 @@ class LUSetGroupParams(LogicalUnit): class LURemoveGroup(LogicalUnit): HPATH = "group-remove" HTYPE = constants.HTYPE_GROUP - - _OP_PARAMS = [ - _PGroupName, - ] - REQ_BGL = False def ExpandNames(self): @@ -10548,12 +10170,6 @@ class LURemoveGroup(LogicalUnit): class LURenameGroup(LogicalUnit): HPATH = "group-rename" HTYPE = constants.HTYPE_GROUP - - _OP_PARAMS = [ - ("old_name", ht.NoDefault, ht.TNonEmptyString), - ("new_name", ht.NoDefault, ht.TNonEmptyString), - ] - REQ_BGL = False def ExpandNames(self): @@ -10655,11 +10271,6 @@ class LUGetTags(TagsLU): """Returns the tags of a given object. """ - _OP_PARAMS = [ - ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES)), - # Name is only meaningful for nodes and instances - ("name", ht.NoDefault, ht.TMaybeString), - ] REQ_BGL = False def ExpandNames(self): @@ -10679,9 +10290,6 @@ class LUSearchTags(NoHooksLU): """Searches the tags for a given pattern. """ - _OP_PARAMS = [ - ("pattern", ht.NoDefault, ht.TNonEmptyString), - ] REQ_BGL = False def ExpandNames(self): @@ -10721,12 +10329,6 @@ class LUAddTags(TagsLU): """Sets a tag on a given object. """ - _OP_PARAMS = [ - ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES)), - # Name is only meaningful for nodes and instances - ("name", ht.NoDefault, ht.TMaybeString), - ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)), - ] REQ_BGL = False def CheckPrereq(self): @@ -10755,12 +10357,6 @@ class LUDelTags(TagsLU): """Delete a list of tags from a given object. """ - _OP_PARAMS = [ - ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES)), - # Name is only meaningful for nodes and instances - ("name", ht.NoDefault, ht.TMaybeString), - ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)), - ] REQ_BGL = False def CheckPrereq(self): @@ -10798,12 +10394,6 @@ class LUTestDelay(NoHooksLU): time. """ - _OP_PARAMS = [ - ("duration", ht.NoDefault, ht.TFloat), - ("on_master", True, ht.TBool), - ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)), - ("repeat", 0, ht.TPositiveInt) - ] REQ_BGL = False def ExpandNames(self): @@ -10849,12 +10439,6 @@ class LUTestJobqueue(NoHooksLU): """Utility LU to test some aspects of the job queue. """ - _OP_PARAMS = [ - ("notify_waitlock", False, ht.TBool), - ("notify_exec", False, ht.TBool), - ("log_messages", ht.EmptyList, ht.TListOf(ht.TString)), - ("fail", False, ht.TBool), - ] REQ_BGL = False # Must be lower than default timeout for WaitForJobChange to see whether it @@ -11352,25 +10936,6 @@ class LUTestAllocator(NoHooksLU): This LU runs the allocator tests """ - _OP_PARAMS = [ - ("direction", ht.NoDefault, - ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS)), - ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES)), - ("name", ht.NoDefault, ht.TNonEmptyString), - ("nics", ht.NoDefault, ht.TOr(ht.TNone, ht.TListOf( - ht.TDictOf(ht.TElemOf(["mac", "ip", "bridge"]), - ht.TOr(ht.TNone, ht.TNonEmptyString))))), - ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList)), - ("hypervisor", None, ht.TMaybeString), - ("allocator", None, ht.TMaybeString), - ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)), - ("mem_size", None, ht.TOr(ht.TNone, ht.TPositiveInt)), - ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt)), - ("os", None, ht.TMaybeString), - ("disk_template", None, ht.TMaybeString), - ("evac_nodes", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString))), - ] - def CheckPrereq(self): """Check prerequisites. diff --git a/test/ganeti.cmdlib_unittest.py b/test/ganeti.cmdlib_unittest.py index a675dfd..8f64c84 100755 --- a/test/ganeti.cmdlib_unittest.py +++ b/test/ganeti.cmdlib_unittest.py @@ -69,33 +69,12 @@ class TestOpcodeParams(testutils.GanetiTestCase): for op in sorted(mcpu.Processor.DISPATCH_TABLE): lu = mcpu.Processor.DISPATCH_TABLE[op] lu_name = lu.__name__ - self.failIf(hasattr(lu, "_OP_REQP"), "LU '%s' has old-style _OP_REQP" % - lu_name) - self.failIf(hasattr(lu, "_OP_DEFS"), "LU '%s' has old-style _OP_DEFS" % - lu_name) - # this needs to remain a list! - defined_params = [v[0] for v in lu._OP_PARAMS] - for row in lu._OP_PARAMS: - # this relies on there being at least one element - param_name = row[0] - self.failIf(len(row) != 3, "LU '%s' parameter %s has invalid length" % - (lu_name, param_name)) - self.failIf(defined_params.count(param_name) > 1, "LU '%s' parameter" - " '%s' is defined multiple times" % (lu_name, param_name)) - - def testParamsDefined(self): - for op in sorted(mcpu.Processor.DISPATCH_TABLE): - lu = mcpu.Processor.DISPATCH_TABLE[op] - lu_name = lu.__name__ - # TODO: this doesn't deal with recursive slots definitions - all_params = set(op.__slots__) - defined_params = set(v[0] for v in lu._OP_PARAMS) - missing = all_params.difference(defined_params) - self.failIf(missing, "Undeclared parameter types for LU '%s': %s" % - (lu_name, utils.CommaJoin(missing))) - extra = defined_params.difference(all_params) - self.failIf(extra, "Extra parameter types for LU '%s': %s" % - (lu_name, utils.CommaJoin(extra))) + self.failIf(hasattr(lu, "_OP_REQP"), + msg=("LU '%s' has old-style _OP_REQP" % lu_name)) + self.failIf(hasattr(lu, "_OP_DEFS"), + msg=("LU '%s' has old-style _OP_DEFS" % lu_name)) + self.failIf(hasattr(lu, "_OP_PARAMS"), + msg=("LU '%s' has old-style _OP_PARAMS" % lu_name)) class TestIAllocatorChecks(testutils.GanetiTestCase): -- 1.7.3.1