Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cnf:network-add-nftables-test-cases #366

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gkopels
Copy link
Collaborator

@gkopels gkopels commented Jan 17, 2025

Add first of two PRs cnf network nftables custom firewall test cases

@gkopels gkopels force-pushed the add-custom-nftables-test-cases branch 10 times, most recently from 19b87aa to 6bbb0c1 Compare January 20, 2025 08:18
@@ -38,6 +38,7 @@ type NetworkConfig struct {
//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"`
SecurityIPAddList string `envconfig:"ECO_CNF_CORE_NET_SECURITY_ADDR_LIST"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need it? Is MlbAddressPoolIP not good for that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use it. Its the same addresses

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

// delete table inet custom_table
// table inet custom_table {
// }`
CustomFireWallDelete = `data:;base64, ` +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CustomFireWallDelete = `data:;base64, ` +
CustomFirewallDelete = `data:;base64, ` +

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

// ReporterCRDsToDump tells to the reporter what CRs to dump.
ReporterCRDsToDump = []k8sreporter.CRData{}
// ExternalMacVlanNADName represents default external NetworkAttachmentDefinition name.
ExternalMacVlanNADName = "external"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls move it to the tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved

apimachinerytype "k8s.io/apimachinery/pkg/types"
)

var (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move all var under describe or to the tsparams

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved

Comment on lines 39 to 40
masterPodIPv4Prefix = "172.16.0.1/24"
masterPodIPv4Address = "172.16.0.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
masterPodIPv4Prefix = "172.16.0.1/24"
masterPodIPv4Address = "172.16.0.1"
masterPodIPv4Address = "172.16.0.1"
masterPodIPv4WithPrefix = masterPodIPv4Address + "/24"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

return testPod
}

func validateTCPTraffic(clientPod *pod.Builder, destIPAddrs []string, interfaceName,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need return an error

Copy link
Collaborator Author

@gkopels gkopels Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to leave the error message. There are tests that I am expecting an error

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move the func to metallb.internal.cmd

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it to network.internal.cmd

stringgzip := "gzip"

mode := 384
fileContents := fileContentString
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is the base64 string

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does it mean?
you can use it
Source: &fileContentString,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using mc WithRawConfig to create and delete the machineConfig. This is using IgnitionConfig. So I am using the fileContents and not directly adding to Source:

Copy link
Collaborator

@evgenLevin evgenLevin Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don'y understand. This is work for me:
https://github.com/openshift-kni/eco-gotests/pull/378/files#diff-22e4ee6efd525f4fd9fbbfbc89a65635f4039a762ef79e6181e6063bbccd3712R550

Yes I already made the change. Not sure why it didnt show after I pushed. I see it now

Create()
Expect(err).ToNot(HaveOccurred(), "Failed to create nftables machine config")

err = WaitForMcpStable(APIClient, 4*time.Minute, 30*time.Second, "workercnf")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"workercnf" should be a var

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

Create()
Expect(err).ToNot(HaveOccurred(), "Failed to create nftables machine config")

err = WaitForMcpStable(APIClient, 4*time.Minute, 30*time.Second, "workercnf")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please increase the timers

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

increased

}

