-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate_launch_test.go
More file actions
814 lines (710 loc) · 23.8 KB
/
Copy pathvalidate_launch_test.go
File metadata and controls
814 lines (710 loc) · 23.8 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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
package domain
import (
"strings"
"testing"
"time"
"github.com/TechnologyTailors/Schedune/schedune-control-plane/pkg/schema"
"github.com/TechnologyTailors/Schedune/schedune-control-plane/pkg/schema/launch"
)
func TestValidateLaunch_HealthyArmProduction(t *testing.T) {
env := readFixture(t, "healthy_arm_production.json")
now := time.Now().Unix()
env.TimestampSec = now
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-001",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "VirtualMachine",
Architecture: "aarch64",
ImageReference: "oci://registry/img",
Vcpu: 4,
MemoryMB: 8192,
LaunchMode: "DryRun",
}
result := ValidateLaunch(spec, node)
if !result.IsValid {
t.Errorf("expected launch to be valid, got false: %v", result.BlockingReasonCodes)
}
if result.RecommendedRuntime != "qemu-system-aarch64" {
t.Errorf("expected 'qemu-system-aarch64', got %s", result.RecommendedRuntime)
}
}
func TestValidateLaunch_CloudHypervisorReady(t *testing.T) {
env := readFixture(t, "cloudhypervisor_ready_arm.json")
now := time.Now().Unix()
env.TimestampSec = now
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-ch",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "VirtualMachine",
Architecture: "aarch64",
ImageReference: "oci://registry/img",
Vcpu: 4,
MemoryMB: 8192,
LaunchMode: "DryRun",
}
result := ValidateLaunch(spec, node)
if !result.IsValid {
t.Errorf("expected launch to be valid, got false: %v", result.BlockingReasonCodes)
}
if result.SelectedBackend != "cloud_hypervisor" {
t.Errorf("expected selected backend to be cloud_hypervisor, got %s", result.SelectedBackend)
}
if result.RecommendedRuntime != "cloud-hypervisor" {
t.Errorf("expected 'cloud-hypervisor', got %s", result.RecommendedRuntime)
}
}
func TestValidateLaunch_FirecrackerHostReadyArtifactInvalid(t *testing.T) {
env := readFixture(t, "firecracker_host_ready.json")
now := time.Now().Unix()
env.TimestampSec = now
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-fc",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "MicroVM",
Architecture: "x86_64",
ImageReference: "oci://registry/img", // Invalid for FC which needs kernel/rootfs in V0
Vcpu: 2,
MemoryMB: 2048,
LaunchMode: "DryRun",
}
result := ValidateLaunch(spec, node)
if result.IsValid {
t.Errorf("expected launch to be invalid due to missing artifact model")
}
hasArtifactBlocker := false
for _, tr := range result.ValidationTrace {
if strings.Contains(tr, schema.ReasonErrLaunchInvalidFirecrackerArtifactModel) {
hasArtifactBlocker = true
}
}
if !hasArtifactBlocker {
t.Errorf("expected ERR_LAUNCH_INVALID_FIRECRACKER_ARTIFACT_MODEL in trace, got %v", result.ValidationTrace)
}
}
func TestValidateLaunch_MissingKvmX86(t *testing.T) {
env := readFixture(t, "missing_kvm_x86.json")
now := time.Now().Unix()
env.TimestampSec = now
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-002",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "VirtualMachine",
Architecture: "x86_64", // Match arch to focus on KVM blocker
ImageReference: "oci://registry/img",
Vcpu: 2,
MemoryMB: 4096,
LaunchMode: "DryRun",
}
result := ValidateLaunch(spec, node)
if result.IsValid {
t.Errorf("expected launch to be invalid")
}
hasKvmBlocker := false
for _, code := range result.BlockingReasonCodes {
if code == schema.ReasonErrLaunchBackendNotSupported {
hasKvmBlocker = true
}
}
if !hasKvmBlocker {
t.Errorf("expected ERR_LAUNCH_BACKEND_NOT_SUPPORTED blocker, got %v", result.BlockingReasonCodes)
}
if result.RejectedBackends["kvm_qemu"] != schema.ReasonErrLaunchMissingCapabilityKvmQemu+" ("+schema.ReasonCapKvmMissing+")" {
t.Errorf("expected rejected backend kvm_qemu with CAP_KVM_MISSING, got %v", result.RejectedBackends)
}
}
func TestValidateLaunch_ArchitectureMismatch(t *testing.T) {
env := readFixture(t, "missing_kvm_x86.json")
now := time.Now().Unix()
env.TimestampSec = now
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-003",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "Container",
Architecture: "aarch64", // Spec asks for aarch64, Node is x86_64
ImageReference: "oci://registry/img",
Vcpu: 2,
MemoryMB: 4096,
LaunchMode: "DryRun",
}
result := ValidateLaunch(spec, node)
if result.IsValid {
t.Errorf("expected launch to be invalid")
}
hasArchBlocker := false
for _, code := range result.BlockingReasonCodes {
if code == schema.ReasonErrLaunchArchMismatch {
hasArchBlocker = true
}
}
if !hasArchBlocker {
t.Errorf("expected ERR_LAUNCH_ARCH_MISMATCH blocker, got %v", result.BlockingReasonCodes)
}
if hint, ok := result.RemediationHints["architecture"]; !ok || !strings.Contains(hint, "matches the node") {
t.Errorf("expected remediation hint for architecture, got %v", result.RemediationHints)
}
}
func TestValidateLaunch_FirecrackerPartialFail(t *testing.T) {
env := readFixture(t, "firecracker_partial_fail.json")
now := time.Now().Unix()
env.TimestampSec = now
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-004",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "MicroVM",
Architecture: "aarch64",
ImageReference: "oci://registry/img",
Vcpu: 2,
MemoryMB: 2048,
LaunchMode: "DryRun",
}
result := ValidateLaunch(spec, node)
if result.IsValid {
t.Errorf("expected launch to be invalid due to missing firecracker_launch capability")
}
hasFcBlocker := false
for _, code := range result.BlockingReasonCodes {
if code == schema.ReasonErrLaunchBackendNotSupported {
hasFcBlocker = true
}
}
if !hasFcBlocker {
t.Errorf("expected ERR_LAUNCH_BACKEND_NOT_SUPPORTED blocker, got %v", result.BlockingReasonCodes)
}
if result.RejectedBackends["firecracker"] != schema.ReasonErrLaunchMissingCapabilityFcBinary {
t.Errorf("expected rejected backend firecracker, got %v", result.RejectedBackends)
}
}
func TestValidateLaunch_KvmExistsNotOpenable(t *testing.T) {
env := readFixture(t, "kvm_exists_not_openable.json")
now := time.Now().Unix()
env.TimestampSec = now
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-005",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "VirtualMachine",
Architecture: "x86_64",
ImageReference: "oci://registry/img",
Vcpu: 2,
MemoryMB: 2048,
LaunchMode: "DryRun",
}
result := ValidateLaunch(spec, node)
if result.IsValid {
t.Errorf("expected launch to be invalid due to unopenable kvm")
}
hasKvmBlocker := false
for _, code := range result.BlockingReasonCodes {
if code == schema.ReasonErrLaunchBackendNotSupported {
hasKvmBlocker = true
}
}
if !hasKvmBlocker {
t.Errorf("expected ERR_LAUNCH_BACKEND_NOT_SUPPORTED blocker, got %v", result.BlockingReasonCodes)
}
if result.RejectedBackends["kvm_qemu"] != schema.ReasonErrLaunchMissingCapabilityKvmQemu+" ("+schema.ReasonCapKvmNotOpenablePerms+")" {
t.Errorf("expected rejected backend kvm_qemu, got %v", result.RejectedBackends)
}
// Optional: verify that the reason trace exposes the exact reason from the agent
traceStr := ""
for _, tr := range result.ValidationTrace {
traceStr += tr + " "
}
if !strings.Contains(traceStr, "CAP_KVM_NOT_OPENABLE_PERMS") {
t.Errorf("expected trace to contain CAP_KVM_NOT_OPENABLE_PERMS, got %s", traceStr)
}
}
func TestValidateLaunch_MissingQemuBinary(t *testing.T) {
env := readFixture(t, "missing_qemu_binary.json")
now := time.Now().Unix()
env.TimestampSec = now
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-006",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "VirtualMachine",
Architecture: "x86_64",
ImageReference: "oci://registry/img",
Vcpu: 2,
MemoryMB: 2048,
LaunchMode: "DryRun",
}
result := ValidateLaunch(spec, node)
if result.IsValid {
t.Errorf("expected launch to be invalid due to missing qemu binary")
}
hasQemuBlocker := false
for _, code := range result.BlockingReasonCodes {
if code == schema.ReasonErrLaunchBackendNotSupported {
hasQemuBlocker = true
}
}
if !hasQemuBlocker {
t.Errorf("expected ERR_LAUNCH_BACKEND_NOT_SUPPORTED blocker, got %v", result.BlockingReasonCodes)
}
if result.RejectedBackends["kvm_qemu"] != schema.ReasonErrLaunchMissingCapabilityQemuBinary+" ("+schema.ReasonCapQemuBinaryMissing+")" {
t.Errorf("expected rejected backend kvm_qemu with CAP_QEMU_BINARY_MISSING error, got %v", result.RejectedBackends)
}
foundEvidence := false
for _, ev := range result.BackendRejectionEvidence {
if ev.Backend == "kvm_qemu" && ev.ReasonCode == schema.ReasonErrLaunchMissingCapabilityQemuBinary {
if ev.CapabilityName != nil && *ev.CapabilityName == "qemu_binary_present" {
if ev.CapabilityReasonCode != nil && *ev.CapabilityReasonCode == "CAP_QEMU_BINARY_MISSING" {
foundEvidence = true
}
}
}
}
if !foundEvidence {
t.Errorf("expected structured evidence for missing qemu binary, got %+v", result.BackendRejectionEvidence)
}
if hint, ok := result.RemediationHints["kvm_qemu_binary"]; !ok || !strings.Contains(hint, "Install qemu-system") {
t.Errorf("expected remediation hint for missing qemu binary, got %v", result.RemediationHints)
}
}
func TestValidateLaunch_TypedStorage(t *testing.T) {
env := readFixture(t, "cloudhypervisor_ready_arm.json")
now := time.Now().Unix()
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-typed",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "VirtualMachine",
Architecture: "aarch64",
Vcpu: 4,
MemoryMB: 8192,
LaunchMode: "DryRun",
Storage: []launch.StorageAttachmentSpec{
{HostPath: "/tmp/vol1.qcow2", Format: "qcow2"},
},
}
result := ValidateLaunch(spec, node)
if !result.IsValid {
t.Errorf("expected typed storage to validate successfully, got false: %v", result.BlockingReasonCodes)
}
}
func TestValidateLaunch_TypedStoragePrecedence(t *testing.T) {
env := readFixture(t, "cloudhypervisor_ready_arm.json")
now := time.Now().Unix()
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-prec",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "VirtualMachine",
Architecture: "aarch64",
Vcpu: 4,
MemoryMB: 8192,
LaunchMode: "DryRun",
ImageReference: "/tmp/legacy.img", // Should trigger warning
Storage: []launch.StorageAttachmentSpec{
{HostPath: "/tmp/typed.qcow2", Format: "qcow2"},
},
}
result := ValidateLaunch(spec, node)
if !result.IsValid {
t.Errorf("expected validation to pass, got false")
}
hasWarning := false
for _, w := range result.Warnings {
if w == schema.ReasonWarnDeprecatedImageReference {
hasWarning = true
}
}
if !hasWarning {
t.Errorf("expected warning for legacy image reference, got: %v", result.Warnings)
}
}
func TestValidateLaunch_FirecrackerQcow2Rejected(t *testing.T) {
env := readFixture(t, "firecracker_host_ready.json")
now := time.Now().Unix()
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-fc-qcow2",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "MicroVM",
Architecture: "x86_64",
Vcpu: 2,
MemoryMB: 1024,
LaunchMode: "DryRun",
Storage: []launch.StorageAttachmentSpec{
{HostPath: "/tmp/vol.qcow2", Format: "qcow2"},
},
}
result := ValidateLaunch(spec, node)
if result.IsValid {
t.Errorf("expected firecracker to reject qcow2, but it validated")
}
if reason, ok := result.RejectedBackends["firecracker"]; !ok || !strings.Contains(reason, schema.ReasonErrLaunchInvalidStorageFormat) {
t.Errorf("expected firecracker rejection with ERR_LAUNCH_INVALID_STORAGE_FORMAT, got %v", result.RejectedBackends)
}
}
func TestValidateLaunch_MissingArtifact(t *testing.T) {
env := readFixture(t, "healthy_arm_production.json")
now := time.Now().Unix()
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-missing-artifact",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "VirtualMachine",
Architecture: "aarch64",
Vcpu: 2,
MemoryMB: 1024,
LaunchMode: "DryRun",
// No ImageReference, no Storage
}
result := ValidateLaunch(spec, node)
if result.IsValid {
t.Errorf("expected failure due to missing artifact, but it validated")
}
if reason, ok := result.RejectedBackends["kvm_qemu"]; !ok || !strings.Contains(reason, schema.ReasonErrLaunchMissingArtifact) {
t.Errorf("expected rejection ERR_LAUNCH_MISSING_ARTIFACT for kvm_qemu, got %v", result.RejectedBackends)
}
}
func TestValidateLaunch_SecurityContextRequiresSeccomp(t *testing.T) {
env := readFixture(t, "missing_seccomp.json")
now := time.Now().Unix()
env.TimestampSec = now
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-seccomp",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "VirtualMachine",
Architecture: "x86_64",
Vcpu: 2,
MemoryMB: 1024,
LaunchMode: "DryRun",
Storage: []launch.StorageAttachmentSpec{
{HostPath: "/tmp/vol.qcow2", Format: "qcow2"},
},
Security: &launch.SecurityContextSpec{
SeccompProfile: "runtime/default",
},
}
result := ValidateLaunch(spec, node)
if result.IsValid {
t.Errorf("expected failure due to missing seccomp capability, but it validated")
}
hasSeccompBlocker := false
for _, code := range result.BlockingReasonCodes {
if code == schema.ReasonErrLaunchMissingCapabilitySeccomp {
hasSeccompBlocker = true
}
}
if !hasSeccompBlocker {
t.Errorf("expected ERR_LAUNCH_MISSING_CAPABILITY_SECCOMP blocker, got %v", result.BlockingReasonCodes)
}
if hint, ok := result.RemediationHints["kernel_seccomp"]; !ok || !strings.Contains(hint, "CONFIG_SECCOMP") {
t.Errorf("expected remediation hint for missing seccomp, got %v", result.RemediationHints)
}
}
func TestValidateLaunch_SecurityContextRequiresNamespaces(t *testing.T) {
env := readFixture(t, "missing_seccomp.json") // We can mock missing namespaces locally for test
now := time.Now().Unix()
env.TimestampSec = now
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
if env.Capabilities[i].Feature == "kernel_namespaces_supported" {
env.Capabilities[i].State = "Unsupported"
rc := "CAP_NAMESPACES_MISSING"
env.Capabilities[i].ReasonCode = &rc
}
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-namespaces",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "VirtualMachine",
Architecture: "x86_64",
Vcpu: 2,
MemoryMB: 1024,
LaunchMode: "DryRun",
Storage: []launch.StorageAttachmentSpec{
{HostPath: "/tmp/vol.qcow2", Format: "qcow2"},
},
Security: &launch.SecurityContextSpec{
DropCapabilities: []string{"CAP_SYS_ADMIN"},
},
}
result := ValidateLaunch(spec, node)
if !result.IsValid {
t.Errorf("expected validation to pass even when namespaces capability is missing, because dropping capabilities does not require full namespace support, got false: %v", result.BlockingReasonCodes)
}
}
func TestValidateLaunch_ReasonCodeRegistryHygiene(t *testing.T) {
// Pick a few representative fixtures that test different validation failure modes
fixtures := []string{
"cloudhypervisor_binary_missing.json",
"firecracker_partial_fail.json",
"missing_kvm_x86.json",
"missing_qemu_binary.json",
"healthy_unsupported_compatibility.json",
"healthy_x86_kvm_openable.json",
"stale_telemetry.json",
}
for _, fname := range fixtures {
env := readFixture(t, fname)
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-test",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "VirtualMachine",
Architecture: "x86_64",
LaunchMode: "DryRun",
Vcpu: 2,
MemoryMB: 1024,
}
res := ValidateLaunch(spec, node)
for _, code := range res.BlockingReasonCodes {
if !schema.IsKnownReasonCode(code) {
t.Errorf("fixture %s produced unregistered blocking reason code: %q", fname, code)
}
}
for _, code := range res.Warnings {
if !schema.IsKnownReasonCode(code) {
t.Errorf("fixture %s produced unregistered warning reason code: %q", fname, code)
}
}
for _, ev := range res.BackendRejectionEvidence {
if !schema.IsKnownReasonCode(ev.ReasonCode) {
t.Errorf("fixture %s produced unregistered structured reason code: %q", fname, ev.ReasonCode)
}
if ev.CapabilityReasonCode != nil && *ev.CapabilityReasonCode != "" {
if !schema.IsKnownReasonCode(*ev.CapabilityReasonCode) {
t.Errorf("fixture %s produced unregistered structured capability reason code: %q", fname, *ev.CapabilityReasonCode)
}
}
}
for _, reason := range res.RejectedBackends {
if reason == "" {
t.Errorf("fixture %s produced an empty rejected backend reason", fname)
}
words := strings.Split(reason, " ")
for _, w := range words {
w = strings.Trim(w, "()[]")
if strings.HasPrefix(w, "ERR_") || strings.HasPrefix(w, "CAP_") {
if !schema.IsKnownReasonCode(w) {
t.Errorf("fixture %s produced unregistered backend rejection code in message %q: %q", fname, reason, w)
}
}
}
}
}
}
func TestValidateLaunch_RuntimeVersionMismatch(t *testing.T) {
env := readFixture(t, "healthy_arm_production.json")
now := time.Now().Unix()
env.TimestampSec = now
for i, cap := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
if cap.Feature == "qemu_binary_present" {
v := "QEMU emulator version 6.2.0 (Debian 1:6.2+dfsg-2ubuntu6.22)"
env.Capabilities[i].Version = &v
}
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-version",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "VirtualMachine",
Architecture: "aarch64",
Vcpu: 2,
MemoryMB: 1024,
LaunchMode: "DryRun",
Storage: []launch.StorageAttachmentSpec{
{HostPath: "/tmp/vol.qcow2", Format: "qcow2"},
},
RuntimeVersion: &launch.RuntimeVersionRequirement{
ExactVersion: "9.9.9",
},
}
result := ValidateLaunch(spec, node)
if result.IsValid {
t.Errorf("expected validation to fail due to runtime version mismatch")
}
hint, ok := result.RemediationHints["runtime_version_mismatch"]
if !ok || !strings.Contains(hint, "Install the exact runtime binary") {
t.Errorf("expected runtime version mismatch hint, got %v", result.RemediationHints)
}
foundEvidence := false
for _, ev := range result.BackendRejectionEvidence {
if ev.ReasonCode == schema.ReasonErrLaunchRuntimeVersionMismatch {
foundEvidence = true
}
}
if !foundEvidence {
t.Errorf("expected structured evidence for runtime version mismatch, got %+v", result.BackendRejectionEvidence)
}
}
func TestValidateLaunch_FirecrackerExecuteUnsupported(t *testing.T) {
env := readFixture(t, "firecracker_host_ready.json")
now := time.Now().Unix()
env.TimestampSec = now
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-fc-execute",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "MicroVM",
Architecture: "x86_64",
Vcpu: 2,
MemoryMB: 1024,
LaunchMode: "Execute",
KernelImagePath: "/tmp/kernel.bin",
RootfsPath: "/tmp/rootfs.ext4",
}
result := ValidateLaunch(spec, node)
if result.IsValid {
t.Errorf("expected launch to be invalid due to Execute mode for Firecracker")
}
hasBlocker := false
for _, code := range result.BlockingReasonCodes {
if code == schema.ReasonErrLaunchBackendExecutionUnsupported {
hasBlocker = true
}
}
if !hasBlocker {
t.Errorf("expected ERR_LAUNCH_BACKEND_EXECUTION_UNSUPPORTED blocker, got %v", result.BlockingReasonCodes)
}
if result.SelectedBackend != schema.BackendFirecracker {
t.Errorf("expected SelectedBackend to be firecracker, got %s", result.SelectedBackend)
}
}
func TestValidateLaunch_FirecrackerDryRunSupported(t *testing.T) {
env := readFixture(t, "firecracker_host_ready.json")
now := time.Now().Unix()
env.TimestampSec = now
for i := range env.Capabilities {
env.Capabilities[i].ObservedAtSec = now
staleAfter := now + 300
env.Capabilities[i].StaleAfterSec = &staleAfter
}
node := ProjectEnvelope(env)
spec := launch.LaunchSpec{
SchemaVersion: "v1alpha1",
WorkloadID: "wl-launch-fc-dryrun",
TenantID: "tenant-1",
NodeID: node.ID,
RuntimeClass: "MicroVM",
Architecture: "x86_64",
Vcpu: 2,
MemoryMB: 1024,
LaunchMode: "DryRun",
KernelImagePath: "/tmp/kernel.bin",
RootfsPath: "/tmp/rootfs.ext4",
}
result := ValidateLaunch(spec, node)
if !result.IsValid {
t.Errorf("expected launch to be valid for Firecracker DryRun, got blockers: %v", result.BlockingReasonCodes)
}
if result.SelectedBackend != schema.BackendFirecracker {
t.Errorf("expected SelectedBackend to be firecracker, got %s", result.SelectedBackend)
}
}