Commit b24b52d9 authored by Helga Velroyen's avatar Helga Velroyen
Browse files

QA: test for --{shared,}-file-storage-dir

This adds tests for 'gnt-cluster modify' wrt to the
options --shared-file-storage-dir=... and
--file-storage-dir. It also separates the two directories'
specification in the QA configuration.
Signed-off-by: default avatarHelga Velroyen <>
Reviewed-by: default avatarThomas Thrainer <>
parent 4b322a76
......@@ -949,9 +949,9 @@ class OpClusterSetParams(OpCode):
"List of enabled disk templates"),
("modify_etc_hosts", None, ht.TMaybeBool,
"Whether the cluster can modify and keep in sync the /etc/hosts files"),
("file_storage_dir", None, ht.TMaybeString,
("file_storage_dir", None, ht.TMaybe(ht.TString),
"Default directory for storing file-backed disks"),
("shared_file_storage_dir", None, ht.TMaybeString,
("shared_file_storage_dir", None, ht.TMaybe(ht.TString),
"Default directory for storing shared-file-backed disks"),
OP_RESULT = ht.TNone
......@@ -213,6 +213,8 @@ def RunClusterTests():
("cluster-modify", qa_cluster.TestClusterModifyBe),
("cluster-modify", qa_cluster.TestClusterModifyDisk),
("cluster-modify", qa_cluster.TestClusterModifyDiskTemplates),
("cluster-modify", qa_cluster.TestClusterModifyFileStorageDir),
("cluster-modify", qa_cluster.TestClusterModifySharedFileStorageDir),
("cluster-rename", qa_cluster.TestClusterRename),
("cluster-info", qa_cluster.TestClusterVersion),
("cluster-info", qa_cluster.TestClusterInfo),
......@@ -35,8 +35,9 @@
"# Default file storage dir (used also for shared storage)": null,
"# Default file storage directories": null,
"default-file-storage-dir": "/srv/ganeti/file-storage",
"default-shared-file-storage-dir": "/srv/ganeti/shared-file-storage",
"# Additional arguments for initializing cluster": null,
"cluster-init-args": [],
......@@ -185,7 +185,8 @@ def TestClusterInit(rapi_user, rapi_secret):
if constants.DT_FILE in enabled_disk_templates:
"--file-storage-dir=%s" %
qa_config.get("file-storage-dir", pathutils.DEFAULT_FILE_STORAGE_DIR))
for spec_type in ("mem-size", "disk-size", "disk-count", "cpu-count",
......@@ -439,6 +440,111 @@ def TestClusterModifyDisk():
AssertCommand(["gnt-cluster", "modify", "-D", param], fail=True)
def _GetOtherEnabledDiskTemplate(undesired_disk_templates,
"""Returns one template that is not in the undesired set.
@type undesired_disk_templates: list of string
@param undesired_disk_templates: a list of disk templates that we want to
exclude when drawing one disk template from the list of enabled
disk templates
@type enabled_disk_templates: list of string
@param enabled_disk_templates: list of enabled disk templates (in QA)
desired_templates = list(set(enabled_disk_templates)
- set(undesired_disk_templates))
if desired_templates:
template = desired_templates[0]
# If no desired disk template is available for QA, choose 'diskless' and
# hope for the best.
template = constants.ST_DISKLESS
return template
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
@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.DT_FILE, constants.DT_SHARED_FILE]
if not qa_config.IsTemplateSupported(file_disk_template):
# Get some non-file-based disk template to disable file storage
other_disk_template = _GetOtherEnabledDiskTemplate(,
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]),
(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]),
(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)])
AssertCommand(cmd, fail=fail)
def TestClusterModifyFileStorageDir():
"""gnt-cluster modify --file-storage-dir=..."""
constants.DT_FILE, "default-file-storage-dir",
def TestClusterModifySharedFileStorageDir():
"""gnt-cluster modify --shared-file-storage-dir=..."""
constants.DT_SHARED_FILE, "default-shared-file-storage-dir",
def TestClusterModifyDiskTemplates():
"""gnt-cluster modify --enabled-disk-templates=..."""
enabled_disk_templates = qa_config.GetEnabledDiskTemplates()
......@@ -530,17 +636,10 @@ def _TestClusterModifyDiskTemplatesVgName(enabled_disk_templates):
# determine an LVM and a non-LVM disk template for the tests
non_lvm_templates = list(set(enabled_disk_templates)
- set(utils.GetLvmDiskTemplates()))
non_lvm_template = _GetOtherEnabledDiskTemplate(utils.GetLvmDiskTemplates(),
lvm_template = list(set(enabled_disk_templates)
non_lvm_template = None
if non_lvm_templates:
non_lvm_template = non_lvm_templates[0]
# If no non-lvm disk template is available for QA, choose 'diskless' and
# hope for the best.
non_lvm_template = constants.ST_DISKLESS
vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment