From 6c29e4c58167b24b857fe7ece1c1c1a532261211 Mon Sep 17 00:00:00 2001 From: evgenLevin Date: Mon, 23 Sep 2024 09:58:33 -0400 Subject: [PATCH] cnf-network: Adjusted day1day2 sriov and exmanaged tests (#132) --- .../core/network/day1day2/tests/day1day2.go | 41 +++++------- .../core/network/internal/netconfig/config.go | 40 ++++++++---- .../network/internal/netnmstate/netnmstate.go | 65 +++++-------------- .../network/sriov/tests/externalllymanaged.go | 10 +-- 4 files changed, 64 insertions(+), 92 deletions(-) diff --git a/tests/cnf/core/network/day1day2/tests/day1day2.go b/tests/cnf/core/network/day1day2/tests/day1day2.go index 997c1a2ee..4d47c7280 100644 --- a/tests/cnf/core/network/day1day2/tests/day1day2.go +++ b/tests/cnf/core/network/day1day2/tests/day1day2.go @@ -27,12 +27,12 @@ import ( var _ = Describe("Day1Day2", Ordered, Label(tsparams.LabelSuite), ContinueOnFailure, func() { var ( - workerNodeList []*nodes.Builder - bondName string - bondInterfaceVlanSlaves []string - juniperSession *juniper.JunosSession - switchInterfaces []string - switchLagNames []string + workerNodeList []*nodes.Builder + bondName string + bondSlaves []string + juniperSession *juniper.JunosSession + switchInterfaces []string + switchLagNames []string ) BeforeAll(func() { @@ -47,9 +47,8 @@ var _ = Describe("Day1Day2", Ordered, Label(tsparams.LabelSuite), ContinueOnFail err = netnmstate.CreateNewNMStateAndWaitUntilItsRunning(7 * time.Minute) Expect(err).ToNot(HaveOccurred(), "Failed to create NMState instance") - By("Verifying that the cluster deployed via bond interface" + - " with enslaved Vlan interfaces which based on SR-IOV VFs") - bondName, bondInterfaceVlanSlaves, _, err = netnmstate.CheckThatWorkersDeployedWithBondVlanVfs( + By("Verifying that the cluster deployed via bond interface with enslaved SR-IOV VFs") + bondName, bondSlaves, err = netnmstate.CheckThatWorkersDeployedWithBondVfs( workerNodeList, tsparams.TestNamespaceName) if err != nil { Skip(fmt.Sprintf("Day1Day2 tests skipped. Cluster is not suitable due to: %s", err.Error())) @@ -65,7 +64,7 @@ var _ = Describe("Day1Day2", Ordered, Label(tsparams.LabelSuite), ContinueOnFail Expect(err).ToNot(HaveOccurred(), "Failed to open a switch session") By("Collecting switch interfaces") - switchInterfaces, err = NetConfig.GetSwitchInterfaces() + switchInterfaces, err = NetConfig.GetPrimarySwitchInterfaces() Expect(err).ToNot(HaveOccurred(), "Failed to get switch interfaces") By("Collecting switch LAG names") @@ -93,7 +92,7 @@ var _ = Describe("Day1Day2", Ordered, Label(tsparams.LabelSuite), ContinueOnFail Expect(err).ToNot(HaveOccurred(), "Failed to remove all NMState policies") }) - It("Day1: Validate cluster deployed via bond interface with 2 interface vlan VFs enslaved and fail-over", + It("Day1: Validate cluster deployed via bond interface with 2 VFs enslaved and fail-over", reportxml.ID("63928"), func() { err := juniper.DumpInterfaceConfigs(juniperSession, switchInterfaces) Expect(err).ToNot(HaveOccurred(), "Failed to save initial switch interfaces configs") @@ -104,10 +103,8 @@ var _ = Describe("Day1Day2", Ordered, Label(tsparams.LabelSuite), ContinueOnFail It("VF: change QOS configuration", reportxml.ID("63926"), func() { By("Collecting information about test interfaces") - vfInterface, err := netnmstate.GetBaseVlanInterface(bondInterfaceVlanSlaves[0], workerNodeList[0].Definition.Name) - Expect(err).ToNot(HaveOccurred(), "Failed to get VF base interface") - pfUnderTest, err := cmd.GetSrIovPf(vfInterface, tsparams.TestNamespaceName, workerNodeList[0].Definition.Name) - Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Failed to get SR-IOV PF for VF %s", vfInterface)) + pfUnderTest, err := cmd.GetSrIovPf(bondSlaves[0], tsparams.TestNamespaceName, workerNodeList[0].Definition.Name) + Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Failed to get SR-IOV PF for VF %s", bondSlaves[0])) By(fmt.Sprintf("Saving MaxTxRate value on the first VF of interface %s before the test", pfUnderTest)) defaultMaxTxRate, err := day1day2env.GetFirstVfInterfaceMaxTxRate(workerNodeList[0].Definition.Name, pfUnderTest) @@ -152,12 +149,6 @@ var _ = Describe("Day1Day2", Ordered, Label(tsparams.LabelSuite), ContinueOnFail }) It("Day2 Bond: change miimon configuration", reportxml.ID("63881"), func() { - By("Collecting information about test interfaces") - bondName, err := netnmstate.GetPrimaryInterfaceBond(workerNodeList[0].Definition.Name) - Expect(err).ToNot(HaveOccurred(), "Failed to get Bond primary interface name") - bondInterfaceVlanSlaves, err := netnmstate.GetBondSlaves(bondName, workerNodeList[0].Definition.Name) - Expect(err).ToNot(HaveOccurred(), "Failed to get bond slave interfaces") - By("Saving miimon value on the bond interface before the test") defaultMiimonValue, err := day1day2env.GetBondInterfaceMiimon(workerNodeList[0].Definition.Name, bondName) Expect(err).ToNot(HaveOccurred(), "Failed to get miimon configuration") @@ -166,7 +157,7 @@ var _ = Describe("Day1Day2", Ordered, Label(tsparams.LabelSuite), ContinueOnFail By("Configuring miimon on the bond interface") nmstatePolicy := nmstate.NewPolicyBuilder(APIClient, "miimon", NetConfig.WorkerLabelMap). - WithBondInterface(bondInterfaceVlanSlaves, bondName, "active-backup"). + WithBondInterface(bondSlaves, bondName, "active-backup"). WithOptions(netnmstate.WithBondOptionMiimon(uint64(newExpectedMiimonValue), bondName)) err = netnmstate.CreatePolicyAndWaitUntilItsAvailable(netparam.DefaultTimeout, nmstatePolicy) Expect(err).ToNot(HaveOccurred(), "Failed to create NMState network policy") @@ -185,7 +176,7 @@ var _ = Describe("Day1Day2", Ordered, Label(tsparams.LabelSuite), ContinueOnFail By("Restoring miimon configuration") nmstatePolicy = nmstate.NewPolicyBuilder(APIClient, "restoremiimon", NetConfig.WorkerLabelMap). - WithBondInterface(bondInterfaceVlanSlaves, bondName, "active-backup"). + WithBondInterface(bondSlaves, bondName, "active-backup"). WithOptions(netnmstate.WithBondOptionMiimon(uint64(defaultMiimonValue), bondName)) err = netnmstate.CreatePolicyAndWaitUntilItsAvailable(netparam.DefaultTimeout, nmstatePolicy) Expect(err).ToNot(HaveOccurred(), "Failed to create NMState network policy") @@ -218,7 +209,7 @@ var _ = Describe("Day1Day2", Ordered, Label(tsparams.LabelSuite), ContinueOnFail AfterEach(func() { By("Reverting active-backup bond mode on the bond interfaces") nmstatePolicy := nmstate.NewPolicyBuilder(APIClient, policyNameBondMode, NetConfig.WorkerLabelMap). - WithBondInterface(bondInterfaceVlanSlaves, bondName, "active-backup"). + WithBondInterface(bondSlaves, bondName, "active-backup"). WithOptions(netnmstate.WithBondOptionFailOverMac("none", bondName)) err := netnmstate.UpdatePolicyAndWaitUntilItsAvailable(netparam.DefaultTimeout, nmstatePolicy) Expect(err).ToNot(HaveOccurred(), "Failed to update NMState network policy") @@ -230,7 +221,7 @@ var _ = Describe("Day1Day2", Ordered, Label(tsparams.LabelSuite), ContinueOnFail It("Day2 Bond: change mode configuration", reportxml.ID("63882"), func() { By("Creating NMState policy to change a bond mode") nmstatePolicy := nmstate.NewPolicyBuilder(APIClient, policyNameBondMode, NetConfig.WorkerLabelMap). - WithBondInterface(bondInterfaceVlanSlaves, bondName, "balance-rr"). + WithBondInterface(bondSlaves, bondName, "balance-rr"). WithOptions(netnmstate.WithBondOptionFailOverMac("active", bondName)) err := netnmstate.CreatePolicyAndWaitUntilItsAvailable(netparam.DefaultTimeout, nmstatePolicy) Expect(err).ToNot(HaveOccurred(), "Failed to create NMState network policy") diff --git a/tests/cnf/core/network/internal/netconfig/config.go b/tests/cnf/core/network/internal/netconfig/config.go index 334cb231e..ed06323a9 100644 --- a/tests/cnf/core/network/internal/netconfig/config.go +++ b/tests/cnf/core/network/internal/netconfig/config.go @@ -23,17 +23,18 @@ const ( // NetworkConfig type keeps network configuration. type NetworkConfig struct { *coreconfig.CoreConfig - CnfNetTestContainer string `yaml:"cnf_net_test_container" envconfig:"ECO_CNF_CORE_NET_TEST_CONTAINER"` - DpdkTestContainer string `yaml:"dpdk_test_container" envconfig:"ECO_CNF_CORE_NET_DPDK_TEST_CONTAINER"` - MlbOperatorNamespace string `yaml:"metal_lb_operator_namespace" envconfig:"ECO_CNF_CORE_NET_MLB_OPERATOR_NAMESPACE"` - CnfMcpLabel string `yaml:"cnf_mcp_label" envconfig:"ECO_CNF_CORE_NET_CNF_MCP_LABEL"` - MultusNamesapce string `yaml:"multus_namespace" envconfig:"ECO_CNF_CORE_NET_MULTUS_NAMESPACE"` - SwitchUser string `envconfig:"ECO_CNF_CORE_NET_SWITCH_USER"` - SwitchPass string `envconfig:"ECO_CNF_CORE_NET_SWITCH_PASS"` - SwitchIP string `envconfig:"ECO_CNF_CORE_NET_SWITCH_IP"` - SwitchInterfaces string `envconfig:"ECO_CNF_CORE_NET_SWITCH_INTERFACES"` - SwitchLagNames string `envconfig:"ECO_CNF_CORE_NET_SWITCH_LAGS"` - ClusterVlan string `envconfig:"ECO_CNF_CORE_NET_CLUSTER_VLAN"` + CnfNetTestContainer string `yaml:"cnf_net_test_container" envconfig:"ECO_CNF_CORE_NET_TEST_CONTAINER"` + DpdkTestContainer string `yaml:"dpdk_test_container" envconfig:"ECO_CNF_CORE_NET_DPDK_TEST_CONTAINER"` + MlbOperatorNamespace string `yaml:"metal_lb_operator_namespace" envconfig:"ECO_CNF_CORE_NET_MLB_OPERATOR_NAMESPACE"` + CnfMcpLabel string `yaml:"cnf_mcp_label" envconfig:"ECO_CNF_CORE_NET_CNF_MCP_LABEL"` + MultusNamesapce string `yaml:"multus_namespace" envconfig:"ECO_CNF_CORE_NET_MULTUS_NAMESPACE"` + SwitchUser string `envconfig:"ECO_CNF_CORE_NET_SWITCH_USER"` + SwitchPass string `envconfig:"ECO_CNF_CORE_NET_SWITCH_PASS"` + SwitchIP string `envconfig:"ECO_CNF_CORE_NET_SWITCH_IP"` + SwitchInterfaces string `envconfig:"ECO_CNF_CORE_NET_SWITCH_INTERFACES"` + PrimarySwitchInterfaces string `envconfig:"ECO_CNF_CORE_NET_PRIMARY_SWITCH_INTERFACES"` + SwitchLagNames string `envconfig:"ECO_CNF_CORE_NET_SWITCH_LAGS"` + ClusterVlan string `envconfig:"ECO_CNF_CORE_NET_CLUSTER_VLAN"` //nolint:lll PrometheusOperatorNamespace string `yaml:"prometheus_operator_namespace" envconfig:"ECO_CNF_CORE_NET_PROMETHEUS_OPERATOR_NAMESPACE"` MlbAddressPoolIP string `envconfig:"ECO_CNF_CORE_NET_MLB_ADDR_LIST"` @@ -151,20 +152,33 @@ func (netConfig *NetworkConfig) GetSwitchInterfaces() ([]string, error) { envValue := strings.Split(netConfig.SwitchInterfaces, ",") if len(envValue) != 4 { - return nil, fmt.Errorf("the number of the switch interfaces is not equal 4," + + return nil, fmt.Errorf("the number of the switch interfaces is not equal to 4," + " check ECO_CNF_CORE_NET_SWITCH_INTERFACES env var") } return envValue, nil } +// GetPrimarySwitchInterfaces checks the environmental variable ECO_CNF_CORE_NET_PRIMARY_SWITCH_INTERFACES +// and returns the value in []string. +func (netConfig *NetworkConfig) GetPrimarySwitchInterfaces() ([]string, error) { + envValue := strings.Split(netConfig.PrimarySwitchInterfaces, ",") + + if len(envValue) != 4 { + return nil, fmt.Errorf("the number of the switch interfaces is not equal to 4," + + " check ECO_CNF_CORE_NET_PRIMARY_SWITCH_INTERFACES env var") + } + + return envValue, nil +} + // GetSwitchLagNames checks the environmental variable ECO_CNF_CORE_NET_SWITCH_LAGS // and returns the value in []string. func (netConfig *NetworkConfig) GetSwitchLagNames() ([]string, error) { envValue := strings.Split(netConfig.SwitchLagNames, ",") if len(envValue) != 2 { - return nil, fmt.Errorf("the number of the switch lag names is not equal 2," + + return nil, fmt.Errorf("the number of the switch lag names is not equal to 2," + " check ECO_CNF_CORE_NET_SWITCH_LAGS env var") } diff --git a/tests/cnf/core/network/internal/netnmstate/netnmstate.go b/tests/cnf/core/network/internal/netnmstate/netnmstate.go index 1d12a577b..27d3099b8 100644 --- a/tests/cnf/core/network/internal/netnmstate/netnmstate.go +++ b/tests/cnf/core/network/internal/netnmstate/netnmstate.go @@ -212,23 +212,6 @@ func GetBondSlaves(bondName, nodeNetworkStateName string) ([]string, error) { return bondInterface.LinkAggregation.Port, nil } -// GetBaseVlanInterface returns base interface under given Vlan interface name. -func GetBaseVlanInterface(vlanInterfaceName, nodeNetworkStateName string) (string, error) { - glog.V(90).Infof("Getting base interface for Vlan interface %s", vlanInterfaceName) - - nodeNetworkState, err := nmstate.PullNodeNetworkState(APIClient, nodeNetworkStateName) - if err != nil { - return "", err - } - - vlanInterface, err := nodeNetworkState.GetInterfaceType(vlanInterfaceName, "vlan") - if err != nil { - return "", err - } - - return vlanInterface.Vlan.BaseIface, nil -} - // GetBondMode returns Bond mode under given Bond interface name. func GetBondMode(bondName, nodeNetworkStateName string) (string, error) { glog.V(90).Infof("Getting Bond mode under Bond interface %s", bondName) @@ -323,17 +306,16 @@ func WithBondOptionFailOverMac( ) } -// CheckThatWorkersDeployedWithBondVlanVfs verifies whether workers have been deployed with the specified configuration +// CheckThatWorkersDeployedWithBondVfs verifies whether workers have been deployed with the specified configuration // of bonded VLAN virtual interfaces (VFs). This function ensures that the network setup adheres to the intended bond // and VLAN configurations. -func CheckThatWorkersDeployedWithBondVlanVfs( - workerNodes []*nodes.Builder, namespace string) (string, []string, []string, error) { +func CheckThatWorkersDeployedWithBondVfs( + workerNodes []*nodes.Builder, namespace string) (string, []string, error) { glog.V(90).Infof("Verifying that the cluster deployed via bond interface") var ( - bondName string - baseInterfaces []string - err error + bondName string + err error ) for _, worker := range workerNodes { @@ -341,61 +323,46 @@ func CheckThatWorkersDeployedWithBondVlanVfs( if err != nil { glog.V(90).Infof("Failed to get Slave Interfaces for the primary bond interface") - return "", nil, nil, err + return "", nil, err } if bondName == "" { glog.V(90).Infof("bondName is empty on worker %s", worker.Definition.Name) - return "", nil, nil, fmt.Errorf("primary interface on worker %s is not a bond interface", + return "", nil, fmt.Errorf("primary interface on worker %s is not a bond interface", worker.Definition.Name) } } glog.V(90).Infof("Gathering enslave interfaces for the bond interface") - bondInterfaceVlanSlaves, err := GetBondSlaves(bondName, workerNodes[0].Definition.Name) + bondSlaves, err := GetBondSlaves(bondName, workerNodes[0].Definition.Name) if err != nil { glog.V(90).Infof("Failed to get bond slave interfaces") - return "", nil, nil, err + return "", nil, err } glog.V(90).Infof( - "Verifying that enslave interfaces are vlan interfaces and base-interface for Vlan interface is a VF interface") - - for _, bondSlave := range bondInterfaceVlanSlaves { - baseInterface, err := GetBaseVlanInterface(bondSlave, workerNodes[0].Definition.Name) - if err != nil && strings.Contains(err.Error(), "it is not a vlan type") { - glog.V(90).Infof("bond slave interfaces are not vlan type") - - return "", nil, nil, fmt.Errorf("bond slave interfaces are not vlan interfaces") - } + "Verifying that enslave interfaces are SR-IOV VF interfaces") - if err != nil { - glog.V(90).Infof("Failed to get Vlan base interface") - - return "", nil, nil, err - } - - // If a Vlan baseInterface has SR-IOV PF, it means that the baseInterface is VF. - _, err = cmd.GetSrIovPf(baseInterface, namespace, workerNodes[0].Definition.Name) + for _, bondSlave := range bondSlaves { + // If a baseInterface has SR-IOV PF, it means that the baseInterface is VF. + _, err = cmd.GetSrIovPf(bondSlave, namespace, workerNodes[0].Definition.Name) if err != nil && strings.Contains(err.Error(), "No such file or directory") { glog.V(90).Infof("Failed to find PF for the baseInterface VFs") - return "", nil, nil, fmt.Errorf("bond slave interfaces are not vlan interfaces") + return "", nil, fmt.Errorf("bond slaves are not SR-IOV VFs") } if err != nil { glog.V(90).Infof("Failed to get SR-IOV PF interface") - return "", nil, nil, err + return "", nil, err } - - baseInterfaces = append(baseInterfaces, baseInterface) } - return bondName, bondInterfaceVlanSlaves, baseInterfaces, nil + return bondName, bondSlaves, nil } // withBondOptionMutator returns a function that mutates a specific option for a bond interface. diff --git a/tests/cnf/core/network/sriov/tests/externalllymanaged.go b/tests/cnf/core/network/sriov/tests/externalllymanaged.go index 6eff29fcd..82dc1ac87 100644 --- a/tests/cnf/core/network/sriov/tests/externalllymanaged.go +++ b/tests/cnf/core/network/sriov/tests/externalllymanaged.go @@ -301,17 +301,17 @@ var _ = Describe("ExternallyManaged", Ordered, Label(tsparams.LabelExternallyMan metav1.ListOptions{LabelSelector: labels.Set(NetConfig.WorkerLabelMap).String()}) Expect(err).ToNot(HaveOccurred(), "Failed to discover worker nodes") - _, _, baseVfInterfaces, err := netnmstate. - CheckThatWorkersDeployedWithBondVlanVfs(workerNodeList, tsparams.TestNamespaceName) + _, bondSlaves, err := netnmstate. + CheckThatWorkersDeployedWithBondVfs(workerNodeList, tsparams.TestNamespaceName) if err != nil { Skip(fmt.Sprintf("The cluster is not suitable for testing: %s", err.Error())) } - Expect(len(baseVfInterfaces)).To(BeNumerically(">", 1), - "Base VF interfaces should be more than 2") + Expect(len(bondSlaves)).To(BeNumerically(">", 1), + "Base VF interfaces should be more than 1") By("Getting VFs for the test") - vfsUnderTest = getVfsUnderTest(baseVfInterfaces) + vfsUnderTest = getVfsUnderTest(bondSlaves) By("Getting cluster vlan for the test") testVlanString, err := NetConfig.GetClusterVlan()