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
13 changes: 3 additions & 10 deletions module/sources/check_redfish/import_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,23 +446,16 @@ def update_fan(self):
health_status = get_string_or_none(grab(fan, "health_status"))
physical_context = get_string_or_none(grab(fan, "physical_context"))
fan_id = get_string_or_none(grab(fan, "id"))
reading = get_string_or_none(grab(fan, "reading"))
reading_unit = get_string_or_none(grab(fan, "reading_unit"))

description = list()
speed = None
if physical_context is not None:
description.append(f"Context: {physical_context}")

if reading is not None and reading_unit is not None:
reading_unit = "%" if reading_unit.lower() == "percent" else reading_unit
speed = f"{reading}{reading_unit}"

# a fan's reading is a live measurement, not something the inventory describes.
# Writing it would update this object in NetBox on every single run
items.append({
"description": description,
"full_name": f"{fan_name} (ID: {fan_id})",
"health": health_status,
"speed": speed
"health": health_status
})

self.update_all_items(items, "Fan")
Expand Down
40 changes: 40 additions & 0 deletions tests/test_check_redfish_fan_speed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
A fan's reading is a live measurement. Syncing it means NetBox records a change on
every run, for every fan of every server (reported by @marcinpsk on #473).
"""
from module.sources.check_redfish.import_inventory import CheckRedfish


def _fan(reading):
return {"inventory": {"fan": [{
"id": "Fan.Embedded.1", "name": "Fan1A", "health_status": "OK",
"physical_context": "SystemBoard", "reading": reading, "reading_unit": "RPM",
}]}}


def _collect(inventory, reading):
source = object.__new__(CheckRedfish)
source.inventory = inventory
source.name = "redfish"
source.source_tag = "Source: redfish"
source.inventory_file_content = _fan(reading)
collected = []
source.update_all_items = lambda items, inventory_type: collected.extend(items)
source.update_fan()
return collected


def test_a_spinning_fan_produces_the_same_item(inventory):
slow = _collect(inventory, 7015)
fast = _collect(inventory, 9120)

assert slow == fast, "the fan item changes with its rpm, so NetBox is written on every run"


def test_the_fan_is_still_described(inventory):
# control: dropping the reading must not empty the item
item = _collect(inventory, 8280)[0]

assert item["full_name"] == "Fan1A (ID: Fan.Embedded.1)"
assert item["health"] == "OK"
assert "Context: SystemBoard" in item["description"]