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

Commit

Permalink
cc-env: Add hypervisor version to output
Browse files Browse the repository at this point in the history
The "cc-env" command now displays the hypervisor version for parity with
the other components.

Fixes #500.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Sep 12, 2017
1 parent 41abb89 commit 098d7bd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
29 changes: 20 additions & 9 deletions cc-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
//
// XXX: Increment for every change to the output format
// (meaning any change to the EnvInfo type).
const formatVersion = "1.0.2"
const formatVersion = "1.0.3"

// MetaInfo stores information on the format of the output itself
type MetaInfo struct {
Expand Down Expand Up @@ -79,8 +79,9 @@ type RuntimeVersionInfo struct {

// HypervisorInfo stores hypervisor details
type HypervisorInfo struct {
Location PathInfo
MachineType string
Version string
Location PathInfo
}

// ProxyInfo stores proxy details
Expand Down Expand Up @@ -285,6 +286,22 @@ func getAgentInfo(config oci.RuntimeConfig) (AgentInfo, error) {
return ccAgent, nil
}

func getHypervisorInfo(config oci.RuntimeConfig, hypervisorDetails hypervisorDetails) HypervisorInfo {
version, err := getCommandVersion(hypervisorDetails.HypervisorPath)
if err != nil {
version = unknown
}

return HypervisorInfo{
MachineType: config.HypervisorConfig.HypervisorMachineType,
Version: version,
Location: PathInfo{
Path: config.HypervisorConfig.HypervisorPath,
Resolved: hypervisorDetails.HypervisorPath,
},
}
}

func getEnvInfo(configFile, logfilePath string, config oci.RuntimeConfig) (env EnvInfo, err error) {
meta := getMetaInfo()

Expand Down Expand Up @@ -315,13 +332,7 @@ func getEnvInfo(configFile, logfilePath string, config oci.RuntimeConfig) (env E
return EnvInfo{}, err
}

hypervisor := HypervisorInfo{
Location: PathInfo{
Path: config.HypervisorConfig.HypervisorPath,
Resolved: resolvedHypervisor.HypervisorPath,
},
MachineType: config.HypervisorConfig.HypervisorMachineType,
}
hypervisor := getHypervisorInfo(config, resolvedHypervisor)

image := PathInfo{
Path: config.HypervisorConfig.ImagePath,
Expand Down
24 changes: 24 additions & 0 deletions cc-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
const testProxyURL = "file:///proxyURL"
const testProxyVersion = "proxy version 0.1"
const testShimVersion = "shim version 0.1"
const testHypervisorVersion = "QEMU emulator version 2.7.0+git.741f430a96-6.1, Copyright (c) 2003-2016 Fabrice Bellard and the QEMU Project developers"

// makeVersionBinary creates a shell script with the specified file
// name. When run as "file --version", it will display the specified
Expand Down Expand Up @@ -104,6 +105,11 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
return "", oci.RuntimeConfig{}, err
}

err = makeVersionBinary(hypervisorPath, testHypervisorVersion)
if err != nil {
return "", oci.RuntimeConfig{}, err
}

runtimeConfig := makeRuntimeConfigFileData(
"qemu",
hypervisorPath,
Expand Down Expand Up @@ -253,6 +259,7 @@ model name : %s

func getExpectedHypervisor(config oci.RuntimeConfig) HypervisorInfo {
return HypervisorInfo{
Version: testHypervisorVersion,
Location: PathInfo{
Path: config.HypervisorConfig.HypervisorPath,
Resolved: config.HypervisorConfig.HypervisorPath,
Expand Down Expand Up @@ -1227,3 +1234,20 @@ func TestCCEnvCLIFunctionFail(t *testing.T) {
err = fn(ctx)
assert.Error(t, err)
}

func TestGetHypervisorInfo(t *testing.T) {
assert := assert.New(t)

tmpdir, err := ioutil.TempDir("", "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)

const logFile = "/tmp/file.log"

_, config, err := makeRuntimeConfig(tmpdir)
assert.NoError(err)

info := getHypervisorInfo(config, hypervisorDetails{})

assert.Equal(info.Version, unknown)
}

0 comments on commit 098d7bd

Please sign in to comment.