From 039dce71d43bd69181b2502cda17f941c95f9497 Mon Sep 17 00:00:00 2001 From: Kai Zhang Date: Thu, 27 Jun 2013 00:31:36 -0700 Subject: [PATCH] Fix check_for_setup_error for sheepdog driver Current implementation of check_for_setup_error() of sheepdog driver cannot work correctly with the latest version of sheepdog cluster. This patch fixes it and adds tests for both old and new version. Fixes: bug #1195098 Change-Id: Ia710789e4bedd7c83cd47eff6b2fc532af39d94a --- cinder/tests/test_sheepdog.py | 30 ++++++++++++++++++++++++++++++ cinder/volume/drivers/sheepdog.py | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/cinder/tests/test_sheepdog.py b/cinder/tests/test_sheepdog.py index 70fab1afd..7fe3862da 100644 --- a/cinder/tests/test_sheepdog.py +++ b/cinder/tests/test_sheepdog.py @@ -24,6 +24,24 @@ COLLIE_NODE_INFO = """ Total 107287605248 3623897354 3% 54760833024 """ +COLLIE_CLUSTER_INFO_0_5 = """ +Cluster status: running + +Cluster created at Tue Jun 25 19:51:41 2013 + +Epoch Time Version +2013-06-25 19:51:41 1 [127.0.0.1:7000, 127.0.0.1:7001, 127.0.0.1:7002] +""" + +COLLIE_CLUSTER_INFO_0_6 = """ +Cluster status: running, auto-recovery enabled + +Cluster created at Tue Jun 25 19:51:41 2013 + +Epoch Time Version +2013-06-25 19:51:41 1 [127.0.0.1:7000, 127.0.0.1:7001, 127.0.0.1:7002] +""" + class SheepdogTestCase(test.TestCase): @@ -62,3 +80,15 @@ class SheepdogTestCase(test.TestCase): QoS_support=False) actual = self.driver.get_volume_stats(True) self.assertDictMatch(expected, actual) + + def test_check_for_setup_error_0_5(self): + def fake_stats(*args): + return COLLIE_CLUSTER_INFO_0_5, '' + self.stubs.Set(self.driver, '_execute', fake_stats) + self.driver.check_for_setup_error() + + def test_check_for_setup_error_0_6(self): + def fake_stats(*args): + return COLLIE_CLUSTER_INFO_0_6, '' + self.stubs.Set(self.driver, '_execute', fake_stats) + self.driver.check_for_setup_error() diff --git a/cinder/volume/drivers/sheepdog.py b/cinder/volume/drivers/sheepdog.py index ea4d296e8..db3b64c4a 100644 --- a/cinder/volume/drivers/sheepdog.py +++ b/cinder/volume/drivers/sheepdog.py @@ -43,7 +43,7 @@ class SheepdogDriver(driver.VolumeDriver): # gives short output, but for compatibility reason we won't # use it and just check if 'running' is in the output. (out, err) = self._execute('collie', 'cluster', 'info') - if 'running' not in out.split(): + if 'status: running' not in out: exception_message = (_("Sheepdog is not working: %s") % out) raise exception.VolumeBackendAPIException( data=exception_message) -- 2.45.2