Merge pull request #1542 from JasonYangShadow/issue/1503

fix issue that --nettagdel does not work properly
This commit is contained in:
Christian Goll
2024-11-11 10:06:28 +01:00
committed by GitHub
4 changed files with 147 additions and 48 deletions

View File

@@ -91,6 +91,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Return non-zero exit code on overlay sub-commands #1423 - Return non-zero exit code on overlay sub-commands #1423
- Simplify passing of arguments to commands through `wwctl container exec`. #253 - Simplify passing of arguments to commands through `wwctl container exec`. #253
- Don't update IPMI if password isn't set. #638 - Don't update IPMI if password isn't set. #638
- Fix issue that `--nettagdel` does not work properly. #1503
## v4.5.8, 2024-10-01 ## v4.5.8, 2024-10-01

View File

@@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"os" "os"
"strings" "strings"
"testing" "testing"
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config" warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
@@ -157,7 +156,8 @@ nodes:
n01: n01:
profiles: profiles:
- default - default
`}, `,
},
{ {
name: "node list profile with comment", name: "node list profile with comment",
args: []string{"-a"}, args: []string{"-a"},
@@ -176,7 +176,8 @@ nodes:
n01: n01:
profiles: profiles:
- default - default
`}, `,
},
{ {
name: "node list profile with comment superseded", name: "node list profile with comment superseded",
args: []string{"-a"}, args: []string{"-a"},
@@ -196,7 +197,8 @@ nodes:
comment: nodecomment comment: nodecomment
profiles: profiles:
- default - default
`}, `,
},
{ {
name: "node list profile with ipmi user", name: "node list profile with ipmi user",
args: []string{"-i"}, args: []string{"-i"},
@@ -215,7 +217,8 @@ nodes:
n01: n01:
profiles: profiles:
- default - default
`}, `,
},
{ {
name: "node list profile with ipmi user superseded", name: "node list profile with ipmi user superseded",
args: []string{"-i"}, args: []string{"-i"},
@@ -236,7 +239,8 @@ nodes:
username: user username: user
profiles: profiles:
- default - default
`}, `,
},
{ {
name: "multiple profiles list", name: "multiple profiles list",
args: []string{}, args: []string{},
@@ -255,7 +259,8 @@ nodes:
profiles: profiles:
- p1 - p1
- p2 - p2
`}, `,
},
{ {
name: "multiple profiles list all", name: "multiple profiles list all",
args: []string{"-a"}, args: []string{"-a"},
@@ -274,7 +279,8 @@ nodes:
profiles: profiles:
- p1 - p1
- p2 - p2
`}, `,
},
{ {
name: "multiple overlays list long with negation", name: "multiple overlays list long with negation",
args: []string{"-l"}, args: []string{"-l"},
@@ -294,7 +300,8 @@ nodes:
n01: n01:
profiles: profiles:
- p1 - p1
`}, `,
},
{ {
name: "multiple overlays list long", name: "multiple overlays list long",
args: []string{"-l"}, args: []string{"-l"},
@@ -319,7 +326,8 @@ nodes:
runtime overlay: runtime overlay:
- nop1 - nop1
- ~rop1 - ~rop1
`}, `,
},
{ {
name: "multiple overlays list all with negation", name: "multiple overlays list all with negation",
args: []string{"-a"}, args: []string{"-a"},
@@ -346,7 +354,8 @@ nodes:
runtime overlay: runtime overlay:
- nop1 - nop1
- ~rop1 - ~rop1
`}, `,
},
{ {
name: "multiple overlays list all", name: "multiple overlays list all",
args: []string{"-a"}, args: []string{"-a"},
@@ -369,7 +378,8 @@ nodes:
- p1 - p1
runtime overlay: runtime overlay:
- nop1 - nop1
`}, `,
},
{ {
name: "network onboot", name: "network onboot",
args: []string{"-a"}, args: []string{"-a"},
@@ -385,7 +395,8 @@ nodes:
network devices: network devices:
default: default:
onboot: true onboot: true
`}, `,
},
{ {
name: "empty network device", name: "empty network device",
args: []string{"-a"}, args: []string{"-a"},
@@ -399,7 +410,8 @@ nodes:
wwnode1: wwnode1:
network devices: network devices:
default: {} default: {}
`}, `,
},
} }
conf_yml := `WW_INTERNAL: 0` conf_yml := `WW_INTERNAL: 0`
@@ -437,7 +449,6 @@ nodes:
err := baseCmd.Execute() err := baseCmd.Execute()
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(tt.stdout), strings.TrimSpace(buf.String())) assert.Equal(t, strings.TrimSpace(tt.stdout), strings.TrimSpace(buf.String()))
}) })
} }
} }
@@ -496,6 +507,7 @@ nodes:
"Interface": "", "Interface": "",
"EscapeChar": "", "EscapeChar": "",
"Write": "", "Write": "",
"Template": "",
"Tags": {} "Tags": {}
}, },
"Init": "", "Init": "",
@@ -545,6 +557,7 @@ nodes:
"Interface": "", "Interface": "",
"EscapeChar": "", "EscapeChar": "",
"Write": "", "Write": "",
"Template": "",
"Tags": {} "Tags": {}
}, },
"Init": "", "Init": "",
@@ -578,6 +591,7 @@ nodes:
"Interface": "", "Interface": "",
"EscapeChar": "", "EscapeChar": "",
"Write": "", "Write": "",
"Template": "",
"Tags": {} "Tags": {}
}, },
"Init": "", "Init": "",

