From 9889f96afdc81442fd4b1966777a8dcd143e243e Mon Sep 17 00:00:00 2001 From: Szymon Wroblewski Date: Thu, 20 Aug 2015 14:13:31 +0200 Subject: [PATCH] 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 --- cinder/backup/manager.py | 9 +++++++++ cinder/tests/unit/test_backup.py | 9 +++++++++ 2 files changed, 18 insertions(+) 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.""" -- 2.45.2