From fca11decb0cd989247f11361e60d783590e6226f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ren=C3=A9=20Nussbaumer?= <rn@google.com>
Date: Wed, 10 Mar 2010 11:25:15 +0100
Subject: [PATCH] Adding qa tests for gnt-os modify
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This adds basic qa tests for gnt-os modify

Signed-off-by: RenΓ© Nussbaumer <rn@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 qa/ganeti-qa.py |  2 ++
 qa/qa_os.py     | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py
index a7f34509d..73c01aee4 100755
--- a/qa/ganeti-qa.py
+++ b/qa/ganeti-qa.py
@@ -127,6 +127,8 @@ def RunOsTests():
   RunTest(qa_os.TestOsValid)
   RunTest(qa_os.TestOsInvalid)
   RunTest(qa_os.TestOsPartiallyValid)
+  RunTest(qa_os.TestOsModifyValid)
+  RunTest(qa_os.TestOsModifyInvalid)
 
 
 def RunCommonInstanceTests(instance):
diff --git a/qa/qa_os.py b/qa/qa_os.py
index 4b6fa5e22..28c2c7360 100644
--- a/qa/qa_os.py
+++ b/qa/qa_os.py
@@ -57,6 +57,24 @@ def TestOsDiagnose():
                        utils.ShellQuoteArgs(cmd)).wait(), 0)
 
 
+def _TestOsModify(hvp_dict, expected_result=0):
+  """gnt-os modify"""
+  master = qa_config.GetMasterNode()
+
+  cmd = ['gnt-os', 'modify']
+
+  for hv_name, hv_params in hvp_dict.items():
+    cmd.append('-H')
+    options = []
+    for key, value in hv_params.items():
+      options.append("%s=%s" % (key, value))
+    cmd.append('%s:%s' % (hv_name, ','.join(options)))
+
+  cmd.append(_TEMP_OS_NAME)
+  AssertEqual(StartSSH(master['primary'],
+                       utils.ShellQuoteArgs(cmd)).wait(), expected_result)
+
+
 def _SetupTempOs(node, dir, valid):
   """Creates a temporary OS definition on the given node.
 
@@ -139,3 +157,27 @@ def TestOsInvalid():
 def TestOsPartiallyValid():
   """Testing partially valid OS definition"""
   return _TestOs(2)
+
+
+def TestOsModifyValid():
+  """Testing a valid os modify invocation"""
+  hv_dict = {
+    constants.HT_XEN_PVM: {
+      constants.HV_ROOT_PATH: "/dev/sda5",
+      },
+    constants.HT_XEN_HVM: {
+      constants.HV_ACPI: False,
+      constants.HV_PAE: True,
+      },
+    }
+
+  return _TestOsModify(hv_dict)
+
+
+def TestOsModifyInvalid():
+  """Testing an invalid os modify invocation"""
+  hv_dict = {
+    "blahblahblubb": {"bar": ""},
+    }
+
+  return _TestOsModify(hv_dict, 1)
-- 
GitLab