def test_create_async_model_exceptions(self): def async_wrapper(): raise test.TestingException() ninfo = model.NetworkInfoAsyncWrapper(async_wrapper) self.assertRaises(test.TestingException, ninfo.wait) # 2nd one doesn't raise self.assertIsNone(ninfo.wait()) # Test that do_raise=False works on .wait() ninfo = model.NetworkInfoAsyncWrapper(async_wrapper) self.assertIsNone(ninfo.wait(do_raise=False)) # Test we also raise calling a method ninfo = model.NetworkInfoAsyncWrapper(async_wrapper) self.assertRaises(test.TestingException, ninfo.fixed_ips)
def test_create_async_model(self): def async_wrapper(): return model.NetworkInfo( [fake_network_cache_model.new_vif(), fake_network_cache_model.new_vif( {'address': 'bb:bb:bb:bb:bb:bb'})]) ninfo = model.NetworkInfoAsyncWrapper(async_wrapper) self.assertEqual(ninfo.fixed_ips(), [fake_network_cache_model.new_ip({'address': '10.10.0.2'}), fake_network_cache_model.new_ip( {'address': '10.10.0.3'})] * 4)
def stub_out_modules(self): # NOTE: if simulation mode is enabled, the virt driver will be replaced # by a fake driver. if CONF_BENCH.nova_patcher.enable_simulation: _SchedulerFakeDriver.setup() self.patch('nova.virt.fake.SchedulerFakeDriver', _SchedulerFakeDriver, add=True) fake_async_networkinfo = \ lambda *args, **kwargs: network_model.NetworkInfoAsyncWrapper( lambda *args, **kwargs: network_model.NetworkInfo()) fake_deallocate_networkinfo = lambda *args, **kwargs: None fake_check_requested_networks = lambda *args, **kwargs: 1 self.patch('nova.compute.manager.ComputeManager._allocate_network', fake_async_networkinfo) self.patch('nova.compute.manager.ComputeManager._deallocate_network', fake_deallocate_networkinfo) self.patch('nova.compute.api.API._check_requested_networks', fake_check_requested_networks)
def fake_async_networkinfo(*args, **kwargs): return network_model.NetworkInfoAsyncWrapper(fake_networkinfo)