cli: fix the issue of using wrong path to get version

Both of the netmon and proxy should use the right path
figured out from the configure instead of the default settings
to get their versions.

Fixes: #868

Signed-off-by: Fupan Li <lifupan@gmail.com>
This commit is contained in:
Fupan Li 2018-10-30 11:24:27 +08:00 committed by fupan
parent 58ce1b88c4
commit 11c6753bd5
2 changed files with 13 additions and 15 deletions

View File

@ -239,7 +239,8 @@ func getProxyInfo(config oci.RuntimeConfig) (ProxyInfo, error) {
return ProxyInfo{Type: string(config.ProxyType)}, nil return ProxyInfo{Type: string(config.ProxyType)}, nil
} }
version, err := getCommandVersion(defaultProxyPath) proxyConfig := config.ProxyConfig
version, err := getCommandVersion(proxyConfig.Path)
if err != nil { if err != nil {
version = unknown version = unknown
} }
@ -247,24 +248,26 @@ func getProxyInfo(config oci.RuntimeConfig) (ProxyInfo, error) {
proxy := ProxyInfo{ proxy := ProxyInfo{
Type: string(config.ProxyType), Type: string(config.ProxyType),
Version: version, Version: version,
Path: config.ProxyConfig.Path, Path: proxyConfig.Path,
Debug: config.ProxyConfig.Debug, Debug: proxyConfig.Debug,
} }
return proxy, nil return proxy, nil
} }
func getNetmonInfo(config oci.RuntimeConfig) (NetmonInfo, error) { func getNetmonInfo(config oci.RuntimeConfig) (NetmonInfo, error) {
version, err := getCommandVersion(defaultNetmonPath) netmonConfig := config.NetmonConfig
version, err := getCommandVersion(netmonConfig.Path)
if err != nil { if err != nil {
version = unknown version = unknown
} }
netmon := NetmonInfo{ netmon := NetmonInfo{
Version: version, Version: version,
Path: config.NetmonConfig.Path, Path: netmonConfig.Path,
Debug: config.NetmonConfig.Debug, Debug: netmonConfig.Debug,
Enable: config.NetmonConfig.Enable, Enable: netmonConfig.Enable,
} }
return netmon, nil return netmon, nil

View File

@ -28,7 +28,6 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
const testProxyURL = "file:///proxyURL"
const testProxyVersion = "proxy version 0.1" const testProxyVersion = "proxy version 0.1"
const testShimVersion = "shim version 0.1" const testShimVersion = "shim version 0.1"
const testNetmonVersion = "netmon version 0.1" const testNetmonVersion = "netmon version 0.1"
@ -69,10 +68,6 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
hotplugVFIOOnRootBus := true hotplugVFIOOnRootBus := true
disableNewNetNs := false disableNewNetNs := false
// override
defaultProxyPath = proxyPath
defaultNetmonPath = netmonPath
filesToCreate := []string{ filesToCreate := []string{
hypervisorPath, hypervisorPath,
kernelPath, kernelPath,
@ -115,7 +110,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
kernelParams, kernelParams,
machineType, machineType,
shimPath, shimPath,
testProxyURL, proxyPath,
netmonPath, netmonPath,
logPath, logPath,
disableBlock, disableBlock,
@ -626,7 +621,7 @@ func TestEnvGetProxyInfoNoVersion(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
// remove the proxy ensuring its version cannot be queried // remove the proxy ensuring its version cannot be queried
err = os.Remove(defaultProxyPath) err = os.Remove(config.ProxyConfig.Path)
assert.NoError(t, err) assert.NoError(t, err)
expectedProxy.Version = unknown expectedProxy.Version = unknown
@ -670,7 +665,7 @@ func TestEnvGetNetmonInfoNoVersion(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
// remove the netmon ensuring its version cannot be queried // remove the netmon ensuring its version cannot be queried
err = os.Remove(defaultNetmonPath) err = os.Remove(config.NetmonConfig.Path)
assert.NoError(t, err) assert.NoError(t, err)
expectedNetmon.Version = unknown expectedNetmon.Version = unknown