From c25998ee429ca796e8b15f3800a775ccdc5ab029 Mon Sep 17 00:00:00 2001 From: dineshbhor Date: Tue, 21 Jun 2016 14:49:34 +0530 Subject: [PATCH] Make dict.keys() PY3 compatible The dict.keys()[0] will raise a TypeError in PY3, as dict.keys() doesn't return a list any more in PY3 but a view of list. Closes-Bug: #1583419 Change-Id: I8e05cf4d68568f9446f752418277764c2ce94ff4 --- cinder/backup/manager.py | 2 +- cinder/tests/unit/backup/test_backup.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cinder/backup/manager.py b/cinder/backup/manager.py index bc4362ac455..7373c7695c1 100644 --- a/cinder/backup/manager.py +++ b/cinder/backup/manager.py @@ -125,7 +125,7 @@ class BackupManager(manager.SchedulerDependentManager): if 'default' not in self.volume_managers: # For multi-backend we just pick the top of the list. - return self.volume_managers.keys()[0] + return next(iter(self.volume_managers)) return 'default' diff --git a/cinder/tests/unit/backup/test_backup.py b/cinder/tests/unit/backup/test_backup.py index b35c0933184..1c4d94eed73 100644 --- a/cinder/tests/unit/backup/test_backup.py +++ b/cinder/tests/unit/backup/test_backup.py @@ -334,6 +334,13 @@ class BackupTestCase(BaseBackupTest): def test_is_working(self): self.assertTrue(self.backup_mgr.is_working()) + def test_get_volume_backend(self): + backup_mgr = manager.BackupManager() + backup_mgr.volume_managers = {'backend1': 'backend1', + 'backend2': 'backend2'} + backend = backup_mgr._get_volume_backend(allow_null_host=True) + self.assertIn(backend, backup_mgr.volume_managers) + def test_cleanup_incomplete_backup_operations_with_exceptions(self): """Test cleanup resilience in the face of exceptions."""