Skip to content

Commit 14780e8

Browse files
committed
change make logs quiet by default and adds a verbose flag to enable verbose log output
Signed-off-by: olalekan odukoya <[email protected]>
1 parent 597ffed commit 14780e8

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed

pkg/limayaml/validate.go

+41
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,44 @@ func Validate(y *LimaYAML, warn bool) error {
372372
}
373373
}
374374

375+
if y.Rosetta.Enabled != nil && *y.Rosetta.Enabled {
376+
if *y.VMType != VZ {
377+
return fmt.Errorf("field `rosetta.enabled` can only be enabled for VMType %q; got %q", VZ, *y.VMType)
378+
}
379+
}
380+
381+
if y.NestedVirtualization != nil && *y.NestedVirtualization {
382+
if *y.VMType != VZ {
383+
return fmt.Errorf("field `nestedVirtualization` can only be enabled for VMType %q; got %q", VZ, *y.VMType)
384+
}
385+
}
386+
387+
if y.MountType != nil {
388+
if err := validateMountType(y, warn); err != nil {
389+
return err
390+
}
391+
}
392+
393+
return nil
394+
}
395+
396+
func validateMountType(y *LimaYAML, warn bool) error {
397+
validMountTypes := map[string]bool{
398+
REVSSHFS: true,
399+
NINEP: true,
400+
VIRTIOFS: true,
401+
}
402+
403+
if !validMountTypes[*y.MountType] {
404+
return fmt.Errorf("field `mountType` %s, valid options are: %s, %s, %s", *y.MountType, REVSSHFS, NINEP, VIRTIOFS)
405+
}
406+
407+
if *y.MountType == VIRTIOFS && runtime.GOOS == "darwin" {
408+
if y.VMType != nil && *y.VMType != VZ {
409+
return fmt.Errorf("field `mountType` requires vmType 'vz' on macOS (darwin); got %s", *y.VMType)
410+
}
411+
}
412+
375413
return nil
376414
}
377415

@@ -432,6 +470,9 @@ func validateNetwork(y *LimaYAML) error {
432470
return fmt.Errorf("field `%s.macAddress` must be a 48 bit (6 bytes) MAC address; actual length of %q is %d bytes", field, nw.MACAddress, len(hw))
433471
}
434472
}
473+
if nw.VZNAT != nil && *nw.VZNAT && *y.VMType != VZ {
474+
return fmt.Errorf("field `%s.vzNAT` needs vmType set to vz; got %s", field, *y.VMType)
475+
}
435476
// FillDefault() will make sure that nw.Interface is not the empty string
436477
if len(nw.Interface) >= 16 {
437478
return fmt.Errorf("field `%s.interface` must be less than 16 bytes, but is %d bytes: %q", field, len(nw.Interface), nw.Interface)

pkg/limayaml/validate_test.go

+107
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"runtime"
66
"testing"
77

8+
"github.com/sirupsen/logrus"
89
"gotest.tools/v3/assert"
910
)
1011

@@ -186,3 +187,109 @@ func TestValidateParamIsUsed(t *testing.T) {
186187
assert.Error(t, err, "field `param` key \"rootFul\" is not used in any provision, probe, copyToHost, or portForward")
187188
}
188189
}
190+
191+
func TestValidateRosetta(t *testing.T) {
192+
images := `images: [{"location": "/"}]`
193+
194+
invalidRosetta := `
195+
rosetta:
196+
enabled: true
197+
vmType: "qemu"
198+
`
199+
y, err := Load([]byte(invalidRosetta+"\n"+images), "lima.yaml")
200+
assert.NilError(t, err)
201+
202+
err = Validate(y, false)
203+
assert.Error(t, err, "field `rosetta.enabled` can only be enabled for VMType \"vz\"; got \"qemu\"")
204+
205+
validRosetta := `
206+
rosetta:
207+
enabled: true
208+
vmType: "vz"
209+
`
210+
y, err = Load([]byte(validRosetta+"\n"+images), "lima.yaml")
211+
assert.NilError(t, err)
212+
213+
err = Validate(y, false)
214+
assert.NilError(t, err)
215+
216+
rosettaDisabled := `
217+
rosetta:
218+
enabled: false
219+
vmType: "qemu"
220+
`
221+
y, err = Load([]byte(rosettaDisabled+"\n"+images), "lima.yaml")
222+
assert.NilError(t, err)
223+
224+
err = Validate(y, false)
225+
assert.NilError(t, err)
226+
}
227+
228+
func TestValidateNestedVirtualization(t *testing.T) {
229+
images := `images: [{"location": "/"}]`
230+
231+
validYAML := `
232+
nestedVirtualization: true
233+
vmType: vz
234+
` + images
235+
236+
y, err := Load([]byte(validYAML), "lima.yaml")
237+
assert.NilError(t, err)
238+
239+
err = Validate(y, false)
240+
assert.NilError(t, err)
241+
242+
invalidYAML := `
243+
nestedVirtualization: true
244+
vmType: qemu
245+
` + images
246+
247+
y, err = Load([]byte(invalidYAML), "lima.yaml")
248+
assert.NilError(t, err)
249+
250+
err = Validate(y, false)
251+
assert.Error(t, err, "field `nestedVirtualization` can only be enabled for VMType \"vz\"; got \"qemu\"")
252+
}
253+
254+
func TestValidateMountTypeOS(t *testing.T) {
255+
images := `images: [{"location": "/"}]`
256+
257+
inValidMountTypeLinux := `
258+
mountType: "rMountType"
259+
`
260+
y, err := Load([]byte(inValidMountTypeLinux+"\n"+images), "lima.yaml")
261+
assert.NilError(t, err)
262+
263+
err = Validate(y, true)
264+
logrus.Info("inValidMountTypeLinux: from within test ", inValidMountTypeLinux)
265+
assert.Error(t, err, "field `mountType` must be \"reverse-sshfs\" or \"9p\" or \"virtiofs\", or \"wsl2\", got \"rMountType\"")
266+
267+
validMountTypeLinux := `
268+
mountType: "virtiofs"
269+
`
270+
y, err = Load([]byte(validMountTypeLinux+"\n"+images), "lima.yaml")
271+
assert.NilError(t, err)
272+
273+
err = Validate(y, true)
274+
assert.Error(t, err, "field `mountType` requires vmType 'vz' on macOS (darwin); got qemu")
275+
276+
validMountTypeMac := `
277+
mountType: "virtiofs"
278+
vmType: "vz"
279+
`
280+
y, err = Load([]byte(validMountTypeMac+"\n"+images), "lima.yaml")
281+
assert.NilError(t, err)
282+
283+
err = Validate(y, false)
284+
assert.NilError(t, err)
285+
286+
invalidMountTypeMac := `
287+
mountType: "virtiofs"
288+
vmType: "qemu"
289+
`
290+
y, err = Load([]byte(invalidMountTypeMac+"\n"+images), "lima.yaml")
291+
assert.NilError(t, err)
292+
293+
err = Validate(y, false)
294+
assert.Error(t, err, "field `mountType` requires vmType 'vz' on macOS (darwin); got qemu")
295+
}

0 commit comments

Comments
 (0)