Skip to content

Commit

Permalink
Have neutron ML2 driver pass port ID when invoking undersync workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Keay committed Aug 30, 2024
1 parent d835258 commit bdaf263
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ spec:
command:
- undersync-device
args:
- --interface-id
- "{{workflow.parameters.interface_uuid}}"
- --device-id
- "{{workflow.parameters.device_uuid}}"
- --network-name
Expand All @@ -32,6 +34,7 @@ spec:
readOnly: true
inputs:
parameters:
- name: interface_uuid
- name: device_uuid
- name: network_name
- name: force
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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,
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit bdaf263

Please sign in to comment.