Skip to content

Commit

Permalink
fix formatting in makefile and minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
abhipth committed May 3, 2021
1 parent 26a633e commit 0c174c3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 31 deletions.
16 changes: 8 additions & 8 deletions test/agent/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
###Test Agent
### Test Agent
The test agent contains multiple binaries that are used by Ginkgo Automation tests.

###List of Go Binaries in the Agent
### List of Go Binaries in the Agent

Currently the agent supports the following Go Binaries.

####Traffic Testing
#### Traffic Testing

For traffic validation across multiple pods we have the following 3 Go binaries.

Expand All @@ -26,13 +26,13 @@ One way to run the traffic test is as follows
- Deploy M Client pods and pass the IP Address of N Servers as input.
- Query the metric server to see the Success/Failure Rate.

####Networking Testing
#### Networking Testing
Networking testing binary must be invoked on a pod that runs in Host Networking mode. It is capable of testing the Pod networking is setup correctly and once the Pod has been deleted the networking has been teared down correctly by the CNI Plugin.

###How to test the Agent locally
### How to test the Agent locally
Apart from running the tests on your local environment. For some test cases where we want to run test on Pod (for instance Pod networking tests) we can copy over the binary to the Pod and execute it. For e2e testing, we can push docker image to ECR and use the image in automation test suite.

####Running individual test component inside a Pod
#### Running individual test component inside a Pod
- While development you could generate the binary for the component you want to test. Let's say you would like to test the pod networking setup on a host network pod.
```
COMPONENT=networking #Example, when testing networking go binary
Expand All @@ -54,15 +54,15 @@ Apart from running the tests on your local environment. For some test cases wher
./tmp/<component> --<flags>
```

####Running the docker Image
#### Running the docker Image

Run the following command to build the agent image and push to ECR. This needs an existing repository with name "amazon/amazon-k8s-cni/test/agent"
```
AWS_ACCOUNT=<account> AWS_REGION=<region> make docker-build docker-push
```
Change the agent image in the Go code and run the test case as usual.

####Finalizing the changes
#### Finalizing the changes
- Submit PR with the change to Agent.
- One of the AWS Maintainer will push the image to ECR (Till we have pipeline that does this for us)
- Use the updated image tag wherever you want to update the docker image in automation tests.
Expand Down
2 changes: 2 additions & 0 deletions test/agent/cmd/networking/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/aws/amazon-vpc-cni-k8s/test/agent/cmd/networking/tester"
)

