From 48e13085d6d1a363a89f5f97ebc3e7a192a28443 Mon Sep 17 00:00:00 2001 From: Cedric Koch-Hofer Date: Mon, 22 Aug 2022 08:50:43 +0000 Subject: [PATCH] DAOS-12746 control: Support of of NetSVC Azure VM NIC Integrate reviewers comments: * Rename FindEnvValue and associated functions https://github.com/daos-stack/daos/pull/12465#discussion_r1246202323 * Remove useless slice initialization with make https://github.com/daos-stack/daos/pull/12465#discussion_r1242789397 * Remove useless slice initialization with make https://github.com/daos-stack/daos/pull/12465#discussion_r1242789489 Features: control Required-githooks: true Signed-off-by: Cedric Koch-Hofer --- src/control/common/env_utils.go | 21 ++++++++++----------- src/control/common/env_utils_test.go | 4 ++-- src/control/lib/hardware/sysfs/provider.go | 7 ++----- src/control/server/config/server.go | 4 ++-- src/control/server/engine/config.go | 10 +++++----- src/control/server/engine/exec.go | 10 +++++----- 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/control/common/env_utils.go b/src/control/common/env_utils.go index 8726e6b5edc..83bf89d329e 100644 --- a/src/control/common/env_utils.go +++ b/src/control/common/env_utils.go @@ -78,9 +78,9 @@ func BoolAsInt(b bool) int { return 0 } -// FindEnvValue will return value from supplied name key if found in input slice of key-pairs -// (environment). ErrNotExist error returned if key cannot be found. -func FindEnvValue(keyPairs []string, name string) (string, error) { +// FindKeyValue will return value from supplied name key if found in input slice of key-pairs +// (e.g. environment). ErrNotExist error returned if key cannot be found. +func FindKeyValue(keyPairs []string, name string) (string, error) { for _, pair := range keyPairs { kv := strings.SplitN(pair, "=", 2) if len(kv) == 2 && kv[0] == name { @@ -91,8 +91,8 @@ func FindEnvValue(keyPairs []string, name string) (string, error) { return "", errors.Wrapf(os.ErrNotExist, "Undefined environment variable %q", name) } -// UpdateEnvValue updates a value for existing key and returns new slice of key-value pairs. -func UpdateEnvValue(keyPairs []string, name, newValue string) ([]string, error) { +// UpdateKeyValue updates a value for existing key and returns new slice of key-value pairs. +func UpdateKeyValue(keyPairs []string, name, newValue string) ([]string, error) { for i, pair := range keyPairs { kv := strings.SplitN(pair, "=", 2) if len(kv) == 2 && kv[0] == name { @@ -104,8 +104,8 @@ func UpdateEnvValue(keyPairs []string, name, newValue string) ([]string, error) return nil, errors.Wrapf(os.ErrNotExist, "Undefined environment variable %q", name) } -// DeleteEnvValue removes an existing key and returns new slice of key-value pairs. -func DeleteEnvValue(keyPairs []string, name string) ([]string, error) { +// DeleteKeyValue removes an existing key and returns new slice of key-value pairs. +func DeleteKeyValue(keyPairs []string, name string) ([]string, error) { for i, pair := range keyPairs { kv := strings.SplitN(pair, "=", 2) if len(kv) == 2 && kv[0] == name { @@ -116,10 +116,9 @@ func DeleteEnvValue(keyPairs []string, name string) ([]string, error) { return nil, errors.Wrapf(os.ErrNotExist, "Undefined environment variable %q", name) } -// MergeEnvVars merges and deduplicates two slices of environment -// variables. Conflicts are resolved by taking the value from the -// second list. -func MergeEnvVars(curVars []string, newVars []string) (merged []string) { +// MergeKeyValues merges and deduplicates two slices of key-value pairs. Conflicts are resolved by +// taking the value from the second list. +func MergeKeyValues(curVars []string, newVars []string) (merged []string) { mergeMap := make(map[string]string) for _, pair := range curVars { kv := strings.SplitN(pair, "=", 2) diff --git a/src/control/common/env_utils_test.go b/src/control/common/env_utils_test.go index f0d29b4f622..2de752e0810 100644 --- a/src/control/common/env_utils_test.go +++ b/src/control/common/env_utils_test.go @@ -163,7 +163,7 @@ func TestScrubProxyVariables(t *testing.T) { } } -func TestCommon_MergeEnvVars(t *testing.T) { +func TestCommon_MergeKeyValues(t *testing.T) { for name, tc := range map[string]struct { baseVars []string mergeVars []string @@ -206,7 +206,7 @@ func TestCommon_MergeEnvVars(t *testing.T) { }, } { t.Run(name, func(t *testing.T) { - gotVars := MergeEnvVars(tc.baseVars, tc.mergeVars) + gotVars := MergeKeyValues(tc.baseVars, tc.mergeVars) if diff := cmp.Diff(tc.wantVars, gotVars, defCmpOpts...); diff != "" { t.Fatalf("(-want, +got):\n%s", diff) } diff --git a/src/control/lib/hardware/sysfs/provider.go b/src/control/lib/hardware/sysfs/provider.go index 48b4f50a906..d064e272be1 100644 --- a/src/control/lib/hardware/sysfs/provider.go +++ b/src/control/lib/hardware/sysfs/provider.go @@ -50,7 +50,7 @@ func isNetvscDevice(path string, subsystem string) bool { return false } - val, err := common.FindEnvValue(strings.Split(string(content), "\n"), "DRIVER") + val, err := common.FindKeyValue(strings.Split(string(content), "\n"), "DRIVER") return err == nil && val == netvscDriver } @@ -123,7 +123,7 @@ func (s *Provider) topologySubsystems() []string { } func (s *Provider) addSubsystemDevices(topo *hardware.Topology, subsystem string) error { - netvscPaths := make([]string, 0) + var netvscPaths []string subsysRoot := s.sysPath("class", subsystem) err := filepath.Walk(subsysRoot, func(path string, fi os.FileInfo, err error) error { if fi == nil { @@ -267,9 +267,6 @@ func (s *Provider) addNetvscDevice(topo *hardware.Topology, path string) error { virt.BackingDevice = backingDev s.log.Tracef("Adding NetVSC network adapter at %q", path) - if len(topo.VirtualDevices) == 0 { - topo.VirtualDevices = make([]*hardware.VirtualDevice, 0) - } topo.VirtualDevices = append(topo.VirtualDevices, virt) return nil diff --git a/src/control/server/config/server.go b/src/control/server/config/server.go index 0414069fd1a..f408aa8a927 100644 --- a/src/control/server/config/server.go +++ b/src/control/server/config/server.go @@ -133,7 +133,7 @@ func (cfg *Server) WithFabricProvider(provider string) *Server { // WithFabricAuthKey sets the top-level fabric authorization key. func (cfg *Server) WithFabricAuthKey(key string) *Server { cfg.Fabric.AuthKey = key - cfg.ClientEnvVars = common.MergeEnvVars(cfg.ClientEnvVars, []string{cfg.Fabric.GetAuthKeyEnv()}) + cfg.ClientEnvVars = common.MergeKeyValues(cfg.ClientEnvVars, []string{cfg.Fabric.GetAuthKeyEnv()}) for _, engine := range cfg.Engines { engine.Fabric.AuthKey = cfg.Fabric.AuthKey } @@ -370,7 +370,7 @@ func (cfg *Server) Load() error { } if cfg.Fabric.AuthKey != "" { - cfg.ClientEnvVars = common.MergeEnvVars(cfg.ClientEnvVars, []string{cfg.Fabric.GetAuthKeyEnv()}) + cfg.ClientEnvVars = common.MergeKeyValues(cfg.ClientEnvVars, []string{cfg.Fabric.GetAuthKeyEnv()}) } return nil diff --git a/src/control/server/engine/config.go b/src/control/server/engine/config.go index b5e1a2fed79..b7fe03e4cf7 100644 --- a/src/control/server/engine/config.go +++ b/src/control/server/engine/config.go @@ -274,10 +274,10 @@ func (c *Config) CmdLineEnv() ([]string, error) { if err != nil { return nil, err } - env = common.MergeEnvVars(env, sEnv) + env = common.MergeKeyValues(env, sEnv) } - return common.MergeEnvVars(c.EnvVars, env), nil + return common.MergeKeyValues(c.EnvVars, env), nil } // HasEnvVar returns true if the configuration contains @@ -299,16 +299,16 @@ func (c *Config) GetEnvVar(name string) (string, error) { return "", err } - env = common.MergeEnvVars(cleanEnvVars(os.Environ(), c.EnvPassThrough), env) + env = common.MergeKeyValues(cleanEnvVars(os.Environ(), c.EnvPassThrough), env) - return common.FindEnvValue(env, name) + return common.FindKeyValue(env, name) } // WithEnvVars applies the supplied list of environment // variables to any existing variables, with new values // overwriting existing values. func (c *Config) WithEnvVars(newVars ...string) *Config { - c.EnvVars = common.MergeEnvVars(c.EnvVars, newVars) + c.EnvVars = common.MergeKeyValues(c.EnvVars, newVars) return c } diff --git a/src/control/server/engine/exec.go b/src/control/server/engine/exec.go index b445b048bcc..c7abed7e2b4 100644 --- a/src/control/server/engine/exec.go +++ b/src/control/server/engine/exec.go @@ -126,12 +126,12 @@ func (r *Runner) run(parent context.Context, args, env []string, exitCh RunnerEx // Try to integrate DD_SUBSYS into D_LOG_MASK then unset DD_SUBSYS in environment. func processLogEnvs(env []string) ([]string, error) { - subsys, err := common.FindEnvValue(env, envLogSubsystems) + subsys, err := common.FindKeyValue(env, envLogSubsystems) if err != nil || subsys == "" { return env, nil // No DD_SUBSYS to process. } - logMasks, err := common.FindEnvValue(env, envLogMasks) + logMasks, err := common.FindKeyValue(env, envLogMasks) if err != nil || logMasks == "" { return env, nil // No D_LOG_MASK to process. } @@ -144,12 +144,12 @@ func processLogEnvs(env []string) ([]string, error) { return nil, errors.New("empty log masks string is invalid") } - env, err = common.UpdateEnvValue(env, envLogMasks, newLogMasks) + env, err = common.UpdateKeyValue(env, envLogMasks, newLogMasks) if err != nil { return nil, err } - env, err = common.DeleteEnvValue(env, envLogSubsystems) + env, err = common.DeleteKeyValue(env, envLogSubsystems) if err != nil && !errors.Is(err, os.ErrNotExist) { return nil, err } @@ -167,7 +167,7 @@ func (r *Runner) Start(ctx context.Context) (RunnerExitChan, error) { if err != nil { return nil, err } - env = common.MergeEnvVars(cleanEnvVars(os.Environ(), r.Config.EnvPassThrough), env) + env = common.MergeKeyValues(cleanEnvVars(os.Environ(), r.Config.EnvPassThrough), env) env, err = processLogEnvs(env) if err != nil {