From 59777b8caf6b65e247e574fe340c4387cddbec81 Mon Sep 17 00:00:00 2001 From: Fei Long Wang Date: Wed, 5 Apr 2017 14:51:17 +1200 Subject: [PATCH] Check if swift is alive instead of hardcode By calling swift /info API to check if swift is alive or not instead of assuming it's always alive. Closes-Bug: #1679821 Change-Id: If382d00e35ae0de1f0106894928276976d68b8f3 --- zaqar/storage/swift/driver.py | 7 ++++++- zaqar/tests/unit/storage/test_impl_swift.py | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/zaqar/storage/swift/driver.py b/zaqar/storage/swift/driver.py index 953a2fdcc..c42c46aed 100644 --- a/zaqar/storage/swift/driver.py +++ b/zaqar/storage/swift/driver.py @@ -46,7 +46,12 @@ class DataDriver(storage.DataDriverBase): return _ClientWrapper(self.swift_conf) def is_alive(self): - return True + try: + self.connection.get_capabilities() + return True + except Exception as e: + LOG.exception(e) + return False @decorators.lazy_property(write=False) def queue_controller(self): diff --git a/zaqar/tests/unit/storage/test_impl_swift.py b/zaqar/tests/unit/storage/test_impl_swift.py index 07f0f0f78..e4377291f 100644 --- a/zaqar/tests/unit/storage/test_impl_swift.py +++ b/zaqar/tests/unit/storage/test_impl_swift.py @@ -10,7 +10,7 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. - +from zaqar.common import cache as oslo_cache from zaqar.storage import mongodb from zaqar.storage.swift import controllers from zaqar.storage.swift import driver @@ -50,3 +50,17 @@ class SwiftSubscriptionsTest(base.SubscriptionControllerTest): config_file = 'wsgi_swift.conf' controller_class = controllers.SubscriptionController control_driver_class = mongodb.ControlDriver + + +@testing.requires_swift +class SwiftDriverTest(testing.TestBase): + config_file = 'wsgi_swift.conf' + + def test_is_alive(self): + oslo_cache.register_config(self.conf) + cache = oslo_cache.get_cache(self.conf) + swift_driver = driver.DataDriver(self.conf, cache, + mongodb.ControlDriver + (self.conf, cache)) + + self.assertTrue(swift_driver.is_alive())