Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/ironic/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ conf:
enabled_boot_interfaces: http-ipxe,ipxe,redfish-virtual-media,redfish-https,idrac-redfish-virtual-media,fake
enabled_console_interfaces: redfish-graphical,no-console
enabled_deploy_interfaces: direct,ramdisk,noop
enabled_firmware_interfaces: redfish,no-firmware
enabled_firmware_interfaces: redfish,panos,no-firmware
enabled_inspect_interfaces: redfish,idrac-redfish,agent,panos,no-inspect
enabled_management_interfaces: redfish,idrac-redfish,panos,noop
enabled_network_interfaces: neutron,noop
Expand Down
15 changes: 10 additions & 5 deletions docs/design-guide/ironic.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ standard password first, then preconfig, then factory, so it works with
appliances at any point in their setup. `[netdev_panos] verify_ssl`
(default off) controls TLS verification.

To use it, add `panos` to `enabled_hardware_types`, `enabled_inspect_interfaces`,
and `enabled_management_interfaces`. Nodes enrolled before the `panos`
interfaces existed keep their stored `no-inspect` and `noop` interfaces until
they are switched with
`openstack baremetal node set --inspect-interface panos --management-interface panos`.
To use it, add `panos` to `enabled_hardware_types`, `enabled_firmware_interfaces`,
`enabled_inspect_interfaces`, and `enabled_management_interfaces`. Nodes
enrolled before the `panos` interfaces existed keep their stored `no-firmware`,
`no-inspect` and `noop` interfaces until they are switched with
`openstack baremetal node set --firmware-interface panos --inspect-interface panos --management-interface panos`.

The firmware interface does not flash anything. Its `cache_firmware_components`
step (a verify, manual clean, and service step) records the PAN-OS release and
the installed content versions (applications, antivirus, WildFire, GlobalProtect
client, device dictionary) as the node's firmware components.
19 changes: 19 additions & 0 deletions python/ironic-understack/ironic_understack/drivers/panos_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""What every PAN-OS (Palo Alto) interface shares."""

from ironic.common import exception


class PanosInterface:
"""Mixin for PAN-OS interfaces: each reaches the appliance at management_ip."""

def get_properties(self):
return {
"management_ip": "Address of the appliance's management interface, "
"used for the XML API. Required.",
}

def validate(self, task):
if not task.node.driver_info.get("management_ip"):
raise exception.MissingParameterValue(
f"Node {task.node.uuid} is missing driver_info management_ip"
)
116 changes: 116 additions & 0 deletions python/ironic-understack/ironic_understack/drivers/panos_firmware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
"""Firmware interface for PAN-OS (Palo Alto) appliances."""

import requests
from ironic import objects
from ironic.common import exception
from ironic.drivers import base
from oslo_log import log

from ironic_understack.drivers.panos_base import PanosInterface
from ironic_understack.utils import panos_api

LOG = log.getLogger(__name__)

VENDOR = "Palo Alto Networks"

# ``show system info`` field -> Ironic firmware component name. Content
# packages that the appliance has never installed report an empty or "0"
# version and are skipped.
COMPONENT_FIELDS = (
("sw-version", "panos"),
("app-version", "app-content"),
("av-version", "antivirus"),
("wildfire-version", "wildfire"),
("global-protect-client-package-version", "globalprotect-client"),
("device-dictionary-version", "device-dictionary"),
)
NOT_INSTALLED = {"", "0", "unknown", "None"}


class PanosFirmware(PanosInterface, base.FirmwareInterface):
"""Record the software versions a PAN-OS appliance reports.

Updating is not implemented; this only populates the node's firmware
components so the running PAN-OS release and content versions are visible
through the Ironic API.
"""

def update(self, task, settings):
raise exception.UnsupportedDriverExtension(
driver=task.node.driver, extension="firmware update"
)

@base.verify_step(priority=5)
@base.clean_step(priority=0, requires_ramdisk=False)
@base.service_step(requires_ramdisk=False)
def cache_firmware_components(self, task):
"""Store or update the appliance's software versions on the node."""
address = task.node.driver_info["management_ip"]
client = panos_api.PanosClient(address)
try:
client.login()
system = client.system_info()
except (panos_api.PanosApiError, requests.RequestException) as e:
raise exception.IronicException(
f"Cannot read firmware versions from PAN-OS {address}: {e}"
) from e
record_versions(task, system)


