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

Add e2e tests for BGPPolicy #6523

Merged
merged 2 commits into from
Jul 26, 2024
Merged

Conversation

hongliangl
Copy link
Contributor

Depends on #6488 #6203

@hongliangl hongliangl added the area/test/e2e Issues or PRs related to Antrea specific end-to-end testing. label Jul 12, 2024
@hongliangl hongliangl added this to the Antrea v2.1 release milestone Jul 12, 2024
@hongliangl hongliangl added the area/transit/bgp Issues or PRs related to BGP support. label Jul 12, 2024
@hongliangl hongliangl force-pushed the 20240712-bgppolicy-e2e branch 2 times, most recently from 7927513 to f53eae6 Compare July 23, 2024 04:37
@hongliangl hongliangl marked this pull request as ready for review July 23, 2024 04:37
test/e2e/bgppolicy_test.go Outdated Show resolved Hide resolved
test/e2e/bgppolicy_test.go Outdated Show resolved Hide resolved
updatedLocalASN = int32(64513)

password = "password"
defaultBGPPolicySecretName = "antrea-bgp-passwords" // #nosec G101
Copy link
Contributor

Choose a reason for hiding this comment

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

why is there "Policy" in this variable name? I think the secret name is global and not specific to a policy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use the const BGPPolicySecretName in pkg/agent/types/bgppolicy.go

test/e2e/bgppolicy_test.go Outdated Show resolved Hide resolved
test/e2e/bgppolicy_test.go Outdated Show resolved Hide resolved
test/e2e/framework.go Outdated Show resolved Hide resolved
test/e2e/bgppolicy_test.go Outdated Show resolved Hide resolved
test/e2e/bgppolicy_test.go Outdated Show resolved Hide resolved
test/e2e/bgppolicy_test.go Outdated Show resolved Hide resolved
require.Equal(t, 0, rc)
}

func dumpFRRRouterBGPRoutes() []FRRRoute {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's not ideal that this function doesn't return an error when applicable, as in case of error the caller will keep looping until the timeout is reached.
I know that it's because of a current limitation of assert.EventuallyWithT (at least until the next release of testify - see stretchr/testify#1396).
For now, I would recommend defining an additional helper function, checkFRRRouterBGPRoutes which will use wait.Poll... to call dumpFRRRouterBGPRoutes in a loop. In case of error, checkFRRRouterBGPRoutes can fail immediately. The function should also probably call t.Helper for improved test debuggability.

@hongliangl hongliangl force-pushed the 20240712-bgppolicy-e2e branch 3 times, most recently from 89926f3 to f124d02 Compare July 25, 2024 13:41
Comment on lines 242 to 260
func generateVtyshCommandsForConfiguringBGP(localASN, remoteASN int32) []string {
commands := []string{
"configure terminal",
fmt.Sprintf("router bgp %d", localASN),
"no bgp ebgp-requires-policy",
"no bgp network import-check",
}
for _, node := range clusterInfo.nodes {
commands = append(commands, fmt.Sprintf("neighbor %s remote-as %d", node.ipv4Addr, remoteASN))
commands = append(commands, fmt.Sprintf("neighbor %s password %s", node.ipv4Addr, bgpPeerPassword))
}
commands = append(commands,
"exit",
"exit",
"write memory")
return commands
}

func generateVtyshCommandsForClearingBGP(localASN int32) []string {
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure why you didn't define configureBGP and cleanupBGP instead? (both function would ultimately call runVtyshCommands).

Copy link
Member

Choose a reason for hiding this comment

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

updated

}

func dumpFRRRouterBGPRoutes() ([]FRRRoute, error) {
rc, stdout, stderr, err := exec.RunDockerExecCommand(externalInfo.externalFRRCID, "/usr/bin/vtysh", "/", nil, "show ip route bgp")
Copy link
Contributor

Choose a reason for hiding this comment

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

should call runVtyshCommands instead

Copy link
Member

Choose a reason for hiding this comment

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

done

Comment on lines 88 to 91
rc, stdout, stderr, err := runVtyshCommands(generateVtyshCommandsForConfiguringBGP(remoteASN, localASN))
defer runVtyshCommands(generateVtyshCommandsForClearingBGP(remoteASN))
t.Log(stdout)
t.Log(stderr)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe runVtyshCommands could be in charge of logging stdout / stderr, as you seem to be doing consistently every time you call the function

Copy link
Member

Choose a reason for hiding this comment

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

moved to configureExternalBGPRouter and logged on failure.


t.Log("Configure the remote FRR router with BGP")
rc, stdout, stderr, err := runVtyshCommands(generateVtyshCommandsForConfiguringBGP(remoteASN, localASN))
defer runVtyshCommands(generateVtyshCommandsForClearingBGP(remoteASN))
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this can handle the case where the previous command (runVtyshCommands(generateVtyshCommandsForConfiguringBGP(remoteASN, localASN))) failed / partially succeeded?

Copy link
Member

Choose a reason for hiding this comment

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

changed to defer on success of configuration.


t.Log("Configure the remote FRR router with BGP")
rc, stdout, stderr, err := runVtyshCommands(generateVtyshCommandsForConfiguringBGP(remoteASN, localASN))
defer runVtyshCommands(generateVtyshCommandsForClearingBGP(remoteASN))
Copy link
Contributor

Choose a reason for hiding this comment

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

the parameter name for generateVtyshCommandsForClearingBGP is localASN but you are passing remoteASN to the function here?

You can probably ignore this comment, as I think I know why: the variables here are named from the point of view of the K8s Node while the Vtysh functions operate on the "external" FRR router. So what is "remote" for the K8s Node is "local" for the router.

Copy link
Member

Choose a reason for hiding this comment

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

changed to externalASN and nodeASN to avoid confusion.

}
}

