From 11c6753bd51919b93d304655e093166248f354cb Mon Sep 17 00:00:00 2001 From: Fupan Li Date: Tue, 30 Oct 2018 11:24:27 +0800 Subject: [PATCH] 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 --- cli/kata-env.go | 17 ++++++++++------- cli/kata-env_test.go | 11 +++-------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/cli/kata-env.go b/cli/kata-env.go index 2f2c38586e..40fbde85fd 100644 --- a/cli/kata-env.go +++ b/cli/kata-env.go @@ -239,7 +239,8 @@ func getProxyInfo(config oci.RuntimeConfig) (ProxyInfo, error) { return ProxyInfo{Type: string(config.ProxyType)}, nil } - version, err := getCommandVersion(defaultProxyPath) + proxyConfig := config.ProxyConfig + version, err := getCommandVersion(proxyConfig.Path) if err != nil { version = unknown } @@ -247,24 +248,26 @@ func getProxyInfo(config oci.RuntimeConfig) (ProxyInfo, error) { proxy := ProxyInfo{ Type: string(config.ProxyType), Version: version, - Path: config.ProxyConfig.Path, - Debug: config.ProxyConfig.Debug, + Path: proxyConfig.Path, + Debug: proxyConfig.Debug, } return proxy, nil } func getNetmonInfo(config oci.RuntimeConfig) (NetmonInfo, error) { - version, err := getCommandVersion(defaultNetmonPath) + netmonConfig := config.NetmonConfig + + version, err := getCommandVersion(netmonConfig.Path) if err != nil { version = unknown } netmon := NetmonInfo{ Version: version, - Path: config.NetmonConfig.Path, - Debug: config.NetmonConfig.Debug, - Enable: config.NetmonConfig.Enable, + Path: netmonConfig.Path, + Debug: netmonConfig.Debug, + Enable: netmonConfig.Enable, } return netmon, nil diff --git a/cli/kata-env_test.go b/cli/kata-env_test.go index 45a2a08f94..8defce9c58 100644 --- a/cli/kata-env_test.go +++ b/cli/kata-env_test.go @@ -28,7 +28,6 @@ import ( "github.com/stretchr/testify/assert" ) -const testProxyURL = "file:///proxyURL" const testProxyVersion = "proxy version 0.1" const testShimVersion = "shim version 0.1" const testNetmonVersion = "netmon version 0.1" @@ -69,10 +68,6 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC hotplugVFIOOnRootBus := true disableNewNetNs := false - // override - defaultProxyPath = proxyPath - defaultNetmonPath = netmonPath - filesToCreate := []string{ hypervisorPath, kernelPath, @@ -115,7 +110,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC kernelParams, machineType, shimPath, - testProxyURL, + proxyPath, netmonPath, logPath, disableBlock, @@ -626,7 +621,7 @@ func TestEnvGetProxyInfoNoVersion(t *testing.T) { assert.NoError(t, err) // remove the proxy ensuring its version cannot be queried - err = os.Remove(defaultProxyPath) + err = os.Remove(config.ProxyConfig.Path) assert.NoError(t, err) expectedProxy.Version = unknown @@ -670,7 +665,7 @@ func TestEnvGetNetmonInfoNoVersion(t *testing.T) { assert.NoError(t, err) // remove the netmon ensuring its version cannot be queried - err = os.Remove(defaultNetmonPath) + err = os.Remove(config.NetmonConfig.Path) assert.NoError(t, err) expectedNetmon.Version = unknown