Restored profile list tests and resolved exposed bugs

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2024-10-17 23:58:37 -04:00
parent 0be1e8464a
commit 30ac144044
25 changed files with 252 additions and 122 deletions

View File

@@ -102,7 +102,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
if err != nil {
return fmt.Errorf("could not get node list: %s", err)
}
nodes = node.FilterByName(nodes, []string{nodename})
nodes = node.FilterNodeListByName(nodes, []string{nodename})
if len(nodes) != 1 {
return fmt.Errorf("no single node idendified with %s", nodename)
}

View File

@@ -296,7 +296,6 @@ nodes:
path: /var
`},
}
// wwlog.SetLogLevel(wwlog.DEBUG)
warewulfd.SetNoDaemon()
for _, tt := range tests {
env := testenv.New(t)

View File

@@ -27,7 +27,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
args = hostlist.Expand(args)
if len(args) > 0 {
nodes = node.FilterByName(nodes, args)
nodes = node.FilterNodeListByName(nodes, args)
} else {
//nolint:errcheck
cmd.Usage()

View File

@@ -364,7 +364,6 @@ n01 RuntimeOverlay p1+nop1,rop1,rop2
t.Run(tt.name, func(t *testing.T) {
baseCmd := GetCommand()
baseCmd.SetArgs(tt.args)
//verifyOutput(t, baseCmd, tt.stdout)
buf := new(bytes.Buffer)
wwlog.SetLogWriter(buf)
wwlog.SetLogWriterErr(buf)

View File

@@ -28,7 +28,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
args = hostlist.Expand(args)
if len(args) > 0 {
nodes = node.FilterByName(nodes, args)
nodes = node.FilterNodeListByName(nodes, args)
} else {
//nolint:errcheck
cmd.Usage()

View File

@@ -29,7 +29,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
args = hostlist.Expand(args)
db = node.FilterByName(db, args)
db = node.FilterNodeListByName(db, args)
if len(db) < len(args) {
return errors.New("failed to find nodes")

View File

@@ -26,7 +26,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if len(args) > 0 {
nodes = node.FilterByName(nodes, hostlist.Expand(args))
nodes = node.FilterNodeListByName(nodes, hostlist.Expand(args))
} else {
//nolint:errcheck
cmd.Usage()

View File

@@ -26,7 +26,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if len(args) > 0 {
nodes = node.FilterByName(nodes, hostlist.Expand(args))
nodes = node.FilterNodeListByName(nodes, hostlist.Expand(args))
} else {
//nolint:errcheck
cmd.Usage()

View File

@@ -26,7 +26,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if len(args) > 0 {
nodes = node.FilterByName(nodes, hostlist.Expand(args))
nodes = node.FilterNodeListByName(nodes, hostlist.Expand(args))
} else {
//nolint:errcheck
cmd.Usage()

View File

@@ -26,7 +26,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if len(args) > 0 {
nodes = node.FilterByName(nodes, hostlist.Expand(args))
nodes = node.FilterNodeListByName(nodes, hostlist.Expand(args))
} else {
//nolint:errcheck
cmd.Usage()

View File

@@ -26,7 +26,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if len(args) > 0 {
nodes = node.FilterByName(nodes, hostlist.Expand(args))
nodes = node.FilterNodeListByName(nodes, hostlist.Expand(args))
} else {
//nolint:errcheck
cmd.Usage()

View File

@@ -26,7 +26,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if len(args) > 0 {
nodes = node.FilterByName(nodes, hostlist.Expand(args))
nodes = node.FilterNodeListByName(nodes, hostlist.Expand(args))
} else {
//nolint:errcheck
cmd.Usage()

View File

@@ -2,11 +2,14 @@ package list
import (
"bytes"
"strings"
"io"
"os"
"testing"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/warewulf/warewulf/internal/pkg/testenv"
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
"github.com/warewulf/warewulf/internal/pkg/node"
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
)
@@ -30,13 +33,127 @@ nodes:
n01:
profiles:
- default
`},
`,
},
{
name: "profile list returns multiple profiles",
args: []string{"default,test"},
stdout: `PROFILE NAME COMMENT/DESCRIPTION
default
test`,
default
test`,
inDb: `WW_INTERNAL: 45
nodeprofiles:
default: {}
test: {}
nodes:
n01:
profiles:
- default
`,
},
{
name: "profile list returns one profile",
args: []string{"test,"},
stdout: `PROFILE NAME COMMENT/DESCRIPTION
test`,
inDb: `WW_INTERNAL: 45
nodeprofiles:
default: {}
test: {}
nodes:
n01:
profiles:
- default
`,
},
{
name: "profile list returns all profiles",
args: []string{","},
stdout: `PROFILE NAME COMMENT/DESCRIPTION
default
test`,
inDb: `WW_INTERNAL: 45
nodeprofiles:
default: {}
test: {}
nodes:
n01:
profiles:
- default
`,
},
}
conf_yml := `WW_INTERNAL: 0`
tempWarewulfConf, warewulfConfErr := os.CreateTemp("", "warewulf.conf-")
assert.NoError(t, warewulfConfErr)
defer os.Remove(tempWarewulfConf.Name())
_, warewulfConfErr = tempWarewulfConf.Write([]byte(conf_yml))
assert.NoError(t, warewulfConfErr)
assert.NoError(t, tempWarewulfConf.Sync())
assert.NoError(t, warewulfconf.New().Read(tempWarewulfConf.Name()))
tempNodeConf, nodesConfErr := os.CreateTemp("", "nodes.conf-")
assert.NoError(t, nodesConfErr)
defer os.Remove(tempNodeConf.Name())
node.ConfigFile = tempNodeConf.Name()
warewulfd.SetNoDaemon()
for _, tt := range tests {
var err error
_, err = tempNodeConf.Seek(0, 0)
assert.NoError(t, err)
assert.NoError(t, tempNodeConf.Truncate(0))
_, err = tempNodeConf.Write([]byte(tt.inDb))
assert.NoError(t, err)
assert.NoError(t, tempNodeConf.Sync())
assert.NoError(t, err)
t.Run(tt.name, func(t *testing.T) {
baseCmd := GetCommand()
baseCmd.SetArgs(tt.args)
verifyOutput(t, baseCmd, tt.stdout)
})
}
}
func TestListMultipleFormats(t *testing.T) {
t.Skip("temporally skip this test")
tests := []struct {
name string
args []string
output []string
inDb string
}{
{
name: "single profile list yaml output",
args: []string{"-y"},
output: []string{"default:\n AssetKey: \"\"\n ClusterName: \"\"\n Comment: \"\"\n ContainerName: \"\"\n Discoverable: \"\"\n Disks: {}\n FileSystems: {}\n Grub: \"\"\n Id: |\n Source: explicit\n Value: default\n Init: \"\"\n Ipmi:\n EscapeChar: \"\"\n Gateway: \"\"\n Interface: \"\"\n Ipaddr: \"\"\n Netmask: \"\"\n Password: \"\"\n Port: \"\"\n Tags: null\n UserName: \"\"\n Write: \"\"\n Ipxe: \"\"\n Kernel:\n Args: \"\"\n Override: \"\"\n NetDevs: {}\n PrimaryNetDev: \"\"\n Profiles: \"\"\n Root: \"\"\n RuntimeOverlay: \"\"\n SystemOverlay: \"\"\n Tags: {}\n"},
inDb: `WW_INTERNAL: 43
nodeprofiles:
default: {}
nodes:
n01:
profiles:
- default
`,
},
{
name: "single profile list json output",
args: []string{"-j"},
output: []string{"{\"default\":{\"Id\":\"Source: explicit\\nValue: default\\n\",\"Comment\":\"\",\"ClusterName\":\"\",\"ContainerName\":\"\",\"Ipxe\":\"\",\"Grub\":\"\",\"RuntimeOverlay\":\"\",\"SystemOverlay\":\"\",\"Root\":\"\",\"Discoverable\":\"\",\"Init\":\"\",\"AssetKey\":\"\",\"Kernel\":{\"Override\":\"\",\"Args\":\"\"},\"Ipmi\":{\"Ipaddr\":\"\",\"Netmask\":\"\",\"Port\":\"\",\"Gateway\":\"\",\"UserName\":\"\",\"Password\":\"\",\"Interface\":\"\",\"EscapeChar\":\"\",\"Write\":\"\",\"Tags\":null},\"Profiles\":\"\",\"PrimaryNetDev\":\"\",\"NetDevs\":{},\"Tags\":{},\"Disks\":{},\"FileSystems\":{}}}\n"},
inDb: `WW_INTERNAL: 43
nodeprofiles:
default: {}
nodes:
n01:
profiles:
- default
`,
},
{
name: "multiple profiles list yaml output",
args: []string{"-y"},
output: []string{"default", "test"},
inDb: `WW_INTERNAL: 43
nodeprofiles:
default: {}
@@ -46,57 +163,83 @@ nodes:
profiles:
- default
`,
}, /*
{
name: "profile list returns one profiles",
args: []string{"test,"},
stdout: `PROFILE NAME COMMENT/DESCRIPTION
test --`,
inDb: `WW_INTERNAL: 43
nodeprofiles:
default: {}
test: {}
nodes:
n01:
profiles:
- default
`,
},
{
name: "profile list returns all profiles",
args: []string{","},
stdout: `PROFILE NAME COMMENT/DESCRIPTION
default --
test --`,
inDb: `WW_INTERNAL: 43
nodeprofiles:
default: {}
test: {}
nodes:
n01:
profiles:
- default
`,
},*/
},
{
name: "multiple profiles list json output",
args: []string{"-j"},
output: []string{"default", "test"},
inDb: `WW_INTERNAL: 43
nodeprofiles:
default: {}
test: {}
nodes:
n01:
profiles:
- default
`,
},
}
conf_yml := `WW_INTERNAL: 0`
tempWarewulfConf, warewulfConfErr := os.CreateTemp("", "warewulf.conf-")
assert.NoError(t, warewulfConfErr)
defer os.Remove(tempWarewulfConf.Name())
_, warewulfConfErr = tempWarewulfConf.Write([]byte(conf_yml))
assert.NoError(t, warewulfConfErr)
assert.NoError(t, tempWarewulfConf.Sync())
assert.NoError(t, warewulfconf.New().Read(tempWarewulfConf.Name()))
tempNodeConf, nodesConfErr := os.CreateTemp("", "nodes.conf-")
assert.NoError(t, nodesConfErr)
defer os.Remove(tempNodeConf.Name())
node.ConfigFile = tempNodeConf.Name()
warewulfd.SetNoDaemon()
//wwlog.SetLogLevel(wwlog.DEBUG)
for _, tt := range tests {
env := testenv.New(t)
env.WriteFile(t, "etc/warewulf/nodes.conf",
tt.inDb)
var err error
_, err = tempNodeConf.Seek(0, 0)
assert.NoError(t, err)
assert.NoError(t, tempNodeConf.Truncate(0))
_, err = tempNodeConf.Write([]byte(tt.inDb))
assert.NoError(t, err)
assert.NoError(t, tempNodeConf.Sync())
t.Run(tt.name, func(t *testing.T) {
baseCmd := GetCommand()
baseCmd.SetArgs(tt.args)
buf := new(bytes.Buffer)
baseCmd.SetOut(buf)
baseCmd.SetErr(buf)
wwlog.SetLogWriter(buf)
assert.NoError(t, baseCmd.Execute())
assert.Equal(t,
strings.Join(strings.Fields(tt.stdout), ""),
strings.Join(strings.Fields(buf.String()), ""))
err := baseCmd.Execute()
assert.NoError(t, err)
for _, output := range tt.output {
assert.Contains(t, buf.String(), output)
}
})
}
}
func verifyOutput(t *testing.T, baseCmd *cobra.Command, content string) {
stdoutR, stdoutW, _ := os.Pipe()
oriout := os.Stdout
os.Stdout = stdoutW
wwlog.SetLogWriter(os.Stdout)
baseCmd.SetOut(os.Stdout)
baseCmd.SetErr(os.Stdout)
err := baseCmd.Execute()
assert.NoError(t, err)
stdoutC := make(chan string)
go func() {
var buf bytes.Buffer
_, _ = io.Copy(&buf, stdoutR)
stdoutC <- buf.String()
}()
stdoutW.Close()
os.Stdout = oriout
stdout := <-stdoutC
assert.NotEmpty(t, stdout)
assert.Contains(t, stdout, content)
}