func checkFRRRouterBGPRoutes(t *testing.T, expectedRouteStrings, notExpectedRouteStrings []string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this function should be in charge of converting the routes to strings (using routesToStrings)

Copy link
Member

Choose a reason for hiding this comment

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

done

Comment on lines 233 to 235
if err != nil {
t.Fatalf("Failed to get the expected BGP routes: %v", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

should use require.NoError for consistency

Copy link
Member

Choose a reason for hiding this comment

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

updated, and added mode details for debugging.

Comment on lines 227 to 221
if notExpectedRoutesSet.Len() != 0 && gotRoutesSet.IsSuperset(notExpectedRoutesSet) {
return false, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't seem correct to me. I think it should be if gotRoutesSet.Intersection(notExpectedRoutesSet).Len() > 0. In other words: if any of the routes in notExpectedRoutesSet are in the output, it's bad.

Alternatively, it can be written as if gotRoutesSet.HasAny(notExpectedRouteStrings...) which is more readable and does not require you to create notExpectedRoutesSet. Personally I would also not create expectedRoutesSet and then you can use if gotRoutesSet.HasAll(expectedRoutesString) for the previous conditions. Giving you:

if !gotRoutesSet.HasAll(expectedRoutesStrings) {
        return false, nil
}
if gotRoutesSet.HasAny(notExpectedRoutesStrings) {
        return false, nil
}

Copy link
Member

Choose a reason for hiding this comment

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

it's much clearer, updated as suggested

@antoninbas
Copy link
Contributor

I assume we will add e2e testing for Egress later?

hongliangl and others added 2 commits July 26, 2024 13:52
Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
Signed-off-by: Quan Tian <quan.tian@broadcom.com>
@tnqn
Copy link
Member

tnqn commented Jul 26, 2024

/skip-all

Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM

@tnqn tnqn merged commit 1456fe0 into antrea-io:main Jul 26, 2024
54 of 58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/test/e2e Issues or PRs related to Antrea specific end-to-end testing. area/transit/bgp Issues or PRs related to BGP support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants