kata-check: use "--strict" to perform version consistency check

Use `kata-runtime kata-check --strict/-s` to perform version
consistency check.
Only if major version number, minor version number and Patch
number are all the same, we determine those two kata components
are version-consistent.

Fixes: #2375

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
This commit is contained in:
Penny Zheng
2020-01-08 15:17:15 +08:00
parent a4b3c65c16
commit 1ad927d4e8
2 changed files with 65 additions and 0 deletions

View File

@@ -63,6 +63,7 @@ const (
moduleParamDir = "parameters"
successMessageCapable = "System is capable of running " + project
successMessageCreate = "System can currently create " + project
successMessageVersion = "Version consistency of " + project + " is verified"
failMessage = "System is not capable of running " + project
kernelPropertyCorrect = "Kernel property value correct"
@@ -309,6 +310,10 @@ var kataCheckCLICommand = cli.Command{
Name: "verbose, v",
Usage: "display the list of checks performed",
},
cli.BoolFlag{
Name: "strict, s",
Usage: "perform strict checking",
},
},
Action: func(context *cli.Context) error {
@@ -357,6 +362,16 @@ var kataCheckCLICommand = cli.Command{
fmt.Println(successMessageCreate)
}
strict := context.Bool("strict")
if strict {
err = checkVersionConsistencyInComponents(runtimeConfig)
if err != nil {
return err
}
fmt.Println(successMessageVersion)
}
return nil
},
}
@@ -454,3 +469,35 @@ func genericCheckKVMExtensions(extensions map[string]kvmExtension) (map[string]i
return results, nil
}
// checkVersionConsistencyInComponents checks version consistency in Kata Components.
func checkVersionConsistencyInComponents(config oci.RuntimeConfig) error {
proxyInfo := getProxyInfo(config)
shimInfo, err := getShimInfo(config)
if err != nil {
return err
}
shimVersionInfo := shimInfo.Version
runtimeVersionInfo := constructVersionInfo(version)
// kata-proxy exists
if proxyInfo.Type != string(vc.NoProxyType) {
proxyVersionInfo := proxyInfo.Version
if !versionEqual(proxyVersionInfo, runtimeVersionInfo) || !versionEqual(shimVersionInfo, runtimeVersionInfo) {
return fmt.Errorf("there exists version inconsistency in kata components. kata-proxy: v%d.%d.%d, kata-shim: v%d.%d.%d, kata-runtime: v%d.%d.%d",
proxyVersionInfo.Major, proxyVersionInfo.Minor, proxyVersionInfo.Patch,
shimVersionInfo.Major, shimVersionInfo.Minor, shimVersionInfo.Patch,
runtimeVersionInfo.Major, runtimeVersionInfo.Minor, runtimeVersionInfo.Patch)
}
} else {
if !versionEqual(shimVersionInfo, runtimeVersionInfo) {
return fmt.Errorf("there exists version inconsistency in kata components. kata-shim: v%d.%d.%d, kata-runtime: v%d.%d.%d",
shimVersionInfo.Major, shimVersionInfo.Minor, shimVersionInfo.Patch,
runtimeVersionInfo.Major, runtimeVersionInfo.Minor, runtimeVersionInfo.Patch)
}
}
return nil
}

View File

@@ -183,3 +183,21 @@ func constructVersionInfo(version string) VersionInfo {
}
}
func versionEqual(a VersionInfo, b VersionInfo) bool {
av, err := semver.Make(a.Semver)
if err != nil {
return false
}
bv, err := semver.Make(b.Semver)
if err != nil {
return false
}
if av.Major == bv.Major && av.Minor == bv.Minor && av.Patch == bv.Patch {
return true
}
return false
}