Skip to content

Commit f8fa52f

Browse files
author
Joe Ellis
committed
Add Docker image for testing Parsec as a systemd service
Signed-off-by: Joe Ellis <[email protected]>
1 parent 9530d64 commit f8fa52f

File tree

4 files changed

+169
-0
lines changed

4 files changed

+169
-0
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ jobs:
4242
run: docker build -t tpm-provider e2e_tests/provider_cfg/tpm
4343
- name: Run the container to execute the test script
4444
run: docker run -v $(pwd):/tmp/parsec -w /tmp/parsec tpm-provider /tmp/parsec/ci.sh tpm
45+
46+
installation-tests:
47+
name: Installation tests
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v1
51+
- name: Build and run the container
52+
run: e2e_tests/install/run-installation-tests.sh

e2e_tests/install/Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM ubuntu:18.04
2+
3+
ENV container docker
4+
5+
RUN apt-get update
6+
RUN apt-get install -y git make gcc python3 python curl wget cmake \
7+
automake autoconf libtool pkg-config libssl-dev \
8+
# These libraries are needed for bindgen as it uses
9+
# libclang.so
10+
clang libclang-dev libc6-dev-i386
11+
RUN apt-get install -y systemd systemd-sysv
12+
RUN apt-get clean
13+
14+
RUN useradd -m parsec
15+
RUN groupadd parsec-clients
16+
17+
USER parsec
18+
WORKDIR /home/parsec
19+
20+
# Install Rust toolchain.
21+
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
22+
ENV PATH "/home/parsec/.cargo/bin:$PATH"
23+
24+
# Install Parsec.
25+
RUN cargo install parsec-service --features mbed-crypto-provider
26+
RUN git clone https://github.com/parallaxsecond/parsec.git
27+
RUN cp parsec/config.toml config.toml
28+
29+
# Install the systemd unit files.
30+
RUN mkdir -p .config/systemd/user
31+
RUN cp parsec/systemd-daemon/parsec.service .config/systemd/user/parsec.service
32+
33+
USER root
34+
WORKDIR /root
35+
COPY context/run-tests.sh ./
36+
VOLUME [ "/sys/fs/cgroup" ]
37+
CMD [ "/lib/systemd/systemd" ]
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
function test_ping_parsec() {
6+
# Creates a new test user, adds them to the parsec-clients group, and
7+
# checks that the Parsec service can be pinged.
8+
9+
useradd -m test-user-1
10+
usermod -a -G parsec-clients test-user-1
11+
12+
su test-user-1 <<' EOSU'
13+
set -eu
14+
cd ${HOME}
15+
curl https://sh.rustup.rs -sSf | bash -s -- -y
16+
export PATH="${HOME}/.cargo/bin:$PATH"
17+
18+
git clone https://github.com/parallaxsecond/parsec-tool.git
19+
cd parsec-tool
20+
cargo build
21+
22+
set +e
23+
cargo run -- ping
24+
25+
# This test passes if the above command pinged the Parsec service
26+
# successfully.
27+
[ $? -eq 0 ]
28+
EOSU
29+
}
30+
31+
function test_ping_parsec_not_in_group() {
32+
# Creates a new test user, and tries to ping the Parsec service. This
33+
# should fail, since the user is not in the appropriate group.
34+
35+
useradd -m test-user-2
36+
37+
su test-user-2 <<' EOSU'
38+
set -eu
39+
cd ${HOME}
40+
curl https://sh.rustup.rs -sSf | bash -s -- -y
41+
export PATH="${HOME}/.cargo/bin:$PATH"
42+
43+
git clone https://github.com/parallaxsecond/parsec-tool.git
44+
cd parsec-tool
45+
cargo build
46+
47+
set +e
48+
cargo run -- ping
49+
50+
# This test passes if the above command failed to ping the Parsec service.
51+
[ $? -ne 0 ]
52+
EOSU
53+
}
54+
55+
function init_parsec() {
56+
mkdir /tmp/parsec
57+
chown parsec:parsec-clients /tmp/parsec
58+
chmod 750 /tmp/parsec
59+
60+
# Start the Parsec service as user parsec.
61+
su parsec -c 'systemctl --user start parsec'
62+
}
63+
64+
function main() {
65+
init_parsec
66+
67+
# Register tests.
68+
declare -a TESTS
69+
TESTS[1]="test_ping_parsec"
70+
TESTS[2]="test_ping_parsec_not_in_group"
71+
72+
# Run tests.
73+
NUM_FAILED=0
74+
for i in "${!TESTS[@]}"; do
75+
TEST_NAME="${TESTS[$i]}"
76+
echo "=== RUNNING TEST ${TEST_NAME} ==="
77+
if ${TESTS[$i]}; then
78+
echo "${TEST_NAME} passed."
79+
else
80+
echo "${TEST_NAME} failed!"
81+
NUM_FAILED=$((NUM_FAILED + 1))
82+
fi
83+
echo "" # spacing
84+
done
85+
86+
if [[ ${NUM_FAILED} -eq 0 ]]; then
87+
echo "All tests passed!"
88+
else
89+
echo "${NUM_FAILED} test(s) failed!"
90+
fi
91+
92+
return ${NUM_FAILED}
93+
}
94+
95+
main "${@}" || exit 1
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6+
7+
DOCKER_IMAGE_DIR="$SCRIPT_DIR"
8+
DOCKER_IMAGE_NAME="parsec"
9+
10+
docker build -t ${DOCKER_IMAGE_NAME} ${DOCKER_IMAGE_DIR}
11+
DOCKER_CONTAINER_ID=$(docker run -d \
12+
--rm \
13+
--tmpfs /run \
14+
--tmpfs /run/lock \
15+
--tmpfs /tmp:exec \
16+
-v /sys/fs/cgroup:/sys/fs/cgroup:ro \
17+
${DOCKER_IMAGE_NAME})
18+
19+
# Give the systemd daemon some time to spin up.
20+
sleep 3
21+
22+
echo "Running tests inside container..."
23+
docker exec ${DOCKER_CONTAINER_ID} /root/run-tests.sh
24+
TEST_STATUS=$?
25+
26+
echo "Testing complete, stopping container."
27+
docker stop ${DOCKER_CONTAINER_ID}
28+
29+
exit ${TEST_STATUS}

0 commit comments

Comments
 (0)