Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
kata-check: use "--strict" to perform version consistency check
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Pennyzct committed Feb 17, 2020
1 parent a4b3c65 commit 1ad927d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
47 changes: 47 additions & 0 deletions cli/kata-check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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
}
18 changes: 18 additions & 0 deletions cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 1ad927d

Please sign in to comment.