diff --git a/cc-env.go b/cc-env.go index a7f7ebae..b8692aff 100644 --- a/cc-env.go +++ b/cc-env.go @@ -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 { @@ -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 @@ -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() @@ -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, diff --git a/cc-env_test.go b/cc-env_test.go index 0b41275b..3c0e55ae 100644 --- a/cc-env_test.go +++ b/cc-env_test.go @@ -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 @@ -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, @@ -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, @@ -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) +}