@@ -102,7 +102,8 @@ class TestCinderStoreUtils(base.MultiStoreClearingUnitTest):
102
102
new_callable = mock .PropertyMock )
103
103
def _test_update_cinder_store_in_location (self , mock_url_prefix ,
104
104
mock_associate_store ,
105
- is_valid = True ):
105
+ is_valid = True ,
106
+ modify_source_url = False ):
106
107
volume_id = 'db457a25-8f16-4b2c-a644-eae8d17fe224'
107
108
store_id = 'fast-cinder'
108
109
expected = 'fast-cinder'
@@ -117,7 +118,11 @@ def _test_update_cinder_store_in_location(self, mock_url_prefix,
117
118
}]
118
119
mock_url_prefix .return_value = 'cinder://%s' % store_id
119
120
image .locations = locations
120
- store_utils .update_store_in_locations (context , image , image_repo )
121
+ if modify_source_url :
122
+ updated_location = store_utils .get_updated_store_location (
123
+ locations , context = context )
124
+ else :
125
+ store_utils .update_store_in_locations (context , image , image_repo )
121
126
122
127
if is_valid :
123
128
# This is the case where we found an image that has an
@@ -129,10 +134,18 @@ def _test_update_cinder_store_in_location(self, mock_url_prefix,
129
134
# format i.e. this is the case when store is valid and location
130
135
# url, metadata are updated and image_repo.save is called
131
136
expected_url = mock_url_prefix .return_value + '/' + volume_id
132
- self .assertEqual (expected_url , image .locations [0 ].get ('url' ))
133
- self .assertEqual (expected , image .locations [0 ]['metadata' ].get (
134
- 'store' ))
135
- self .assertEqual (1 , image_repo .save .call_count )
137
+ if modify_source_url :
138
+ # This is the case where location url is modified to be
139
+ # compatible with multistore as below,
140
+ # `cinder://store_id/volume_id` to avoid InvalidLocation error
141
+ self .assertEqual (expected_url , updated_location [0 ].get ('url' ))
142
+ self .assertEqual (expected ,
143
+ updated_location [0 ]['metadata' ].get ('store' ))
144
+ else :
145
+ self .assertEqual (expected_url , image .locations [0 ].get ('url' ))
146
+ self .assertEqual (expected , image .locations [0 ]['metadata' ].get (
147
+ 'store' ))
148
+ self .assertEqual (1 , image_repo .save .call_count )
136
149
else :
137
150
# Here, we've got an image backed by a volume which does
138
151
# not have a corresponding store specifying the volume_type.
@@ -151,6 +164,15 @@ def test_update_cinder_store_location_valid_type(self):
151
164
def test_update_cinder_store_location_invalid_type (self ):
152
165
self ._test_update_cinder_store_in_location (is_valid = False )
153
166
167
+ def test_get_updated_cinder_store_location (self ):
168
+ """
169
+ Test if location url is modified to be compatible
170
+ with multistore.
171
+ """
172
+
173
+ self ._test_update_cinder_store_in_location (
174
+ modify_source_url = True )
175
+
154
176
155
177
class TestUtils (test_utils .BaseTestCase ):
156
178
"""Test routines in glance.utils"""
0 commit comments