Merge pull request #1045 from JasonYangShadow/issue/967

Fix the issue that the same tag added via `node set` is ignored
This commit is contained in:
Jonathon Anderson
2024-01-24 15:59:51 -07:00
committed by GitHub
3 changed files with 72 additions and 0 deletions

View File

@@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed a bug when using `wwctl container import --force` to replace an existing container
will generate an error #474
- Create `/etc/systemd/network/10-persistent-net-<netdev>.link` file per network device
- Fix the issue that the same tag added in `node set` is ignored. #967
### Changed

View File

@@ -414,3 +414,69 @@ nodes:
run_test(t, tt)
}
}
func Test_Node_Add(t *testing.T) {
tests := []test_description{
{
args: []string{"--tagadd=email=node", "n01"},
wantErr: false,
stdout: "",
inDB: `WW_INTERNAL: 43
nodeprofiles:
default:
comment: testit
tags:
email: profile
nodes:
n01:
profiles:
- default`,
outDb: `WW_INTERNAL: 43
nodeprofiles:
default:
comment: testit
tags:
email: profile
nodes:
n01:
profiles:
- default
tags:
email: node
`},
{
args: []string{"--tagadd=newtag=newval", "n01"},
wantErr: false,
stdout: "",
inDB: `WW_INTERNAL: 43
nodeprofiles:
default:
comment: testit
tags:
email: profile
nodes:
n01:
profiles:
- default
tags:
email: node`,
outDb: `WW_INTERNAL: 43
nodeprofiles:
default:
comment: testit
tags:
email: profile
nodes:
n01:
profiles:
- default
tags:
email: node
newtag: newval
`},
}
for _, tt := range tests {
run_test(t, tt)
}
}

View File

@@ -206,6 +206,11 @@ func recursiveSetter(source, target interface{}, nameArg string, setter func(*En
newEntr := new(Entry)
setter(newEntr, sourceIter.Value().String(), nameArg)
targetValue.Elem().Field(i).SetMapIndex(sourceIter.Key(), reflect.ValueOf(newEntr))
} else {
// update the entry with latest value
if entry, ok := targetValue.Elem().Field(i).MapIndex(sourceIter.Key()).Interface().(*Entry); ok {
setter(entry, sourceIter.Value().String(), nameArg)
}
}
}
} else {