Revert "update subport status when trunk/subport create/delete is triggerred"

This reverts commit 101ccbaeb3.

Reason for revert: This commit is probably reason of some race condition
which causes random failures in the test_trunk_subport_lifecycle scenario
test.

Change-Id: Ia042384e0ac333f30235b76e50fdc8748fc2b29a
Closes-Bug: #1943708
(cherry picked from commit b0e01c7df3)
This commit is contained in:
Slawek Kaplonski 2021-09-17 07:54:38 +00:00
parent 6d8775cb09
commit e227b0e976
2 changed files with 0 additions and 182 deletions

View File

@ -14,8 +14,6 @@
import copy
import eventlet
from neutron_lib.api.definitions import port as port_def
from neutron_lib.api.definitions import portbindings
from neutron_lib.api.definitions import trunk as trunk_apidef
@ -474,59 +472,3 @@ class TrunkPlugin(service_base.ServicePluginBase):
self.update_trunk(
context, trunk_id,
{'trunk': {'status': constants.TRUNK_DOWN_STATUS}})
@registry.receives(resources.SUBPORTS,
[events.AFTER_CREATE, events.AFTER_DELETE])
@registry.receives(resources.TRUNK,
[events.AFTER_CREATE, events.AFTER_DELETE])
def _update_device_attributes(self, resource, event, triggers, payload):
device_id = ''
device_owner = ''
host_id = None
if event == events.AFTER_CREATE:
device_id = payload.resource_id
device_owner = constants.TRUNK_SUBPORT_OWNER
if resource == resources.TRUNK:
subports = payload.states[0].sub_ports
elif resource == resources.SUBPORTS:
if len(payload.states) < 2:
LOG.debug("Invalid payload format for '%(resource)s' "
"'%(event)s' scenario. Current Trunk data "
"is missing",
{'resource': resources.TRUNK,
'event': events.AFTER_CREATE})
return
subports = payload.metadata['subports']
parent_port = directory.get_plugin().get_port(
context.get_admin_context(),
payload.states[1]['port_id'])
host_id = parent_port['binding:host_id']
elif event == events.AFTER_DELETE:
host_id = ''
if resource == resources.TRUNK:
subports = payload.states[0].sub_ports
elif resource == resources.SUBPORTS:
subports = payload.metadata['subports']
eventlet.spawn_n(self._update_subports, context.get_admin_context(),
subports, device_id, device_owner, host_id)
def _update_subports(self, context, subports, device_id, device_owner,
host_id):
port_data = (
{'port': {'device_id': device_id, 'device_owner': device_owner}})
if host_id is not None:
port_data['port']['binding:host_id'] = host_id
core_plugin = directory.get_plugin()
for subport in subports:
try:
core_plugin.update_port(context, subport.port_id, port_data)
except Exception as e:
LOG.error("Unable to update device_id = '%(device_id)s'"
"and device_owner='%(device_owner)s'"
"and host_id='%(host_id)'"
"for port=%(port_id)s: %(reason)s",
{'device_id': device_id,
'device_owner': device_owner,
'host_id': host_id,
'port_id': subport.port_id,
'reason': e})

View File

