diff --git a/glance/common/utils.py b/glance/common/utils.py index c26753ceb9..9d2b9fccca 100644 --- a/glance/common/utils.py +++ b/glance/common/utils.py @@ -720,13 +720,12 @@ def sort_image_locations(locations): if not store_id: return 0 try: - store = glance_store.get_store_from_store_identifier(store_id) + return glance_store.get_store_weight(store_id) except glance_store.exceptions.UnknownScheme: msg = (_LW("Unable to find store '%s', returning " "default weight '0'") % store_id) LOG.warning(msg) return 0 - return store.weight if store is not None else 0 sorted_locations = sorted(locations, key=get_store_weight, reverse=True) LOG.debug(('Sorted locations: %s'), sorted_locations) diff --git a/glance/tests/unit/common/test_utils.py b/glance/tests/unit/common/test_utils.py index ae676171bf..339e98b508 100644 --- a/glance/tests/unit/common/test_utils.py +++ b/glance/tests/unit/common/test_utils.py @@ -192,7 +192,7 @@ class TestUtils(test_utils.BaseTestCase): 'url': 'rbd://cccccccc/images/id', 'metadata': {'store': 'rbd3'} }] - mp = "glance.common.utils.glance_store.get_store_from_store_identifier" + mp = "glance.common.utils.glance_store.get_store_weight" with mock.patch(mp) as mock_get_store: utils.sort_image_locations(locations) @@ -218,10 +218,9 @@ class TestUtils(test_utils.BaseTestCase): 'url': 'rbd://cccccccc/images/id', 'metadata': {'store': 'rbd3'} }] - mp = "glance.common.utils.glance_store.get_store_from_store_identifier" + mp = "glance.common.utils.glance_store.get_store_weight" with mock.patch(mp) as mock_get_store: - mock_store = mock_get_store.return_value - mock_store.weight = 100 + mock_get_store.return_value = 100 utils.sort_image_locations(locations) # Since 3 stores are configured, internal method will be called 3 times @@ -246,7 +245,7 @@ class TestUtils(test_utils.BaseTestCase): 'url': 'rbd://cccccccc/images/id', 'metadata': {} }] - mp = "glance.common.utils.glance_store.get_store_from_store_identifier" + mp = "glance.common.utils.glance_store.get_store_weight" with mock.patch(mp) as mock_get_store: utils.sort_image_locations(locations) @@ -273,10 +272,9 @@ class TestUtils(test_utils.BaseTestCase): 'url': 'rbd://cccccccc/images/id', 'metadata': {} }] - mp = "glance.common.utils.glance_store.get_store_from_store_identifier" + mp = "glance.common.utils.glance_store.get_store_weight" with mock.patch(mp) as mock_get_store: - mock_store = mock_get_store.return_value - mock_store.weight = 100 + mock_get_store.return_value = 100 utils.sort_image_locations(locations) # Since 3 stores are configured, but only one location has @@ -303,7 +301,7 @@ class TestUtils(test_utils.BaseTestCase): 'url': 'rbd://cccccccc/images/id', 'metadata': {'store': 'rbd3'} }] - mp = "glance.common.utils.glance_store.get_store_from_store_identifier" + mp = "glance.common.utils.glance_store.get_store_weight" with mock.patch(mp) as mock_get_store: mock_get_store.side_effect = store.UnknownScheme() sorted_locations = utils.sort_image_locations(locations)