View File

@@ -32,7 +32,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if len(args) > 0 {
nodes = node.FilterByName(nodes, hostlist.Expand(args))
nodes = node.FilterNodeListByName(nodes, hostlist.Expand(args))
} else {
//nolint:errcheck
cmd.Usage()

View File

@@ -37,7 +37,6 @@ func NodeDelete(ndp *wwapiv1.NodeDeleteParameter) (err error) {
if err != nil {
wwlog.Error("%s", err)
} else {
//count++
wwlog.Verbose("Deleting node: %s\n", n.Id())
}
}

View File

@@ -39,7 +39,7 @@ func FilteredNodes(nodeList *wwapiv1.NodeList) *wwapiv1.NodeYaml {
os.Exit(1)
}
nodeMap, _ := nodeDB.FindAllNodes()
nodeMap = node.FilterByName(nodeMap, nodeList.Output)
nodeMap = node.FilterNodeListByName(nodeMap, nodeList.Output)
buffer, _ := yaml.Marshal(nodeMap)
retVal := wwapiv1.NodeYaml{
NodeConfMapYaml: string(buffer),

View File

@@ -32,7 +32,7 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
if nodeGet.Type == wwapiv1.GetNodeList_Simple {
nodeList.Output = append(nodeList.Output,
fmt.Sprintf("%s:=:%s:=:%s", "NODE NAME", "PROFILES", "NETWORK"))
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
for _, n := range node.FilterNodeListByName(nodes, nodeGet.Nodes) {
var netNames []string
for k := range n.NetDevs {
netNames = append(netNames, k)
@@ -44,7 +44,7 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
} else if nodeGet.Type == wwapiv1.GetNodeList_Network {
nodeList.Output = append(nodeList.Output,
fmt.Sprintf("%s:=:%s:=:%s:=:%s:=:%s:=:%s", "NODE", "NETWORK", "HWADDR", "IPADDR", "GATEWAY", "DEVICE"))
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
for _, n := range node.FilterNodeListByName(nodes, nodeGet.Nodes) {
if len(n.NetDevs) > 0 {
for name := range n.NetDevs {
nodeList.Output = append(nodeList.Output,
@@ -62,7 +62,7 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
} else if nodeGet.Type == wwapiv1.GetNodeList_Ipmi {
nodeList.Output = append(nodeList.Output,
fmt.Sprintf("%s:=:%s:=:%s:=:%s:=:%s", "NODE", "IPMI IPADDR", "IPMI PORT", "IPMI USERNAME", "IPMI INTERFACE"))
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
for _, n := range node.FilterNodeListByName(nodes, nodeGet.Nodes) {
nodeList.Output = append(nodeList.Output,
fmt.Sprintf("%s:=:%s:=:%s:=:%s:=:%s:=:%s", n.Id(),
n.Ipmi.Ipaddr.String(),
@@ -74,7 +74,7 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
} else if nodeGet.Type == wwapiv1.GetNodeList_Long {
nodeList.Output = append(nodeList.Output,
fmt.Sprintf("%s:=:%s:=:%s:=:%s", "NODE NAME", "KERNEL OVERRIDE", "CONTAINER", "OVERLAYS (S/R)"))
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
for _, n := range node.FilterNodeListByName(nodes, nodeGet.Nodes) {
nodeList.Output = append(nodeList.Output,
fmt.Sprintf("%s:=:%s:=:%s:=:%s", n.Id(),
n.Kernel.Override,
@@ -82,7 +82,7 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
strings.Join(n.SystemOverlay, ",")+"/"+strings.Join(n.RuntimeOverlay, ",")))
}
} else if nodeGet.Type == wwapiv1.GetNodeList_All {
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
for _, n := range node.FilterNodeListByName(nodes, nodeGet.Nodes) {
nodeList.Output = append(nodeList.Output,
fmt.Sprintf("%s:=:%s:=:%s:=:%s", "NODE", "FIELD", "PROFILE", "VALUE"))
fields := nodeDB.GetFields(n)
@@ -92,7 +92,7 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
}
}
} else if nodeGet.Type == wwapiv1.GetNodeList_YAML || nodeGet.Type == wwapiv1.GetNodeList_JSON {
filterNodes := node.FilterByName(nodes, nodeGet.Nodes)
filterNodes := node.FilterNodeListByName(nodes, nodeGet.Nodes)
var buf []byte
if nodeGet.Type == wwapiv1.GetNodeList_JSON {
buf, _ = json.MarshalIndent(filterNodes, "", " ")

View File

@@ -41,7 +41,6 @@ func NodeSetParameterCheck(set *wwapiv1.ConfSetParameter) (nodeDB node.NodeYaml,
wwlog.Error("Could not open configuration: %s", err)
return
}
//func AbstractSetParameterCheck(set *wwapiv1.ConfSetParameter, confMap map[string]*node.NodeConf, confs []string) (count uint, err error) {
if set == nil {
err = fmt.Errorf("node set parameter is nil")
return

View File

@@ -38,9 +38,9 @@ func FilteredProfiles(profileList *wwapiv1.NodeList) *wwapiv1.NodeYaml {
wwlog.Error("Could not open nodeDB: %s\n", err)
os.Exit(1)
}
profileMap, _ := nodeDB.FindAllProfiles()
//profileMap = node.FilterProfilesByName(profileMap, profileList.Output)
buffer, _ := yaml.Marshal(profileMap)
profiles, _ := nodeDB.FindAllProfiles()
profiles = node.FilterProfileListByName(profiles, profileList.Output)
buffer, _ := yaml.Marshal(profiles)
retVal := wwapiv1.NodeYaml{
NodeConfMapYaml: string(buffer),
}

View File

@@ -23,7 +23,7 @@ func ProfileList(ShowOpt *wwapiv1.GetProfileList) (profileList wwapiv1.ProfileLi
if err != nil {
return
}
//profiles = node.FilterByName(profiles, ShowOpt.Profiles)
profiles = node.FilterProfileListByName(profiles, ShowOpt.Profiles)
sort.Slice(profiles, func(i, j int) bool {
return profiles[i].Id() < profiles[j].Id()
})

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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 {