13
13
# License for the specific language governing permissions and limitations
14
14
# under the License.
15
15
16
+ import socket
16
17
from unittest import mock
17
18
import uuid
18
19
@@ -52,6 +53,8 @@ def setUp(self):
52
53
get = lambda v_id : mock .MagicMock (volume_type = 'fast' ),
53
54
create = lambda size_gb , name , metadata , volume_type :
54
55
self .volume ))
56
+ fake_ip = '127.0.0.1'
57
+ self .fake_socket_return = [[0 , 1 , 2 , 3 , [fake_ip ]]]
55
58
56
59
def setup_stores (self ):
57
60
pass
@@ -138,14 +141,16 @@ def _mock_wait_volume_status(self, volume, status_transition,
138
141
@mock .patch .object (cinder , 'open' )
139
142
@mock .patch ('glance_store._drivers.cinder.Store._wait_volume_status' )
140
143
@mock .patch .object (strutils , 'mask_dict_password' )
141
- def test_create_image (self , mock_mask_pass , mock_wait , mock_open ,
142
- mock_connector , mock_chown , mocked_cc ):
144
+ @mock .patch .object (socket , 'getaddrinfo' )
145
+ def test_create_image (self , mock_host_addr , mock_mask_pass , mock_wait ,
146
+ mock_open , mock_connector , mock_chown , mocked_cc ):
143
147
# setup multiple cinder stores
144
148
self .setup_multiple_stores ()
145
149
self .start_server ()
146
150
147
151
mocked_cc .return_value = self .cinder_store_mock
148
152
mock_wait .side_effect = self ._mock_wait_volume_status
153
+ mock_host_addr .return_value = self .fake_socket_return
149
154
# create an image
150
155
image_id = self ._create_and_import (stores = ['store1' ])
151
156
image = self .api_get ('/v2/images/%s' % image_id ).json
@@ -166,8 +171,9 @@ def test_create_image(self, mock_mask_pass, mock_wait, mock_open,
166
171
@mock .patch .object (cinder , 'open' )
167
172
@mock .patch ('glance_store._drivers.cinder.Store._wait_volume_status' )
168
173
@mock .patch .object (strutils , 'mask_dict_password' )
169
- def test_migrate_image_after_upgrade (self , mock_mask_pass , mock_wait ,
170
- mock_open , mock_connector ,
174
+ @mock .patch .object (socket , 'getaddrinfo' )
175
+ def test_migrate_image_after_upgrade (self , mock_host_addr , mock_mask_pass ,
176
+ mock_wait , mock_open , mock_connector ,
171
177
mock_chown , mocked_cc ):
172
178
"""Test to check if an image is successfully migrated when we
173
179
@@ -178,6 +184,7 @@ def test_migrate_image_after_upgrade(self, mock_mask_pass, mock_wait,
178
184
self .start_server ()
179
185
mocked_cc .return_value = self .cinder_store_mock
180
186
mock_wait .side_effect = self ._mock_wait_volume_status
187
+ mock_host_addr .return_value = self .fake_socket_return
181
188
182
189
# create image in single store
183
190
image_id = self ._create_and_import (stores = ['store1' ])
@@ -212,7 +219,9 @@ def test_migrate_image_after_upgrade(self, mock_mask_pass, mock_wait,
212
219
@mock .patch .object (cinder , 'open' )
213
220
@mock .patch ('glance_store._drivers.cinder.Store._wait_volume_status' )
214
221
@mock .patch .object (strutils , 'mask_dict_password' )
215
- def test_migrate_image_after_upgrade_not_owner (self , mock_mask_pass ,
222
+ @mock .patch .object (socket , 'getaddrinfo' )
223
+ def test_migrate_image_after_upgrade_not_owner (self , mock_host_addr ,
224
+ mock_mask_pass ,
216
225
mock_wait , mock_open ,
217
226
mock_connector ,
218
227
mock_chown , mocked_cc ):
@@ -225,6 +234,7 @@ def test_migrate_image_after_upgrade_not_owner(self, mock_mask_pass,
225
234
self .start_server ()
226
235
mocked_cc .return_value = self .cinder_store_mock
227
236
mock_wait .side_effect = self ._mock_wait_volume_status
237
+ mock_host_addr .return_value = self .fake_socket_return
228
238
229
239
# create image in single store, owned by someone else
230
240
image_id = self ._create_and_import (stores = ['store1' ],
0 commit comments