Skip to content

Commit

Permalink
Merge pull request #200 from rackerlabs/fix-wf-param
Browse files Browse the repository at this point in the history
fix: sync interfaces errors
  • Loading branch information
ctria authored Aug 6, 2024
2 parents 6c108d3 + 06909a9 commit 435ed5d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/containers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
images: ghcr.io/rackerlabs/understack/dnsmasq
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=latest,enable=${{ github.event_name == 'workflow_dispatch' }}
type=sha,enable={{is_default_branch}}
labels: |
org.opencontainers.image.title=dnsmasq for Understack's Ironic
Expand Down Expand Up @@ -130,6 +131,7 @@ jobs:
images: ghcr.io/rackerlabs/understack/${{ matrix.container.name }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=latest,enable=${{ github.event_name == 'workflow_dispatch' }}
type=ref,event=tag
type=ref,event=pr
labels: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ spec:
dependencyName: nautobot-dep
- dest: spec.arguments.parameters.1.value
src:
dataKey: body.data.device.name
dataKey: body.data.device.id
dependencyName: nautobot-dep
- dest: spec.arguments.parameters.2.value
src:
Expand Down
32 changes: 31 additions & 1 deletion python/understack-workflows/tests/test_node_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import json
import pathlib
from unittest.mock import MagicMock

import pytest

from understack_workflows.ironic.client import IronicClient
from understack_workflows.node_configuration import IronicNodeConfiguration


Expand All @@ -14,13 +16,41 @@ def interface_event() -> dict:
return json.load(f)


@pytest.fixture
def bmc_ip(interface_event: dict) -> str:
return interface_event["data"]["ip_addresses"][0]["host"]


@pytest.fixture
def ironic_client() -> IronicClient:
return MagicMock(spec_set=IronicClient)


def test_node_config_from_event_none_event():
with pytest.raises(ValueError):
_ = IronicNodeConfiguration.from_event({})


def test_node_config_from_event_interface_event(interface_event):
def test_node_config_from_event_interface_event(interface_event, bmc_ip):
node = IronicNodeConfiguration.from_event(interface_event)
assert node.uuid == interface_event["data"]["device"]["id"]
assert node.name == interface_event["data"]["device"]["name"]
assert node.driver == "idrac"
assert node.driver_info.redfish_address == f"https://{bmc_ip}"


def test_node_create_from_event(interface_event, bmc_ip, ironic_client):
node = IronicNodeConfiguration.from_event(interface_event)
node.create_node(ironic_client)

expected = {
"uuid": node.uuid,
"name": node.name,
"driver": node.driver,
"driver_info": {
"redfish_address": f"https://{bmc_ip}",
"redfish_verify_ca": False,
},
}

ironic_client.create_node.assert_called_once_with(expected)
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
from dataclasses import dataclass
from dataclasses import field

from ironicclient.common.utils import args_array_to_dict
from ironicclient.v1.node import Node

from understack_workflows.redfish_driver_info import RedfishDriverInfo


def dict_without_none(data):
return {k: v for k, v in data if v is not None}


@dataclass
class IronicNodeConfiguration:
"""The boot interface for a Node, e.g. “pxe”."""
Expand Down Expand Up @@ -167,10 +170,9 @@ def create_node(self, client) -> Node:
field_list = ["uuid", "name", "driver", "driver_info"]
fields = dict(
(k, v)
for (k, v) in asdict(self).items()
for (k, v) in asdict(self, dict_factory=dict_without_none).items()
if k in field_list and v is not None
)
fields = args_array_to_dict(fields, "driver_info")
return client.create_node(fields)

@staticmethod
Expand Down

0 comments on commit 435ed5d

Please sign in to comment.