Skip to content

Commit e4c6d22

Browse files
authored
Merge pull request #487 from vyaghras/Bottlerocket_esting_cli
Bottlerocket Testing Cli
2 parents 317b755 + 7335679 commit e4c6d22

File tree

23 files changed

+785
-7
lines changed

23 files changed

+785
-7
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
- run: make duplicator-resource-agent
2828
- run: make example-resource-agent
2929
- run: make example-test-agent
30+
- run: make example-test-agent-cli
3031
- run: make integ-test
3132
env:
3233
TESTSYS_SELFTEST_SKIP_IMAGE_BUILDS: true

Cargo.lock

Lines changed: 68 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members = [
33
"agent/agent-common",
44
"agent/resource-agent",
55
"agent/test-agent",
6+
"agent/test-agent-cli",
67
"bottlerocket/agents",
78
"cli",
89
"bottlerocket/types",

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ TAG_IMAGES = $(addprefix tag-, $(IMAGES))
3030
# Store targets to push images
3131
PUSH_IMAGES = $(addprefix push-, $(IMAGES))
3232

33-
.PHONY: build sdk-openssl example-test-agent example-resource-agent \
33+
.PHONY: build sdk-openssl example-test-agent example-test-agent-cli example-resource-agent \
3434
images fetch integ-test show-variables cargo-deny tools $(IMAGES) \
3535
tag-images $(TAG_IMAGES) push-images $(PUSH_IMAGES) print-image-names \
3636
help
@@ -97,6 +97,14 @@ example-resource-agent: show-variables fetch
9797
--network none \
9898
-f agent/resource-agent/examples/example_resource_agent/Dockerfile .
9999

100+
# Build the container image for the example test-agent-cli program
101+
example-test-agent-cli: show-variables fetch
102+
docker build $(DOCKER_BUILD_FLAGS) \
103+
--build-arg ARCH="$(TESTSYS_BUILD_HOST_UNAME_ARCH)" \
104+
--build-arg BUILDER_IMAGE="$(BUILDER_IMAGE)" \
105+
--tag "example-test-agent-cli" \
106+
-f agent/test-agent-cli/examples/example_test_agent_cli/Dockerfile .
107+
100108
# Build the container image for the example duplicator resource-agent program
101109
duplicator-resource-agent: show-variables fetch
102110
docker build $(DOCKER_BUILD_FLAGS) \
@@ -155,6 +163,7 @@ integ-test: $(if $(TESTSYS_SELFTEST_SKIP_IMAGE_BUILDS), ,controller example-test
155163
$(shell pwd)/bin/download-kind.sh --platform $(TESTSYS_BUILD_HOST_PLATFORM) --goarch ${TESTSYS_BUILD_HOST_GOARCH}
156164
docker tag example-test-agent example-test-agent:integ
157165
docker tag controller controller:integ
166+
docker tag example-test-agent-cli example-test-agent-cli:integ
158167
docker tag duplicator-resource-agent duplicator-resource-agent:integ
159168
cargo test --features integ -- --test-threads=$(TESTSYS_SELFTEST_THREADS)
160169

agent/test-agent-cli/Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "test-agent-cli"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
license = "MIT OR Apache-2.0"
7+
8+
[dependencies]
9+
argh = "0.1"
10+
agent-common = { version = "0.0.1", path = "../agent-common" }
11+
test-agent = { version = "0.0.1", path = "../test-agent" }
12+
tokio = { version = "1", features = ["macros", "rt-multi-thread", "fs"] }
13+
tokio-util = "0.7"
14+
log = "0.4"
15+
model = { version = "0.0.1", path = "../../model" }
16+
snafu = "0.7"
17+
async-trait = "0.1"
18+
tempfile = "3"
19+
serde_json = "1"
20+
env_logger = "0.9"
21+
serde_plain = "0.3"
22+
serde_derive = "1"
23+
serde = "1"
24+
tar = "0.4"
25+
26+
[dev-dependencies]
27+
assert_cmd = "2.0"
28+
selftest = { version = "0.0.1", path = "../../selftest" }
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Steps to use Test-agent Command Line Interface
2+
`test-agent-cli` lets you write TestSys test using Bash and help in receiving and sending information from/to the TestSys cluster.
3+
4+
## Prerequisites:
5+
* kind: https://kind.sigs.k8s.io/docs/user/quick-start/
6+
* Kubectl: https://kubernetes.io/docs/tasks/tools/
7+
* Docker : https://docs.docker.com/get-started/
8+
9+
## Steps to install TestSys
10+
Set the TESTSYS_DIR variable to point to the directory in which you have cloned the project. For example:
11+
```shell
12+
export TESTSYS_DIR="${HOME}/repos/bottlerocket-test-system"
13+
```
14+
Set alias
15+
```shell
16+
alias cli="${TESTSYS_DIR}/.cargo/bin/cli"
17+
```
18+
Install the `cli` command line tool into the local CARGO_HOME as:
19+
```shell
20+
cd "${TESTSYS_DIR}"
21+
cargo install --path "${TESTSYS_DIR}/cli" --force
22+
```
23+
24+
## Steps to create Bash based TestAgent:
25+
26+
The following commands can be used to communicate with a TestSys cluster. Create a bash script like [Example test](../examples/example_test_agent_cli/example-test.sh).
27+
```shell
28+
# Get the configuration details and set the task state running
29+
test-agent-cli init
30+
31+
# Get the number of retires allowed in case of failing tests
32+
test-agent-cli retry-count
33+
34+
# Get the secret value using the secret key
35+
test-agent-cli get-secret secret-key
36+
37+
# Send the result of every test run to test object in Controller
38+
test-agent-cli send-result -o pass -p 1 -f 0 -s 0
39+
40+
# Send any error encountered in test
41+
test-agent-cli send-error error-message
42+
43+
# Mark the test as completed
44+
test-agent-cli terminate --results-dir results_directory
45+
```
46+
Create a [Dockerfile](../examples/example_test_agent_cli/Dockerfile).\
47+
Remember to set the ENTRYPOINT to the test Bash script and install the required packages.
48+
49+
Create the docker image.\
50+
**Note**: Add a target to the `Makefile` to create the new image.
51+
```shell
52+
make example-test-agent-cli
53+
docker image tag example-test-agent-cli example-test-agent-cli:bash
54+
```
55+
56+
Create and tag the controller image.
57+
```shell
58+
make controller
59+
docker image tag controller controller:bash
60+
```
61+
62+
## Steps to use Bash based TestAgent:
63+
64+
Check if the cluster already exists:
65+
```shell
66+
kind get clusters
67+
```
68+
If the cluster already exists, it should be deleted.
69+
```shell
70+
kind delete cluster --name <testsys_cluster_name>
71+
```
72+
Create the new cluster.
73+
```shell
74+
kind create cluster --name <testsys_cluster_name>
75+
```
76+
Now the images created earlier need to be added to the cluster.
77+
```shell
78+
kind load docker-image controller:bash example-test-agent-cli:bash --name <testsys_cluster_name>
79+
```
80+
Install TestSys to the cluster.
81+
```shell
82+
cli install --controller-uri controller:bash
83+
```
84+
85+
Create a [yaml file](../tests/data/deploy_test.yaml) for Test.
86+
87+
Run the test.
88+
```shell
89+
cli run file <filename>
90+
```
91+
Check the status of the test.
92+
```shell
93+
cli status -c
94+
```
95+
Cleanup all the resources.
96+
```shell
97+
cli delete
98+
```
99+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# syntax=docker/dockerfile:1.1.3-experimental
2+
ARG BUILDER_IMAGE
3+
FROM ${BUILDER_IMAGE} as build
4+
5+
ARG ARCH
6+
USER root
7+
# We need these environment variables set for building the `openssl-sys` crate
8+
ENV PKG_CONFIG_PATH=/${ARCH}-bottlerocket-linux-musl/sys-root/usr/lib/pkgconfig
9+
ENV PKG_CONFIG_ALLOW_CROSS=1
10+
ENV CARGO_HOME=/src/.cargo
11+
ENV OPENSSL_STATIC=true
12+
ENV CARGO_HOME=/src/.cargo
13+
ADD ./ /src/
14+
WORKDIR /src/agent/test-agent-cli
15+
RUN --mount=type=cache,mode=0777,target=/src/target \
16+
cargo install --locked --offline --target ${ARCH}-bottlerocket-linux-musl --path . --root ./
17+
18+
FROM public.ecr.aws/amazonlinux/amazonlinux:2
19+
# Install all the required packages for Bash test script.
20+
RUN yum update -y \
21+
&& yum install -y jq \
22+
&& yum clean all
23+
24+
COPY --from=build /src/agent/test-agent-cli/bin/test-agent-cli /usr/local/bin/
25+
# Copy the Bash test script
26+
COPY --from=build /src/agent/test-agent-cli/examples/example_test_agent_cli/example-test.sh ./
27+
28+
# Mark the test script as entry point
29+
ENTRYPOINT ["/bin/bash", "./example-test.sh"]
30+

0 commit comments

Comments
 (0)