// TODO: Instead of passing the list of pods, get the pods from API Server so this agent can run as DS
// TODO: Export metrics via Prometheus for debugging and analysis purposes
func main() {
var podNetworkingValidationInput tester.PodNetworkingValidationInput
var podNetworkingValidationInputString string
Expand Down
58 changes: 40 additions & 18 deletions test/agent/cmd/traffic-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"log"
"net"
"net/http"
"os"
"strings"
"time"

Expand Down Expand Up @@ -58,39 +59,46 @@ func main() {
log.Printf("will test connection %s to the list of server %v on port %s",
connectionMode, serverList, serverPort)

hostName, err := os.Hostname()
if err != nil {
log.Fatalf("failed to get the host name: %v", err)
}

var failureList []input.Failure
for _, server := range serverList {
serverAddr := fmt.Sprintf("%s:%s", server, serverPort)

// Get connection based on the server mode - tcp/udp
conn, err := getConnection(serverAddr, connectionMode)
if err != nil {
log.Printf("failed to get connection to server %s: %v", serverAddr, err)
failure++
conn, failure := getConnection(serverAddr, connectionMode)
if failure != nil {
failureList = append(failureList, *failure)
continue
}

// Send data to the server and wait for response from the server (this sequence is
// expected from the server)
err = sendAndReceiveResponse(conn, serverAddr)
if err != nil {
log.Printf("failed to send/receive response from server %s: %v", serverAddr, err)
failure++
failure = sendAndReceiveResponse(conn, serverAddr)
if failure != nil {
failureList = append(failureList, *failure)
continue
}

// Connection successfully tested, mark as success and test next server
success++

}

fmt.Printf("Success: %d, Failure: %d", success, failure)
failure = len(failureList)

fmt.Printf("Success: %d, Failure: %d, Failure Reason: %v", success, failure, failureList)

// Report metrics to the aggregator address from all the clients if provided
// Otherwise the results can be read from stdout
if metricAggregatorAddr != "" {
body, _ := json.Marshal(input.TestStatus{
SuccessCount: success,
FailureCount: failure,
SourcePod: hostName,
Failures: failureList,
})
resp, err := http.Post(metricAggregatorAddr, "application/json", bytes.NewBuffer(body))
if err != nil {
Expand All @@ -105,46 +113,60 @@ func main() {
}
}

func getConnection(serverAddr string, serverMode string) (net.Conn, error) {
func getConnection(serverAddr string, serverMode string) (net.Conn, *input.Failure) {
failure := &input.Failure{
DestinationIP: serverAddr,
}

if serverMode == "tcp" {
conn, err := net.DialTimeout("tcp", serverAddr, TcpTimeout)
if err != nil {
return nil, fmt.Errorf("failed to connect to server %s: %v", serverAddr, err)
failure.FailureReason = fmt.Sprintf("failed to connect to server %v", err)
return nil, failure
}
return conn, nil
}
if serverMode == "udp" {
udpAddr, err := net.ResolveUDPAddr("udp", serverAddr)
if err != nil {
return nil, fmt.Errorf("failed to resolve the server address: %v", err)
failure.FailureReason = fmt.Sprintf("failed to resolve the server address: %v", err)
return nil, failure
}

conn, err := net.DialUDP("udp", nil, udpAddr)
if err != nil {
return nil, fmt.Errorf("failed to connect to udp server: %v", err)
failure.FailureReason = fmt.Sprintf("failed to connect to udp server: %v", err)
return nil, failure
}
return conn, nil
}

return nil, fmt.Errorf("invalid server mode provided %s", serverMode)
failure.FailureReason = fmt.Sprintf("invalid server mode provided %s", serverMode)
return nil, failure
}

func sendAndReceiveResponse(conn net.Conn, serverAddr string) error {
func sendAndReceiveResponse(conn net.Conn, serverAddr string) *input.Failure {
defer conn.Close()

failure := &input.Failure{
DestinationIP: serverAddr,
}

data := []byte(ClientRequestData)

_, err := conn.Write(data)
if err != nil {
return fmt.Errorf("failed to write to server: %v", err)
failure.FailureReason = fmt.Sprintf("failed to write to server: %v", err)
return failure
}

log.Printf("successfully sent data to the server %s", serverAddr)

buffer := make([]byte, 1024)
respLen, err := conn.Read(buffer)
if err != nil || respLen == 0 {
return fmt.Errorf("failed to read from the server, resp length %d: %v", respLen, err)
failure.FailureReason = fmt.Sprintf("failed to read from the server, resp length %d: %v", respLen, err)
return failure
}

log.Printf("successfully recieved response from server %s: %s", serverAddr, string(buffer))
Expand Down
2 changes: 1 addition & 1 deletion test/agent/cmd/traffic-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {

flag.Parse()

addr := fmt.Sprintf("%s:%s", "localhost", serverPort)
addr := fmt.Sprintf(":%s", serverPort)

if serverMode == "tcp" {
StartTCPServer(addr)
Expand Down
7 changes: 7 additions & 0 deletions test/agent/pkg/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ package input
type TestStatus struct {
SuccessCount int
FailureCount int
SourcePod string
Failures []Failure
}

type Failure struct {
DestinationIP string
FailureReason string
}
8 changes: 4 additions & 4 deletions test/integration-new/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
##CNI Integration Test Suites
## CNI Integration Test Suites

The package contains automated integration tests suites for `amazon-vpc-cni-k8s` .

###Prerequisites
### Prerequisites
The integration test requires
- At least 2 nodes in a node group.
- Nodes in the nodegroup shouldn't have existing pods.
- Ginkgo installed on your environment. To install `go get github.com/onsi/ginkgo/ginkgo`
- Supports instance types having at least 3 ENIs and 16+ Secondary IPv4 Addresses across all ENIs.

####Testing
#### Testing
Set the environment variables that will be passed to Ginkgo script. If you want to directly pass the arguments you can skip to next step.
```
CLUSTER_NAME=<eks-cluster-name>
Expand Down Expand Up @@ -37,7 +37,7 @@ ginkgo -v --failOnPending -- \
--ng-name-label-val=$NG_NAME_LABEL_VAL
```

###Future Work
### Future Work
Currently the package is named as `integraiton-new` because we already have `integration` directory with existing Ginkgo test cases with a separate `go.mod`. Once the older package is completely deprecated we will rename this package to `integration`.


Expand Down

0 comments on commit 0c174c3

Please sign in to comment.