13
13
# License for the specific language governing permissions and limitations
14
14
# under the License.
15
15
16
+ import io
16
17
import six
17
18
18
19
import mock
@@ -56,6 +57,14 @@ def _setup_scheduler_service(self):
56
57
return self .start_service ('scheduler' )
57
58
58
59
60
+ @mock .patch ('nova.virt.libvirt.LibvirtDriver._get_local_gb_info' ,
61
+ new = mock .Mock (return_value = {'total' : 128 ,
62
+ 'used' : 44 ,
63
+ 'free' : 84 }))
64
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname' ,
65
+ new = mock .Mock (return_value = True ))
66
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.file_open' ,
67
+ new = mock .Mock (side_effect = [io .BytesIO (b'' ), io .BytesIO (b'' )]))
59
68
class NUMAServersTest (NUMAServersTestBase ):
60
69
61
70
def _run_build_test (self , flavor_id , end_status = 'ACTIVE' ):
@@ -179,7 +188,16 @@ def _test_create_server_with_networks(self, flavor_id, networks):
179
188
180
189
return self ._wait_for_state_change (found_server , 'BUILD' )
181
190
182
- def test_create_server_with_single_physnet (self ):
191
+ @mock .patch ('nova.virt.libvirt.LibvirtDriver._get_local_gb_info' ,
192
+ return_value = {'total' : 128 ,
193
+ 'used' : 44 ,
194
+ 'free' : 84 })
195
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname' ,
196
+ return_value = True )
197
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.file_open' ,
198
+ side_effect = [io .BytesIO (b'' ), io .BytesIO (b'' )])
199
+ def test_create_server_with_single_physnet (
200
+ self , mock_file_open , mock_valid_hostname , mock_get_fs_info ):
183
201
extra_spec = {'hw:numa_nodes' : '1' }
184
202
flavor_id = self ._create_flavor (extra_spec = extra_spec )
185
203
networks = [
@@ -192,7 +210,16 @@ def test_create_server_with_single_physnet(self):
192
210
self .assertTrue (self .mock_filter .called )
193
211
self .assertEqual ('ACTIVE' , status )
194
212
195
- def test_create_server_with_multiple_physnets (self ):
213
+ @mock .patch ('nova.virt.libvirt.LibvirtDriver._get_local_gb_info' ,
214
+ return_value = {'total' : 128 ,
215
+ 'used' : 44 ,
216
+ 'free' : 84 })
217
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname' ,
218
+ return_value = True )
219
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.file_open' ,
220
+ side_effect = [io .BytesIO (b'' ), io .BytesIO (b'' )])
221
+ def test_create_server_with_multiple_physnets (
222
+ self , mock_file_open , mock_valid_hostname , mock_get_fs_info ):
196
223
"""Test multiple networks split across host NUMA nodes.
197
224
198
225
This should pass because the networks requested are split across
@@ -212,7 +239,16 @@ def test_create_server_with_multiple_physnets(self):
212
239
self .assertTrue (self .mock_filter .called )
213
240
self .assertEqual ('ACTIVE' , status )
214
241
215
- def test_create_server_with_multiple_physnets_fail (self ):
242
+ @mock .patch ('nova.virt.libvirt.LibvirtDriver._get_local_gb_info' ,
243
+ return_value = {'total' : 128 ,
244
+ 'used' : 44 ,
245
+ 'free' : 84 })
246
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname' ,
247
+ return_value = True )
248
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.file_open' ,
249
+ side_effect = [io .BytesIO (b'' ), io .BytesIO (b'' )])
250
+ def test_create_server_with_multiple_physnets_fail (
251
+ self , mock_file_open , mock_valid_hostname , mock_get_fs_info ):
216
252
"""Test multiple networks split across host NUMA nodes.
217
253
218
254
This should fail because we've requested a single-node instance but the
@@ -231,7 +267,16 @@ def test_create_server_with_multiple_physnets_fail(self):
231
267
self .assertTrue (self .mock_filter .called )
232
268
self .assertEqual ('ERROR' , status )
233
269
234
- def test_create_server_with_physnet_and_tunneled_net (self ):
270
+ @mock .patch ('nova.virt.libvirt.LibvirtDriver._get_local_gb_info' ,
271
+ return_value = {'total' : 128 ,
272
+ 'used' : 44 ,
273
+ 'free' : 84 })
274
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname' ,
275
+ return_value = True )
276
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.file_open' ,
277
+ side_effect = [io .BytesIO (b'' ), io .BytesIO (b'' )])
278
+ def test_create_server_with_physnet_and_tunneled_net (
279
+ self , mock_file_open , mock_valid_hostname , mock_get_fs_info ):
235
280
"""Test combination of physnet and tunneled network.
236
281
237
282
This should pass because we've requested a single-node instance and the
@@ -250,7 +295,16 @@ def test_create_server_with_physnet_and_tunneled_net(self):
250
295
self .assertTrue (self .mock_filter .called )
251
296
self .assertEqual ('ACTIVE' , status )
252
297
253
- def test_rebuild_server_with_network_affinity (self ):
298
+ @mock .patch ('nova.virt.libvirt.LibvirtDriver._get_local_gb_info' ,
299
+ return_value = {'total' : 128 ,
300
+ 'used' : 44 ,
301
+ 'free' : 84 })
302
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname' ,
303
+ return_value = True )
304
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.file_open' ,
305
+ side_effect = [io .BytesIO (b'' ), io .BytesIO (b'' )])
306
+ def test_rebuild_server_with_network_affinity (
307
+ self , mock_file_open , mock_valid_hostname , mock_get_fs_info ):
254
308
extra_spec = {'hw:numa_nodes' : '1' }
255
309
flavor_id = self ._create_flavor (extra_spec = extra_spec )
256
310
networks = [
@@ -299,7 +353,16 @@ def test_rebuild_server_with_network_affinity(self):
299
353
self .assertEqual (500 , ex .response .status_code )
300
354
self .assertIn ('NoValidHost' , six .text_type (ex ))
301
355
302
- def test_cold_migrate_with_physnet (self ):
356
+ @mock .patch ('nova.virt.libvirt.LibvirtDriver._get_local_gb_info' ,
357
+ return_value = {'total' : 128 ,
358
+ 'used' : 44 ,
359
+ 'free' : 84 })
360
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname' ,
361
+ return_value = True )
362
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.file_open' ,
363
+ side_effect = [io .BytesIO (b'' ), io .BytesIO (b'' )])
364
+ def test_cold_migrate_with_physnet (
365
+ self , mock_file_open , mock_valid_hostname , mock_get_fs_info ):
303
366
host_info = fakelibvirt .NUMAHostInfo (cpu_nodes = 2 , cpu_sockets = 1 ,
304
367
cpu_cores = 2 , cpu_threads = 2 ,
305
368
kB_mem = 15740000 )
@@ -363,7 +426,16 @@ def test_cold_migrate_with_physnet(self):
363
426
self .assertIsNotNone (network_metadata )
364
427
self .assertEqual (set (['foo' ]), network_metadata .physnets )
365
428
366
- def test_cold_migrate_with_physnet_fails (self ):
429
+ @mock .patch ('nova.virt.libvirt.LibvirtDriver._get_local_gb_info' ,
430
+ return_value = {'total' : 128 ,
431
+ 'used' : 44 ,
432
+ 'free' : 84 })
433
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname' ,
434
+ return_value = True )
435
+ @mock .patch ('nova.virt.libvirt.driver.libvirt_utils.file_open' ,
436
+ side_effect = [io .BytesIO (b'' ), io .BytesIO (b'' )])
437
+ def test_cold_migrate_with_physnet_fails (
438
+ self , mock_file_open , mock_valid_hostname , mock_get_fs_info ):
367
439
host_infos = [
368
440
# host 1 has room on both nodes
369
441
fakelibvirt .NUMAHostInfo (cpu_nodes = 2 , cpu_sockets = 1 ,
0 commit comments