From: Szymon Wroblewski Date: Thu, 20 Aug 2015 12:13:31 +0000 (+0200) Subject: Support initialization state in Backup Manager X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=9889f96afdc81442fd4b1966777a8dcd143e243e;p=openstack-build%2Fcinder-build.git Support initialization state in Backup Manager 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 --- diff --git a/cinder/backup/manager.py b/cinder/backup/manager.py index ca238583a..819d57ecf 100644 --- a/cinder/backup/manager.py +++ b/cinder/backup/manager.py @@ -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: diff --git a/cinder/tests/unit/test_backup.py b/cinder/tests/unit/test_backup.py index 6de7d0130..62dec53fd 100644 --- a/cinder/tests/unit/test_backup.py +++ b/cinder/tests/unit/test_backup.py @@ -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."""