def record_versions(task, system: dict[str, str]) -> None:
"""Store the versions ``show system info`` reported as firmware components."""
settings = _components_from_system_info(system)
if not settings:
raise exception.UnsupportedDriverExtension(
driver=task.node.driver, extension="firmware components"
)
_sync(task, settings)


def _components_from_system_info(system: dict[str, str]) -> list[dict]:
"""Return a firmware component for each installed version."""
# The appliance itself is the one thing here with an identity.
appliance = {
"vendor": VENDOR,
"model": system.get("model") or None,
"serial_number": system.get("serial") or None,
}
return [
{
"component": component,
"current_version": version,
**(appliance if component == "panos" else dict.fromkeys(appliance)),
}
for field, component in COMPONENT_FIELDS
if (version := system.get(field, "")) not in NOT_INSTALLED
]


def _sync(task, settings: list[dict]) -> None:
node_id = task.node.id
create_list, update_list, _ = (
objects.FirmwareComponentList.sync_firmware_components(
task.context, node_id, settings
)
)
for new in create_list:
objects.FirmwareComponent(
task.context,
node_id=node_id,
component=new["component"],
current_version=new["current_version"],
vendor=new["vendor"],
model=new["model"],
serial_number=new["serial_number"],
).create()
for up in update_list:
existing = objects.FirmwareComponent.get(
task.context, node_id=node_id, name=up["component"]
)
if existing.current_version != up["current_version"]:
existing.last_version_flashed = up["current_version"]
existing.current_version = up["current_version"]
existing.vendor = up["vendor"]
existing.model = up["model"]
existing.serial_number = up["serial_number"]
existing.save()
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
from ironic.drivers.modules import noop_mgmt

from ironic_understack.drivers.netdev_hardware import NetdevHardware
from ironic_understack.drivers.panos_firmware import PanosFirmware
from ironic_understack.drivers.panos_inspect import PanosInspect
from ironic_understack.drivers.panos_management import PanosManagement


class PanosHardware(NetdevHardware):
"""Hardware type for PAN-OS (Palo Alto) network appliances.

A :class:`NetdevHardware` with PAN-OS inspect and management interfaces,
A :class:`NetdevHardware` with PAN-OS firmware, inspect and management interfaces,
which talk to the appliance over its XML API. The netdev no-op interfaces
stay supported as fallbacks.
"""

@property
def supported_firmware_interfaces(self):
return [PanosFirmware, noop.NoFirmware]

@property
def supported_inspect_interfaces(self):
return [PanosInspect, noop.NoInspect]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
from ironic.objects import port
from oslo_log import log

from ironic_understack.drivers import panos_firmware
from ironic_understack.drivers.panos_base import PanosInterface
from ironic_understack.utils import panos_api
from ironic_understack.utils import vlan_group_name_convention

LOG = log.getLogger(__name__)


class PanosInspect(base.InspectInterface):
class PanosInspect(PanosInterface, base.InspectInterface):
"""Inspect a PAN-OS appliance over its XML API.

No ramdisk is involved; everything goes over the management address in
Expand All @@ -29,18 +31,6 @@ class PanosInspect(base.InspectInterface):
# A firewall has no memory_mb/local_gb/cpu_arch to report.
ESSENTIAL_PROPERTIES: ClassVar[set] = set()

def get_properties(self):
return {
"management_ip": "Address of the appliance's management interface, "
"used for the XML API. Required.",
}

def validate(self, task):
if not task.node.driver_info.get("management_ip"):
raise exception.MissingParameterValue(
f"Node {task.node.uuid} is missing driver_info management_ip"
)

def inspect_hardware(self, task):
node = task.node
address = node.driver_info["management_ip"]
Expand All @@ -49,6 +39,8 @@ def inspect_hardware(self, task):
client.login()
system = client.system_info()
_apply_system_info(node, system)
# Keep the node's firmware list current on every inspection.
panos_firmware.record_versions(task, system)
# Discover data plane connectivity via LLDP. A failure fails
# inspection so ports from an earlier run are never trusted.
_discover_and_update_ports(task, client)
Expand Down Expand Up @@ -96,8 +88,6 @@ def _apply_system_info(node, system: dict[str, str]) -> None:
found,
target[key],
)
if system.get("sw-version"):
Comment thread
cardoe marked this conversation as resolved.
Resolved
properties["firmware_version"] = system["sw-version"]
node.properties = properties
node.extra = extra

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,18 @@
from ironic.drivers.modules import noop_mgmt
from oslo_log import log

from ironic_understack.drivers.panos_base import PanosInterface

LOG = log.getLogger(__name__)


class PanosManagement(noop_mgmt.NoopManagement):
class PanosManagement(PanosInterface, noop_mgmt.NoopManagement):
"""Lifecycle steps for PAN-OS appliances.

