Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- run: make duplicator-resource-agent
- run: make example-resource-agent
- run: make example-test-agent
- run: make example-test-agent-cli
- run: make integ-test
env:
TESTSYS_SELFTEST_SKIP_IMAGE_BUILDS: true
Expand Down
74 changes: 68 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"agent/agent-common",
"agent/resource-agent",
"agent/test-agent",
"agent/test-agent-cli",
"bottlerocket/agents",
"cli",
"bottlerocket/types",
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TAG_IMAGES = $(addprefix tag-, $(IMAGES))
# Store targets to push images
PUSH_IMAGES = $(addprefix push-, $(IMAGES))

.PHONY: build sdk-openssl example-test-agent example-resource-agent \
.PHONY: build sdk-openssl example-test-agent example-test-agent-cli example-resource-agent \
images fetch integ-test show-variables cargo-deny tools $(IMAGES) \
tag-images $(TAG_IMAGES) push-images $(PUSH_IMAGES) print-image-names

Expand Down Expand Up @@ -86,6 +86,14 @@ example-resource-agent: show-variables fetch
--network none \
-f agent/resource-agent/examples/example_resource_agent/Dockerfile .

# Build the container image for the example test-agent-cli program
example-test-agent-cli: show-variables fetch
docker build $(DOCKER_BUILD_FLAGS) \
--build-arg ARCH="$(TESTSYS_BUILD_HOST_UNAME_ARCH)" \
--build-arg BUILDER_IMAGE="$(BUILDER_IMAGE)" \
--tag "example-test-agent-cli" \
-f agent/test-agent-cli/examples/example_test_agent_cli/Dockerfile .

# Build the container image for the example duplicator resource-agent program
duplicator-resource-agent: show-variables fetch
docker build $(DOCKER_BUILD_FLAGS) \
Expand Down Expand Up @@ -143,6 +151,7 @@ integ-test: $(if $(TESTSYS_SELFTEST_SKIP_IMAGE_BUILDS), ,controller example-test
$(shell pwd)/bin/download-kind.sh --platform $(TESTSYS_BUILD_HOST_PLATFORM) --goarch ${TESTSYS_BUILD_HOST_GOARCH}
docker tag example-test-agent example-test-agent:integ
docker tag controller controller:integ
docker tag example-test-agent-cli example-test-agent-cli:integ
docker tag duplicator-resource-agent duplicator-resource-agent:integ
cargo test --features integ -- --test-threads=$(TESTSYS_SELFTEST_THREADS)

Expand Down
28 changes: 28 additions & 0 deletions agent/test-agent-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "test-agent-cli"
version = "0.1.0"
edition = "2021"
publish = false
license = "MIT OR Apache-2.0"

[dependencies]
argh = "0.1"
agent-common = { version = "0.0.1", path = "../agent-common" }
test-agent = { version = "0.0.1", path = "../test-agent" }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "fs"] }
tokio-util = "0.7"
log = "0.4"
model = { version = "0.0.1", path = "../../model" }
snafu = "0.7"
async-trait = "0.1"
tempfile = "3"
serde_json = "1"
env_logger = "0.9"
serde_plain = "0.3"
serde_derive = "1"
serde = "1"
tar = "0.4"

[dev-dependencies]
assert_cmd = "2.0"
selftest = { version = "0.0.1", path = "../../selftest" }
99 changes: 99 additions & 0 deletions agent/test-agent-cli/design/RUNBOOK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Steps to use Test-agent Command Line Interface
Comment thread
vyaghras marked this conversation as resolved.
Comment thread
vyaghras marked this conversation as resolved.
`test-agent-cli` lets you write TestSys test using Bash and help in receiving and sending information from/to the TestSys cluster.

## Prerequisites:
Comment thread
vyaghras marked this conversation as resolved.
* kind: https://kind.sigs.k8s.io/docs/user/quick-start/
* Kubectl: https://kubernetes.io/docs/tasks/tools/
* Docker : https://docs.docker.com/get-started/