View File

@@ -66,6 +66,7 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err err
NetTagDel: vars.nodeDel.NetTagsDel, NetTagDel: vars.nodeDel.NetTagsDel,
IpmiTagAdd: vars.nodeAdd.IpmiTagsAdd, IpmiTagAdd: vars.nodeAdd.IpmiTagsAdd,
IpmiTagDel: vars.nodeDel.IpmiTagsDel, IpmiTagDel: vars.nodeDel.IpmiTagsDel,
Netdev: vars.nodeAdd.Net,
AllConfs: vars.setNodeAll, AllConfs: vars.setNodeAll,
Force: vars.setForce, Force: vars.setForce,
ConfList: args, ConfList: args,

View File

@@ -72,7 +72,8 @@ nodes:
n01: n01:
profiles: profiles:
- foo - foo
`} `,
}
run_test(t, test) run_test(t, test)
} }
@@ -94,7 +95,8 @@ nodes:
n01: n01:
profiles: profiles:
- default - default
`} `,
}
run_test(t, test) run_test(t, test)
} }
@@ -114,9 +116,11 @@ nodes:
n01: n01:
ipmi: ipmi:
write: "true" write: "true"
`} `,
}
run_test(t, test) run_test(t, test)
} }
func Test_Set_Ipmi_Write_Implicit(t *testing.T) { func Test_Set_Ipmi_Write_Implicit(t *testing.T) {
test := test_description{ test := test_description{
args: []string{"--ipmiwrite", "n01"}, args: []string{"--ipmiwrite", "n01"},
@@ -133,7 +137,8 @@ nodes:
n01: n01:
ipmi: ipmi:
write: "true" write: "true"
`} `,
}
run_test(t, test) run_test(t, test)
} }
@@ -153,9 +158,11 @@ nodes:
nodeprofiles: {} nodeprofiles: {}
nodes: nodes:
n01: {} n01: {}
`} `,
}
run_test(t, test) run_test(t, test)
} }
func Test_Unset_Ipmi_Write_False(t *testing.T) { func Test_Unset_Ipmi_Write_False(t *testing.T) {
test := test_description{ test := test_description{
args: []string{"--ipmiwrite=UNDEF", "n01"}, args: []string{"--ipmiwrite=UNDEF", "n01"},
@@ -172,9 +179,11 @@ nodes:
nodeprofiles: {} nodeprofiles: {}
nodes: nodes:
n01: {} n01: {}
`} `,
}
run_test(t, test) run_test(t, test)
} }
func Test_Ipmi_Hidden_False(t *testing.T) { func Test_Ipmi_Hidden_False(t *testing.T) {
test := test_description{ test := test_description{
args: []string{"--ipmiwrite=false", "n01"}, args: []string{"--ipmiwrite=false", "n01"},
@@ -201,13 +210,62 @@ nodes:
- default - default
ipmi: ipmi:
write: "false" write: "false"
`} `,
}
run_test(t, test)
}
func Test_Add_NetTags(t *testing.T) {
test := test_description{
args: []string{"--nettagadd=dns=1.1.1.1", "n01"},
wantErr: false,
stdout: "",
inDB: `WW_INTERNAL: 43
nodeprofiles: {}
nodes:
n01: {}
`,
outDb: `WW_INTERNAL: 43
nodeprofiles: {}
nodes:
n01:
network devices:
default:
tags:
dns: 1.1.1.1
`,
}
run_test(t, test)
}
func Test_Del_NetTags(t *testing.T) {
test := test_description{
args: []string{"--netname=default", "--nettagdel=dns1,dns2", "n01"},
wantErr: false,
stdout: "",
inDB: `WW_INTERNAL: 43
nodeprofiles: {}
nodes:
n01:
network devices:
default:
tags:
dns1: 1.1.1.1
dns2: 2.2.2.2
`,
outDb: `WW_INTERNAL: 43
nodeprofiles: {}
nodes:
n01: {}
`,
}
run_test(t, test) run_test(t, test)
} }
func Test_Multiple_Set_Tests(t *testing.T) { func Test_Multiple_Set_Tests(t *testing.T) {
tests := []test_description{ tests := []test_description{
{name: "single node change profile", {
name: "single node change profile",
args: []string{"--profile=foo", "n01"}, args: []string{"--profile=foo", "n01"},
wantErr: false, wantErr: false,
stdout: "", stdout: "",
@@ -227,8 +285,10 @@ nodes:
n01: n01:
profiles: profiles:
- foo - foo
`}, `,
{name: "multiple nodes change profile", },
{
name: "multiple nodes change profile",
args: []string{"--profile=foo", "n0[1-2]"}, args: []string{"--profile=foo", "n0[1-2]"},
wantErr: false, wantErr: false,
stdout: "", stdout: "",
@@ -254,8 +314,10 @@ nodes:
n02: n02:
profiles: profiles:
- foo - foo
`}, `,
{name: "single node set ipmitag", },
{
name: "single node set ipmitag",
args: []string{"--ipmitagadd", "foo=baar", "n01"}, args: []string{"--ipmitagadd", "foo=baar", "n01"},
wantErr: false, wantErr: false,
stdout: "", stdout: "",
@@ -278,8 +340,10 @@ nodes:
ipmi: ipmi:
tags: tags:
foo: baar foo: baar
`}, `,
{name: "single node delete tag", },
{
name: "single node delete tag",
args: []string{"--tagdel", "tag1", "n01"}, args: []string{"--tagdel", "tag1", "n01"},
wantErr: false, wantErr: false,
stdout: "", stdout: "",
@@ -304,8 +368,10 @@ nodes:
- default - default
tags: tags:
tag2: value2 tag2: value2
`}, `,
{name: "single node set fs,part and disk", },
{
name: "single node set fs,part and disk",
args: []string{"--fsname=var", "--fspath=/var", "--fsformat=btrfs", "--partname=var", "--partnumber=1", "--diskname=/dev/vda", "n01"}, args: []string{"--fsname=var", "--fspath=/var", "--fsformat=btrfs", "--partname=var", "--partnumber=1", "--diskname=/dev/vda", "n01"},
wantErr: false, wantErr: false,
stdout: "", stdout: "",
@@ -335,8 +401,10 @@ nodes:
/dev/disk/by-partlabel/var: /dev/disk/by-partlabel/var:
format: btrfs format: btrfs
path: /var path: /var
`}, `,
{name: "single delete not existing fs", },
{
name: "single delete not existing fs",
args: []string{"--fsdel=foo", "n01"}, args: []string{"--fsdel=foo", "n01"},
wantErr: true, wantErr: true,
stdout: "", stdout: "",
@@ -376,8 +444,10 @@ nodes:
/dev/disk/by-partlabel/var: /dev/disk/by-partlabel/var:
format: btrfs format: btrfs
path: /var path: /var
`}, `,
{name: "single node delete existing fs", },
{
name: "single node delete existing fs",
args: []string{"--fsdel=/dev/disk/by-partlabel/var", "n01"}, args: []string{"--fsdel=/dev/disk/by-partlabel/var", "n01"},
wantErr: false, wantErr: false,
stdout: "", stdout: "",
@@ -413,8 +483,10 @@ nodes:
partitions: partitions:
var: var:
number: "1" number: "1"
`}, `,
{name: "single node delete existing partition", },
{
name: "single node delete existing partition",
args: []string{"--partdel=var", "n01"}, args: []string{"--partdel=var", "n01"},
wantErr: false, wantErr: false,
stdout: "", stdout: "",
@@ -449,8 +521,10 @@ nodes:
/dev/disk/by-partlabel/var: /dev/disk/by-partlabel/var:
format: btrfs format: btrfs
path: /var path: /var
`}, `,
{name: "single node delete existing disk", },
{
name: "single node delete existing disk",
args: []string{"--diskdel=/dev/vda", "n01"}, args: []string{"--diskdel=/dev/vda", "n01"},
wantErr: false, wantErr: false,
stdout: "", stdout: "",
@@ -484,8 +558,10 @@ nodes:
/dev/disk/by-partlabel/var: /dev/disk/by-partlabel/var:
format: btrfs format: btrfs
path: /var path: /var
`}, `,
{name: "single node set mtu", },
{
name: "single node set mtu",
args: []string{"--mtu", "1234", "--netname=mynet", "n01"}, args: []string{"--mtu", "1234", "--netname=mynet", "n01"},
wantErr: false, wantErr: false,
stdout: "", stdout: "",
@@ -508,8 +584,10 @@ nodes:
network devices: network devices:
mynet: mynet:
mtu: "1234" mtu: "1234"
`}, `,
{name: "single node set ipmitag", },
{
name: "single node set ipmitag",
args: []string{"--tagadd", "nodetag1=nodevalue1", "n01"}, args: []string{"--tagadd", "nodetag1=nodevalue1", "n01"},
wantErr: false, wantErr: false,
stdout: "", stdout: "",
@@ -545,8 +623,10 @@ nodes:
- p2 - p2
tags: tags:
nodetag1: nodevalue1 nodetag1: nodevalue1
`}, `,
{name: "single node set comma in comment", },
{
name: "single node set comma in comment",
args: []string{"n01", "--comment", "This is a , comment"}, args: []string{"n01", "--comment", "This is a , comment"},
wantErr: false, wantErr: false,
stdout: "", stdout: "",
@@ -560,7 +640,8 @@ nodeprofiles: {}
nodes: nodes:
n01: n01:
comment: This is a , comment comment: This is a , comment
`}, `,
},
} }
conf_yml := `WW_INTERNAL: 0` conf_yml := `WW_INTERNAL: 0`
@@ -610,7 +691,8 @@ nodes:
- default - default
tags: tags:
email: node email: node
`}, `,
},
{ {
args: []string{"--tagadd=newtag=newval", "n01"}, args: []string{"--tagadd=newtag=newval", "n01"},
wantErr: false, wantErr: false,
@@ -640,7 +722,8 @@ nodes:
tags: tags:
email: node email: node
newtag: newval newtag: newval
`}, `,
},
} }
for _, tt := range tests { for _, tt := range tests {