From 2932dc444d14375d00f3096a827b28679c2e4173 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Mon, 7 Mar 2011 20:01:08 +0100 Subject: [PATCH] QA: Improve tests for gnt-os MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Test OS lists via command line and RAPI - Test βgnt-os diagnoseβ and βgnt-os infoβ Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/client/gnt_os.py | 1 + qa/ganeti-qa.py | 14 +++++++++ qa/qa_os.py | 74 ++++++++++++++++++++++++++++++++++++++------ qa/qa_rapi.py | 7 +++++ 4 files changed, 87 insertions(+), 9 deletions(-) diff --git a/lib/client/gnt_os.py b/lib/client/gnt_os.py index 4241e34f9..fe786463c 100644 --- a/lib/client/gnt_os.py +++ b/lib/client/gnt_os.py @@ -195,6 +195,7 @@ def DiagnoseOS(opts, args): else: nodes_bad[node_name] = "OS not found" + # TODO: Shouldn't the global status be calculated by the LU? if nodes_valid and not nodes_bad: status = "valid" elif not nodes_valid and nodes_bad: diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py index e0c62d7c2..b2a7158f4 100755 --- a/qa/ganeti-qa.py +++ b/qa/ganeti-qa.py @@ -70,6 +70,7 @@ def _DescriptionOf(fn): return desc.rstrip(".") + def RunTest(fn, *args): """Runs a test after printing a header. @@ -180,12 +181,25 @@ def RunOsTests(): """Runs all tests related to gnt-os. """ + if qa_config.TestEnabled("rapi"): + rapi_getos = qa_rapi.GetOperatingSystems + else: + rapi_getos = None + for fn in [ qa_os.TestOsList, qa_os.TestOsDiagnose, + ]: + RunTestIf("os", fn) + + for fn in [ qa_os.TestOsValid, qa_os.TestOsInvalid, qa_os.TestOsPartiallyValid, + ]: + RunTestIf("os", fn, rapi_getos) + + for fn in [ qa_os.TestOsModifyValid, qa_os.TestOsModifyInvalid, qa_os.TestOsStatesNonExisting, diff --git a/qa/qa_os.py b/qa/qa_os.py index cbc3142cd..b050c1691 100644 --- a/qa/qa_os.py +++ b/qa/qa_os.py @@ -31,8 +31,9 @@ from ganeti import constants import qa_config import qa_utils +import qa_error -from qa_utils import AssertCommand +from qa_utils import AssertCommand, AssertIn, AssertNotIn _TEMP_OS_NAME = "TEMP-Ganeti-QA-OS" @@ -114,12 +115,19 @@ def _RemoveTempOs(node, dirname): AssertCommand(["rm", "-rf", dirname], node=node) -def _TestOs(mode): +def _TestOs(mode, rapi_cb): """Generic function for OS definition testing """ + master = qa_config.GetMasterNode() + + name = _TEMP_OS_NAME dirname = _TEMP_OS_PATH + # Ensure OS is usable + cmd = ["gnt-os", "modify", "--hidden=no", "--blacklisted=no", name] + AssertCommand(cmd) + nodes = [] try: for i, node in enumerate(qa_config.get("nodes")): @@ -134,25 +142,73 @@ def _TestOs(mode): raise AssertionError("Unknown mode %s" % mode) _SetupTempOs(node, dirname, valid) - AssertCommand(["gnt-os", "diagnose"], fail=(mode != _ALL_VALID)) + # TODO: Use Python 2.6's itertools.permutations + for (hidden, blacklisted) in [(False, False), (True, False), + (False, True), (True, True)]: + # Change OS' visibility + cmd = ["gnt-os", "modify", "--hidden", ["no", "yes"][int(hidden)], + "--blacklisted", ["no", "yes"][int(blacklisted)], name] + AssertCommand(cmd) + + # Diagnose, checking exit status + AssertCommand(["gnt-os", "diagnose"], fail=(mode != _ALL_VALID)) + + # Diagnose again, ignoring exit status + output = qa_utils.GetCommandOutput(master["primary"], + "gnt-os diagnose || :") + for line in output.splitlines(): + if line.startswith("OS: %s [global status:" % name): + break + else: + raise qa_error.Error("Didn't find OS '%s' in 'gnt-os diagnose'" % name) + + # Check info for all + cmd = ["gnt-os", "info"] + output = qa_utils.GetCommandOutput(master["primary"], + utils.ShellQuoteArgs(cmd)) + AssertIn("%s:" % name, output.splitlines()) + + # Check info for OS + cmd = ["gnt-os", "info", name] + output = qa_utils.GetCommandOutput(master["primary"], + utils.ShellQuoteArgs(cmd)).splitlines() + AssertIn("%s:" % name, output) + for (field, value) in [("valid", mode == _ALL_VALID), + ("hidden", hidden), + ("blacklisted", blacklisted)]: + AssertIn(" - %s: %s" % (field, value), output) + + # Only valid OSes should be listed + cmd = ["gnt-os", "list", "--no-headers"] + output = qa_utils.GetCommandOutput(master["primary"], + utils.ShellQuoteArgs(cmd)) + if mode == _ALL_VALID and not (hidden or blacklisted): + assert_fn = AssertIn + else: + assert_fn = AssertNotIn + assert_fn(name, output.splitlines()) + + # Check via RAPI + if rapi_cb: + assert_fn(name, rapi_cb()) finally: for node in nodes: _RemoveTempOs(node, dirname) -def TestOsValid(): +def TestOsValid(rapi_cb): """Testing valid OS definition""" - return _TestOs(_ALL_VALID) + return _TestOs(_ALL_VALID, rapi_cb) -def TestOsInvalid(): +def TestOsInvalid(rapi_cb): """Testing invalid OS definition""" - return _TestOs(_ALL_INVALID) + return _TestOs(_ALL_INVALID, rapi_cb) -def TestOsPartiallyValid(): +def TestOsPartiallyValid(rapi_cb): """Testing partially valid OS definition""" - return _TestOs(_PARTIALLY_VALID) + return _TestOs(_PARTIALLY_VALID, rapi_cb) def TestOsModifyValid(): diff --git a/qa/qa_rapi.py b/qa/qa_rapi.py index 6653ecc01..a9c9ef828 100644 --- a/qa/qa_rapi.py +++ b/qa/qa_rapi.py @@ -517,6 +517,13 @@ def TestRapiStoppedInstanceConsole(instance): " return HTTP 503") +def GetOperatingSystems(): + """Retrieves a list of all available operating systems. + + """ + return _rapi_client.GetOperatingSystems() + + def TestInterClusterInstanceMove(src_instance, dest_instance, pnode, snode, tnode): """Test tools/move-instance""" -- GitLab