forked from oxidecomputer/omicron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.rs
More file actions
578 lines (546 loc) · 19.5 KB
/
Copy pathexamples.rs
File metadata and controls
578 lines (546 loc) · 19.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! Example collections used for testing
use crate::CollectionBuilder;
use clickhouse_admin_types::ClickhouseKeeperClusterMembership;
use clickhouse_admin_types::KeeperId;
use gateway_client::types::PowerState;
use gateway_client::types::RotSlot;
use gateway_client::types::RotState;
use gateway_client::types::SpComponentCaboose;
use gateway_client::types::SpState;
use gateway_client::types::SpType;
use nexus_sled_agent_shared::inventory::Baseboard;
use nexus_sled_agent_shared::inventory::Inventory;
use nexus_sled_agent_shared::inventory::InventoryDataset;
use nexus_sled_agent_shared::inventory::InventoryDisk;
use nexus_sled_agent_shared::inventory::InventoryZpool;
use nexus_sled_agent_shared::inventory::OmicronZonesConfig;
use nexus_sled_agent_shared::inventory::SledRole;
use nexus_types::inventory::BaseboardId;
use nexus_types::inventory::CabooseWhich;
use nexus_types::inventory::RotPage;
use nexus_types::inventory::RotPageWhich;
use omicron_common::api::external::ByteCount;
use omicron_common::api::external::Generation;
use omicron_common::disk::DiskVariant;
use omicron_uuid_kinds::SledUuid;
use std::sync::Arc;
use strum::IntoEnumIterator;
/// Returns an example Collection used for testing
///
/// This collection is intended to cover a variety of possible inventory data,
/// including:
///
/// - all three baseboard types (switch, sled, PSC)
/// - various valid values for all fields (sources, slot numbers, power
/// states, baseboard revisions, cabooses, etc.)
/// - some empty slots
/// - some missing cabooses
/// - some cabooses common to multiple baseboards; others not
/// - serial number reused across different model numbers
pub fn representative() -> Representative {
let mut builder = CollectionBuilder::new("example");
// an ordinary, working sled
let sled1_bb = builder
.found_sp_state(
"fake MGS 1",
SpType::Sled,
3,
SpState {
base_mac_address: [0; 6],
hubris_archive_id: String::from("hubris1"),
model: String::from("model1"),
power_state: PowerState::A0,
revision: 0,
rot: RotState::V2 {
active: RotSlot::A,
pending_persistent_boot_preference: None,
persistent_boot_preference: RotSlot::A,
slot_a_sha3_256_digest: Some(String::from("slotAdigest1")),
slot_b_sha3_256_digest: Some(String::from("slotBdigest1")),
transient_boot_preference: None,
},
serial_number: String::from("s1"),
},
)
.unwrap();
// another ordinary sled with different values for ordinary fields
let sled2_bb = builder
.found_sp_state(
"fake MGS 2",
SpType::Sled,
4,
SpState {
base_mac_address: [1; 6],
hubris_archive_id: String::from("hubris2"),
model: String::from("model2"),
power_state: PowerState::A2,
revision: 1,
rot: RotState::V2 {
active: RotSlot::B,
pending_persistent_boot_preference: Some(RotSlot::A),
persistent_boot_preference: RotSlot::A,
slot_a_sha3_256_digest: Some(String::from("slotAdigest2")),
slot_b_sha3_256_digest: Some(String::from("slotBdigest2")),
transient_boot_preference: Some(RotSlot::B),
},
// same serial number, which is okay because it's a
// different model number
serial_number: String::from("s1"),
},
)
.unwrap();
// a switch
let switch1_bb = builder
.found_sp_state(
"fake MGS 2",
SpType::Switch,
0,
SpState {
base_mac_address: [2; 6],
hubris_archive_id: String::from("hubris3"),
model: String::from("model3"),
power_state: PowerState::A1,
revision: 2,
rot: RotState::V2 {
active: RotSlot::B,
pending_persistent_boot_preference: None,
persistent_boot_preference: RotSlot::A,
slot_a_sha3_256_digest: Some(String::from("slotAdigest3")),
slot_b_sha3_256_digest: Some(String::from("slotBdigest3")),
transient_boot_preference: None,
},
// same serial number, which is okay because it's a
// different model number
serial_number: String::from("s1"),
},
)
.unwrap();
// a PSC
let psc_bb = builder
.found_sp_state(
"fake MGS 1",
SpType::Power,
1,
SpState {
base_mac_address: [3; 6],
hubris_archive_id: String::from("hubris4"),
model: String::from("model4"),
power_state: PowerState::A2,
revision: 3,
rot: RotState::V2 {
active: RotSlot::B,
pending_persistent_boot_preference: None,
persistent_boot_preference: RotSlot::A,
slot_a_sha3_256_digest: Some(String::from("slotAdigest4")),
slot_b_sha3_256_digest: Some(String::from("slotBdigest4")),
transient_boot_preference: None,
},
serial_number: String::from("s2"),
},
)
.unwrap();
// a sled with no RoT state or other optional fields
let sled3_bb = builder
.found_sp_state(
"fake MGS 1",
SpType::Sled,
5,
SpState {
base_mac_address: [4; 6],
hubris_archive_id: String::from("hubris5"),
model: String::from("model1"),
power_state: PowerState::A2,
revision: 1,
rot: RotState::CommunicationFailed {
message: String::from("test suite injected error"),
},
serial_number: String::from("s2"),
},
)
.unwrap();
// Report some cabooses.
// We'll use the same cabooses for most of these components, although
// that's not possible in a real system. We deliberately construct a
// new value each time to make sure the builder correctly normalizes it.
let common_caboose_baseboards = [&sled1_bb, &sled2_bb, &switch1_bb];
for bb in &common_caboose_baseboards {
for which in CabooseWhich::iter() {
assert!(!builder.found_caboose_already(bb, which));
builder
.found_caboose(bb, which, "test suite", caboose("1"))
.unwrap();
assert!(builder.found_caboose_already(bb, which));
}
}
// For the PSC, use different cabooses for both slots of both the SP and
// RoT, just to exercise that we correctly keep track of different
// cabooses.
builder
.found_caboose(
&psc_bb,
CabooseWhich::SpSlot0,
"test suite",
caboose("psc_sp_0"),
)
.unwrap();
builder
.found_caboose(
&psc_bb,
CabooseWhich::SpSlot1,
"test suite",
caboose("psc_sp_1"),
)
.unwrap();
builder
.found_caboose(
&psc_bb,
CabooseWhich::RotSlotA,
"test suite",
caboose("psc_rot_a"),
)
.unwrap();
builder
.found_caboose(
&psc_bb,
CabooseWhich::RotSlotB,
"test suite",
caboose("psc_rot_b"),
)
.unwrap();
// We deliberately provide no cabooses for sled3.
// Report some RoT pages.
// We'll use the same RoT pages for most of these components, although
// that's not possible in a real system. We deliberately construct a new
// value each time to make sure the builder correctly normalizes it.
let common_rot_page_baseboards = [&sled1_bb, &sled3_bb, &switch1_bb];
for bb in common_rot_page_baseboards {
for which in RotPageWhich::iter() {
assert!(!builder.found_rot_page_already(bb, which));
builder
.found_rot_page(bb, which, "test suite", rot_page("1"))
.unwrap();
assert!(builder.found_rot_page_already(bb, which));
}
}
// For the PSC, use different RoT page data for each kind of page, just to
// exercise that we correctly keep track of different data values.
builder
.found_rot_page(
&psc_bb,
RotPageWhich::Cmpa,
"test suite",
rot_page("psc cmpa"),
)
.unwrap();
builder
.found_rot_page(
&psc_bb,
RotPageWhich::CfpaActive,
"test suite",
rot_page("psc cfpa active"),
)
.unwrap();
builder
.found_rot_page(
&psc_bb,
RotPageWhich::CfpaInactive,
"test suite",
rot_page("psc cfpa inactive"),
)
.unwrap();
builder
.found_rot_page(
&psc_bb,
RotPageWhich::CfpaScratch,
"test suite",
rot_page("psc cfpa scratch"),
)
.unwrap();
// We deliberately provide no RoT pages for sled2.
// Report a representative set of Omicron zones, used in the sled-agent
// constructors below.
//
// We've hand-selected a minimal set of files to cover each type of zone.
// These files were constructed by:
//
// (1) copying the "omicron zones" ledgers from the sleds in a working
// Omicron deployment
// (2) pretty-printing each one with `json --in-place --file FILENAME`
// (3) adjusting the format slightly with
// `jq '{ generation: .omicron_generation, zones: .zones }'`
let sled14_data = include_str!("../example-data/madrid-sled14.json");
let sled16_data = include_str!("../example-data/madrid-sled16.json");
let sled17_data = include_str!("../example-data/madrid-sled17.json");
let sled14: OmicronZonesConfig = serde_json::from_str(sled14_data).unwrap();
let sled16: OmicronZonesConfig = serde_json::from_str(sled16_data).unwrap();
let sled17: OmicronZonesConfig = serde_json::from_str(sled17_data).unwrap();
// Report some sled agents.
//
// This first one will match "sled1_bb"'s baseboard information.
let sled_agent_id_basic =
"c5aec1df-b897-49e4-8085-ccd975f9b529".parse().unwrap();
// Add some disks to this first sled.
let disks = vec![
// Let's say we have one manufacturer for our M.2...
InventoryDisk {
identity: omicron_common::disk::DiskIdentity {
vendor: "macrohard".to_string(),
model: "box".to_string(),
serial: "XXIV".to_string(),
},
variant: DiskVariant::M2,
slot: 0,
active_firmware_slot: 1,
next_active_firmware_slot: None,
number_of_firmware_slots: 1,
slot1_is_read_only: true,
slot_firmware_versions: vec![Some("EXAMP1".to_string())],
},
// ... and a couple different vendors for our U.2s
InventoryDisk {
identity: omicron_common::disk::DiskIdentity {
vendor: "memetendo".to_string(),
model: "swatch".to_string(),
serial: "0001".to_string(),
},
variant: DiskVariant::U2,
slot: 1,
active_firmware_slot: 1,
next_active_firmware_slot: None,
number_of_firmware_slots: 1,
slot1_is_read_only: true,
slot_firmware_versions: vec![Some("EXAMP1".to_string())],
},
InventoryDisk {
identity: omicron_common::disk::DiskIdentity {
vendor: "memetendo".to_string(),
model: "swatch".to_string(),
serial: "0002".to_string(),
},
variant: DiskVariant::U2,
slot: 2,
active_firmware_slot: 1,
next_active_firmware_slot: None,
number_of_firmware_slots: 1,
slot1_is_read_only: true,
slot_firmware_versions: vec![Some("EXAMP1".to_string())],
},
InventoryDisk {
identity: omicron_common::disk::DiskIdentity {
vendor: "tony".to_string(),
model: "craystation".to_string(),
serial: "5".to_string(),
},
variant: DiskVariant::U2,
slot: 3,
active_firmware_slot: 1,
next_active_firmware_slot: None,
number_of_firmware_slots: 1,
slot1_is_read_only: true,
slot_firmware_versions: vec![Some("EXAMP1".to_string())],
},
];
let zpools = vec![InventoryZpool {
id: "283f5475-2606-4e83-b001-9a025dbcb8a0".parse().unwrap(),
total_size: ByteCount::from(4096),
}];
let datasets = vec![InventoryDataset {
id: Some("afc00483-0d7b-4181-87d5-0def937d3cd7".parse().unwrap()),
name: "mydataset".to_string(),
available: ByteCount::from(1024),
used: ByteCount::from(0),
quota: None,
reservation: None,
compression: "lz4".to_string(),
}];
builder
.found_sled_inventory(
"fake sled agent 1",
sled_agent(
sled_agent_id_basic,
Baseboard::Gimlet {
identifier: String::from("s1"),
model: String::from("model1"),
revision: 0,
},
SledRole::Gimlet,
sled14,
disks,
zpools,
datasets,
),
)
.unwrap();
// Here, we report a different sled *with* baseboard information that
// doesn't match one of the baseboards we found. This is unlikely but could
// happen. Make this one a Scrimlet.
let sled4_bb = Arc::new(BaseboardId {
part_number: String::from("model1"),
serial_number: String::from("s4"),
});
let sled_agent_id_extra =
"d7efa9c4-833d-4354-a9a2-94ba9715c154".parse().unwrap();
builder
.found_sled_inventory(
"fake sled agent 4",
sled_agent(
sled_agent_id_extra,
Baseboard::Gimlet {
identifier: sled4_bb.serial_number.clone(),
model: sled4_bb.part_number.clone(),
revision: 0,
},
SledRole::Scrimlet,
sled16,
vec![],
vec![],
vec![],
),
)
.unwrap();
// Now report a different sled as though it were a PC. It'd be unlikely to
// see a mix of real Oxide hardware and PCs in the same deployment, but this
// exercises different code paths.
let sled_agent_id_pc =
"c4a5325b-e852-4747-b28a-8aaa7eded8a0".parse().unwrap();
builder
.found_sled_inventory(
"fake sled agent 5",
sled_agent(
sled_agent_id_pc,
Baseboard::Pc {
identifier: String::from("fellofftruck1"),
model: String::from("fellofftruck"),
},
SledRole::Gimlet,
sled17,
vec![],
vec![],
vec![],
),
)
.unwrap();
// Finally, report a sled with unknown baseboard information. This should
// look the same as the PC as far as inventory is concerned but let's verify
// it.
let sled_agent_id_unknown =
"5c5b4cf9-3e13-45fd-871c-f177d6537510".parse().unwrap();
builder
.found_sled_inventory(
"fake sled agent 6",
sled_agent(
sled_agent_id_unknown,
Baseboard::Unknown,
SledRole::Gimlet,
// We only have omicron zones for three sleds so use empty zone
// info here.
OmicronZonesConfig {
generation: Generation::new(),
zones: Vec::new(),
},
vec![],
vec![],
vec![],
),
)
.unwrap();
builder.found_clickhouse_keeper_cluster_membership(
ClickhouseKeeperClusterMembership {
queried_keeper: KeeperId(1),
leader_committed_log_index: 1000,
raft_config: [KeeperId(1)].into_iter().collect(),
},
);
Representative {
builder,
sleds: [sled1_bb, sled2_bb, sled3_bb, sled4_bb],
switch: switch1_bb,
psc: psc_bb,
sled_agents: [
sled_agent_id_basic,
sled_agent_id_extra,
sled_agent_id_pc,
sled_agent_id_unknown,
],
}
}
pub struct Representative {
pub builder: CollectionBuilder,
pub sleds: [Arc<BaseboardId>; 4],
pub switch: Arc<BaseboardId>,
pub psc: Arc<BaseboardId>,
pub sled_agents: [SledUuid; 4],
}
impl Representative {
pub fn new(
builder: CollectionBuilder,
sleds: [Arc<BaseboardId>; 4],
switch: Arc<BaseboardId>,
psc: Arc<BaseboardId>,
sled_agents: [SledUuid; 4],
) -> Self {
Self { builder, sleds, switch, psc, sled_agents }
}
}
/// Returns an SP state that can be used to populate a collection for testing
pub fn sp_state(unique: &str) -> SpState {
SpState {
base_mac_address: [0; 6],
hubris_archive_id: format!("hubris{}", unique),
model: format!("model{}", unique),
power_state: PowerState::A2,
revision: 0,
rot: RotState::V2 {
active: RotSlot::A,
pending_persistent_boot_preference: None,
persistent_boot_preference: RotSlot::A,
slot_a_sha3_256_digest: Some(String::from("slotAdigest1")),
slot_b_sha3_256_digest: Some(String::from("slotBdigest1")),
transient_boot_preference: None,
},
serial_number: format!("serial{}", unique),
}
}
pub fn caboose(unique: &str) -> SpComponentCaboose {
SpComponentCaboose {
board: format!("board_{}", unique),
git_commit: format!("git_commit_{}", unique),
name: format!("name_{}", unique),
version: format!("version_{}", unique),
sign: Some(format!("sign_{}", unique)),
epoch: None,
}
}
pub fn rot_page(unique: &str) -> RotPage {
use base64::Engine;
RotPage {
data_base64: base64::engine::general_purpose::STANDARD.encode(unique),
}
}
pub fn sled_agent(
sled_id: SledUuid,
baseboard: Baseboard,
sled_role: SledRole,
omicron_zones: OmicronZonesConfig,
disks: Vec<InventoryDisk>,
zpools: Vec<InventoryZpool>,
datasets: Vec<InventoryDataset>,
) -> Inventory {
Inventory {
baseboard,
reservoir_size: ByteCount::from(1024),
sled_role,
sled_agent_address: "[::1]:56792".parse().unwrap(),
sled_id,
usable_hardware_threads: 10,
usable_physical_ram: ByteCount::from(1024 * 1024),
omicron_zones,
disks,
zpools,
datasets,
omicron_physical_disks_generation: Generation::new(),
}
}