Restored profile list tests and resolved exposed bugs
Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -29,7 +29,6 @@ func (profileConf *ProfileConf) Check() (err error) {
|
||||
func check(infoType reflect.Type, infoVal reflect.Value) (err error) {
|
||||
// now iterate of every field
|
||||
for i := 0; i < infoVal.Elem().NumField(); i++ {
|
||||
//wwlog.Debug("checking field: %s type: %s", infoType.Elem().Field(i).Name, infoVal.Elem().Field(i).Type())
|
||||
if infoType.Elem().Field(i).Type.Kind() == reflect.String {
|
||||
newFmt, err := checker(infoVal.Elem().Field(i).Interface().(string), infoType.Elem().Field(i).Tag.Get("type"))
|
||||
if err != nil {
|
||||
@@ -42,7 +41,6 @@ func check(infoType reflect.Type, infoVal reflect.Value) (err error) {
|
||||
nestVal := reflect.ValueOf(infoVal.Elem().Field(i).Interface())
|
||||
for j := 0; j < nestType.Elem().NumField(); j++ {
|
||||
if nestType.Elem().Field(j).Type.Kind() == reflect.String {
|
||||
//wwlog.Debug("checking field: %s type: %s", nestType.Elem().Field(j).Name, nestType.Elem().Field(j).Tag.Get("type"))
|
||||
newFmt, err := checker(nestVal.Elem().Field(j).Interface().(string), nestType.Elem().Field(j).Tag.Get("type"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("field: %s value:%s err: %s", nestType.Elem().Field(j).Name, nestVal.Elem().Field(j).String(), err)
|
||||
@@ -74,7 +72,6 @@ func checker(value string, valType string) (niceValue string, err error) {
|
||||
if valType == "" || value == "" || util.InSlice(wwtype.GetUnsetVerbs(), value) {
|
||||
return "", nil
|
||||
}
|
||||
//wwlog.Debug("checker: %s is %s", value, valType)
|
||||
switch valType {
|
||||
case "":
|
||||
return "", nil
|
||||
|
||||
@@ -87,43 +87,6 @@ func (config *NodeYaml) GetNode(id string) (node NodeConf, err error) {
|
||||
return node, err
|
||||
}
|
||||
}
|
||||
// err = mergo.Merge(&node, config.nodes[id], mergo.WithOverride, mergo.WithoutDereference)
|
||||
// err = mergo.Merge(&node, config.nodes[id], mergo.WithOverride)
|
||||
// err = mergo.Merge(&node, config.nodes[id])
|
||||
/*
|
||||
node = EmptyNode()
|
||||
var buf bytes.Buffer
|
||||
enc := gob.NewEncoder(&buf)
|
||||
dec := gob.NewDecoder(&buf)
|
||||
includedProfile, err := config.GetProfile(p)
|
||||
appendStringSlices(&node, &includedProfile)
|
||||
if err != nil {
|
||||
return node, err
|
||||
}
|
||||
err = enc.Encode(includedProfile)
|
||||
if err != nil {
|
||||
return node, err
|
||||
}
|
||||
err = dec.Decode(&node)
|
||||
if err != nil {
|
||||
return node, err
|
||||
}
|
||||
wwlog.Debug("merged in profile: %s", p)
|
||||
}
|
||||
var bufNode bytes.Buffer
|
||||
encNode := gob.NewEncoder(&bufNode)
|
||||
decNode := gob.NewDecoder(&bufNode)
|
||||
appendStringSlices(&node, &config.nodes[id].ProfileConf)
|
||||
|
||||
err = encNode.Encode(config.nodes[id])
|
||||
if err != nil {
|
||||
return node, err
|
||||
}
|
||||
err = decNode.Decode(&node)
|
||||
if err != nil {
|
||||
return node, err
|
||||
}
|
||||
*/
|
||||
// finally set no exported values
|
||||
node.id = id
|
||||
node.valid = true
|
||||
|
||||
@@ -60,7 +60,6 @@ nodes:
|
||||
}
|
||||
|
||||
func Test_Primary_Network(t *testing.T) {
|
||||
//wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
c := newConstructorPrimaryNetworkTest(t)
|
||||
test_node1, err := c.GetNode("test_node1")
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -10,11 +10,17 @@ import (
|
||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||
)
|
||||
|
||||
type sortByName []NodeConf
|
||||
type nodeList []NodeConf
|
||||
|
||||
func (a sortByName) Len() int { return len(a) }
|
||||
func (a sortByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a sortByName) Less(i, j int) bool { return a[i].id < a[j].id }
|
||||
func (a nodeList) Len() int { return len(a) }
|
||||
func (a nodeList) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a nodeList) Less(i, j int) bool { return a[i].id < a[j].id }
|
||||
|
||||
type profileList []ProfileConf
|
||||
|
||||
func (a profileList) Len() int { return len(a) }
|
||||
func (a profileList) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a profileList) Less(i, j int) bool { return a[i].id < a[j].id }
|
||||
|
||||
/**********
|
||||
*
|
||||
@@ -26,7 +32,7 @@ func (a sortByName) Less(i, j int) bool { return a[i].id < a[j].id }
|
||||
Filter a given slice of NodeConf against a given
|
||||
regular expression
|
||||
*/
|
||||
func FilterByName(set []NodeConf, searchList []string) []NodeConf {
|
||||
func FilterNodeListByName(set []NodeConf, searchList []string) []NodeConf {
|
||||
var ret []NodeConf
|
||||
unique := make(map[string]NodeConf)
|
||||
|
||||
@@ -45,14 +51,41 @@ func FilterByName(set []NodeConf, searchList []string) []NodeConf {
|
||||
ret = set
|
||||
}
|
||||
|
||||
sort.Sort(sortByName(ret))
|
||||
sort.Sort(nodeList(ret))
|
||||
return ret
|
||||
}
|
||||
|
||||
/*
|
||||
Filter a given slice of ProfileConf against a given
|
||||
regular expression
|
||||
*/
|
||||
func FilterProfileListByName(set []ProfileConf, searchList []string) []ProfileConf {
|
||||
var ret []ProfileConf
|
||||
unique := make(map[string]ProfileConf)
|
||||
|
||||
if len(searchList) > 0 {
|
||||
for _, search := range searchList {
|
||||
for _, entry := range set {
|
||||
if match, _ := regexp.MatchString("^"+search+"$", entry.id); match {
|
||||
unique[entry.id] = entry
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, n := range unique {
|
||||
ret = append(ret, n)
|
||||
}
|
||||
} else {
|
||||
ret = set
|
||||
}
|
||||
|
||||
sort.Sort(profileList(ret))
|
||||
return ret
|
||||
}
|
||||
|
||||
/*
|
||||
Filter a given map of NodeConf against given regular expression.
|
||||
*/
|
||||
func FilterNodesByName(inputMap map[string]*NodeConf, searchList []string) (retMap map[string]*NodeConf) {
|
||||
func FilterNodeMapByName(inputMap map[string]*NodeConf, searchList []string) (retMap map[string]*NodeConf) {
|
||||
retMap = map[string]*NodeConf{}
|
||||
if len(searchList) > 0 {
|
||||
for _, search := range searchList {
|
||||
@@ -67,9 +100,9 @@ func FilterNodesByName(inputMap map[string]*NodeConf, searchList []string) (retM
|
||||
}
|
||||
|
||||
/*
|
||||
Filter a given map of NodeConf against given regular expression.
|
||||
Filter a given map of ProfileConf against given regular expression.
|
||||
*/
|
||||
func FilterProfilesByName(inputMap map[string]*ProfileConf, searchList []string) (retMap map[string]*ProfileConf) {
|
||||
func FilterProfileMapByName(inputMap map[string]*ProfileConf, searchList []string) (retMap map[string]*ProfileConf) {
|
||||
retMap = map[string]*ProfileConf{}
|
||||
if len(searchList) > 0 {
|
||||
for _, search := range searchList {
|
||||
|
||||
@@ -72,7 +72,6 @@ func ObjectIsEmpty(obj interface{}) bool {
|
||||
}
|
||||
} else if varType.Field(i).Type == reflect.TypeOf(map[string]string{}) {
|
||||
if varVal.Field(i).Len() != 0 {
|
||||
// if len(varVal.Field(i).Interface().(map[string]string)) != 0 {
|
||||
return false
|
||||
}
|
||||
} else if varType.Field(i).Type.Kind() == reflect.Ptr {
|
||||
|
||||
Reference in New Issue
Block a user