Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.

Commit 75198e7

Browse files
committed
BUG/MINOR: global: fix numa-cpu-mapping parsing
1 parent 0a469b2 commit 75198e7

8 files changed

Lines changed: 267 additions & 1 deletion

File tree

parsers/numa-cpu-mapping.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Copyright 2022 HAProxy Technologies
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package parsers
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/haproxytech/config-parser/v4/common"
23+
"github.com/haproxytech/config-parser/v4/errors"
24+
"github.com/haproxytech/config-parser/v4/types"
25+
)
26+
27+
type NumaCPUMapping struct {
28+
data *types.NumaCPUMapping
29+
preComments []string // comments that appear before the the actual line
30+
}
31+
32+
func (n *NumaCPUMapping) Parse(line string, parts []string, comment string) (string, error) {
33+
if len(parts) > 0 && parts[0] == "numa-cpu-mapping" {
34+
n.data = &types.NumaCPUMapping{
35+
NoOption: false,
36+
Comment: comment,
37+
}
38+
return "", nil
39+
} else if len(parts) > 1 && parts[0] == "no" && parts[1] == "numa-cpu-mapping" {
40+
n.data = &types.NumaCPUMapping{
41+
NoOption: true,
42+
Comment: comment,
43+
}
44+
return "", nil
45+
}
46+
return "", &errors.ParseError{Parser: "NumaCPUMapping", Line: line}
47+
}
48+
49+
func (n *NumaCPUMapping) Result() ([]common.ReturnResultLine, error) {
50+
if n.data == nil {
51+
return nil, errors.ErrFetch
52+
}
53+
noOption := ""
54+
if n.data.NoOption {
55+
noOption = "no "
56+
}
57+
return []common.ReturnResultLine{
58+
{
59+
Data: fmt.Sprintf("%s%s", noOption, "numa-cpu-mapping"),
60+
Comment: n.data.Comment,
61+
},
62+
}, nil
63+
}

parsers/numa-cpu-mapping_generated.go

Lines changed: 99 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

section-parsers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (p *configParser) getGlobalParser() *Parsers {
339339
addParser(parser, &sequence, &simple.String{Name: "lua-load-per-thread"})
340340
addParser(parser, &sequence, &simple.Number{Name: "mworker-max-reloads"})
341341
addParser(parser, &sequence, &simple.String{Name: "node"})
342-
addParser(parser, &sequence, &simple.Enabled{Name: "numa-cpu-mapping"})
342+
addParser(parser, &sequence, &parsers.NumaCPUMapping{})
343343
addParser(parser, &sequence, &simple.Enabled{Name: "pp2-never-send-local"})
344344
addParser(parser, &sequence, &simple.Number{Name: "ulimit-n"})
345345
addParser(parser, &sequence, &simple.Enabled{Name: "set-dumpable"})

tests/configs/haproxy_generated.cfg.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/global_data_test.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/global_test.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/numa-cpu-mapping_generated_test.go

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,3 +1463,12 @@ type Source struct {
14631463
Interface string
14641464
Comment string
14651465
}
1466+
1467+
//sections:global
1468+
//name:numa-cpu-mapping
1469+
//test:ok:numa-cpu-mapping
1470+
//test:ok:no numa-cpu-mapping
1471+
type NumaCPUMapping struct {
1472+
NoOption bool
1473+
Comment string
1474+
}

0 commit comments

Comments
 (0)