Rack: link items to devices, shelves, several racks, export; fix layout and light mode
Lint / JS (eslint) (push) Successful in 7s
Lint / Python (flake8) (push) Successful in 48s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 49s
Lint / Python (flake8) (pull_request) Successful in 51s
Test / Python Tests (pytest) (push) Successful in 1m2s
Lint / JS (eslint) (pull_request) Successful in 7s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 50s
Test / Python Tests (pytest) (pull_request) Successful in 53s

Cutsheet items gain a "Gandalf device" link, so an item named after the
product (UDM-Pro) shows the live device's faceplate, ports and status.
Cable checks, suggestions, tickets and the device page treat an item and
its linked device as one. Without this, product-named items drew as bare
name plates.

Items can sit on a shelf instead of a rack unit; the shelf draws what is
on it with live status. Items have a rack, the page shows a tab per rack
(config "racks"), and a rack can be downloaded as SVG or PNG.

The rack is centred, long runs of empty units fold into one band (with a
toggle), every device fills the 19" width, the UPS shows its front only,
and the rack keeps its own palette so it reads in light mode.

New cutsheet_items columns rack, shelf and device are added on first use.
Deleting a shelf, or making it something else, is refused while it holds
items; renaming it carries over.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 21:44:59 -05:00
co-authored by Claude Opus 5.5
parent 4f353888f8
commit bdd68a397d
12 changed files with 540 additions and 64 deletions
+42 -1
View File
@@ -456,7 +456,7 @@ class TestRackApi:
pp, sw = data['items']
assert pp['labels'] == {'5': 'OFFICE'} and pp['url'] == '/cutsheet#item-2'
assert pp['ports']['5']['run'] == [7] and pp['ports']['5']['cable_id'] == 7
assert sw['url'] == '/device/USW%20Flex' and 'switch' not in sw # no port data in this snapshot
assert sw['url'] == '/device/USW%20Flex' and sw['switch']['model'] == 'USF5P' # model from UniFi
assert sw['ports']['2']['mark'] in ('ok', 'bad', 'doc')
def test_rack_page_and_auth(self, client):
@@ -468,3 +468,44 @@ class TestRackApi:
gandalf.db.cutsheet_load.return_value = {'items': [], 'cables': [], 'port_labels': []}
with patch.object(gandalf, '_cfg', dict(CONFIG, rack={'units': 24})):
assert client.get('/api/rack', headers=AUTH).get_json()['units'] == 24
class TestRackRacksShelvesLinks:
def _items(self, *items):
base = {'port_count': None, 'rack_u': None, 'rack_height': None, 'rack': '', 'shelf': '', 'device': '',
'location': '', 'notes': ''}
gandalf._cutsheet_schema_ready = True
gandalf.db.cutsheet_load.return_value = {
'items': [dict(base, id=n, **i) for n, i in enumerate(items, 1)], 'cables': [], 'port_labels': []}
def test_product_named_item_links_to_its_device(self, client):
self._items({'name': 'Flex (desk)', 'kind': 'device', 'rack_u': 5, 'rack_height': 1, 'device': 'USW Flex'})
item = client.get('/api/rack', headers=AUTH).get_json()['items'][0]
assert item['device'] == 'USW Flex' and item['linked'] and item['url'] == '/device/USW%20Flex'
assert item['status'] == 'up' and item['switch']['model'] == 'USF5P'
def test_unlinked_item(self, client):
self._items({'name': 'UNVR-Pro', 'kind': 'device', 'rack_u': 5, 'rack_height': 2})
item = client.get('/api/rack', headers=AUTH).get_json()['items'][0]
assert not item['linked'] and item['url'] == '/cutsheet#item-1' and 'switch' not in item
def test_shelf_lists_what_is_on_it(self, client):
self._items({'name': 'Shelf', 'kind': 'shelf', 'rack_u': 3, 'rack_height': 1},
{'name': 'large1', 'kind': 'device', 'shelf': 'Shelf'},
{'name': 'Mini', 'kind': 'device', 'shelf': 'Shelf', 'device': 'USW Flex'})
data = client.get('/api/rack', headers=AUTH).get_json()
assert [i['name'] for i in data['items']] == ['Shelf'] and data['unplaced'] == []
assert [(c['name'], c['status']) for c in data['items'][0]['contents']] == [('large1', 'up'), ('Mini', 'up')]
def test_racks_tabs_and_selection(self, client):
self._items({'name': 'A', 'kind': 'other', 'rack_u': 1, 'rack_height': 1},
{'name': 'B', 'kind': 'other', 'rack_u': 1, 'rack_height': 1, 'rack': 'Garage'})
cfg = dict(CONFIG, racks=[{'name': 'Main', 'units': 24}])
with patch.object(gandalf, '_cfg', cfg):
data = client.get('/api/rack', headers=AUTH).get_json()
assert data['racks'] == [{'name': 'Main', 'units': 24, 'count': 1},
{'name': 'Garage', 'units': 42, 'count': 1}]
assert data['rack'] == 'Main' and [i['name'] for i in data['items']] == ['A']
garage = client.get('/api/rack?rack=Garage', headers=AUTH).get_json()
assert [i['name'] for i in garage['items']] == ['B'] and garage['units'] == 42
assert client.get('/api/rack?rack=Nope', headers=AUTH).status_code == 404
+25
View File
@@ -296,3 +296,28 @@ class TestPortMarks:
dict(cable(2, ('PP1', '1', 'rear'), ('jack', '1')), verdict='idle', detail='Idle', run=[1, 2]),
]
assert cs.port_marks(cables)[('PP1', '1')]['text'] == 'cables C1, #2: Idle'
class TestDeviceAliases:
ITEMS = {'UDM-Pro': {'name': 'UDM-Pro', 'kind': 'device', 'device': 'udm'},
'Big box': {'name': 'Big box', 'kind': 'device', 'device': 'large1'}}
def test_cable_on_an_item_is_checked_against_its_device(self):
switches = {'udm': switch([port(3, seen='large1')])['sw']}
c = cable(1, ('UDM-Pro', '3'), ('Big box', 'eth0'))
assert cs.evaluate([c], self.ITEMS, switches)[1]['verdict'] == 'match'
def test_wrong_neighbor_still_caught_through_an_alias(self):
switches = {'udm': switch([port(3, seen='printer')])['sw']}
c = cable(1, ('UDM-Pro', '3'), ('Big box', 'eth0'))
assert cs.evaluate([c], self.ITEMS, switches)[1]['verdict'] == 'wrong_neighbor'
def test_aliased_cable_counts_as_documented(self):
switches = {'udm': switch([port(3, seen='large1')])['sw']}
c = cable(1, ('UDM-Pro', '3'), ('Big box', 'eth0'))
assert cs.undocumented([c], switches, self.ITEMS) == []
assert len(cs.undocumented([c], switches)) == 1
def test_runs_for_the_device_include_aliased_cables(self):
c = cable(1, ('UDM-Pro', '3'), ('Big box', 'eth0'), label='C1')
assert [r['label'] for r in cs.runs_for('udm', [c], self.ITEMS, {})] == ['C1']