Commit a08e181f authored by Michael Hanselmann's avatar Michael Hanselmann

Refactor storage of runtime exclusive storage flag in QA

This is a follow-up for “qa_config: Remove exclusive storage flag from
config”. Instead of storing the flag in a module-level variable it is
now stored within the new QA configuration class and unit tests are
provided. Wrappers in “qa_config” maintain the existing interface.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent 8a96c5a6
......@@ -1035,6 +1035,7 @@ TEST_FILES = \
test/data/proc_drbd83_sync.txt \
test/data/proc_drbd83_sync_want.txt \
test/data/proc_drbd83_sync_krnl2.6.39.txt \
test/data/qa-minimal-nodes-instances-only.json \
test/data/sys_drbd_usermode_helper.txt \
test/data/vgreduce-removemissing-2.02.02.txt \
test/data/vgreduce-removemissing-2.02.66-fail.txt \
......
......@@ -36,10 +36,6 @@ import qa_error
_INSTANCE_CHECK_KEY = "instance-check"
_ENABLED_HV_KEY = "enabled-hypervisors"
#: Cluster-wide run-time value of the exclusive storage flag
_exclusive_storage = None
#: QA configuration (L{_QaConfig})
_config = None
......@@ -51,6 +47,9 @@ class _QaConfig(object):
"""
self._data = data
#: Cluster-wide run-time value of the exclusive storage flag
self._exclusive_storage = None
@classmethod
def Load(cls, filename):
"""Loads a configuration file and produces a configuration object.
......@@ -159,6 +158,29 @@ class _QaConfig(object):
"""
return self.GetEnabledHypervisors()[0]
def SetExclusiveStorage(self, value):
"""Set the expected value of the C{exclusive_storage} flag for the cluster.
"""
self._exclusive_storage = bool(value)
def GetExclusiveStorage(self):
"""Get the expected value of the C{exclusive_storage} flag for the cluster.
"""
value = self._exclusive_storage
assert value is not None
return value
def IsTemplateSupported(self, templ):
"""Is the given disk template supported by the current configuration?
"""
if self.GetExclusiveStorage():
return templ in constants.DTS_EXCL_STORAGE
else:
return True
def Load(path):
"""Loads the passed configuration file.
......@@ -337,31 +359,24 @@ def SetInstanceTemplate(inst, template):
def SetExclusiveStorage(value):
"""Set the expected value of the exclusive_storage flag for the cluster.
"""Wrapper for L{_QaConfig.SetExclusiveStorage}.
"""
global _exclusive_storage # pylint: disable=W0603
_exclusive_storage = bool(value)
return GetConfig().SetExclusiveStorage(value)
def GetExclusiveStorage():
"""Get the expected value of the exclusive_storage flag for the cluster.
"""Wrapper for L{_QaConfig.GetExclusiveStorage}.
"""
val = _exclusive_storage
assert val is not None
return val
return GetConfig().GetExclusiveStorage()
def IsTemplateSupported(templ):
"""Is the given disk template supported by the current configuration?
"""Wrapper for L{_QaConfig.GetExclusiveStorage}.
"""
if GetExclusiveStorage():
return templ in constants.DTS_EXCL_STORAGE
else:
return True
return GetConfig().IsTemplateSupported(templ)
def AcquireNode(exclude=None):
......
{
"name": "xen-test-qa-minimal-nodes-instances-only",
"disk": ["1G", "512M"],
"disk-growth": ["2G", "768M"],
"nodes": [
{
"# Master node": null,
"primary": "xen-test-0",
"secondary": "192.0.2.1"
},
{
"primary": "xen-test-1",
"secondary": "192.0.2.2"
},
{
"primary": "xen-test-2",
"secondary": "192.0.2.3"
},
{
"primary": "xen-test-3",
"secondary": "192.0.2.4"
}
],
"instances": [
{
"name": "xen-test-inst1",
"nic.mac/0": "AA:00:00:11:11:11"
},
{
"name": "xen-test-inst2",
"nic.mac/0": "AA:00:00:22:22:22"
}
],
"tests": {
"default": false
},
"# vim: set syntax=javascript :": null
}
......@@ -252,5 +252,26 @@ class TestQaConfigWithSampleConfig(unittest.TestCase):
self.assertEqual(self.config.GetMasterNode(), self.config["nodes"][0])
class TestQaConfig(unittest.TestCase):
def setUp(self):
filename = \
testutils.TestDataFilename("qa-minimal-nodes-instances-only.json")
self.config = qa_config._QaConfig.Load(filename)
def testExclusiveStorage(self):
self.assertRaises(AssertionError, self.config.GetExclusiveStorage)
for value in [False, True, 0, 1, 30804, ""]:
self.config.SetExclusiveStorage(value)
self.assertEqual(self.config.GetExclusiveStorage(), bool(value))
for template in constants.DISK_TEMPLATES:
if value and template not in constants.DTS_EXCL_STORAGE:
self.assertFalse(self.config.IsTemplateSupported(template))
else:
self.assertTrue(self.config.IsTemplateSupported(template))
if __name__ == "__main__":
testutils.GanetiTestProgram()
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