From e0f7bfaeaf2fd01afe711487e90a7e298f47a78c Mon Sep 17 00:00:00 2001 From: asarfaty Date: Thu, 15 Oct 2020 08:18:06 +0200 Subject: [PATCH] NSX|P: Wait with segment realization until it is fully done Nova boot may fail if the logical switch is not accessible. This patch wait until the segment consolidated state is successful before returning the LS id to nova. Change-Id: Ib055feda79877fe4ebcc5db193f7d9d081724a94 --- vmware_nsx/plugins/nsx_p/plugin.py | 4 ++++ vmware_nsx/tests/unit/nsx_p/test_plugin.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/vmware_nsx/plugins/nsx_p/plugin.py b/vmware_nsx/plugins/nsx_p/plugin.py index e68f55264f..153eb1326c 100644 --- a/vmware_nsx/plugins/nsx_p/plugin.py +++ b/vmware_nsx/plugins/nsx_p/plugin.py @@ -1618,6 +1618,10 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base): try: nsx_id = self.nsxpolicy.segment.get_realized_logical_switch_id( segment_id) + # Make sure the LS is already active before letting nova use it + if utils.is_nsx_version_3_1_0(self._nsx_version): + self.nsxpolicy.segment.wait_until_state_successful( + segment_id, with_refresh=True) # Add result to caches NET_NEUTRON_2_NSX_ID_CACHE[network_id] = nsx_id NET_NSX_2_NEUTRON_ID_CACHE[nsx_id] = network_id diff --git a/vmware_nsx/tests/unit/nsx_p/test_plugin.py b/vmware_nsx/tests/unit/nsx_p/test_plugin.py index 6f073de755..ef3321fcea 100644 --- a/vmware_nsx/tests/unit/nsx_p/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_p/test_plugin.py @@ -126,6 +126,9 @@ class NsxPPluginTestCaseMixin( "NsxPolicySegmentApi.get_realized_logical_switch_id", return_value=LOGICAL_SWITCH_ID ).start() + mock.patch("vmware_nsxlib.v3.policy.core_resources." + "NsxPolicySegmentApi.wait_until_state_successful" + ).start() mock.patch("vmware_nsxlib.v3.policy.core_resources." "NsxPolicySegmentApi.get_realized_id", return_value=LOGICAL_SWITCH_ID