@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import time
from unittest import mock
from neutron_lib.api.definitions import portbindings
@ -24,8 +23,6 @@ from neutron_lib.plugins import directory
from neutron_lib.services.trunk import constants
import testtools
from neutron.common import utils
from neutron.objects import ports
from neutron.objects import trunk as trunk_objects
from neutron.services.trunk import drivers
from neutron.services.trunk import exceptions as trunk_exc
@ -373,127 +370,6 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
self.assertEqual(final_trunk_status, current_trunk.status)
return trunk, current_trunk
def test__update_device_attributes_trunk_create(self):
with self.port() as parent, self.port() as childport:
subport = create_subport_dict(childport['port']['id'])
trunk = self._create_test_trunk(parent)
self.trunk_plugin.add_subports(
self.context, trunk['id'], {'sub_ports': [subport]})
trunk_obj = self._get_trunk_obj(trunk['id'])
trunk_obj.status = constants.TRUNK_ACTIVE_STATUS
trunk_obj.update()
payload = events.DBEventPayload(
self.context, resource_id=trunk_obj.id, states=(trunk_obj,))
self.trunk_plugin._update_device_attributes(
resources.TRUNK, events.AFTER_CREATE, None, payload)
utils.wait_until_true(
lambda: ports.Port.get_object(
self.context,
id=[childport['port']['id']]
).device_owner == constants.TRUNK_SUBPORT_OWNER,
timeout=5)
subport_obj = ports.Port.get_object(self.context,
id=[childport['port']['id']])
self.assertEqual(subport_obj.device_owner,
constants.TRUNK_SUBPORT_OWNER)
self.assertEqual(subport_obj.device_id, trunk['id'])
def test__update_device_attributes_trunk_delete(self):
with self.port() as parent, self.port() as childport:
subport = create_subport_dict(childport['port']['id'])
trunk = self._create_test_trunk(parent)
self.trunk_plugin.add_subports(
self.context, trunk['id'], {'sub_ports': [subport]})
trunk_obj = self._get_trunk_obj(trunk['id'])
trunk_obj.status = constants.TRUNK_ACTIVE_STATUS
trunk_obj.update()
payload = events.DBEventPayload(
self.context, resource_id=trunk_obj.id, states=(trunk_obj,))
self.trunk_plugin._update_device_attributes(
resources.TRUNK, events.AFTER_DELETE, None, payload)
time.sleep(0.1)
utils.wait_until_true(
lambda: ports.Port.get_object(
self.context,
id=[childport['port']['id']]
).device_owner == '',
timeout=5)
subport_obj = ports.Port.get_object(self.context,
id=[childport['port']['id']])
self.assertEqual('', subport_obj.device_owner)
self.assertEqual('', subport_obj.device_id)
def test__update_device_attributes_subport_create(self):
with self.port() as parent, self.port() as childport:
subport = create_subport_dict(childport['port']['id'])
trunk = self._create_test_trunk(parent)
parent['port']['binding:host_id'] = 'host'
core_plugin = directory.get_plugin()
core_plugin.update_port(self.context, parent['port']['id'], parent)
self.trunk_plugin.add_subports(
self.context, trunk['id'], {'sub_ports': [subport]})
trunk_obj = self._get_trunk_obj(trunk['id'])
trunk_obj.status = constants.TRUNK_ACTIVE_STATUS
trunk_obj.update()
utils.wait_until_true(
lambda: ports.Port.get_object(
self.context,
id=[childport['port']['id']]
).device_owner == constants.TRUNK_SUBPORT_OWNER,
timeout=5)
subport_obj = ports.Port.get_object(self.context,
id=[childport['port']['id']])
self.assertEqual(subport_obj.device_owner,
constants.TRUNK_SUBPORT_OWNER)
self.assertEqual(subport_obj.device_id, trunk['id'])
self.assertEqual('host', subport_obj.bindings[0]['host'])
def test__update_device_attributes_subport_delete(self):
with self.port() as parent, self.port() as childport:
subport = create_subport_dict(childport['port']['id'])
trunk = self._create_test_trunk(parent)
parent['port']['binding:host_id'] = 'host'
core_plugin = directory.get_plugin()
core_plugin.update_port(self.context, parent['port']['id'], parent)
self.trunk_plugin.add_subports(
self.context, trunk['id'], {'sub_ports': [subport]})
trunk_obj = self._get_trunk_obj(trunk['id'])
trunk_obj.status = constants.TRUNK_ACTIVE_STATUS
trunk_obj.update()
utils.wait_until_true(
lambda: ports.Port.get_object(
self.context,
id=[childport['port']['id']]
).device_owner == constants.TRUNK_SUBPORT_OWNER,
timeout=5)
subport_obj = ports.Port.get_object(self.context,
id=[childport['port']['id']])
self.assertEqual(constants.TRUNK_SUBPORT_OWNER,
subport_obj.device_owner)
self.assertEqual(subport_obj.device_id, trunk['id'])
self.assertEqual('host', subport_obj.bindings[0]['host'])
payload = events.DBEventPayload(
self.context,
resource_id=trunk_obj.id,
states=(None, trunk_obj,),
metadata={'subports': trunk_obj.sub_ports})
self.trunk_plugin._update_device_attributes(
resources.SUBPORTS, events.AFTER_DELETE, None, payload)
time.sleep(0.1)
utils.wait_until_true(
lambda: ports.Port.get_object(
self.context,
id=[childport['port']['id']]
).device_owner == '',
timeout=5)
subport_obj = ports.Port.get_object(self.context,
id=[childport['port']['id']])
self.assertEqual('', subport_obj.device_owner)
self.assertEqual('', subport_obj.device_id)
self.assertEqual('', subport_obj.bindings[0]['host'])
class TrunkPluginCompatDriversTestCase(test_plugin.Ml2PluginV2TestCase):