def TestInstanceAddWithPlainDisk(nodes, fail=False): """gnt-instance add -t plain""" if constants.DT_PLAIN in qa_config.GetEnabledDiskTemplates(): instance = CreateInstanceByDiskTemplateOneNode(nodes, constants.DT_PLAIN, fail=fail) if not fail: qa_utils.RunInstanceCheck(instance, True) return instance
def _RestoreEnabledDiskTemplates(): """Sets the list of enabled disk templates back to the list of enabled disk templates from the QA configuration. This can be used to make sure that the tests that modify the list of disk templates do not interfere with other tests. """ enabled_disk_templates = qa_config.GetEnabledDiskTemplates() cmd = [ "gnt-cluster", "modify", "--enabled-disk-templates=%s" % ",".join(enabled_disk_templates), "--ipolicy-disk-templates=%s" % ",".join(enabled_disk_templates), ] if utils.IsLvmEnabled(qa_config.GetEnabledDiskTemplates()): vgname = qa_config.get("vg-name", constants.DEFAULT_VG) cmd.append("--vg-name=%s" % vgname) AssertCommand(cmd, fail=False)
def TestClusterModifyDiskTemplates(): """gnt-cluster modify --enabled-disk-templates=...""" enabled_disk_templates = qa_config.GetEnabledDiskTemplates() default_disk_template = qa_config.GetDefaultDiskTemplate() _TestClusterModifyDiskTemplatesArguments(default_disk_template) _TestClusterModifyDiskTemplatesDrbdHelper(enabled_disk_templates) _TestClusterModifyDiskTemplatesVgName(enabled_disk_templates) _RestoreEnabledDiskTemplates() nodes = qa_config.AcquireManyNodes(2) instance_template = enabled_disk_templates[0] instance = qa_instance.CreateInstanceByDiskTemplate( nodes, instance_template) _TestClusterModifyUsedDiskTemplate(instance_template, enabled_disk_templates) qa_instance.TestInstanceRemove(instance) _RestoreEnabledDiskTemplates()
def TestClusterModifyFileBasedStorageDir(file_disk_template, dir_config_key, default_dir, option_name): """Tests gnt-cluster modify wrt to file-based directory options. @type file_disk_template: string @param file_disk_template: file-based disk template @type dir_config_key: string @param dir_config_key: key for the QA config to retrieve the default directory value @type default_dir: string @param default_dir: default directory, if the QA config does not specify it @type option_name: string @param option_name: name of the option of 'gnt-cluster modify' to change the directory """ enabled_disk_templates = qa_config.GetEnabledDiskTemplates() assert file_disk_template in constants.DTS_FILEBASED if not qa_config.IsTemplateSupported(file_disk_template): return # Get some non-file-based disk template to disable file storage other_disk_template = _GetOtherEnabledDiskTemplate( utils.storage.GetDiskTemplatesOfStorageTypes(constants.ST_FILE, constants.ST_SHARED_FILE), enabled_disk_templates) file_storage_dir = qa_config.get(dir_config_key, default_dir) invalid_file_storage_dir = "/boot/" for fail, cmd in [ (False, [ "gnt-cluster", "modify", "--enabled-disk-templates=%s" % file_disk_template, "--ipolicy-disk-templates=%s" % file_disk_template ]), (False, [ "gnt-cluster", "modify", "--%s=%s" % (option_name, file_storage_dir) ]), (False, [ "gnt-cluster", "modify", "--%s=%s" % (option_name, invalid_file_storage_dir) ]), # file storage dir is set to an inacceptable path, thus verify # should fail (True, ["gnt-cluster", "verify"]), # unsetting the storage dir while file storage is enabled # should fail (True, ["gnt-cluster", "modify", "--%s=" % option_name]), (False, [ "gnt-cluster", "modify", "--%s=%s" % (option_name, file_storage_dir) ]), (False, [ "gnt-cluster", "modify", "--enabled-disk-templates=%s" % other_disk_template, "--ipolicy-disk-templates=%s" % other_disk_template ]), (False, [ "gnt-cluster", "modify", "--%s=%s" % (option_name, invalid_file_storage_dir) ]), # file storage is set to an inacceptable path, but file storage # is disabled, thus verify should not fail (False, ["gnt-cluster", "verify"]), # unsetting the file storage dir while file storage is not enabled # should be fine (False, ["gnt-cluster", "modify", "--%s=" % option_name]), # resetting everything to sane values (False, [ "gnt-cluster", "modify", "--%s=%s" % (option_name, file_storage_dir), "--enabled-disk-templates=%s" % ",".join(enabled_disk_templates), "--ipolicy-disk-templates=%s" % ",".join(enabled_disk_templates) ]) ]: AssertCommand(cmd, fail=fail)
def TestClusterInit(rapi_user, rapi_secret): """gnt-cluster init""" master = qa_config.GetMasterNode() rapi_users_path = qa_utils.MakeNodePath(master, pathutils.RAPI_USERS_FILE) rapi_dir = os.path.dirname(rapi_users_path) # First create the RAPI credentials fh = tempfile.NamedTemporaryFile() try: fh.write("%s %s write\n" % (rapi_user, rapi_secret)) fh.flush() tmpru = qa_utils.UploadFile(master.primary, fh.name) try: AssertCommand(["mkdir", "-p", rapi_dir]) AssertCommand(["mv", tmpru, rapi_users_path]) finally: AssertCommand(["rm", "-f", tmpru]) finally: fh.close() # Initialize cluster enabled_disk_templates = qa_config.GetEnabledDiskTemplates() cmd = [ "gnt-cluster", "init", "--primary-ip-version=%d" % qa_config.get("primary_ip_version", 4), "--enabled-hypervisors=%s" % ",".join(qa_config.GetEnabledHypervisors()), "--enabled-disk-templates=%s" % ",".join(enabled_disk_templates), ] if constants.DT_FILE in enabled_disk_templates: cmd.append("--file-storage-dir=%s" % qa_config.get( "default-file-storage-dir", pathutils.DEFAULT_FILE_STORAGE_DIR)) for spec_type in ("mem-size", "disk-size", "disk-count", "cpu-count", "nic-count"): for spec_val in ("min", "max", "std"): spec = qa_config.get( "ispec_%s_%s" % (spec_type.replace("-", "_"), spec_val), None) if spec is not None: cmd.append("--specs-%s=%s=%d" % (spec_type, spec_val, spec)) if master.secondary: cmd.append("--secondary-ip=%s" % master.secondary) if utils.IsLvmEnabled(qa_config.GetEnabledDiskTemplates()): vgname = qa_config.get("vg-name", constants.DEFAULT_VG) if vgname: cmd.append("--vg-name=%s" % vgname) else: raise qa_error.Error("Please specify a volume group if you enable" " lvm-based disk templates in the QA.") master_netdev = qa_config.get("master-netdev", None) if master_netdev: cmd.append("--master-netdev=%s" % master_netdev) nicparams = qa_config.get("default-nicparams", None) if nicparams: cmd.append("--nic-parameters=%s" % ",".join(utils.FormatKeyValue(nicparams))) # Cluster value of the exclusive-storage node parameter e_s = qa_config.get("exclusive-storage") if e_s is not None: cmd.extend(["--node-parameters", "exclusive_storage=%s" % e_s]) else: e_s = False qa_config.SetExclusiveStorage(e_s) extra_args = qa_config.get("cluster-init-args") if extra_args: # This option was removed in 2.10, but in order to not break QA of older # branches we remove it from the extra_args if it is in there. opt_drbd_storage = "--no-drbd-storage" if opt_drbd_storage in extra_args: extra_args.remove(opt_drbd_storage) cmd.extend(extra_args) cmd.append(qa_config.get("name")) AssertCommand(cmd) cmd = ["gnt-cluster", "modify"] # hypervisor parameter modifications hvp = qa_config.get("hypervisor-parameters", {}) for k, v in hvp.items(): cmd.extend(["-H", "%s:%s" % (k, v)]) # backend parameter modifications bep = qa_config.get("backend-parameters", "") if bep: cmd.extend(["-B", bep]) if len(cmd) > 2: AssertCommand(cmd) # OS parameters osp = qa_config.get("os-parameters", {}) for k, v in osp.items(): AssertCommand(["gnt-os", "modify", "-O", v, k]) # OS hypervisor parameters os_hvp = qa_config.get("os-hvp", {}) for os_name in os_hvp: for hv, hvp in os_hvp[os_name].items(): AssertCommand( ["gnt-os", "modify", "-H", "%s:%s" % (hv, hvp), os_name])
def TestInstanceAddDiskless(nodes): """gnt-instance add -t diskless""" assert len(nodes) == 1 if constants.DT_DISKLESS in qa_config.GetEnabledDiskTemplates(): return CreateInstanceByDiskTemplateOneNode(nodes, constants.DT_DISKLESS)
def TestInstanceAddSharedFile(nodes): """gnt-instance add -t sharedfile""" assert len(nodes) == 1 if constants.DT_SHARED_FILE in qa_config.GetEnabledDiskTemplates(): return CreateInstanceByDiskTemplateOneNode(nodes, constants.DT_SHARED_FILE)
def TestInstanceAddWithDrbdDisk(nodes): """gnt-instance add -t drbd""" if constants.DT_DRBD8 in qa_config.GetEnabledDiskTemplates(): return CreateInstanceDrbd8(nodes)
def TestInstanceCreationRestrictedByDiskTemplates(): """Test adding instances for disabled disk templates.""" if qa_config.TestEnabled("cluster-exclusive-storage"): # These tests are valid only for non-exclusive storage return enabled_disk_templates = qa_config.GetEnabledDiskTemplates() nodes = qa_config.AcquireManyNodes(2) # Setup the cluster with the enabled_disk_templates AssertCommand([ "gnt-cluster", "modify", "--enabled-disk-templates=%s" % ",".join(enabled_disk_templates), "--ipolicy-disk-templates=%s" % ",".join(enabled_disk_templates) ], fail=False) # Test instance creation for enabled disk templates for disk_template in enabled_disk_templates: instance = CreateInstanceByDiskTemplate(nodes, disk_template, fail=False) TestInstanceRemove(instance) instance.Release() # Test that instance creation fails for disabled disk templates disabled_disk_templates = list(constants.DISK_TEMPLATES - set(enabled_disk_templates)) for disk_template in disabled_disk_templates: instance = CreateInstanceByDiskTemplate(nodes, disk_template, fail=True) # Test instance creation for after disabling enabled disk templates if (len(enabled_disk_templates) > 1): # Partition the disk templates, enable them separately and check if the # disabled ones cannot be used by instances. middle = len(enabled_disk_templates) / 2 templates1 = enabled_disk_templates[:middle] templates2 = enabled_disk_templates[middle:] for (enabled, disabled) in [(templates1, templates2), (templates2, templates1)]: AssertCommand([ "gnt-cluster", "modify", "--enabled-disk-templates=%s" % ",".join(enabled), "--ipolicy-disk-templates=%s" % ",".join(enabled) ], fail=False) for disk_template in disabled: CreateInstanceByDiskTemplate(nodes, disk_template, fail=True) elif (len(enabled_disk_templates) == 1): # If only one disk template is enabled in the QA config, we have to enable # some other templates in order to test if the disabling the only enabled # disk template prohibits creating instances of that template. other_disk_templates = list( set([constants.DT_DISKLESS, constants.DT_BLOCK]) - set(enabled_disk_templates)) AssertCommand([ "gnt-cluster", "modify", "--enabled-disk-templates=%s" % ",".join(other_disk_templates), "--ipolicy-disk-templates=%s" % ",".join(other_disk_templates) ], fail=False) CreateInstanceByDiskTemplate(nodes, enabled_disk_templates[0], fail=True) else: raise qa_error.Error("Please enable at least one disk template" " in your QA setup.") # Restore initially enabled disk templates AssertCommand([ "gnt-cluster", "modify", "--enabled-disk-templates=%s" % ",".join(enabled_disk_templates), "--ipolicy-disk-templates=%s" % ",".join(enabled_disk_templates) ], fail=False)
def RunMaintdTests(): if constants.DT_DRBD8 in qa_config.GetEnabledDiskTemplates(): RunTestIf("maintd", qa_maintd.TestEvacuate) RunTestIf("maintd", qa_maintd.TestEvacuateFailover) if constants.ENABLE_RESTRICTED_COMMANDS: RunTestIf("maintd", qa_maintd.TestLiveRepair)