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

Refactor static canary tests. #2966

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/run-static-canary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function run_ginkgo_test() {
local focus=$1
echo "Running ginkgo tests with focus: $focus"

(CGO_ENABLED=0 ginkgo $EXTRA_GINKGO_FLAGS --no-color --focus="$focus" -v --timeout 10m --fail-on-pending $GINKGO_TEST_BUILD/cni.test -- \
(CGO_ENABLED=0 ginkgo $EXTRA_GINKGO_FLAGS --no-color --focus="$focus" -v --timeout 10m --fail-on-pending $GINKGO_TEST_BUILD/az-traffic.test -- \
--cluster-kubeconfig="$KUBE_CONFIG_PATH" \
--cluster-name="$CLUSTER_NAME" \
--aws-region="$REGION" \
Expand Down
49 changes: 49 additions & 0 deletions test/integration/az-traffic/pod_az_traffic_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package az_traffic

import (
"fmt"
"testing"

"github.com/aws/amazon-vpc-cni-k8s/test/framework"
"github.com/aws/amazon-vpc-cni-k8s/test/framework/utils"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestAZConnectivity(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "CNI AZ Traffic Test Suite")
}

var _ = BeforeSuite(func() {
f = framework.New(framework.GlobalOptions)

By("creating test namespace")
f.K8sResourceManagers.NamespaceManager().CreateNamespace(utils.DefaultTestNamespace)

By(fmt.Sprintf("getting the node with the node label key %s and value %s",
f.Options.NgNameLabelKey, f.Options.NgNameLabelVal))
_, err := f.K8sResourceManagers.NodeManager().GetNodes(f.Options.NgNameLabelKey, f.Options.NgNameLabelVal)
Expect(err).ToNot(HaveOccurred())

})

var _ = AfterSuite(func() {
By("deleting test namespace")
f.K8sResourceManagers.NamespaceManager().
DeleteAndWaitTillNamespaceDeleted(utils.DefaultTestNamespace)
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cni
package az_traffic

import (
"fmt"
Expand All @@ -7,10 +7,10 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatch"

"github.com/aws/amazon-vpc-cni-k8s/test/framework"
"github.com/aws/amazon-vpc-cni-k8s/test/framework/resources/k8s/manifest"
"github.com/aws/amazon-vpc-cni-k8s/test/framework/utils"
"github.com/aws/amazon-vpc-cni-k8s/test/integration/common"
"github.com/aws/aws-sdk-go/service/ec2"
coreV1 "k8s.io/api/core/v1"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -24,6 +24,8 @@ var (

const MetricNamespace = "NetworkingAZConnectivity"

var f *framework.Framework

var _ = Describe("[STATIC_CANARY] AZ Node Presence", FlakeAttempts(retries), func() {

Context("While testing AZ availability", func() {
Expand Down Expand Up @@ -69,7 +71,6 @@ var _ = Describe("[STATIC_CANARY] test pod networking", FlakeAttempts(retries),
var (
err error
serverPort int
protocol string

// The command to run on server pods, to allow incoming
// connections for different traffic type
Expand Down Expand Up @@ -99,16 +100,6 @@ var _ = Describe("[STATIC_CANARY] test pod networking", FlakeAttempts(retries),
)

JustBeforeEach(func() {
By("authorizing security group ingress on instance security group")
err = f.CloudServices.EC2().
AuthorizeSecurityGroupIngress(instanceSecurityGroupID, protocol, serverPort, serverPort, "0.0.0.0/0", false)
Expect(err).ToNot(HaveOccurred())

By("authorizing security group egress on instance security group")
err = f.CloudServices.EC2().
AuthorizeSecurityGroupEgress(instanceSecurityGroupID, protocol, serverPort, serverPort, "0.0.0.0/0")
Expect(err).ToNot(HaveOccurred())

netcatContainer := manifest.
NewNetCatAlpineContainer(f.Options.TestImageRegistry).
Command(serverListenCmd).
Expand Down Expand Up @@ -138,16 +129,6 @@ var _ = Describe("[STATIC_CANARY] test pod networking", FlakeAttempts(retries),
})

JustAfterEach(func() {
By("revoking security group ingress on instance security group")
err = f.CloudServices.EC2().
RevokeSecurityGroupIngress(instanceSecurityGroupID, protocol, serverPort, serverPort, "0.0.0.0/0", false)
Expect(err).ToNot(HaveOccurred())

By("revoking security group egress on instance security group")
err = f.CloudServices.EC2().
RevokeSecurityGroupEgress(instanceSecurityGroupID, protocol, serverPort, serverPort, "0.0.0.0/0")
Expect(err).ToNot(HaveOccurred())

By("deleting the Daemonset.")
err = f.K8sResourceManagers.DaemonSetManager().DeleteAndWaitTillDaemonSetIsDeleted(testDaemonSet, utils.DefaultDeploymentReadyTimeout)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -157,7 +138,6 @@ var _ = Describe("[STATIC_CANARY] test pod networking", FlakeAttempts(retries),

BeforeEach(func() {
serverPort = 2273
protocol = ec2.ProtocolTcp
// Test tcp connection using netcat
serverListenCmd = []string{"nc"}
// The nc flag "-l" for listen mode, "-k" to keep server up and not close
Expand Down Expand Up @@ -380,3 +360,23 @@ func RunCommandOnPod(receiverPod coreV1.Pod, command []string) (string, string,
}
}
}

// testConnectivity verifies connectivity between tester and server
func testConnectivity(senderPod coreV1.Pod, receiverPod coreV1.Pod, expectedStdout string,
expectedStderr string, port int, getTestCommandFunc func(receiverPod coreV1.Pod, port int) []string) {

testerCommand := getTestCommandFunc(receiverPod, port)

fmt.Fprintf(GinkgoWriter, "verifying connectivity from pod %s on node %s with IP %s to pod"+
" %s on node %s with IP %s\n", senderPod.Name, senderPod.Spec.NodeName, senderPod.Status.PodIP,
receiverPod.Name, receiverPod.Spec.NodeName, receiverPod.Status.PodIP)

stdOut, stdErr, err := f.K8sResourceManagers.PodManager().
PodExec(senderPod.Namespace, senderPod.Name, testerCommand)
Expect(err).ToNot(HaveOccurred())

fmt.Fprintf(GinkgoWriter, "stdout: %s and stderr: %s\n", stdOut, stdErr)

Expect(stdErr).To(ContainSubstring(expectedStderr))
Expect(stdOut).To(ContainSubstring(expectedStdout))
}
Loading