Add tests exercising the "crashed" state handling
authorHrvoje Ribicic <riba@google.com>
Mon, 6 Jul 2015 17:23:31 +0000 (17:23 +0000)
committerHrvoje Ribicic <riba@google.com>
Tue, 7 Jul 2015 15:12:47 +0000 (17:12 +0200)
This patch adds a few tests that make sure the state is handled
properly, using examples taken from a running cluster.

Signed-off-by: Hrvoje Ribicic <riba@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>

Makefile.am
test/data/xen-xl-list-4.4-crashed-instances.txt [copied from test/data/xen-xm-list-4.0.1-four-instances.txt with 60% similarity]
test/py/ganeti.hypervisor.hv_xen_unittest.py

index 79c964e..939f88c 100644 (file)
@@ -1698,6 +1698,7 @@ TEST_FILES = \
        test/data/vgreduce-removemissing-2.02.66-ok.txt \
        test/data/vgs-missing-pvs-2.02.02.txt \
        test/data/vgs-missing-pvs-2.02.66.txt \
+       test/data/xen-xl-list-4.4-crashed-instances.txt \
        test/data/xen-xm-info-4.0.1.txt \
        test/data/xen-xm-list-4.0.1-dom0-only.txt \
        test/data/xen-xm-list-4.0.1-four-instances.txt \
@@ -1,5 +1,5 @@
 Name                                        ID   Mem VCPUs      State   Time(s)
 Domain-0                                     0  1023     1     r----- 154706.1
 server01.example.com                         1  1024     1     -b---- 167643.2
-web3106215069.example.com                    3  4096     1     -b---- 466690.9
-testinstance.example.com                     2  2048     2     r----- 244443.0
+(null)                                   28441   789     1     --psc-      1.2
+alsodying.example.com                    28448  1024     1     --psc-      1.4
index ddb92d4..ba6324e 100755 (executable)
@@ -198,6 +198,19 @@ class TestInstanceStateParsing(unittest.TestCase):
       self.assertEqual(hv_xen._XenToHypervisorInstanceState(state),
                        hv_base.HvInstanceState.SHUTDOWN)
 
+  def testCrashingStates(self):
+    states = [
+      "--psc-",
+      "---sc-",
+      "---scd",
+      "--p-c-",
+      "----c-",
+      "----cd",
+    ]
+    for state in states:
+      self.assertRaises(hv_xen._InstanceCrashed,
+                        hv_xen._XenToHypervisorInstanceState, state)
+
 
 class TestGetInstanceList(testutils.GanetiTestCase):
   def _Fail(self):
@@ -241,6 +254,23 @@ class TestGetInstanceList(testutils.GanetiTestCase):
 
     self.assertEqual(fn.Count(), 1)
 
+  def testOmitCrashed(self):
+    data = testutils.ReadTestData("xen-xl-list-4.4-crashed-instances.txt")
+
+    fn = testutils.CallCounter(compat.partial(self._Success, data))
+
+    result = hv_xen._GetAllInstanceList(fn, True, delays=(0.02, 1.0, 0.03),
+                                        timeout=0.1)
+
+    self.assertEqual(len(result), 2)
+
+    self.assertEqual(map(compat.fst, result), [
+      "Domain-0",
+      "server01.example.com",
+      ])
+
+    self.assertEqual(fn.Count(), 1)
+
 
 class TestParseNodeInfo(testutils.GanetiTestCase):
   def testEmpty(self):