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

acceptance-tests #29

Merged
merged 24 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c33cd97
ci: Setup for acceptance tests
b1tamara Jun 2, 2023
9f1ef93
ci: basic test
domdom82 Jun 15, 2023
524a05d
fix(pcap-bosh-cli): Assume https for BOSH URL on missing scheme.
domdom82 Jun 26, 2023
eb599c5
fix(pcap-bosh-cli): Use BOSH default port if none provided in config.
domdom82 Jun 26, 2023
96c59e6
fix(pcap-bosh-cli): abort if director does not have UAA
domdom82 Jun 27, 2023
f028559
fix(pcap-bosh-cli): missing env expansion on config write
domdom82 Jun 27, 2023
f369238
fix(pcap-bosh-cli): throw error if user not logged in.
domdom82 Jun 28, 2023
79a318c
ci: do interactive bosh login to get refresh token
domdom82 Jun 28, 2023
b85c455
fix(pcap-bosh-cli): remove unused type option. only valid for cf.
domdom82 Jun 28, 2023
968893e
fix(pcap-bosh-cli): missing null check
domdom82 Jun 28, 2023
06924c4
ci: use apache as capture target
domdom82 Jun 30, 2023
8c3439a
ci: update pipeline.yml with acceptance tests
domdom82 Jun 30, 2023
55b5873
Merge branch 'main' into acceptance-tests
domdom82 Jun 30, 2023
346c4ec
fix(packaging): libpcap.tgz -> libpcap.tar.gz
domdom82 Jul 3, 2023
404f2f3
ci: remove dev pipeline
domdom82 Jul 3, 2023
70e49ab
Apply suggestions from code review
domdom82 Jul 3, 2023
a1d74c0
refactor(acceptance tests): Add comments on review
domdom82 Jul 3, 2023
a91ee73
refactor(pcap-bosh-cli): remove obsolete else case
domdom82 Jul 3, 2023
41d9da9
doc(acceptance tests): add go docs to common functions.
domdom82 Jul 3, 2023
af01bf2
refactor(acceptance tests): remove unused client auth on pcap-agent c…
domdom82 Jul 3, 2023
b6689a3
doc(acceptance tests): Add README.me to acceptance tests and explain …
domdom82 Jul 3, 2023
8db65c0
fix(pcap-bosh-cli): fix linter errors
domdom82 Jul 4, 2023
d5b50b6
ci: update dependabot and linter checks to apply to acceptance-tests dir
b1tamara Jul 5, 2023
5ad9c1a
doc(ci): Add docs for local stemcell
domdom82 Jul 5, 2023
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
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ updates:
prefix: "dep"
labels:
- run-ci
- package-ecosystem: gomod
directory: /acceptance-tests
schedule:
interval: weekly
day: "monday"
time: "09:00"
timezone: "Europe/Berlin"
commit-message:
prefix: "dep"
labels:
- run-ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package.json
# Releases/tarballs
.final_builds/jobs/**/*.tgz
.final_builds/packages/**/*.tgz
ci/scripts/stemcell/*.tgz
pcap-server.tgz
releases/*.tgz
releases/**/*.tgz
Expand Down
101 changes: 101 additions & 0 deletions acceptance-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Acceptance Tests

## Requirements

* Docker installed locally
* A matching Jammy stemcell tgz downloaded to `ci/scripts/stemcell`
* Get it from https://bosh.io/stemcells/bosh-warden-boshlite-ubuntu-jammy-go_agent

## Running

```shell
cd acceptance-tests
./run-local.sh
```

### Running on Docker for Mac

The BOSH Docker CPI requires cgroups v1 to be active. Docker for Mac since 4.3.x uses cgroups v2 by default.

v1 can be restored with the flag `deprecatedCgroupv1` to `true` in `~/Library/Group Containers/group.com.docker/settings.json`.

A convenience script that does this for you is below.

**WARNING:** This will restart your Docker Desktop!

```shell
docker_restart_with_cgroupsv1() {
SETTINGS=~/Library/Group\ Containers/group.com.docker/settings.json

if ! command -v jq >/dev/null || ! command -v sponge; then
echo "Requires jq and sponge. Consider installing via:"
echo " brew install jq moreutils"
return
fi

cgroupsV1Enabled=$(jq '.deprecatedCgroupv1' "$SETTINGS")
if [ "$cgroupsV1Enabled" = "true" ]; then
echo "deprecatedCgroupv1 is already set to 'true'. Acceptance tests should work."
else
echo "Stopping Docker to set the config flag deprecatedCgroupv1 = true in $SETTINGS"

while docker ps -q 2>/dev/null; do
launchctl stop $(launchctl list | grep docker.docker | awk '{print $3}')
osascript -e 'quit app "Docker"'
echo "Waiting for Docker daemon to stop responding."
sleep 1
done
echo 'Setting "deprecatedCgroupv1" to true.'

# Add the needed cgroup config to docker settings.json
# sponge is needed because we're updating the same file in place
echo '{"deprecatedCgroupv1": true}' |
jq -s '.[0] * .[1]' "$SETTINGS" - |
sponge "$SETTINGS"
# Restart docker desktop
echo "Restarting Docker"
open --background -a Docker

while ! docker ps -q 2>/dev/null; do
echo "Waiting for Docker daemon to be back up again. Sleeping 1s."
sleep 1
done
fi

docker info | grep "Cgroup"
}

docker_restart_with_cgroupsv1
```