Boot device methods don't apply to a firewall, so those are inherited from
NoopManagement.
"""

def get_properties(self):
return {
"management_ip": "Address of the appliance's management interface, "
"used for the XML API. Required.",
}

def validate(self, task):
if not task.node.driver_info.get("management_ip"):
raise exception.MissingParameterValue(
f"Node {task.node.uuid} is missing driver_info management_ip"
)

@base.verify_step(priority=10)
def setup_initial_configuration(self, task):
"""First-time setup of a factory-fresh appliance.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
from unittest.mock import Mock

import pytest
import requests
from ironic import objects
from ironic.common import exception

from ironic_understack.drivers import panos_firmware
from ironic_understack.drivers.panos_firmware import PanosFirmware
from ironic_understack.utils import panos_api

SYSTEM = {
"model": "PA-1410",
"serial": "000000000001",
"sw-version": "11.0.0",
"app-version": "8900-9000",
"av-version": "0",
"wildfire-version": "",
"global-protect-client-package-version": "6.2.0",
}


@pytest.fixture
def task():
task = Mock()
task.node.id = 7
task.node.uuid = "node-uuid"
task.node.driver_info = {"management_ip": "192.0.2.10"}
return task


@pytest.fixture
def client(mocker):
client = Mock()
client.system_info.return_value = dict(SYSTEM)
mocker.patch.object(panos_api, "PanosClient", return_value=client)
return client


@pytest.fixture
def sync(mocker):
objects.register_all()
mocker.patch.object(objects, "FirmwareComponent")
return mocker.patch.object(
objects.FirmwareComponentList,
"sync_firmware_components",
return_value=([], [], []),
)


def test_steps_are_registered():
fw = PanosFirmware()
assert {s["step"]: s["priority"] for s in fw.get_clean_steps(Mock())} == {
"cache_firmware_components": 0
}
assert [s["step"] for s in fw.get_verify_steps(Mock())] == [
"cache_firmware_components"
]
assert [s["step"] for s in fw.get_service_steps(Mock())] == [
"cache_firmware_components"
]


def test_components_skip_uninstalled_content():
settings = panos_firmware._components_from_system_info(SYSTEM)
assert {s["component"]: s["current_version"] for s in settings} == {
"panos": "11.0.0",
"app-content": "8900-9000",
"globalprotect-client": "6.2.0",
}
panos = settings[0]
assert panos["vendor"] == "Palo Alto Networks"
assert panos["model"] == "PA-1410"
assert panos["serial_number"] == "000000000001"


def test_cache_creates_new_components(task, client, sync, mocker):
sync.return_value = (
panos_firmware._components_from_system_info(SYSTEM),
[],
[],
)

PanosFirmware().cache_firmware_components(task)

panos_api.PanosClient.assert_called_once_with("192.0.2.10")
assert objects.FirmwareComponent.call_count == 3
created = objects.FirmwareComponent.call_args_list[0].kwargs
assert created["component"] == "panos"
assert created["current_version"] == "11.0.0"


def test_cache_updates_changed_component(task, client, sync):
new = panos_firmware._components_from_system_info(SYSTEM)[0]
sync.return_value = ([], [new], [])
existing = Mock(current_version="10.2.0")
objects.FirmwareComponent.get.return_value = existing

PanosFirmware().cache_firmware_components(task)

assert existing.current_version == "11.0.0"
assert existing.last_version_flashed == "11.0.0"
existing.save.assert_called_once()


@pytest.mark.parametrize(
"error",
[panos_api.PanosApiError("rejected"), requests.ConnectionError("unreachable")],
)
def test_cache_failure(task, client, sync, error):
client.login.side_effect = error
with pytest.raises(exception.IronicException, match=r"192\.0\.2\.10"):
PanosFirmware().cache_firmware_components(task)
sync.assert_not_called()
Loading
Loading