From bdaf26394ce27a9e0fd9b50069b1f000cbc9ecfd Mon Sep 17 00:00:00 2001 From: Steve Keay Date: Fri, 30 Aug 2024 22:33:57 +0100 Subject: [PATCH] Have neutron ML2 driver pass port ID when invoking undersync workflow --- .../workflowtemplates/undersync-device.yaml | 3 ++ .../neutron_understack_mech.py | 4 +- .../neutron_update_port_postcommit.json | 35 ++++++++++++++++++ .../tests/test_neutron_understack_mech.py | 37 +++++++++++++++++++ .../main/undersync_device.py | 3 ++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 python/neutron-understack/neutron_understack/tests/fixtures/neutron_update_port_postcommit.json create mode 100644 python/neutron-understack/neutron_understack/tests/test_neutron_understack_mech.py diff --git a/argo-workflows/trigger-undersync/workflowtemplates/undersync-device.yaml b/argo-workflows/trigger-undersync/workflowtemplates/undersync-device.yaml index 238fa3f38..c24b6317c 100644 --- a/argo-workflows/trigger-undersync/workflowtemplates/undersync-device.yaml +++ b/argo-workflows/trigger-undersync/workflowtemplates/undersync-device.yaml @@ -15,6 +15,8 @@ spec: command: - undersync-device args: + - --interface-id + - "{{workflow.parameters.interface_uuid}}" - --device-id - "{{workflow.parameters.device_uuid}}" - --network-name @@ -32,6 +34,7 @@ spec: readOnly: true inputs: parameters: + - name: interface_uuid - name: device_uuid - name: network_name - name: force diff --git a/python/neutron-understack/neutron_understack/neutron_understack_mech.py b/python/neutron-understack/neutron_understack/neutron_understack_mech.py index e8a38bb92..ad699fd7c 100644 --- a/python/neutron-understack/neutron_understack/neutron_understack_mech.py +++ b/python/neutron-understack/neutron_understack/neutron_understack_mech.py @@ -263,14 +263,16 @@ def __network_name(self, network_id: str): return "tenant" def _move_to_network(self, context): + interface_uuid = context.current["id"] device_uuid = context.current["binding:host_id"] network_name = self.__network_name(context.current["network_id"]) - LOG.debug(f"Selected {network_name=} for {device_uuid=}") + LOG.debug(f"Selected {network_name=} for {device_uuid=} {interface_id=}") result = argo_client.submit( template_name="undersync-device", entrypoint="trigger-undersync", parameters={ + "interface_uuid": interface_uuid, "device_uuid": device_uuid, "network_name": network_name, "dry_run": cfg.CONF.ml2_type_understack.argo_dry_run, diff --git a/python/neutron-understack/neutron_understack/tests/fixtures/neutron_update_port_postcommit.json b/python/neutron-understack/neutron_understack/tests/fixtures/neutron_update_port_postcommit.json new file mode 100644 index 000000000..b824ffcf9 --- /dev/null +++ b/python/neutron-understack/neutron_understack/tests/fixtures/neutron_update_port_postcommit.json @@ -0,0 +1,35 @@ +{ + "admin_state_up": true, + "allowed_address_pairs": [], + "binding:host_id": "", + "binding:profile": {}, + "binding:vif_details": {}, + "binding:vif_type": "unbound", + "binding:vnic_type": "normal", + "created_at": "2024-07-24T13:42:24Z", + "description": "", + "device_id": "41d18c6a-5548-4ee9-926f-4e3ebf43153f", + "device_owner": "compute:nova", + "extra_dhcp_opts": [], + "fixed_ips": [ + { + "ip_address": "192.168.17.17", + "subnet_id": "7f2f436c-fd65-44b0-9265-6b642cecbec5" + } + ], + "id": "e5d5cd73-ca9a-4b74-9d52-43188d0cdcaa", + "mac_address": "fa:16:3e:35:1c:3d", + "name": "", + "network_id": "c2702769-5592-4555-8ae6-e670db82c31e", + "port_security_enabled": true, + "project_id": "ebc5b22e420d4dfc9e385a63b4583623", + "revision_number": 2, + "security_groups": [ + "684dcc25-f419-44a5-b4e7-fdcad4335ecd" + ], + "standard_attr_id": 56, + "status": "DOWN", + "tags": [], + "tenant_id": "ebc5b22e420d4dfc9e385a63b4583623", + "updated_at": "2024-07-24T13:42:25Z" +} diff --git a/python/neutron-understack/neutron_understack/tests/test_neutron_understack_mech.py b/python/neutron-understack/neutron_understack/tests/test_neutron_understack_mech.py new file mode 100644 index 000000000..f7bf03684 --- /dev/null +++ b/python/neutron-understack/neutron_understack/tests/test_neutron_understack_mech.py @@ -0,0 +1,37 @@ +from dataclasses import dataclass +from unittest.mock import patch, MagicMock +import pytest +from neutron_understack.argo.workflows import ArgoClient + +from neutron_understack.neutron_understack_mech import UnderstackDriver + +# TODO: I am not sure how we run tests in this project. + +@dataclass +class ContextDouble: + current: dict + +def mock_context_data(file): + ref = pathlib.Path(__file__).joinpath(filename) + with ref.open("r") as f: + return ContextDouble(json.load(f)) + +@patch('neutron_understack.argo.workflows.ArgoClient') +def test_update_port_postcommit(mock_argo_client): + context_data = mock_context_data( + "fixtures/neutron_update_port_postcommit.json" + ) + + UnderstackDriver.update_port_postcommit(context_data) + + mock_argo_client.assert_called_once_with( + template_name="undersync-device", + entrypoint="trigger-undersync", + parameters={ + "interface_uuid": "e5d5cd73-ca9a-4b74-9d52-43188d0cdcaa", + "device_uuid": "41d18c6a-5548-4ee9-926f-4e3ebf43153f", + "network_name": "provisioning", + "dry_run": false, + "force": false, + }, + ) diff --git a/python/understack-workflows/understack_workflows/main/undersync_device.py b/python/understack-workflows/understack_workflows/main/undersync_device.py index 34ecc0b92..c17cb773a 100644 --- a/python/understack-workflows/understack_workflows/main/undersync_device.py +++ b/python/understack-workflows/understack_workflows/main/undersync_device.py @@ -50,6 +50,9 @@ def argument_parser(): prog=os.path.basename(__file__), description="Trigger undersync run for a device", ) + parser.add_argument( + "--interface-id", type=UUID, required=True, help="Nautobot interface UUID" + ) parser.add_argument( "--device-id", type=UUID, required=True, help="Nautobot device UUID" )