-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rosetta: add option to ignore rosetta failure when installation cance…
…lled this adds a ignore-if-missing option that allows vfkit to not fail if the rosetta installation is cancelled by the user. So far, if the rosetta installation was cancelled vfkit exited with an error. This behavior still exists if ignore-if-missing option is not set. This will be used by podman bc there could be a fallback and rosetta could also be not mandatory containers/podman#23153
- Loading branch information
Luca Stocchi
authored and
Luca Stocchi
committed
Oct 4, 2024
1 parent
41bbe77
commit 39cc8c3
Showing
3 changed files
with
133 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package vf | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/Code-Hex/vz/v3" | ||
"github.com/crc-org/vfkit/pkg/config" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type checkRosettaAvailabilityTest struct { | ||
installRosetta bool | ||
ignoreIfMissing bool | ||
checkRosettaDirectoryShareAvailability func() vz.LinuxRosettaAvailability | ||
doInstallRosetta func() error | ||
errorValue string | ||
} | ||
|
||
var checkRosettaAvailabilityTests = map[string]checkRosettaAvailabilityTest{ | ||
"TestRosettaIsNotSupported": { | ||
checkRosettaDirectoryShareAvailability: func() vz.LinuxRosettaAvailability { | ||
return vz.LinuxRosettaAvailabilityNotSupported | ||
}, | ||
errorValue: "rosetta is not supported", | ||
}, | ||
"TestRosettaInstalled": { | ||
checkRosettaDirectoryShareAvailability: func() vz.LinuxRosettaAvailability { | ||
return vz.LinuxRosettaAvailabilityInstalled | ||
}, | ||
}, | ||
"TestRosettaNotInstalled-NotToBeInstalled": { | ||
installRosetta: false, | ||
checkRosettaDirectoryShareAvailability: func() vz.LinuxRosettaAvailability { | ||
return vz.LinuxRosettaAvailabilityNotInstalled | ||
}, | ||
errorValue: "rosetta is not installed", | ||
}, | ||
"TestRosettaNotInstalled-InstallationCancelledButIgnoreIfMissingFalse": { | ||
installRosetta: true, | ||
ignoreIfMissing: false, | ||
checkRosettaDirectoryShareAvailability: func() vz.LinuxRosettaAvailability { | ||
return vz.LinuxRosettaAvailabilityNotInstalled | ||
}, | ||
doInstallRosetta: func() error { | ||
return fmt.Errorf("VZErrorDomain Code=%d", vz.ErrorOperationCancelled) | ||
}, | ||
errorValue: fmt.Sprintf("failed to install rosetta: VZErrorDomain Code=%d", vz.ErrorOperationCancelled), | ||
}, | ||
"TestRosettaNotInstalled-InstallationCancelledButIgnoreIfMissingTrue": { | ||
installRosetta: true, | ||
ignoreIfMissing: true, | ||
checkRosettaDirectoryShareAvailability: func() vz.LinuxRosettaAvailability { | ||
return vz.LinuxRosettaAvailabilityNotInstalled | ||
}, | ||
doInstallRosetta: func() error { | ||
return fmt.Errorf("VZErrorDomain Code=%d", vz.ErrorOperationCancelled) | ||
}, | ||
}, | ||
"TestRosettaNotInstalled-InstallationFailed": { | ||
installRosetta: true, | ||
ignoreIfMissing: true, | ||
checkRosettaDirectoryShareAvailability: func() vz.LinuxRosettaAvailability { | ||
return vz.LinuxRosettaAvailabilityNotInstalled | ||
}, | ||
doInstallRosetta: func() error { | ||
return fmt.Errorf("VZErrorDomain Code=%d", vz.ErrorInstallationFailed) | ||
}, | ||
errorValue: fmt.Sprintf("failed to install rosetta: VZErrorDomain Code=%d", vz.ErrorInstallationFailed), | ||
}, | ||
} | ||
|
||
func TestCheckRosettaAvailability(t *testing.T) { | ||
t.Run("name", func(t *testing.T) { | ||
for name := range checkRosettaAvailabilityTests { | ||
t.Run(name, func(t *testing.T) { | ||
test := checkRosettaAvailabilityTests[name] | ||
testCheckRosettaAvailability(t, &test) | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
func testCheckRosettaAvailability(t *testing.T, test *checkRosettaAvailabilityTest) { | ||
rosetta := | ||
RosettaShare{ | ||
InstallRosetta: test.installRosetta, | ||
IgnoreIfMissing: test.ignoreIfMissing, | ||
DirectorySharingConfig: config.DirectorySharingConfig{ | ||
MountTag: "mount", | ||
}, | ||
} | ||
|
||
origCheckRosettaDirectoryShareAvailability := checkRosettaDirectoryShareAvailability | ||
checkRosettaDirectoryShareAvailability = test.checkRosettaDirectoryShareAvailability | ||
origDoInstallRosetta := doInstallRosetta | ||
doInstallRosetta = test.doInstallRosetta | ||
defer func() { | ||
checkRosettaDirectoryShareAvailability = origCheckRosettaDirectoryShareAvailability | ||
doInstallRosetta = origDoInstallRosetta | ||
}() | ||
|
||
err := rosetta.checkRosettaAvailability() | ||
|
||
if test.errorValue != "" { | ||
require.Error(t, err) | ||
require.ErrorContains(t, err, test.errorValue) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
} |