@@ -3,17 +3,20 @@ package runtime
33import (
44 "github.com/TechnologyTailors/Schedune/schedune-control-plane/pkg/schema/launch"
55 "os"
6+ "strings"
67 "testing"
78)
89
910func TestKvmExecutor_PrepareMissingImage (t * testing.T ) {
1011 exec := & KvmExecutor {}
1112
1213 spec := launch.LaunchSpec {
13- Architecture : "aarch64" ,
14- ImageReference : "/tmp/non_existent_image_12345.qcow2" ,
15- Vcpu : 2 ,
16- MemoryMB : 1024 ,
14+ Architecture : "aarch64" ,
15+ Storage : []launch.StorageAttachmentSpec {
16+ {HostPath : "/tmp/non_existent_image_12345.qcow2" , Format : "qcow2" },
17+ },
18+ Vcpu : 2 ,
19+ MemoryMB : 1024 ,
1720 }
1821
1922 _ , err := exec .Prepare (spec )
@@ -22,10 +25,9 @@ func TestKvmExecutor_PrepareMissingImage(t *testing.T) {
2225 }
2326}
2427
25- func TestKvmExecutor_PrepareValidImage (t * testing.T ) {
28+ func TestKvmExecutor_PrepareValidImageLegacy (t * testing.T ) {
2629 exec := & KvmExecutor {}
2730
28- // create a dummy file
2931 f , err := os .CreateTemp ("" , "dummy_img_*.qcow2" )
3032 if err != nil {
3133 t .Fatalf ("could not create temp file: %v" , err )
@@ -52,8 +54,120 @@ func TestKvmExecutor_PrepareValidImage(t *testing.T) {
5254 t .Errorf ("expected qemu-system-aarch64, got %s" , prep .KvmQemu .BinaryPath )
5355 }
5456
55- if len (prep .KvmQemu .CommandArgs ) < 6 {
56- t .Errorf ("expected populated command args, got %v" , prep .KvmQemu .CommandArgs )
57+ foundDrive := false
58+ for _ , arg := range prep .KvmQemu .CommandArgs {
59+ if strings .Contains (arg , "format=qcow2" ) {
60+ foundDrive = true
61+ }
62+ }
63+ if ! foundDrive {
64+ t .Errorf ("expected format=qcow2 in args, got %v" , prep .KvmQemu .CommandArgs )
65+ }
66+ }
67+
68+ func TestKvmExecutor_PrepareValidImageTyped (t * testing.T ) {
69+ exec := & KvmExecutor {}
70+
71+ f , err := os .CreateTemp ("" , "dummy_img_*.raw" )
72+ if err != nil {
73+ t .Fatalf ("could not create temp file: %v" , err )
74+ }
75+ defer os .Remove (f .Name ())
76+
77+ spec := launch.LaunchSpec {
78+ Architecture : "x86_64" ,
79+ Storage : []launch.StorageAttachmentSpec {
80+ {HostPath : f .Name (), Format : "raw" },
81+ },
82+ Vcpu : 2 ,
83+ MemoryMB : 1024 ,
84+ }
85+
86+ prep , err := exec .Prepare (spec )
87+ if err != nil {
88+ t .Errorf ("expected Prepare to succeed, got %v" , err )
89+ }
90+
91+ if prep .KvmQemu == nil {
92+ t .Fatalf ("expected KvmQemu prepared state, got nil" )
93+ }
94+
95+ foundDrive := false
96+ for _ , arg := range prep .KvmQemu .CommandArgs {
97+ if strings .Contains (arg , "format=raw" ) {
98+ foundDrive = true
99+ }
100+ }
101+ if ! foundDrive {
102+ t .Errorf ("expected format=raw in args, got %v" , prep .KvmQemu .CommandArgs )
103+ }
104+ }
105+
106+ func TestCloudHypervisorExecutor_PrepareValidImageTyped (t * testing.T ) {
107+ exec := & CloudHypervisorExecutor {}
108+
109+ f , err := os .CreateTemp ("" , "dummy_img_*.raw" )
110+ if err != nil {
111+ t .Fatalf ("could not create temp file: %v" , err )
112+ }
113+ defer os .Remove (f .Name ())
114+
115+ spec := launch.LaunchSpec {
116+ Architecture : "x86_64" ,
117+ Storage : []launch.StorageAttachmentSpec {
118+ {HostPath : f .Name (), Format : "raw" },
119+ },
120+ Vcpu : 2 ,
121+ MemoryMB : 1024 ,
122+ }
123+
124+ prep , err := exec .Prepare (spec )
125+ if err != nil {
126+ t .Errorf ("expected Prepare to succeed, got %v" , err )
127+ }
128+
129+ if prep .CloudHypervisor == nil {
130+ t .Fatalf ("expected CloudHypervisor prepared state, got nil" )
131+ }
132+
133+ foundDrive := false
134+ for _ , arg := range prep .CloudHypervisor .CommandArgs {
135+ if strings .Contains (arg , "path=" + f .Name ()) {
136+ foundDrive = true
137+ }
138+ }
139+ if ! foundDrive {
140+ t .Errorf ("expected path in args, got %v" , prep .CloudHypervisor .CommandArgs )
141+ }
142+ }
143+
144+ func TestFirecrackerExecutor_PrepareValidImageTyped (t * testing.T ) {
145+ exec := & FirecrackerExecutor {}
146+
147+ spec := launch.LaunchSpec {
148+ Architecture : "x86_64" ,
149+ Storage : []launch.StorageAttachmentSpec {
150+ {HostPath : "/tmp/rootfs.ext4" , Format : "ext4" , MountPoint : "/" },
151+ {HostPath : "/tmp/vmlinux" , Format : "raw" , ReadOnly : true , MountPoint : "/boot/vmlinux" },
152+ },
153+ Vcpu : 2 ,
154+ MemoryMB : 1024 ,
155+ }
156+
157+ prep , err := exec .Prepare (spec )
158+ if err != nil {
159+ t .Errorf ("expected Prepare to succeed, got %v" , err )
160+ }
161+
162+ if prep .Firecracker == nil {
163+ t .Fatalf ("expected Firecracker prepared state, got nil" )
164+ }
165+
166+ if prep .Firecracker .RootfsPath != "/tmp/rootfs.ext4" {
167+ t .Errorf ("expected rootfs path to be set from typed storage" )
168+ }
169+ if prep .Firecracker .KernelImagePath != "/tmp/vmlinux" {
170+ t .Errorf ("expected kernel image path to be set from typed storage" )
57171 }
58172}
59173
0 commit comments