// WaitForMcpStable waits for the stability of the MCP with the given name.
func WaitForMcpStable(apiClient *clients.Settings, waitingTime, stableDuration time.Duration, mcpName string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure we have the same func somewhere, please reuse it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found it

@gkopels gkopels force-pushed the add-custom-nftables-test-cases branch 18 times, most recently from b336a5a to e306cc0 Compare January 22, 2025 11:11
Comment on lines 21 to 22
// This yaml is created using butane file.
// butane mc-update-input-rule8888.bu -o mc-custom-firewall-input-port8888.yaml.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

`

// FRRDefaultBGPPreConfig represents FRR daemon BGP minimal config.
FRRDefaultBGPPreConfig = ` bgp router-id 10.10.10.11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you use it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

`GRXpH7IcoJX2/I3Z6/a57e/Xffuy2Gze0C2WD+2AVf/U3WGGVEW9O/uz/w0AAP//` +
`kU0CJQUBAAA=`
// FRRBaseConfig represents FRR daemon minimal configuration.
FRRBaseConfig = `!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find where it is being used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct removed

ipv4SecurityIPList []string,
hubIPv4ExternalAddresses []string,
ipv4NodeAddrList []string,
hubPodWorkerName []string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need.
_ = createFrrPodTest("hub-pod-worker-0", workerNodeList[0].Object.Name, hubConfigMap.Definition.Name, containerFrrName, []string{}, hub0BRstaticIPAnnotation, false)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

"Failed to update the machineconfiguration cluster file")
}

func createExternalNad(name string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is the same func in common

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used existing define.CreateNadWithMasterPlugin func

Copy link
Collaborator

@evgenLevin evgenLevin Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still here
fixed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

return ipAddressListWithoutPrefix
}

func buildRoutesMapWithSpecificRoutes(podList []*pod.Builder, workerNodeList []*nodes.Builder,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reuse from frrk8-tests.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here again. I will give you a call and we can discuss where to place it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to network.internal.frrconfig

return routesMap
}

func setStaticRoute(frrPod *pod.Builder, action, destIP string, nextHopMap map[string]string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reuse frr.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to network.internal.frrconfig

return testPod
}

func validateTCPTraffic(clientPod *pod.Builder, destIPAddrs []string, interfaceName,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move the func to metallb.internal.cmd

stringgzip := "gzip"

mode := 384
fileContents := fileContentString
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does it mean?
you can use it
Source: &fileContentString,

Expect(err).ToNot(HaveOccurred(), "Failed to wait for MCP to be stable")
}

func createStaticRouteOnWorkerNodes(testPodList []*pod.Builder, routeMap map[string]string, routeAction,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename the func, it's not only create

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed name

@gkopels gkopels force-pushed the add-custom-nftables-test-cases branch 14 times, most recently from ee3ba43 to 5ffcef2 Compare January 27, 2025 06:27
@@ -160,3 +176,12 @@ func getNumberOfPackets(line, firstFieldSubstr string) int {

return numberOfPackets
}

func removePrefixFromIPList(ipAddressList []string) []string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please reuse func from metallb common: move it and use it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already moved it to network.internal.frrconfig

}

if len(nextHopList) == 0 {
glog.Error("Nexthop IP addresses list is empty")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use glog.V(90).Infof instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

}

// BuildRoutesMapWithSpecificRoutes creates a route map with specific routes.
func BuildRoutesMapWithSpecificRoutes(podList []*pod.Builder, workerNodeList []*nodes.Builder,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BuildRoutesMapWithSpecificRoutes and SetStaticRoute are not related to frr. Please move them to cmd.go or netenv.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to netenv

}

// RemovePrefixFromIPList removes the prefix from an IP address.
func RemovePrefixFromIPList(ipAddressList []string) []string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to frr func. And you already added it to cmd.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed from frrconfig


// ReporterNamespacesToDump tells to the reporter from where to collect logs.
ReporterNamespacesToDump = map[string]string{
"openshift-performance-addon-operator": "performance",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to dump openshift-performance-addon-operator ns? Please add ns that you're using in the test suite

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct removed and changed to security-tests

err error
)
BeforeAll(func() {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls remove line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


It("Verify the creation of a new custom node firewall NFTables table with an ingress rule",
reportxml.ID("77412"), func() {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls remove line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

"Failed to update the machineconfiguration cluster file")
}

func createExternalNad(name string) {
Copy link
Collaborator

@evgenLevin evgenLevin Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still here
fixed

masterConfigMap.Definition.Name, containerFrrName, []string{}, masterStaticIPAnnotation, true)
}

func createStaticIPAnnotations(internalNADName, externalNADName string, internalIPAddresses,
Copy link
Collaborator

@evgenLevin evgenLevin Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still here
In my code its changed. Try refreshing and look again?

stringgzip := "gzip"

mode := 384
fileContents := fileContentString
Copy link
Collaborator

@evgenLevin evgenLevin Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don'y understand. This is work for me:
https://github.com/openshift-kni/eco-gotests/pull/378/files#diff-22e4ee6efd525f4fd9fbbfbc89a65635f4039a762ef79e6181e6063bbccd3712R550

Yes I already made the change. Not sure why it didnt show after I pushed. I see it now

@gkopels gkopels force-pushed the add-custom-nftables-test-cases branch 4 times, most recently from a4ab1e0 to 602b55a Compare January 28, 2025 14:23
tests/cnf/core/network/internal/cmd/cmd.go Show resolved Hide resolved
tests/cnf/core/network/internal/cmd/cmd.go Show resolved Hide resolved

// CreateExternalNad creats an external network-attchment-definition using the br-ex interface.
func CreateExternalNad(apiClient *clients.Settings, name, testNameSpace string) {
glog.V(2).Info("Creating external BR-EX NetworkAttachmentDefinition")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
glog.V(2).Info("Creating external BR-EX NetworkAttachmentDefinition")
glog.V(90).Info("Creating external BR-EX NetworkAttachmentDefinition")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

Comment on lines 311 to 319
return
}

// Create the NetworkAttachmentDefinition
_, err = define.CreateNadWithMasterPlugin(apiClient, name, testNameSpace, macVlanPlugin)
if err != nil {
glog.V(90).Infof("Failed to create external NetworkAttachmentDefinition: %v", err)

return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please return the error

Copy link
Collaborator

@evgenLevin evgenLevin Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please return err

return
}

glog.V(2).Infof("Successfully created external NetworkAttachmentDefinition: %s", name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
glog.V(2).Infof("Successfully created external NetworkAttachmentDefinition: %s", name)
glog.V(90).Infof("Successfully created external NetworkAttachmentDefinition: %s", name)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

}

// WaitForMcpStable waits for the stability of the MCP with the given name.
func WaitForMcpStable(apiClient *clients.Settings, waitingTime, stableDuration time.Duration, mcpName string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add glog.V(90).Infof

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@@ -628,14 +643,17 @@ var _ = Describe("FRR", Ordered, Label(tsparams.LabelFRRTestCases), ContinueOnFa
srIovInterfacesUnderTest[0], frrNodeSecIntIPv4Addresses[1], "2001:100::253", vlanID)

By("Adding static routes to the speakers")
speakerRoutesMap := buildRoutesMapWithSpecificRoutes(frrk8sPods, hubSecIntIPv4Addresses)
// speakerRoutesMap := buildRoutesMapWithSpecificRoutes(frrk8sPods, hubSecIntIPv4Addresses)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


// ReporterNamespacesToDump tells to the reporter from where to collect logs.
ReporterNamespacesToDump = map[string]string{
"security-tests": "security-tests",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use TestNamespaceName

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

masterConfigMap.Definition.Name, containerFrrName, []string{}, masterStaticIPAnnotation, true)
}

func createStaticIPAnnotations(internalNADName, externalNADName string, internalIPAddresses,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still can see it

@gkopels gkopels force-pushed the add-custom-nftables-test-cases branch from 602b55a to 471b138 Compare January 29, 2025 10:57
Comment on lines 311 to 319
return
}

// Create the NetworkAttachmentDefinition
_, err = define.CreateNadWithMasterPlugin(apiClient, name, testNameSpace, macVlanPlugin)
if err != nil {
glog.V(90).Infof("Failed to create external NetworkAttachmentDefinition: %v", err)

return
Copy link
Collaborator

@evgenLevin evgenLevin Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please return err

err = mcp.WaitToBeStableFor(stableDuration, waitingTime)

if err != nil {
glog.V(90).Infof("Failed to create external NetworkAttachmentDefinition: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong description

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

func WaitForMcpStable(apiClient *clients.Settings, waitingTime, stableDuration time.Duration, mcpName string) error {
mcp, err := mco.Pull(apiClient, mcpName)

glog.V(90).Info("Waiting for mcp to be stable after adding or deleting a machine-Config")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
glog.V(90).Info("Waiting for mcp to be stable after adding or deleting a machine-Config")
glog.V(90).Info("Waiting for mcp to be stable")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

// TestNamespaceName security-tests namespace where all test cases are performed.
TestNamespaceName = "security-tests"
// ReporterCRDsToDump tells to the reporter what CRs to dump.
ReporterCRDsToDump = []k8sreporter.CRData{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add CRs what you want to dump after the failure. machineconfigs or something else

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know when you are free for a call

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@gkopels gkopels force-pushed the add-custom-nftables-test-cases branch from 471b138 to 3686479 Compare January 30, 2025 17:31
@gkopels gkopels force-pushed the add-custom-nftables-test-cases branch from 3686479 to 36d1201 Compare January 30, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants