From fc709e728ba5c0d04c9df195fb879df010528f65 Mon Sep 17 00:00:00 2001 From: TommyLike Date: Mon, 20 Aug 2018 18:42:24 +0800 Subject: [PATCH] Add 'volume_attachment' to volume expected attributes 'volume_attachment' is a frequently used attribute when listing volumes inside or outside cinder, considering it already has been loaded from database [1], this patch adds it to volume's expected attributes to improve performance. [1]: https://github.com/openstack/cinder/blob/0652085f23ba22f0a6335726d9f0f7018d4662ea/cinder/db/sqlalchemy/api.py#L1926 Change-Id: I3be3c99f9317726fa3182f750b27690da3cdab83 (cherry picked from commit af66bce67638626e9c32f1ab75d1d67c8984b1b6) --- cinder/objects/volume.py | 2 +- cinder/tests/unit/keymgr/test_migration.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cinder/objects/volume.py b/cinder/objects/volume.py index 4314aba688e..a528182f261 100644 --- a/cinder/objects/volume.py +++ b/cinder/objects/volume.py @@ -597,7 +597,7 @@ class VolumeList(base.ObjectListBase, base.CinderObject): @classmethod def _get_expected_attrs(cls, context, *args, **kwargs): - expected_attrs = ['metadata', 'volume_type'] + expected_attrs = ['metadata', 'volume_type', 'volume_attachment'] if context.is_admin: expected_attrs.append('admin_metadata') diff --git a/cinder/tests/unit/keymgr/test_migration.py b/cinder/tests/unit/keymgr/test_migration.py index d668161e4a8..1272a0df08d 100644 --- a/cinder/tests/unit/keymgr/test_migration.py +++ b/cinder/tests/unit/keymgr/test_migration.py @@ -62,9 +62,8 @@ class KeyMigrationTestCase(base.BaseVolumeTestCase): if key_id: vol.encryption_key_id = key_id vol.save() - self.my_vols = objects.VolumeList.get_all_by_host(self.context, - self.conf.host) vol.refresh() + self.my_vols.append(vol) return vol def create_backup(self, volume_id=fake.VOLUME_ID, key_id=FIXED_KEY_ID):