Skip to content

Commit

Permalink
remove swp0 from all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iljarotar committed Sep 18, 2024
1 parent 8abf726 commit d3e5a05
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 51 deletions.
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/datastore/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 21 additions & 21 deletions cmd/metal-api/internal/metal/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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},
},
Expand All @@ -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},
},
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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'",
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions cmd/metal-api/internal/service/switch-service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
},
},
Expand All @@ -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",
},
},
Expand All @@ -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",
},
Expand Down
28 changes: 5 additions & 23 deletions cmd/metal-api/internal/testdata/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -649,7 +649,7 @@ var (
}
Nic4 = metal.Nic{
MacAddress: metal.MacAddress("41:11:11:11:11:11"),
Name: "swp1",
Name: "swp2",
}

// IPMIs
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit d3e5a05

Please sign in to comment.