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,17 +270,19 @@ func GetTopologyInfo(devs []string) (*pluginapi.TopologyInfo, error) {
} }
for _, hint := range hints { for _, hint := range hints {
for _, nNode := range strings.Split(hint.NUMAs, ",") { if hint.NUMAs != "" {
nNodeID, err := strconv.ParseInt(strings.TrimSpace(nNode), 10, 64) for _, nNode := range strings.Split(hint.NUMAs, ",") {
if err != nil { nNodeID, err := strconv.ParseInt(strings.TrimSpace(nNode), 10, 64)
return nil, errors.Wrapf(err, "unable to convert numa node %s into int64", nNode) if err != nil {
} return nil, errors.Wrapf(err, "unable to convert numa node %s into int64", nNode)
if nNodeID < 0 { }
return nil, errors.Wrapf(err, "numa node is negative: %d", nNodeID) if nNodeID < 0 {
} return nil, errors.Wrapf(err, "numa node is negative: %d", nNodeID)
if _, ok := nodeIDs[nNodeID]; !ok { }
result.Nodes = append(result.Nodes, &pluginapi.NUMANode{ID: nNodeID}) if _, ok := nodeIDs[nNodeID]; !ok {
nodeIDs[nNodeID] = struct{}{} result.Nodes = append(result.Nodes, &pluginapi.NUMANode{ID: nNodeID})
nodeIDs[nNodeID] = struct{}{}
}
} }
} }
} }

View File

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