Handle Xen 4.3 states better
authorHrvoje Ribicic <riba@google.com>
Tue, 15 Sep 2015 08:37:11 +0000 (10:37 +0200)
committerHrvoje Ribicic <riba@google.com>
Wed, 16 Sep 2015 08:24:15 +0000 (10:24 +0200)
In Xen commit e1475a6693aac8cddc4bdd456548aa05a625556b, the output from
xl list was extended to provide a reason for shutdowns. This breaks
our somewhat strict parsing of the output in certain situations where
the new states appear (e.g. the short suspension during a migration, or
an instance reboot).

This patch makes sure the new states (barring the mysterious watchdog
state) are handled correctly.

Signed-off-by: Hrvoje Ribicic <riba@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

lib/hypervisor/hv_xen.py
test/py/ganeti.hypervisor.hv_xen_unittest.py

index 576b518..a3f7af8 100644 (file)
@@ -215,11 +215,25 @@ def _IsInstanceRunning(instance_info):
   @return: Whether an instance is running.
 
   """
-  return instance_info == "r-----" \
-      or instance_info == "rb----" \
-      or instance_info == "-b----" \
-      or instance_info == "-----d" \
-      or instance_info == "------"
+  allowable_running_prefixes = [
+    "r--",
+    "rb-",
+    "-b-",
+    "---",
+  ]
+
+  def _RunningWithSuffix(suffix):
+    return map(lambda x: x + suffix, allowable_running_prefixes)
+
+  return instance_info in _RunningWithSuffix("---") \
+      # The shutdown suspend state is encountered during migration, where the
+      # instance is still considered to be running.
+      # See Xen commit e1475a6693aac8cddc4bdd456548aa05a625556b
+      or instance_info in _RunningWithSuffix("ss-") \
+      # The shutdown restart state is probably encountered during reboots.
+      # See the Xen commit above.
+      or instance_info in _RunningWithSuffix("sr-") \
+      or instance_info == "-----d"
 
 
 def _IsInstanceShutdown(instance_info):
index ba6324e..5c85d3d 100755 (executable)
@@ -182,6 +182,20 @@ class TestInstanceStateParsing(unittest.TestCase):
       "--p--d",
       "------",
       "--p---",
+      "r--ss-",
+      "r-pss-",
+      "rb-ss-",
+      "rbpss-",
+      "-b-ss-",
+      "-bpss-",
+      "---ss-",
+      "r--sr-",
+      "r-psr-",
+      "rb-sr-",
+      "rbpsr-",
+      "-b-sr-",
+      "-bpsr-",
+      "---sr-",
     ]
     for state in states:
       self.assertEqual(hv_xen._XenToHypervisorInstanceState(state),