Skip to content

Commit

Permalink
cmd/microcloud/preseed: Update test
Browse files Browse the repository at this point in the history
Signed-off-by: Julian Pelizäus <[email protected]>
  • Loading branch information
roosterfish committed Sep 4, 2024
1 parent 4447909 commit f079e24
Showing 1 changed file with 29 additions and 78 deletions.
107 changes: 29 additions & 78 deletions cmd/microcloud/preseed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ func TestPreseedSuite(t *testing.T) {
func (s *preseedSuite) Test_preseedValidateInvalid() {
cases := []struct {
desc string
subnet string
iface string
systems []System
ovn InitNetwork
storage StorageFilter
Expand All @@ -31,8 +29,6 @@ func (s *preseedSuite) Test_preseedValidateInvalid() {
}{
{
desc: "No systems",
subnet: "10.0.0.1/24",
iface: "enp5s0",
systems: nil,
ovn: InitNetwork{IPv4Gateway: "10.0.0.1/24", IPv4Range: "10.0.0.100-10.0.0.254", IPv6Gateway: "cafe::1/64"},
storage: StorageFilter{
Expand All @@ -45,9 +41,7 @@ func (s *preseedSuite) Test_preseedValidateInvalid() {
},
{
desc: "Single node preseed",
subnet: "10.0.0.1/24",
iface: "enp5s0",
systems: []System{{Name: "n1", UplinkInterface: "eth0", Storage: InitStorage{}}},
systems: []System{{Name: "n1", UplinkInterface: "eth0", Address: "1.0.0.1", Storage: InitStorage{}}},
ovn: InitNetwork{IPv4Gateway: "10.0.0.1/24", IPv4Range: "10.0.0.100-10.0.0.254", IPv6Gateway: "cafe::1/64"},
storage: StorageFilter{
Local: []DiskFilter{{Find: "abc", FindMin: 0, FindMax: 3, Wipe: false}},
Expand All @@ -58,31 +52,16 @@ func (s *preseedSuite) Test_preseedValidateInvalid() {
err: nil,
},
{
desc: "Missing lookup subnet",
desc: "Missing listen address",
systems: []System{{Name: "n1"}, {Name: "n2"}},
storage: StorageFilter{
Local: []DiskFilter{{Find: "abc", FindMin: 0, FindMax: 3, Wipe: false}},
},

addErr: true,
err: errors.New("invalid CIDR address: "),
},
{
desc: "Missing lookup interface",
subnet: "10.0.0.1/24",
systems: []System{{Name: "n1"}, {Name: "n2"}},
storage: StorageFilter{
Local: []DiskFilter{{Find: "abc", FindMin: 0, FindMax: 3, Wipe: false}},
},
storage: StorageFilter{},

addErr: true,
err: errors.New("Missing interface name for machine lookup"),
err: errors.New(`Missing listen address for system "n1"`),
},
{
desc: "Systems missing name",
subnet: "10.0.0.1/24",
iface: "enp5s0",
systems: []System{{Name: "", UplinkInterface: "eth0"}, {Name: "n2", UplinkInterface: "eth0"}},
systems: []System{{Name: "", UplinkInterface: "eth0", Address: "1.0.0.1"}, {Name: "n2", UplinkInterface: "eth0", Address: "1.0.0.2"}},
ovn: InitNetwork{IPv4Gateway: "10.0.0.1/24", IPv4Range: "10.0.0.100-10.0.0.254", IPv6Gateway: "cafe::1/64"},
storage: StorageFilter{
Local: []DiskFilter{{Find: "abc", FindMin: 0, FindMax: 3, Wipe: false}},
Expand All @@ -94,9 +73,7 @@ func (s *preseedSuite) Test_preseedValidateInvalid() {
},
{
desc: "FindMin too low for ceph filter",
subnet: "10.0.0.1/24",
iface: "enp5s0",
systems: []System{{Name: "n1"}, {Name: "n2"}},
systems: []System{{Name: "n1", Address: "1.0.0.1"}, {Name: "n2", Address: "1.0.0.2"}},
storage: StorageFilter{
Local: []DiskFilter{{Find: "abc", FindMin: 0, FindMax: 3, Wipe: false}},
Ceph: []DiskFilter{{Find: "def", FindMin: 0, FindMax: 3, Wipe: false}},
Expand All @@ -106,42 +83,34 @@ func (s *preseedSuite) Test_preseedValidateInvalid() {
err: errors.New("Remote storage filter cannot be defined with find_min less than 1"),
},
{
desc: "Ceph direct selection (3) with more systems (4)",
subnet: "10.0.0.1/24",
iface: "enp5s0",
desc: "Ceph direct selection (3) with more systems (4)",
systems: []System{
{Name: "n1", Storage: InitStorage{Ceph: []DirectStorage{{Path: "def"}}}},
{Name: "n2", Storage: InitStorage{Ceph: []DirectStorage{{Path: "def"}}}},
{Name: "n3", Storage: InitStorage{Ceph: []DirectStorage{{Path: "def"}}}},
{Name: "n4"}},
{Name: "n1", Address: "1.0.0.1", Storage: InitStorage{Ceph: []DirectStorage{{Path: "def"}}}},
{Name: "n2", Address: "1.0.0.2", Storage: InitStorage{Ceph: []DirectStorage{{Path: "def"}}}},
{Name: "n3", Address: "1.0.0.3", Storage: InitStorage{Ceph: []DirectStorage{{Path: "def"}}}},
{Name: "n4", Address: "1.0.0.4"}},
addErr: false,
err: nil,
},
{
desc: "Minimum ceph direct selection (1) with more systems (4)",
subnet: "10.0.0.1/24",
iface: "enp5s0",
desc: "Minimum ceph direct selection (1) with more systems (4)",
systems: []System{
{Name: "n1", Storage: InitStorage{Ceph: []DirectStorage{{Path: "def"}}}},
{Name: "n2"},
{Name: "n3"},
{Name: "n4"}},
{Name: "n1", Address: "1.0.0.1", Storage: InitStorage{Ceph: []DirectStorage{{Path: "def"}}}},
{Name: "n2", Address: "1.0.0.2"},
{Name: "n3", Address: "1.0.0.3"},
{Name: "n4", Address: "1.0.0.4"}},
addErr: false,
err: nil,
},
{
desc: "Incomplete zfs direct selection",
subnet: "10.0.0.1/24",
iface: "enp5s0",
systems: []System{{Name: "n1", Storage: InitStorage{Local: DirectStorage{Path: "def"}}}, {Name: "n2", Storage: InitStorage{Local: DirectStorage{Path: "def"}}}, {Name: "n3"}},
systems: []System{{Name: "n1", Address: "1.0.0.1", Storage: InitStorage{Local: DirectStorage{Path: "def"}}}, {Name: "n2", Address: "1.0.0.2", Storage: InitStorage{Local: DirectStorage{Path: "def"}}}, {Name: "n3", Address: "1.0.0.3"}},
addErr: true,
err: errors.New("Some systems are missing local storage disks"),
},
{
desc: "Invalid zfs filter constraint",
subnet: "10.0.0.1/24",
iface: "enp5s0",
systems: []System{{Name: "n1"}, {Name: "n2"}},
systems: []System{{Name: "n1", Address: "1.0.0.1"}, {Name: "n2", Address: "1.0.0.2"}},
storage: StorageFilter{
Local: []DiskFilter{{Find: "abc", FindMin: 3, FindMax: 2, Wipe: false}},
},
Expand All @@ -150,9 +119,7 @@ func (s *preseedSuite) Test_preseedValidateInvalid() {
},
{
desc: "Invalid zfs filter value",
subnet: "10.0.0.1/24",
iface: "enp5s0",
systems: []System{{Name: "n1"}, {Name: "n2"}},
systems: []System{{Name: "n1", Address: "1.0.0.1"}, {Name: "n2", Address: "1.0.0.2"}},
storage: StorageFilter{
Local: []DiskFilter{{Find: "", FindMin: 3, FindMax: 2, Wipe: false}},
},
Expand All @@ -161,9 +128,7 @@ func (s *preseedSuite) Test_preseedValidateInvalid() {
},
{
desc: "Invalid ceph filter min > max",
subnet: "10.0.0.1/24",
iface: "enp5s0",
systems: []System{{Name: "n1"}, {Name: "n2"}, {Name: "n3"}},
systems: []System{{Name: "n1", Address: "1.0.0.1"}, {Name: "n2", Address: "1.0.0.2"}, {Name: "n3", Address: "1.0.0.3"}},
storage: StorageFilter{
Ceph: []DiskFilter{{Find: "def", FindMin: 4, FindMax: 3, Wipe: false}},
},
Expand All @@ -172,9 +137,7 @@ func (s *preseedSuite) Test_preseedValidateInvalid() {
},
{
desc: "Invalid ceph filter constraints",
subnet: "10.0.0.1/24",
iface: "enp5s0",
systems: []System{{Name: "n1"}, {Name: "n2"}, {Name: "n3"}},
systems: []System{{Name: "n1", Address: "1.0.0.1"}, {Name: "n2", Address: "1.0.0.2"}, {Name: "n3", Address: "1.0.0.3"}},
storage: StorageFilter{
Ceph: []DiskFilter{{Find: "", FindMin: 4, FindMax: 3, Wipe: false}},
},
Expand All @@ -183,9 +146,7 @@ func (s *preseedSuite) Test_preseedValidateInvalid() {
},
{
desc: "Systems missing interface",
subnet: "10.0.0.1/24",
iface: "enp5s0",
systems: []System{{Name: "n1", UplinkInterface: ""}, {Name: "n2", UplinkInterface: "eth0"}, {Name: "n3", UplinkInterface: "eth0"}},
systems: []System{{Name: "n1", Address: "1.0.0.1", UplinkInterface: ""}, {Name: "n2", Address: "1.0.0.2", UplinkInterface: "eth0"}, {Name: "n3", Address: "1.0.0.3", UplinkInterface: "eth0"}},
ovn: InitNetwork{IPv4Gateway: "10.0.0.1/24", IPv4Range: "10.0.0.100-10.0.0.254", IPv6Gateway: "cafe::1/64"},
storage: StorageFilter{
Local: []DiskFilter{{Find: "abc", FindMin: 0, FindMax: 3, Wipe: false}},
Expand All @@ -197,9 +158,7 @@ func (s *preseedSuite) Test_preseedValidateInvalid() {
},
{
desc: "OVN IPv4 Ranges with no gateway",
subnet: "10.0.0.1/24",
iface: "enp5s0",
systems: []System{{Name: "n1", UplinkInterface: "eth0"}, {Name: "n2", UplinkInterface: "eth0"}, {Name: "n3", UplinkInterface: "eth0"}},
systems: []System{{Name: "n1", Address: "1.0.0.1", UplinkInterface: "eth0"}, {Name: "n2", Address: "1.0.0.2", UplinkInterface: "eth0"}, {Name: "n3", Address: "1.0.0.3", UplinkInterface: "eth0"}},
ovn: InitNetwork{IPv4Range: "10.0.0.100-10.0.0.254", IPv6Gateway: "cafe::1/64"},
storage: StorageFilter{
Local: []DiskFilter{{Find: "abc", FindMin: 0, FindMax: 3, Wipe: false}},
Expand All @@ -211,9 +170,7 @@ func (s *preseedSuite) Test_preseedValidateInvalid() {
},
{
desc: "Invalid OVN IPv4 Ranges",
subnet: "10.0.0.1/24",
iface: "enp5s0",
systems: []System{{Name: "n1", UplinkInterface: "eth0"}, {Name: "n2", UplinkInterface: "eth0"}, {Name: "n3", UplinkInterface: "eth0"}},
systems: []System{{Name: "n1", Address: "1.0.0.1", UplinkInterface: "eth0"}, {Name: "n2", Address: "1.0.0.2", UplinkInterface: "eth0"}, {Name: "n3", Address: "1.0.0.3", UplinkInterface: "eth0"}},
ovn: InitNetwork{IPv4Gateway: "10.0.0.1/24", IPv4Range: "10.0.0.100,10.0.0.254", IPv6Gateway: "cafe::1/64"},
storage: StorageFilter{
Local: []DiskFilter{{Find: "abc", FindMin: 0, FindMax: 3, Wipe: false}},
Expand All @@ -226,22 +183,16 @@ func (s *preseedSuite) Test_preseedValidateInvalid() {
}

s.T().Log("Preseed init missing local system")
p := Preseed{LookupSubnet: "10.0.0.1/24", Systems: []System{{Name: "B"}, {Name: "C"}}}
p := Preseed{Systems: []System{{Name: "B", Address: "1.0.0.1"}, {Name: "C", Address: "1.0.0.2"}}}
err := p.validate("A", true)
s.EqualError(err, "Local MicroCloud must be included in the list of systems when initializing")
s.T().Log("Preseed add includes local system")
p = Preseed{LookupSubnet: "10.0.0.1/24", Systems: []System{{Name: "A"}, {Name: "B"}}}
err = p.validate("A", false)
s.EqualError(err, "Local MicroCloud must not be included in the list of systems when adding new members")

for _, c := range cases {
s.T().Log(c.desc)
p := Preseed{
LookupSubnet: c.subnet,
LookupInterface: c.iface,
Systems: c.systems,
OVN: c.ovn,
Storage: c.storage,
Systems: c.systems,
OVN: c.ovn,
Storage: c.storage,
}

err := p.validate("n1", true)
Expand Down Expand Up @@ -280,7 +231,7 @@ func (s *preseedSuite) Test_preseedMatchDisksMemory() {

// Tests that ReuseExistingClusters only works when initializing, not when growing the cluster.
func (s *preseedSuite) Test_restrictClusterReuse() {
p := Preseed{ReuseExistingClusters: true, LookupSubnet: "10.0.0.1/24", LookupInterface: "enp5s0", Systems: []System{{Name: "B"}, {Name: "C"}}}
p := Preseed{ReuseExistingClusters: true, Systems: []System{{Name: "B", Address: "1.0.0.1"}, {Name: "C", Address: "1.0.0.2"}}}

s.NoError(p.validate("B", true))

Expand Down

0 comments on commit f079e24

Please sign in to comment.