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
51 changes: 51 additions & 0 deletions docs/development/device-custody.md
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,57 @@ which a test pins, because the coordinator lists every registered kind.

The boot interface is fixed at `primary`, like the allocator's in every mode.

### The Redfish commissioning worker

The Redfish worker for `DeviceCommissioning` is **implemented and inert**. It
is tested against a TLS BMC stub, and no site registers it yet. The lab
emulator's adapter reports each target's serial, its one disk and a firmware
inventory, which a local read with the worker's Redfish client matched to a
plan's hardware and firmware.

- **Preflight.** It reads the system's identity, processors, memory, storage,
network interfaces and firmware inventory with GETs only. A serial number
or system UUID other than the admission snapshot's gets no verdict: the
operation is refused with `DeviceIdentityMismatch` before anything is sent.
Otherwise it compares the hardware and firmware with the plan, and a
mismatch is a `Failed` result with nothing sent. The passing evidence is
stored before burn-in sends anything, and a resumed worker reuses it.
- **Collections.** Every member of each hardware and firmware collection is
read, following `Members@odata.nextLink`, so no component goes uncounted
or unchecked. A collection that reaches 1,024 members or 64 pages, or a
Storage controller set that links 1,024 drives, fails the inspection
rather than being read in part. Each GET is bounded by the Redfish
client's per-request timeout, 30 seconds for a pinned client, and the
whole inspection by the operation's deadline.
- **Firmware.** A baseline component matches the inventory entry whose `Id`
it names. Only when no entry has that `Id` does it match by `Name`, and
only a `Name` exactly one entry has: a BMC may list a previous version
beside the running one under the same name.
- **Health.** Only `Warning` or `Critical` is unhealthy. Redfish lets a
component omit its health, and an omitted health counts as healthy.
- **Disks.** Drives come from `Storage`, or from `SimpleStorage` when
`Storage` yields no disk, as on a BMC that links an empty `Storage`
collection. A drive may sit under the System or under a Chassis, and a
drive linked twice counts once.
- **Memory.** An `Absent` or `Disabled` module does not count.
- **Burn-in.** The site serves one burn-in image, and a plan that names
another digest is refused before anything is sent. The worker powers the
server off, arms a one-time network boot, powers it on once, and waits for
exactly one result receipt. The boot server passes the plan's duration to
the image. Burn-in starts when the boot server finished delivering the
image, not at power-on, so firmware start and the network boot do not
count. It ends at the last time a worker saw the console without the
receipt, which is never after the image reported. A worker stores that
time at least every 30 seconds while burn-in runs, and exactly when it
sees the receipt appear. A worker restarted after the receipt appeared
uses the stored time, so a restart can shorten the recorded burn-in but
never lengthen it. A burn-in that reported before the plan's duration, or
that no worker saw run that long, is a `Failed` result. The boot server
and the worker share the site's clock.
- **Evidence.** Strings the BMC supplies are cut to 128 bytes, and the
component lists are dropped before the verdict if the evidence would pass
the kind's limit.

## Points for a person

These need a decision before the increment that depends on them.
Expand Down
6 changes: 4 additions & 2 deletions docs/operations/redfish-lab.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ hardware.
The 1.2.2 release was 14 months old at integration and is the newest release.
The emulator tree is copied into the image **unmodified**. Configuration comes
from Fleet files: `emulator-config.json`, an infragen `populate-config.json`
with one chassis and two Systems, and `targets.json`. The image ID, its registry
with one chassis and two Systems, `targets.json` and `firmware.json`. The image ID, its registry
digest and the archive provenance are recorded in `evidence/image-id` and
`evidence/redfish-upstream.json`.

