diff --git a/nova/network/model.py b/nova/network/model.py index 36cd85499c38..e2183b77b95a 100644 --- a/nova/network/model.py +++ b/nova/network/model.py @@ -467,6 +467,15 @@ class NetworkInfo(list): network_info = jsonutils.loads(network_info) return cls([VIF.hydrate(vif) for vif in network_info]) + def wait(self, do_raise=True): + """Wait for asynchronous call to finish.""" + # There is no asynchronous call for this class, so this is a no-op + # here, but subclasses may override to provide asynchronous + # capabilities. Must be defined here in the parent class so that code + # which works with both parent and subclass types can reference this + # method. + pass + def json(self): return jsonutils.dumps(self) @@ -529,7 +538,7 @@ class NetworkInfoAsyncWrapper(NetworkInfo): return self._sync_wrapper(fn, *args, **kwargs) def wait(self, do_raise=True): - """Wait for async call to finish.""" + """Wait for asynchronous call to finish.""" if self._gt is not None: try: # NOTE(comstud): This looks funky, but this object is diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index 13442ed5c348..b15c40cb164f 100755 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -4378,11 +4378,12 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): system_metadata={}, expected_attrs=['system_metadata']) - self.compute._build_networks_for_instance(self.context, instance, - self.requested_networks, self.security_groups) + nw_info_obj = self.compute._build_networks_for_instance(self.context, + instance, self.requested_networks, self.security_groups) mock_allocate.assert_called_once_with(self.context, instance, self.requested_networks, None, self.security_groups, None) + self.assertTrue(hasattr(nw_info_obj, 'wait'), "wait must be there") @mock.patch.object(manager.ComputeManager, '_allocate_network') @mock.patch.object(network_api.API, 'get_instance_nw_info') @@ -4391,11 +4392,12 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): system_metadata=dict(network_allocated='False'), expected_attrs=['system_metadata']) - self.compute._build_networks_for_instance(self.context, instance, - self.requested_networks, self.security_groups) + nw_info_obj = self.compute._build_networks_for_instance(self.context, + instance, self.requested_networks, self.security_groups) mock_allocate.assert_called_once_with(self.context, instance, self.requested_networks, None, self.security_groups, None) + self.assertTrue(hasattr(nw_info_obj, 'wait'), "wait must be there") @mock.patch.object(network_api.API, 'setup_instance_network_on_host') @mock.patch.object(manager.ComputeManager, '_allocate_network') @@ -4409,8 +4411,9 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): def fake_network_info(): return network_model.NetworkInfo([{'address': '123.123.123.123'}]) - mock_get.return_value = network_model.NetworkInfoAsyncWrapper( - fake_network_info) + # this should be a NetworkInfo, not NetworkInfoAsyncWrapper, to match + # what get_instance_nw_info really returns + mock_get.return_value = fake_network_info() self.compute._build_networks_for_instance(self.context, instance, self.requested_networks, self.security_groups)