check if entry has real value in recursive getter
Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
fecdce6684
commit
539002088c
@@ -41,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Fix build for API.
|
||||
- Bindd mounts for `wwctl exec` are now on the same fs
|
||||
- Fixed the ability to set MTU with wwctl #947
|
||||
- Fixed a bug where profile tags were erroneously overridden by empty node
|
||||
values. #884
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@@ -371,6 +371,43 @@ nodes:
|
||||
network devices:
|
||||
mynet:
|
||||
mtu: "1234"
|
||||
`},
|
||||
{name: "single node set ipmitag",
|
||||
args: []string{"--tagadd", "nodetag1=nodevalue1", "n01"},
|
||||
wantErr: false,
|
||||
stdout: "",
|
||||
inDB: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
p1:
|
||||
comment: testit 1
|
||||
tags:
|
||||
p1tag1: p1val1
|
||||
p2:
|
||||
comment: testit 1
|
||||
tags:
|
||||
p2tag2: p1val2
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- p1
|
||||
- p2`,
|
||||
outDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
p1:
|
||||
comment: testit 1
|
||||
tags:
|
||||
p1tag1: p1val1
|
||||
p2:
|
||||
comment: testit 1
|
||||
tags:
|
||||
p2tag2: p1val2
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- p1
|
||||
- p2
|
||||
tags:
|
||||
nodetag1: nodevalue1
|
||||
`},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -72,8 +72,12 @@ func recursiveGetter(
|
||||
// go over a simple map with strings
|
||||
for sourceIter.Next() {
|
||||
if !targetValue.Elem().Field(i).MapIndex(sourceIter.Key()).IsValid() {
|
||||
str := getter((sourceIter.Value().Interface()).(*Entry))
|
||||
targetValue.Elem().Field(i).SetMapIndex(sourceIter.Key(), reflect.ValueOf(str))
|
||||
// Only write entries for which have real values. This matters for
|
||||
// tags, as empty map elements can be created without this check
|
||||
if ((sourceIter.Value().Interface()).(*Entry)).GotReal() {
|
||||
str := getter((sourceIter.Value().Interface()).(*Entry))
|
||||
targetValue.Elem().Field(i).SetMapIndex(sourceIter.Key(), reflect.ValueOf(str))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -175,7 +179,7 @@ func recursiveSetter(source, target interface{}, nameArg string, setter func(*En
|
||||
if targetValue.Elem().Field(i).IsZero() {
|
||||
targetValue.Elem().Field(i).Set(reflect.MakeMap(targetType.Elem().Field(i).Type))
|
||||
}
|
||||
// delete a ap element which is only in the target
|
||||
// delete a map element which is only in the target
|
||||
if targetValue.Elem().Field(i).Len() > 0 && targetValue.Elem().Field(i).Len() < 0 {
|
||||
sourceIter := sourceValueMatched.MapRange()
|
||||
targetIter := targetValue.Elem().Field(i).MapRange()
|
||||
|
||||
Reference in New Issue
Block a user