Expand Down Expand Up @@ -91,7 +91,9 @@ does not fork or patch upstream files.
| `ComputerSystem.Reset` with `On`, `ForceOff` and `ForceRestart` applied to one exact persistent libvirt domain per System | Adapter (replaces upstream's in-memory handler for the two lab Systems) |
| `PowerState` read from libvirt on every System read | Adapter |
| `Boot` source override (`Pxe` or `Hdd`, `Once`), persisted in NVRAM state on the site volume and consumed at power-on | Adapter |
| `ResetType` and boot `AllowableValues` narrowed to what the adapter implements; System `UUID` set from the lab target | Adapter |
| `ResetType` and boot `AllowableValues` narrowed to what the adapter implements; System `UUID` and `SerialNumber` set from the lab target | Adapter |
| No `Storage` link on the lab Systems: upstream's sample `Storage` drives are not the target's disk, so commissioning reads the populated `SimpleStorage` device | Adapter |
| A read-only `UpdateService` and `FirmwareInventory` from `firmware.json`, synthetic versions upstream does not serve, so a commissioning plan's firmware baseline can be checked | Adapter |
| Definition of the lab domains and the provisioning network, re-created with the same identity if the runtime loses them | Adapter |
| Append-only request audit: method, path, status, principal class, client User-Agent, ResetType, boot override, effect and fault. It never records bodies or credentials. | Adapter |
| `DELETE /redfish/v1/reset` and non-Redfish paths | Refused by the adapter |
Expand Down
25 changes: 24 additions & 1 deletion hack/local-vm/init
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ modprobe virtio_pci
modprobe virtio_blk
modprobe ext4
mode=install
for arg in $(cat /proc/cmdline); do case "$arg" in fleet.receipt=*) receipt=${arg#fleet.receipt=};; fleet.mode=*) mode=${arg#fleet.mode=};; esac; done
for arg in $(cat /proc/cmdline); do case "$arg" in fleet.receipt=*) receipt=${arg#fleet.receipt=};; fleet.mode=*) mode=${arg#fleet.mode=};; fleet.duration=*) duration=${arg#fleet.duration=};; esac; done
[ ${#receipt} = 64 ] || /bin/busybox poweroff -f
if [ "$mode" = wipe ]; then
# Redfish-mode cleanup environment: zero the whole disk, then verify by
Expand All @@ -33,6 +33,29 @@ if [ "$mode" = wipe ]; then
sync
exit 0
fi
if [ "$mode" = burnin ]; then
# Lab burn-in: read the whole disk, then keep every CPU busy for the plan's
# duration, then report the result. It writes nothing to the disk. A real
# burn-in image is operator policy; this one only proves the boot and
# receipt path. Tracing stops for the loop, so the console stays small.
trap '/bin/busybox poweroff -f' EXIT
case "$duration" in ''|*[!0-9]*) exit 1;; esac
result=passed
/bin/busybox dd if=/dev/vda of=/dev/null bs=4M || result=failed
set +x
cpus=$(grep -c ^processor /proc/cpuinfo)
end=$(($(cut -d. -f1 /proc/uptime) + duration))
i=0
while [ "$i" -lt "$cpus" ]; do
( while [ "$(cut -d. -f1 /proc/uptime)" -lt "$end" ]; do /bin/busybox sha256sum /proc/meminfo >/dev/null; done ) &
i=$((i + 1))
done
wait || result=failed
set -x
printf 'FLEET-BURNIN:%s:%s\n' "$receipt" "$result"
sync
exit 0
fi
[ "$mode" = install ] || /bin/busybox poweroff -f
printf 'label: dos\n, , L, *\n' | sfdisk /dev/vda
# One line, in one write, once the disk is partitioned: the shell trace above
Expand Down
2 changes: 1 addition & 1 deletion hack/redfish-lab/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins
COPY requirements.lock /tmp/requirements.lock
RUN pip install --no-cache-dir --no-deps --require-hashes -r /tmp/requirements.lock && rm /tmp/requirements.lock
COPY --from=upstream . /opt/redfish-emulator
COPY emulator-config.json populate-config.json targets.json /etc/fleet-bmc/
COPY emulator-config.json populate-config.json targets.json firmware.json /etc/fleet-bmc/
COPY fleet_lab_adapter.py test_adapter.py fake_virsh.py /opt/fleet-lab/
RUN chmod 755 /opt/fleet-lab/*.py
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
Expand Down
4 changes: 4 additions & 0 deletions hack/redfish-lab/firmware.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
{"Id": "BMC", "Name": "Fleet lab BMC firmware", "Version": "1.2.2-fleet-lab.1"},
{"Id": "BIOS", "Name": "Fleet lab system firmware", "Version": "lab-bios-1.0.0"}
]
39 changes: 39 additions & 0 deletions hack/redfish-lab/fleet_lab_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
persistent libvirt domain per System, and PowerState read from libvirt;
* Boot source override (Pxe or Hdd, Once) persisted like BMC NVRAM and
consumed when the domain is started;
* a firmware inventory (UpdateService and FirmwareInventory) from
firmware.json, which upstream does not serve, so a commissioning plan's
firmware baseline can be checked against the lab;
* an append-only request audit log (no bodies, no credentials), each
entry naming the client's User-Agent so a check can tell readers apart;
* bounded, one-shot lab fault injection driven by a state file.
Expand Down Expand Up @@ -236,6 +239,13 @@ def create_app(targets, state, credentials, boot_ip):
def publish(sid, power=None):
m = cs.members[sid]
m['UUID'] = targets[sid]['uuid']
# The serial the target's synthetic Device records, so commissioning
# can match the chassis to the Device.
m['SerialNumber'] = targets[sid]['serial']
# The target's one disk is the populated SimpleStorage device. The
# upstream Storage collection links sample drives the target does not
# have, so the System does not link it.
m.pop('Storage', None)
m['Name'] = targets[sid]['name']
m['Manufacturer'] = 'DMTF Redfish Interface Emulator (Fleet lab adapter)'
m['Model'] = 'libvirt/QEMU lab target'
Expand Down Expand Up @@ -282,6 +292,18 @@ def fn(value):
return None
return faults.update(fn)

firmware = load_firmware()
inventory = '/redfish/v1/UpdateService/FirmwareInventory'
firmware_docs = {
'/redfish/v1/UpdateService': {'@odata.id': '/redfish/v1/UpdateService', '@odata.type': '#UpdateService.v1_11_0.UpdateService',
'Id': 'UpdateService', 'Name': 'Update Service', 'FirmwareInventory': {'@odata.id': inventory}},
inventory: {'@odata.id': inventory, '@odata.type': '#SoftwareInventoryCollection.SoftwareInventoryCollection', 'Name': 'Firmware Inventory',
'Members@odata.count': len(firmware), 'Members': [{'@odata.id': inventory + '/' + f['Id']} for f in firmware]},
}
for f in firmware:
firmware_docs[inventory + '/' + f['Id']] = dict(f, **{'@odata.id': inventory + '/' + f['Id'], '@odata.type': '#SoftwareInventory.v1_10_0.SoftwareInventory',
'Status': {'State': 'Enabled', 'Health': 'OK'}, 'Updateable': False})

@g.app.before_request
def guard():
request_context.principal, request_context.detail = 'anonymous', {}
Expand All @@ -297,6 +319,8 @@ def guard():
request_context.principal, request_context.detail = 'rejected', {'fault': 'reject-auth'}
return challenge()
request_context.principal = 'authenticated'
if path in firmware_docs:
return (firmware_docs[path], 200) if request.method == 'GET' else error(405, 'the lab firmware inventory is read-only')
m = re.fullmatch(r'/redfish/v1/Systems/([^/]+)(/Actions/ComputerSystem\.Reset|/ResetActionInfo)?', path)
if not m:
return None
Expand Down Expand Up @@ -362,6 +386,16 @@ def reset(sid):
time.sleep(min(int(drop.get('seconds', 45)), 120))
return '', 204

@g.app.after_request
def link_update_service(response):
# Upstream's service root names no UpdateService; link the adapter's.
if request.method == 'GET' and (request.path.rstrip('/') or '/') == '/redfish/v1' and response.status_code == 200:
root = response.get_json(silent=True)
if isinstance(root, dict):
root['UpdateService'] = {'@odata.id': '/redfish/v1/UpdateService'}
response.set_data(json.dumps(root))
return response

@g.app.after_request
def audit(response):
entry = {'at': now(), 'method': request.method, 'path': request.path, 'status': response.status_code,
Expand All @@ -376,6 +410,11 @@ def audit(response):
return g.app


def load_firmware():
with open(os.path.join(CONFIG_DIR, 'firmware.json')) as f:
return json.load(f)


def load_targets():
with open(os.path.join(CONFIG_DIR, 'targets.json')) as f:
return {t['system']: t for t in json.load(f)}
Expand Down
4 changes: 2 additions & 2 deletions hack/redfish-lab/targets.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[
{"system": "System-1", "name": "fleet-lab-target-a", "domain": "fleet-lab-target-a",
{"system": "System-1", "name": "fleet-lab-target-a", "domain": "fleet-lab-target-a", "serial": "serial-synthetic-device-central-01",
"uuid": "7f3d0c2e-1a5b-4c6d-8e9f-0a1b2c3d4e0a", "mac": "52:54:00:77:01:0a", "ip": "192.168.77.10",
"disk": "/var/lib/fleet-lab/disks/target-a.raw", "console": "/var/lib/fleet-lab-console/target-a.log"},
{"system": "System-2", "name": "fleet-lab-target-b", "domain": "fleet-lab-target-b",
{"system": "System-2", "name": "fleet-lab-target-b", "domain": "fleet-lab-target-b", "serial": "serial-fleet-lab-target-b",
"uuid": "7f3d0c2e-1a5b-4c6d-8e9f-0a1b2c3d4e0b", "mac": "52:54:00:77:01:0b", "ip": "192.168.77.11",
"disk": "/var/lib/fleet-lab/disks/target-b.raw", "console": "/var/lib/fleet-lab-console/target-b.log"}
]
16 changes: 16 additions & 0 deletions hack/redfish-lab/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_1_service_root_is_upstream_and_unauthenticated(self):
r = self.app.get('/redfish/v1/')
self.assertEqual(r.status_code, 200)
self.assertEqual(r.json['Systems'], {'@odata.id': '/redfish/v1/Systems'})
self.assertEqual(r.json['UpdateService'], {'@odata.id': '/redfish/v1/UpdateService'})
self.assertEqual(self.app.delete('/redfish/v1/reset/').status_code, 404)

def test_2_authentication_is_enforced(self):
Expand All @@ -56,7 +57,22 @@ def test_3_system_identity_and_capabilities(self):
s = self.app.get('/redfish/v1/Systems/System-1', headers=AUTH).json
self.assertEqual(s['UUID'], '7f3d0c2e-1a5b-4c6d-8e9f-0a1b2c3d4e0a')
self.assertEqual(s['PowerState'], 'Off')
# Commissioning reads the serial the Device records and the one
# populated disk, never the upstream sample drives.
self.assertEqual(s['SerialNumber'], 'serial-synthetic-device-central-01')
self.assertNotIn('Storage', s)
controllers = self.app.get(s['SimpleStorage']['@odata.id'], headers=AUTH).json['Members']
devices = [d for c in controllers for d in self.app.get(c['@odata.id'], headers=AUTH).json['Devices']]
self.assertEqual([d['CapacityBytes'] for d in devices], [2 * 1024 ** 3])
self.assertEqual(s['Boot']['BootSourceOverrideTarget@Redfish.AllowableValues'], ['None', 'Pxe', 'Hdd'])
# Commissioning checks firmware against the lab's inventory, behind
# authentication and read-only.
self.assertEqual(self.app.get('/redfish/v1/UpdateService/FirmwareInventory').status_code, 401)
service = self.app.get(self.app.get('/redfish/v1/').json['UpdateService']['@odata.id'], headers=AUTH).json
members = self.app.get(service['FirmwareInventory']['@odata.id'], headers=AUTH).json['Members']
versions = {f['Id']: f['Version'] for f in (self.app.get(m['@odata.id'], headers=AUTH).json for m in members)}
self.assertEqual(versions, {'BMC': '1.2.2-fleet-lab.1', 'BIOS': 'lab-bios-1.0.0'})
self.assertEqual(self.app.patch(members[0]['@odata.id'], headers=AUTH, json={'Version': 'x'}).status_code, 405)
info = self.app.get(s['Actions']['#ComputerSystem.Reset']['@Redfish.ActionInfo'], headers=AUTH).json
self.assertEqual(info['Parameters'][0]['AllowableValues'], ['On', 'ForceOff', 'ForceRestart'])

Expand Down
Loading
Loading