From d3e5a05f5d0b2304ab5de1de2daa57d7e52b38e7 Mon Sep 17 00:00:00 2001 From: iljarotar Date: Wed, 18 Sep 2024 09:34:32 +0200 Subject: [PATCH] remove swp0 from all tests --- cmd/metal-api/internal/datastore/switch.go | 2 +- cmd/metal-api/internal/metal/switch_test.go | 42 +++++++++---------- .../machine-service_allocation_test.go | 2 +- .../internal/service/switch-service_test.go | 10 ++--- cmd/metal-api/internal/testdata/testdata.go | 28 +++---------- 5 files changed, 33 insertions(+), 51 deletions(-) diff --git a/cmd/metal-api/internal/datastore/switch.go b/cmd/metal-api/internal/datastore/switch.go index 311e10ad..1f8b4e34 100644 --- a/cmd/metal-api/internal/datastore/switch.go +++ b/cmd/metal-api/internal/datastore/switch.go @@ -177,7 +177,7 @@ func (rs *RethinkStore) ConnectMachineWithSwitches(m *metal.Machine) error { if err != nil { return err } - // e.g. "swp0s0" -> "Ethernet0" + // e.g. "swp1s0" -> "Ethernet0" switchPortMapping, err := s1.MapPortNames(s2.OS.Vendor) if err != nil { return fmt.Errorf("could not create port mapping %w", err) diff --git a/cmd/metal-api/internal/metal/switch_test.go b/cmd/metal-api/internal/metal/switch_test.go index 86ed0961..eaa85a7f 100644 --- a/cmd/metal-api/internal/metal/switch_test.go +++ b/cmd/metal-api/internal/metal/switch_test.go @@ -294,19 +294,19 @@ func TestSwitch_TranslateNicMap(t *testing.T) { name: "both twins have the same os", sw: &Switch{ Nics: []Nic{ - {Name: "swp0s0"}, - {Name: "swp0s1"}, - {Name: "swp0s2"}, - {Name: "swp0s3"}, + {Name: "swp1s0"}, + {Name: "swp1s1"}, + {Name: "swp1s2"}, + {Name: "swp1s3"}, }, OS: &SwitchOS{Vendor: SwitchOSVendorCumulus}, }, targetOS: SwitchOSVendorCumulus, want: map[string]*Nic{ - "swp0s0": {Name: "swp0s0"}, - "swp0s1": {Name: "swp0s1"}, - "swp0s2": {Name: "swp0s2"}, - "swp0s3": {Name: "swp0s3"}, + "swp1s0": {Name: "swp1s0"}, + "swp1s1": {Name: "swp1s1"}, + "swp1s2": {Name: "swp1s2"}, + "swp1s3": {Name: "swp1s3"}, }, wantErr: false, }, @@ -432,10 +432,10 @@ func TestSwitch_MapPortNames(t *testing.T) { name: "cumulus names in sonic switch", sw: &Switch{ Nics: []Nic{ - {Name: "swp0s0"}, - {Name: "swp0s1"}, - {Name: "swp0s2"}, - {Name: "swp0s3"}, + {Name: "swp1s0"}, + {Name: "swp1s1"}, + {Name: "swp1s2"}, + {Name: "swp1s3"}, }, OS: &SwitchOS{Vendor: SwitchOSVendorSonic}, }, @@ -447,7 +447,7 @@ func TestSwitch_MapPortNames(t *testing.T) { name: "invalid name", sw: &Switch{ Nics: []Nic{ - {Name: "swp0s"}, + {Name: "swp1s"}, }, OS: &SwitchOS{Vendor: SwitchOSVendorSonic}, }, @@ -532,7 +532,7 @@ func Test_getLinesFromPortNames(t *testing.T) { }{ { name: "invalid switch os", - ports: []string{"swp0", "swp1s2"}, + ports: []string{"swp1", "swp1s2"}, os: "cumulus", want: nil, wantErr: true, @@ -546,7 +546,7 @@ func Test_getLinesFromPortNames(t *testing.T) { }, { name: "mismatch between port names and os sonic", - ports: []string{"swp0s0", "swp0s1"}, + ports: []string{"swp1s0", "swp1s1"}, os: SwitchOSVendorSonic, want: nil, wantErr: true, @@ -597,9 +597,9 @@ func Test_sonicPortNameToLine(t *testing.T) { }, { name: "missing prefix 'Ethernet'", - port: "swp0s0", + port: "swp1s0", want: 0, - wantErr: fmt.Errorf("invalid port name swp0s0, expected to find prefix 'Ethernet'"), + wantErr: fmt.Errorf("invalid port name swp1s0, expected to find prefix 'Ethernet'"), }, { name: "invalid prefix before 'Ethernet'", @@ -635,7 +635,7 @@ func Test_sonicPortNameToLine(t *testing.T) { } func Test_cumulusPortNameToLine(t *testing.T) { - _, parseIntError1 := strconv.Atoi("0t0") + _, parseIntError1 := strconv.Atoi("1t0") _, parseIntError2 := strconv.Atoi("_0") tests := []struct { @@ -658,13 +658,13 @@ func Test_cumulusPortNameToLine(t *testing.T) { }, { name: "invalid prefix before 'swp'", - port: "port_swp0s0", + port: "port_swp1s0", want: 0, - wantErr: fmt.Errorf("invalid port name port_swp0s0, port name is expected to start with 'swp'"), + wantErr: fmt.Errorf("invalid port name port_swp1s0, port name is expected to start with 'swp'"), }, { name: "wrong delimiter", - port: "swp0t0", + port: "swp1t0", want: 0, wantErr: fmt.Errorf("unable to convert port name to line number: %w", parseIntError1), }, diff --git a/cmd/metal-api/internal/service/machine-service_allocation_test.go b/cmd/metal-api/internal/service/machine-service_allocation_test.go index c5c61f65..f0f7f0ed 100644 --- a/cmd/metal-api/internal/service/machine-service_allocation_test.go +++ b/cmd/metal-api/internal/service/machine-service_allocation_test.go @@ -89,7 +89,7 @@ func TestMachineAllocationIntegration(t *testing.T) { e, _ := errgroup.WithContext(context.Background()) for i := range machineCount { e.Go(func() error { - mr := createMachineRegisterRequest(i) + mr := createMachineRegisterRequest(i + 1) err := retry.Do( func() error { var err2 error diff --git a/cmd/metal-api/internal/service/switch-service_test.go b/cmd/metal-api/internal/service/switch-service_test.go index 80d2dae7..aad60efd 100644 --- a/cmd/metal-api/internal/service/switch-service_test.go +++ b/cmd/metal-api/internal/service/switch-service_test.go @@ -1719,7 +1719,7 @@ func TestToggleSwitchNicWithoutMachine(t *testing.T) { require.Equal(t, result.Message, fmt.Sprintf("switch %q does not have a connected machine at port %q", testdata.Switch1.ID, testdata.Switch1.Nics[1].Name)) } -func Test_adjustNics(t *testing.T) { +func Test_adjustMachineNics(t *testing.T) { tests := []struct { name string nics metal.Nics @@ -1792,7 +1792,7 @@ func Test_adjustNics(t *testing.T) { MacAddress: "11:11:11:11:11:11", Neighbors: []metal.Nic{ { - Name: "swp1", + Name: "swp2", MacAddress: "aa:aa:aa:aa:aa:aa", }, }, @@ -1802,7 +1802,7 @@ func Test_adjustNics(t *testing.T) { MacAddress: "11:11:11:11:11:22", Neighbors: []metal.Nic{ { - Name: "swp1", + Name: "swp2", MacAddress: "aa:aa:aa:aa:aa:bb", }, }, @@ -1811,13 +1811,13 @@ func Test_adjustNics(t *testing.T) { connections: []metal.Connection{ { Nic: metal.Nic{ - Name: "swp1", + Name: "swp2", MacAddress: "aa:aa:aa:aa:aa:aa", }, }, }, nicMap: map[string]*metal.Nic{ - "swp0": { + "swp1": { Name: "Ethernet0", MacAddress: "dd:dd:dd:dd:dd:dd", }, diff --git a/cmd/metal-api/internal/testdata/testdata.go b/cmd/metal-api/internal/testdata/testdata.go index bd3a10b4..c471bd60 100644 --- a/cmd/metal-api/internal/testdata/testdata.go +++ b/cmd/metal-api/internal/testdata/testdata.go @@ -551,7 +551,7 @@ var ( "1": metal.Connections{ metal.Connection{ Nic: metal.Nic{ - Name: "swp1", + Name: "swp2", MacAddress: metal.MacAddress("21:11:11:11:11:11"), }, MachineID: "1", @@ -613,7 +613,7 @@ var ( // Nics Nic1 = metal.Nic{ MacAddress: metal.MacAddress("11:11:11:11:11:11"), - Name: "swp0", + Name: "swp1", Neighbors: []metal.Nic{ { MacAddress: "21:11:11:11:11:11", @@ -625,7 +625,7 @@ var ( } Nic2 = metal.Nic{ MacAddress: metal.MacAddress("21:11:11:11:11:11"), - Name: "swp1", + Name: "swp2", Neighbors: []metal.Nic{ { MacAddress: "11:11:11:11:11:11", @@ -637,7 +637,7 @@ var ( } Nic3 = metal.Nic{ MacAddress: metal.MacAddress("31:11:11:11:11:11"), - Name: "swp2", + Name: "swp3", Neighbors: []metal.Nic{ { MacAddress: "21:11:11:11:11:11", @@ -649,7 +649,7 @@ var ( } Nic4 = metal.Nic{ MacAddress: metal.MacAddress("41:11:11:11:11:11"), - Name: "swp1", + Name: "swp2", } // IPMIs @@ -759,24 +759,6 @@ var ( "33:11:11:11:11:11", } - // Create the Connections Array - TestConnections = []metal.Connection{ - { - Nic: metal.Nic{ - Name: "swp1", - MacAddress: "11:11:11", - }, - MachineID: "machine-1", - }, - { - Nic: metal.Nic{ - Name: "swp2", - MacAddress: "22:11:11", - }, - MachineID: "machine-2", - }, - } - TestMachinesHardwares = []metal.MachineHardware{ MachineHardware1, MachineHardware2, }