Skip to content

Commit 254d3d0

Browse files
committed
[Trunk] Update the trunk status with the parent status
After a trunk VM has been migrated the trunk status remains DOWN, After the parent port is back to active modify the trunk status. Closes-Bug: #1988549 Change-Id: Ia0f7a6e8510af2c3545993e0d0d4bb06a9b70b79 (cherry picked from commit 178ee6f)
1 parent b0081ea commit 254d3d0

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

neutron/services/trunk/plugin.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from neutron_lib.callbacks import events
2222
from neutron_lib.callbacks import registry
2323
from neutron_lib.callbacks import resources
24+
from neutron_lib import constants as const
2425
from neutron_lib import context
2526
from neutron_lib.db import api as db_api
2627
from neutron_lib.db import resource_extend
@@ -463,12 +464,19 @@ def _trigger_trunk_status_change(self, resource, event, trigger, payload):
463464
original_port = payload.states[0]
464465
orig_vif_type = original_port.get(portbindings.VIF_TYPE)
465466
new_vif_type = updated_port.get(portbindings.VIF_TYPE)
467+
orig_status = original_port.get('status')
468+
new_status = updated_port.get('status')
466469
vif_type_changed = orig_vif_type != new_vif_type
470+
trunk_id = trunk_details['trunk_id']
467471
if vif_type_changed and new_vif_type == portbindings.VIF_TYPE_UNBOUND:
468-
trunk_id = trunk_details['trunk_id']
469472
# NOTE(status_police) Trunk status goes to DOWN when the parent
470473
# port is unbound. This means there are no more physical resources
471474
# associated with the logical resource.
472475
self.update_trunk(
473476
context, trunk_id,
474477
{'trunk': {'status': constants.TRUNK_DOWN_STATUS}})
478+
elif new_status == const.PORT_STATUS_ACTIVE and \
479+
new_status != orig_status:
480+
self.update_trunk(
481+
context, trunk_id,
482+
{'trunk': {'status': constants.TRUNK_ACTIVE_STATUS}})

neutron/tests/unit/services/trunk/test_plugin.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from neutron_lib.callbacks import events
2020
from neutron_lib.callbacks import registry
2121
from neutron_lib.callbacks import resources
22+
from neutron_lib import constants as neutron_const
2223
from neutron_lib.plugins import directory
2324
from neutron_lib.services.trunk import constants
2425
import testtools
@@ -285,6 +286,32 @@ def test_remove_subports_trunk_goes_to_down(self):
285286
{'sub_ports': [{'port_id': subport['port']['id']}]})
286287
self.assertEqual(constants.TRUNK_DOWN_STATUS, trunk['status'])
287288

289+
def test__trigger_trunk_status_change_parent_port_status_down(self):
290+
callback = register_mock_callback(resources.TRUNK, events.AFTER_UPDATE)
291+
with self.port() as parent:
292+
parent['status'] = neutron_const.PORT_STATUS_DOWN
293+
original_port = {'status': neutron_const.PORT_STATUS_DOWN}
294+
_, _ = (
295+
self._test__trigger_trunk_status_change(
296+
parent, original_port,
297+
constants.TRUNK_DOWN_STATUS,
298+
constants.TRUNK_DOWN_STATUS))
299+
callback.assert_not_called()
300+
301+
def test__trigger_trunk_status_change_parent_port_status_up(self):
302+
callback = register_mock_callback(resources.TRUNK, events.AFTER_UPDATE)
303+
with self.port() as parent:
304+
parent['status'] = neutron_const.PORT_STATUS_ACTIVE
305+
original_port = {'status': neutron_const.PORT_STATUS_DOWN}
306+
_, _ = (
307+
self._test__trigger_trunk_status_change(
308+
parent, original_port,
309+
constants.TRUNK_DOWN_STATUS,
310+
constants.TRUNK_ACTIVE_STATUS))
311+
callback.assert_called_once_with(
312+
resources.TRUNK, events.AFTER_UPDATE,
313+
self.trunk_plugin, payload=mock.ANY)
314+
288315
def test__trigger_trunk_status_change_vif_type_changed_unbound(self):
289316
callback = register_mock_callback(resources.TRUNK, events.AFTER_UPDATE)
290317
with self.port() as parent:

0 commit comments

Comments
 (0)