overlays from different profiles are merged

If a node contains several profiles and these profiles have
overlays attached, these profiles are now merged. Overlays
can't be excluded as this can not be displayed to the user

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Christian Goll
2023-10-09 15:26:42 +02:00
committed by Jonathon Anderson
parent 67998ce6b6
commit 85eaa20708
3 changed files with 72 additions and 8 deletions

View File

@@ -138,3 +138,60 @@ func Test_FindDiscoverableNode(t *testing.T) {
})
}
}
func Test_Profile_Overlay_Merge(t *testing.T) {
nodesconf := `
nodeprofiles:
profile1:
runtime overlay:
- p1o1
- p1o2
profile2:
runtime overlay:
- p2o1
- p2o2
nodes:
node1:
profiles:
- profile1
node2:
profiles:
- profile1
- profile2
node3:
runtime overlay:
- n1o1
- n1o2
profiles:
- profile1
node4:
runtime overlay:
- n1o1
- n1o2
profiles:
- profile1
- profile2
`
assert := assert.New(t)
var ymlSrc NodeYaml
err := yaml.Unmarshal([]byte(nodesconf), &ymlSrc)
assert.NoError(err)
nodes, err := ymlSrc.FindAllNodes()
assert.NoError(err)
nodemap := make(map[string]*NodeInfo)
for i := range nodes {
nodemap[nodes[i].Id.Get()] = &nodes[i]
}
assert.Contains(nodemap, "node1")
assert.ElementsMatch(nodemap["node1"].RuntimeOverlay.GetSlice(), []string{"p1o1", "p1o2"})
assert.Equal(nodemap["node1"].RuntimeOverlay.Print(), "p1o1,p1o2")
assert.Contains(nodemap, "node2")
assert.ElementsMatch(nodemap["node2"].RuntimeOverlay.GetSlice(), []string{"p1o1", "p1o2", "p2o1", "p2o2"})
assert.Equal(nodemap["node2"].RuntimeOverlay.Print(), "p1o1,p1o2,p2o1,p2o2")
assert.Contains(nodemap, "node3")
assert.ElementsMatch(nodemap["node3"].RuntimeOverlay.GetSlice(), []string{"p1o1", "p1o2", "n1o1", "n1o2"})
assert.Equal(nodemap["node3"].RuntimeOverlay.Print(), "n1o1,n1o2,p1o1,p1o2")
assert.Contains(nodemap, "node4")
assert.ElementsMatch(nodemap["node4"].RuntimeOverlay.GetSlice(), []string{"p1o1", "p1o2", "p2o1", "p2o2", "n1o1", "n1o2"})
assert.Equal(nodemap["node4"].RuntimeOverlay.Print(), "n1o1,n1o2,p1o1,p1o2,p2o1,p2o2")
}

View File

@@ -152,8 +152,8 @@ func (ent *Entry) SetAltSlice(val []string, from string) {
if len(val) == 0 {
return
}
ent.altvalue = val
ent.from = from
ent.altvalue = append(ent.altvalue, val...)
ent.from = ent.from + "," + from
}
/*
@@ -200,7 +200,7 @@ func (ent *Entry) SliceRemoveElement(val string) {
*
*********/
/*
Gets the the entry of the value in folowing order
Gets the the entry of the value in following order
* node value if set
* profile value if set
* default value if set
@@ -244,10 +244,13 @@ Returns a string slice created from a comma seperated list of the value.
func (ent *Entry) GetSlice() []string {
var retval []string
if len(ent.value) != 0 {
return ent.value
retval = ent.value
}
if len(ent.altvalue) != 0 {
return ent.altvalue
retval = append(retval, ent.altvalue...)
}
if len(retval) != 0 {
return retval
}
if len(ent.def) != 0 {
return ent.def
@@ -324,12 +327,15 @@ Returns the value of Entry if it was defined set or
alternative is presend. Default value is in '()'. If
nothing is defined '--' is returned.
*/
func (ent *Entry) Print() string {
func (ent *Entry) Print() (ret string) {
if len(ent.value) != 0 {
return strings.Join(ent.value, ",")
ret = strings.Join(ent.value, ",")
}
if len(ent.altvalue) != 0 {
return strings.Join(ent.altvalue, ",")
ret = strings.Join(append(ent.value, ent.altvalue...), ",")
}
if ret != "" {
return ret
}
if len(ent.def) != 0 {
return "(" + strings.Join(ent.def, ",") + ")"