]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Support initialization state in Backup Manager
authorSzymon Wroblewski <szymon.wroblewski@intel.com>
Thu, 20 Aug 2015 12:13:31 +0000 (14:13 +0200)
committerSzymon Wroblewski <szymon.wroblewski@intel.com>
Wed, 21 Oct 2015 09:48:52 +0000 (11:48 +0200)
This commit adds is_working method to Backup Manager class to
return initialization state of the underlying volume drivers and
indicate that service has some problems and isn't running correctly.
This is used to block refreshing Service heartbeats if Manager will
return False from is_working.

Related-Bug: 1446750
Change-Id: I3165d01f60bd80ead5163d8678886bd2828af3f9

cinder/backup/manager.py
cinder/tests/unit/test_backup.py

index ca238583a6f98b938c96a0e3aaf954166c0b78a4..819d57ecfb7c5fd153f73acbae0305920eafb8f0 100644 (file)
@@ -276,6 +276,15 @@ class BackupManager(manager.SchedulerDependentManager):
                 # By default, delete backups sequentially
                 self.delete_backup(ctxt, backup)
 
+    def is_working(self):
+        """Return if Manager is ready to accept requests.
+
+        This is to inform Service class that in case of volume manager(s)
+        initialization failure the manager is actually down and
+        may not accept some or all requests.
+        """
+        return all(mgr.is_working() for mgr in self.volume_managers.values())
+
     def _detach_all_attachments(self, ctxt, mgr, volume):
         attachments = volume['volume_attachment'] or []
         for attachment in attachments:
index 6de7d0130bff6f36a46e66ce1ac9620b0f8a11ad..62dec53fd5e206ca44fd7e9f9a57812ce885aef7 100644 (file)
@@ -270,6 +270,15 @@ class BackupTestCase(BaseBackupTest):
         mock_add_threadpool.assert_has_calls(calls, any_order=True)
         self.assertEqual(2, mock_add_threadpool.call_count)
 
+    def test_is_working(self):
+        self.assertTrue(self.backup_mgr.is_working())
+
+        vmanager_mock = mock.Mock()
+        vmanager_mock.is_working.side_effect = [True, False, True]
+        vms = {'a': vmanager_mock, 'b': vmanager_mock, 'c': vmanager_mock}
+        with mock.patch.dict(self.backup_mgr.volume_managers, vms, True):
+            self.assertFalse(self.backup_mgr.is_working())
+
     def test_init_host_handles_exception(self):
         """Test that exception in cleanup is handled."""