Check the network_info obj type before invoke wait function
When instance schedule to host and it isn't first time schedule, the instance may already allocated network. And then the code will return an NetworkInfo object, not an NetworkInfoAsyncWrapper. The checking code only assume it is NetworkInfoAsyncWrapper object. Change-Id: I987902fc47e509e4fd08f762d66b16c09eaf5008 Partial-Bug: #1326207
This commit is contained in:
parent
cb3fb0203a
commit
24a04c405a
@ -380,6 +380,14 @@ class NetworkInfo(list):
|
|||||||
def json(self):
|
def json(self):
|
||||||
return jsonutils.dumps(self)
|
return jsonutils.dumps(self)
|
||||||
|
|
||||||
|
def wait(self, do_raise=True):
|
||||||
|
"""A no-op method.
|
||||||
|
|
||||||
|
This is useful to avoid type checking when NetworkInfo might be
|
||||||
|
subclassed with NetworkInfoAsyncWrapper.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NetworkInfoAsyncWrapper(NetworkInfo):
|
class NetworkInfoAsyncWrapper(NetworkInfo):
|
||||||
"""Wrapper around NetworkInfo that allows retrieving NetworkInfo
|
"""Wrapper around NetworkInfo that allows retrieving NetworkInfo
|
||||||
|
@ -1820,6 +1820,30 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
|
|||||||
mock.call(self.context, self.instance,
|
mock.call(self.context, self.instance,
|
||||||
self.requested_networks, self.security_groups))
|
self.requested_networks, self.security_groups))
|
||||||
|
|
||||||
|
def test_build_resources_with_network_info_obj_on_spawn_failure(self):
|
||||||
|
self.mox.StubOutWithMock(self.compute, '_cleanup_build_resources')
|
||||||
|
self.mox.StubOutWithMock(self.compute, '_build_networks_for_instance')
|
||||||
|
self.compute._build_networks_for_instance(self.context, self.instance,
|
||||||
|
self.requested_networks, self.security_groups).AndReturn(
|
||||||
|
network_model.NetworkInfo())
|
||||||
|
self._build_resources_instance_update()
|
||||||
|
self.compute._cleanup_build_resources(self.context, self.instance,
|
||||||
|
self.block_device_mapping)
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
|
test_exception = test.TestingException()
|
||||||
|
|
||||||
|
def fake_spawn():
|
||||||
|
raise test_exception
|
||||||
|
|
||||||
|
try:
|
||||||
|
with self.compute._build_resources(self.context, self.instance,
|
||||||
|
self.requested_networks, self.security_groups,
|
||||||
|
self.image, self.block_device_mapping):
|
||||||
|
fake_spawn()
|
||||||
|
except Exception as e:
|
||||||
|
self.assertEqual(test_exception, e)
|
||||||
|
|
||||||
def test_build_resources_cleans_up_and_reraises_on_spawn_failure(self):
|
def test_build_resources_cleans_up_and_reraises_on_spawn_failure(self):
|
||||||
self.mox.StubOutWithMock(self.compute, '_cleanup_build_resources')
|
self.mox.StubOutWithMock(self.compute, '_cleanup_build_resources')
|
||||||
self.mox.StubOutWithMock(self.compute, '_build_networks_for_instance')
|
self.mox.StubOutWithMock(self.compute, '_build_networks_for_instance')
|
||||||
|
Loading…
Reference in New Issue
Block a user