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 <[email protected]>
---
 lib/hypervisor/hv_xen.py                     | 24 +++++++++++++++++++-----
 test/py/ganeti.hypervisor.hv_xen_unittest.py | 14 ++++++++++++++
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
index 576b518..a3f7af8 100644
--- a/lib/hypervisor/hv_xen.py
+++ b/lib/hypervisor/hv_xen.py
@@ -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):
diff --git a/test/py/ganeti.hypervisor.hv_xen_unittest.py 
b/test/py/ganeti.hypervisor.hv_xen_unittest.py
index ba6324e..5c85d3d 100755
--- a/test/py/ganeti.hypervisor.hv_xen_unittest.py
+++ b/test/py/ganeti.hypervisor.hv_xen_unittest.py
@@ -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),
-- 
2.6.0.rc0.131.gf624c3d

Reply via email to