## Steps to install TestSys
Set the TESTSYS_DIR variable to point to the directory in which you have cloned the project. For example:
```shell
export TESTSYS_DIR="${HOME}/repos/bottlerocket-test-system"
```
Set alias
```shell
alias cli="${TESTSYS_DIR}/.cargo/bin/cli"
```
Install the `cli` command line tool into the local CARGO_HOME as:
```shell
cd "${TESTSYS_DIR}"
cargo install --path "${TESTSYS_DIR}/cli" --force
```

## Steps to create Bash based TestAgent:

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).
```shell
# Get the configuration details and set the task state running
test-agent-cli init

# Get the number of retires allowed in case of failing tests
test-agent-cli retry-count

# Get the secret value using the secret key
test-agent-cli get-secret secret-key

# Send the result of every test run to test object in Controller
test-agent-cli send-result -o pass -p 1 -f 0 -s 0

# Send any error encountered in test
test-agent-cli send-error error-message

# Mark the test as completed
test-agent-cli terminate --results-dir results_directory
```
Create a [Dockerfile](../examples/example_test_agent_cli/Dockerfile).\
Remember to set the ENTRYPOINT to the test Bash script and install the required packages.

Create the docker image.\
**Note**: Add a target to the `Makefile` to create the new image.
```shell
make example-test-agent-cli
Comment thread
vyaghras marked this conversation as resolved.
docker image tag example-test-agent-cli example-test-agent-cli:bash
```

Create and tag the controller image.
```shell
make controller
docker image tag controller controller:bash
```

## Steps to use Bash based TestAgent:

Check if the cluster already exists:
```shell
kind get clusters
```
If the cluster already exists, it should be deleted.
```shell
kind delete cluster --name <testsys_cluster_name>
```
Create the new cluster.
```shell
kind create cluster --name <testsys_cluster_name>
```
Now the images created earlier need to be added to the cluster.
```shell
kind load docker-image controller:bash example-test-agent-cli:bash --name <testsys_cluster_name>
```
Install TestSys to the cluster.
```shell
cli install --controller-uri controller:bash
```

Create a [yaml file](../tests/data/deploy_test.yaml) for Test.

Run the test.
```shell
cli run file <filename>
```
Check the status of the test.
```shell
cli status -c
```
Cleanup all the resources.
```shell
cli delete
```

30 changes: 30 additions & 0 deletions agent/test-agent-cli/examples/example_test_agent_cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# syntax=docker/dockerfile:1.1.3-experimental
Comment thread
vyaghras marked this conversation as resolved.
ARG BUILDER_IMAGE
FROM ${BUILDER_IMAGE} as build

ARG ARCH
USER root
# We need these environment variables set for building the `openssl-sys` crate
ENV PKG_CONFIG_PATH=/${ARCH}-bottlerocket-linux-musl/sys-root/usr/lib/pkgconfig
ENV PKG_CONFIG_ALLOW_CROSS=1
ENV CARGO_HOME=/src/.cargo
ENV OPENSSL_STATIC=true
ENV CARGO_HOME=/src/.cargo
ADD ./ /src/
WORKDIR /src/agent/test-agent-cli
RUN --mount=type=cache,mode=0777,target=/src/target \
cargo install --locked --offline --target ${ARCH}-bottlerocket-linux-musl --path . --root ./

FROM public.ecr.aws/amazonlinux/amazonlinux:2
# Install all the required packages for Bash test script.
RUN yum update -y \
&& yum install -y jq \
&& yum clean all

COPY --from=build /src/agent/test-agent-cli/bin/test-agent-cli /usr/local/bin/
# Copy the Bash test script
COPY --from=build /src/agent/test-agent-cli/examples/example_test_agent_cli/example-test.sh ./

# Mark the test script as entry point
ENTRYPOINT ["/bin/bash", "./example-test.sh"]

Loading