resync: hyper-v: wait for neutron vif plug events
(cherry-picked from commit 00fdf284085866c77590255059ae74b672dd5a85) Change-Id: Icba6f86a5ec1d303da6dd37f8d0acefd29570b1d
This commit is contained in:
parent
da4c9ad33d
commit
c2e8cc605c
|
@ -298,8 +298,10 @@ class VMOps(object):
|
|||
|
||||
try:
|
||||
with self.wait_vif_plug_events(instance, network_info):
|
||||
# waiting will occur after the instance is created.
|
||||
self.create_instance(context, instance, network_info,
|
||||
block_device_info, vm_gen, image_meta)
|
||||
|
||||
self._save_device_metadata(context, instance, block_device_info)
|
||||
|
||||
if configdrive.required_by(instance):
|
||||
|
@ -319,10 +321,7 @@ class VMOps(object):
|
|||
@contextlib.contextmanager
|
||||
def wait_vif_plug_events(self, instance, network_info):
|
||||
timeout = CONF.vif_plugging_timeout
|
||||
if utils.is_neutron():
|
||||
events = self._get_neutron_events(network_info)
|
||||
else:
|
||||
events = []
|
||||
events = self._get_neutron_events(network_info)
|
||||
|
||||
try:
|
||||
with self._virtapi.wait_for_instance_event(
|
||||
|
@ -348,8 +347,11 @@ class VMOps(object):
|
|||
# already up will not undergo that transition, and for
|
||||
# anything that might be stale (cache-wise) assume it's
|
||||
# already up so we don't block on it.
|
||||
return [('network-vif-plugged', vif['id'])
|
||||
for vif in network_info if vif.get('active') is False]
|
||||
if utils.is_neutron() and CONF.vif_plugging_timeout:
|
||||
return [('network-vif-plugged', vif['id'])
|
||||
for vif in network_info if vif.get('active') is False]
|
||||
else:
|
||||
return []
|
||||
|
||||
def create_instance(self, context, instance, network_info,
|
||||
block_device_info, vm_gen, image_meta):
|
||||
|
|
|
@ -519,8 +519,7 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
mock.sentinel.INFO, mock.sentinel.DEV_INFO)
|
||||
|
||||
@mock.patch.object(vmops.VMOps, '_get_neutron_events')
|
||||
@mock.patch.object(vmops.utils, 'is_neutron')
|
||||
def test_wait_vif_plug_events(self, mock_is_neutron, mock_get_events):
|
||||
def test_wait_vif_plug_events(self, mock_get_events):
|
||||
self._vmops._virtapi.wait_for_instance_event.side_effect = (
|
||||
etimeout.Timeout)
|
||||
self.flags(vif_plugging_timeout=1)
|
||||
|
@ -534,7 +533,6 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
self.assertRaises(exception.VirtualInterfaceCreateException,
|
||||
_context_user)
|
||||
|
||||
mock_is_neutron.assert_called_once_with()
|
||||
mock_get_events.assert_called_once_with(mock.sentinel.network_info)
|
||||
self._vmops._virtapi.wait_for_instance_event.assert_called_once_with(
|
||||
mock.sentinel.instance, mock_get_events.return_value,
|
||||
|
@ -547,7 +545,8 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
self._vmops._neutron_failed_callback,
|
||||
mock.sentinel.event_name, mock.sentinel.instance)
|
||||
|
||||
def test_get_neutron_events(self):
|
||||
@mock.patch.object(vmops.utils, 'is_neutron')
|
||||
def test_get_neutron_events(self, mock_is_neutron):
|
||||
network_info = [{'id': mock.sentinel.vif_id1, 'active': True},
|
||||
{'id': mock.sentinel.vif_id2, 'active': False},
|
||||
{'id': mock.sentinel.vif_id3}]
|
||||
|
@ -555,6 +554,16 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
events = self._vmops._get_neutron_events(network_info)
|
||||
self.assertEqual([('network-vif-plugged', mock.sentinel.vif_id2)],
|
||||
events)
|
||||
mock_is_neutron.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(vmops.utils, 'is_neutron')
|
||||
def test_get_neutron_events_no_timeout(self, mock_is_neutron):
|
||||
self.flags(vif_plugging_timeout=0)
|
||||
network_info = [{'id': mock.sentinel.vif_id1, 'active': True}]
|
||||
|
||||
events = self._vmops._get_neutron_events(network_info)
|
||||
self.assertEqual([], events)
|
||||
mock_is_neutron.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(vmops.VMOps, '_configure_secure_vm')
|
||||
@mock.patch.object(vmops.VMOps, '_requires_secure_boot')
|
||||
|
|
Loading…
Reference in New Issue