topology: avoid unnecessary warning prints

Doing strings.Split with a non-empty separator against a potentially
empty string (hint.NUMAs) may return an empty string in a slice of
size one, which then doesn't parse nicely with ParseInt and results
in a repeating warning.

It is better to check for hint.NUMAs emptiness before trying to
split it.

Signed-off-by: Ukri Niemimuukko <ukri.niemimuukko@intel.com>
This commit is contained in:
Ukri Niemimuukko 2020-04-16 16:14:36 +03:00
parent f261b27423
commit 39c934b22f
2 changed files with 16 additions and 14 deletions

View File

@ -270,6 +270,7 @@ func GetTopologyInfo(devs []string) (*pluginapi.TopologyInfo, error) {
}
for _, hint := range hints {
if hint.NUMAs != "" {
for _, nNode := range strings.Split(hint.NUMAs, ",") {
nNodeID, err := strconv.ParseInt(strings.TrimSpace(nNode), 10, 64)
if err != nil {
@ -285,6 +286,7 @@ func GetTopologyInfo(devs []string) (*pluginapi.TopologyInfo, error) {
}
}
}
}
sort.Slice(result.Nodes, func(i, j int) bool { return result.Nodes[i].ID < result.Nodes[j].ID })
return &result, nil
}

View File

@ -373,10 +373,10 @@ func TestGetTopologyInfo(t *testing.T) {
expectedErr: true,
},
{
name: "incorrect numa node ID",
name: "valid: missing numa node ID",
input: []string{"/dev/random"},
output: nil,
expectedErr: true,
output: &pluginapi.TopologyInfo{},
expectedErr: false,
},
}
for _, test := range cases {