The output at the end should be:
```plain
Cgroup Driver: cgroupfs
Cgroup Version: 1
```

### Focussed Tests

If you want to run only a specific part of the suite, you can use [focussed specs](https://onsi.github.io/ginkgo/#focused-specs)

The easiest way is to just provide the name of the tests you want to run as a command line argument like so:

```shell
./run-local.sh "description of the test to run"
```

The argument is passed as a regular expression that will match all `Describe`, `Context` or `It` closure descriptions in the suite.
So, e.g. if you want to run all tests that use mTLS, you can run:

```shell
./run-local.sh mTLS
```

However, if you want to run exactly one specific test, make sure you pass the exact description of the matching `It` closure:

```shell
./run-local.sh "Correctly terminates mTLS requests"
```

Alternatively, you add an `F` to your `Describe`, `Context` or `It` closures.
Don't forget to do a local commit before running the tests, else BOSH will fail to produce a release. The git repo must be clean before running the tests.
50 changes: 50 additions & 0 deletions acceptance-tests/acceptance_tests_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package acceptance_tests

import (
"encoding/json"
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"testing"
)

func TestAcceptanceTests(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "AcceptanceTests Suite")
}

var _ = SynchronizedBeforeSuite(func() []byte {
// Load config once, and pass to other
// threads as JSON-encoded byte array
var err error
config, err = loadConfig()
Expect(err).NotTo(HaveOccurred(), "loading common config")

// Deploy pcap-api deployment
deployPcap(
baseManifestVars{
deploymentName: deploymentNameForTestNode(),
},
[]string{},
map[string]interface{}{},
true,
)

configBytes, err := json.Marshal(&config)
Expect(err).NotTo(HaveOccurred())

return configBytes
}, func(configBytes []byte) {
// populate thread-local variable `config` in each thread
err := json.Unmarshal(configBytes, &config)
Expect(err).NotTo(HaveOccurred())
})

var _ = SynchronizedAfterSuite(func() {
// Clean up deployments on each thread
deleteDeployment(deploymentNameForTestNode())
}, func() {})

func deploymentNameForTestNode() string {
return fmt.Sprintf("pcap-%d", GinkgoParallelProcess())
}
68 changes: 68 additions & 0 deletions acceptance-tests/basic_pcap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package acceptance_tests

import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"net/http"
"os"
"os/exec"
"time"
)

var _ = Describe("Pcap Deployment", func() {
It("Deploys and Captures Traffic Successfully", func() {

info, _ := deployPcap(
baseManifestVars{
deploymentName: deploymentNameForTestNode(),
},
[]string{},
map[string]interface{}{},
true,
)

domdom82 marked this conversation as resolved.
Show resolved Hide resolved
By("Logging on to BOSH director to get a refresh token")
login(config.BoshClient, config.BoshClientSecret)

pcapBoshCliFile, err := os.CreateTemp("", "pcap-bosh-cli-*")
Expect(err).NotTo(HaveOccurred())
pcapBoshCli := pcapBoshCliFile.Name()

By("Downloading remote pcap-bosh-cli-linux-amd64 to " + pcapBoshCli)
domdom82 marked this conversation as resolved.
Show resolved Hide resolved
err = downloadFile(info, "/var/vcap/packages/pcap-api/bin/cli/build/pcap-bosh-cli-linux-amd64", pcapBoshCliFile, 0755)
Expect(err).NotTo(HaveOccurred())
err = pcapBoshCliFile.Close()
Expect(err).NotTo(HaveOccurred())

pcapFile := fmt.Sprintf("%s-capture.pcap", pcapBoshCli)
By("Starting capture of traffic on pcap-agent instance to file " + pcapFile)
cmdPcap := exec.Command(
pcapBoshCli,
"-d", deploymentNameForTestNode(),
"-g", "pcap-agent",
"-o", pcapFile,
"-u", fmt.Sprintf("http://%s:8080/", info.PcapAPIPublicIP), //TODO: make URL configurable in tests
"-v")
sessionPcap, err := gexec.Start(cmdPcap, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

By("Calling apache on pcap-agent instance to produce some traffic")
for request := 1; request <= 10; request++ {
time.Sleep(time.Second)
response, err := http.Get(fmt.Sprintf("http://%s:80/", info.PcapAgentPublicIP))
Expect(err).NotTo(HaveOccurred())
Expect(response.StatusCode).To(Equal(200))
}

By("Stopping capture after curl has finished")
sessionPcap.Interrupt()
Eventually(sessionPcap, time.Minute, time.Second).Should(gexec.Exit())

By("Checking that the capture has produced a valid pcap file")
pcapFileStat, err := os.Stat(pcapFile)
Expect(err).NotTo(HaveOccurred())
Expect(pcapFileStat.Size()).To(BeNumerically(">", 24)) // 24 bytes == pcap header only
domdom82 marked this conversation as resolved.
Show resolved Hide resolved
})
})
Loading