Skip to content

Commit

Permalink
cnf-network: Adjusted day1day2 sriov and exmanaged tests (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenLevin committed Sep 23, 2024
1 parent 0db99e5 commit 6c29e4c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 92 deletions.
41 changes: 16 additions & 25 deletions tests/cnf/core/network/day1day2/tests/day1day2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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()))
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
40 changes: 27 additions & 13 deletions tests/cnf/core/network/internal/netconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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")
}

Expand Down
65 changes: 16 additions & 49 deletions tests/cnf/core/network/internal/netnmstate/netnmstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -323,79 +306,63 @@ 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 {
bondName, err = GetPrimaryInterfaceBond(worker.Definition.Name)
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.
Expand Down
10 changes: 5 additions & 5 deletions tests/cnf/core/network/sriov/tests/externalllymanaged.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 6c29e4c

Please sign in to comment.