Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add validation for nestedVirtualization, rosetta, and mountType #3127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

olamilekan000
Copy link
Contributor

change validates config values for `nestedVirtualization`, `rosetta`, and `mountType` 
when a user starts or tries to create a VM.

Fixes #3126

@olamilekan000 olamilekan000 force-pushed the add-validation-for-lima-config-values branch 9 times, most recently from 14780e8 to f458f0e Compare January 19, 2025 05:37
@olamilekan000
Copy link
Contributor Author

@AkihiroSuda kindly review. Also, I am not sure why unit tests are failing for windows, go version 1.22 and 1.23, even though everything looks fine.

@olamilekan000 olamilekan000 force-pushed the add-validation-for-lima-config-values branch from f458f0e to 7772fb5 Compare January 19, 2025 12:58
@AkihiroSuda
Copy link
Member

https://github.com/lima-vm/lima/actions/runs/12853756300/job/35837296730?pr=3127

=== RUN   TestValidateRosetta
time="2025-01-19T12:59:05Z" level=debug msg="ResolveVMType: resolved VMType \"qemu\" (explicitly specified in []*LimaYAML{o,y,d}[1])"
    validate_test.go:202: assertion failed: expected an error, got nil
--- FAIL: TestValidateRosetta (0.00s)
=== RUN   TestValidateMountTypeOS
time="2025-01-19T12:59:05Z" level=debug msg="ResolveVMType: resolved VMType \"qemu\" (default for GOOS=\"linux\")"
time="2025-01-19T12:59:05Z" level=debug msg="ResolveVMType: resolved VMType \"qemu\" (default for GOOS=\"linux\")"
time="2025-01-19T12:59:05Z" level=warning msg="`mountType: virtiofs` on Linux is experimental"
    validate_test.go:272: assertion failed: expected an error, got nil
--- FAIL: TestValidateMountTypeOS (0.01s)

@olamilekan000
Copy link
Contributor Author

I have tried to replicate it locally but it passes. Not sure what I'm missing

@olamilekan000 olamilekan000 force-pushed the add-validation-for-lima-config-values branch 12 times, most recently from 5dc7b37 to 9c6b92d Compare January 20, 2025 05:52
@olamilekan000
Copy link
Contributor Author

@AkihiroSuda Found and fixed the issue. Thanks

@jandubois
Copy link
Member

@olamilekan000 I don't know if all your pushes where necessary to deal with CI problems, but please be aware that each full CI run costs about $6 due to our use of large GitHub runners for macOS, and this PR had like 18 force-pushes1. That's ok if the problem is only reproducible in CI, but otherwise please try to resolve problems locally first.

Footnotes

  1. I have not checked, maybe the macOS jobs where skipped due to earlier compile/lint failures, in which case the cost will have been minimal.

Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only reviewed the validate changes, not the tests.

There may be more conditions that the validation could check for, but I'm out of time for now to think about it more.

pkg/limayaml/validate.go Outdated Show resolved Hide resolved
pkg/limayaml/validate.go Outdated Show resolved Hide resolved
pkg/limayaml/validate.go Outdated Show resolved Hide resolved
pkg/limayaml/validate.go Outdated Show resolved Hide resolved
pkg/limayaml/validate.go Outdated Show resolved Hide resolved
pkg/limayaml/validate.go Outdated Show resolved Hide resolved
@olamilekan000
Copy link
Contributor Author

@olamilekan000 I don't know if all your pushes where necessary to deal with CI problems, but please be aware that each full CI run costs about $6 due to our use of large GitHub runners for macOS, and this PR had like 18 force-pushes1. That's ok if the problem is only reproducible in CI, but otherwise please try to resolve problems locally first.

Footnotes

  1. I have not checked, maybe the macOS jobs where skipped due to earlier compile/lint failures, in which case the cost will have been minimal.

Thanks for bringing this to my attention. The reason for that many pushes was due to me trying to figure why the test passes locally but fails with the CI. Apologies for the inconvenience

@olamilekan000 olamilekan000 force-pushed the add-validation-for-lima-config-values branch from 9c6b92d to e5c21f4 Compare January 20, 2025 08:44
@olamilekan000 olamilekan000 force-pushed the add-validation-for-lima-config-values branch 3 times, most recently from 4cba40b to 4ec0da9 Compare January 20, 2025 09:04
@olamilekan000 olamilekan000 force-pushed the add-validation-for-lima-config-values branch from 4ec0da9 to a27ec96 Compare January 21, 2025 23:25
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still invalid setting combinations that are not covered by tests.

It is a bit unfortunate that complete test coverage can only be achieved by running the test on each supported os and arch.

I think it would be better if the validation code had global variables for os and arch that can then be overridden in the tests to check for all scenarios with just a single local test run. But that should be a separate PR.

REVSSHFS: true,
NINEP: true,
VIRTIOFS: true,
WSLMount: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have a test that on Windows the only valid mountType is WSLMount.

@@ -432,6 +463,9 @@ func validateNetwork(y *LimaYAML) error {
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))
}
}
if nw.VZNAT != nil && *nw.VZNAT && *y.VMType != VZ {
return fmt.Errorf("field `%s.vzNAT` needs vmType set to %q; got %q", field, VZ, *y.VMType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar errors should use similar wording. So always use requires or always needs (check what existing errors already use), and don't mix and match.

Suggested change
return fmt.Errorf("field `%s.vzNAT` needs vmType set to %q; got %q", field, VZ, *y.VMType)
return fmt.Errorf("field `%s.vzNAT` requires vmType %q; got %q", field, VZ, *y.VMType)

@@ -372,6 +372,37 @@ func Validate(y *LimaYAML, warn bool) error {
}
}

if y.Rosetta.Enabled != nil && *y.Rosetta.Enabled && *y.VMType != VZ {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check should also make sure the arch is aarch64. Theoretically it should also check that the OS is darwin, but you can set the vmType to VZ unless you are on macOS, so that should already be covered.

assert.NilError(t, err)

err = Validate(y, false)
assert.NilError(t, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have expected this to fail on Linux and Windows, which don't support the VZ vm type. If it doesn't fail validation on Linux, then that needs to be added.

assert.NilError(t, err)

err = Validate(y, false)
if runtime.GOOS == "darwin" && IsNativeArch(AARCH64) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows this should return a validation error that vm type QEMU is not supported.

y, err = Load([]byte(rosettaDisabled+"\n"+images), "lima.yaml")
assert.NilError(t, err)

err = Validate(y, false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, expected to fail validation on Windows.

I'm stopping the review here; this continues to be an issue for the rest of the tests.

Instead of testing for the specific failure on e.g. Windows, I think you should probably skip the whole tests on platforms where they are expected to fail for different reasons than the one you are testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nestedVirtualization, rosetta, and mountType fields in the Lima config file are not Validated on Start Command
3 participants