1
0
mirror of https://github.com/projectatomic/atomic.git synced 2026-02-05 18:45:01 +01:00
Files
atomic/tests/integration/test_run.sh
Brent Baude 2dfeae1356 Atomic/backends/_docker.py: Error prevention with atomic run
There were two primary cases where a secondary atomic run with a command
would trigger an exception.  The first was reported in
https://github.com/projectatomic/atomic/issues/1006. Basically it can
be summarized as:

```
atomic run registry.fedoraproject.org/fedora:25 date  # works fine
atomic run registry.fedoraproject.org/fedora:26 date  # tries to run in the existing f25 container
```

The second case is as simple as:

```
atomic run registry.fedoraproject.org/fedora:25 date  # works fine
atomic run registry.fedoraproject.org/fedora:25 date  # fails
```

This fails because atomic starts the stopped f25 container and then attempts a docker exec.  The
exec fails because the 'date' command is short-lived and the container exits prior to the exec
being run.

We now catch those exceptions and notify the user.  We added a `--replace` option to run where
atomic will now delete the container in question and re-run it from the correct image.

Closes: #1019
Approved by: baude
2017-05-31 19:20:25 +00:00

70 lines
1.1 KiB
Bash
Executable File

#!/bin/bash -x
set -euo pipefail
IFS=$'\n\t'
ATOMIC=${ATOMIC:="/usr/bin/atomic"}
ATOMIC=$(grep -v -- --debug <<< "$ATOMIC")
DOCKER=${DOCKER:="/usr/bin/docker"}
teardown () {
set +e
${DOCKER} rm -f RUN_TEST > /dev/null
set -e
}
fail () {
echo "Fail: TEST ${1} should have failed and did not"
exit 1
}
passed () {
echo "Passed: TEST ${1}"
}
failed () {
echo "Fail: TEST ${1}"
exit 1
}
trap teardown EXIT
# Check that atomic run's naming
TEST_NUM=1
${ATOMIC} run -n RUN_TEST atomic-test-1 date
CID=$("$DOCKER" ps -alq)
NAME=$("$DOCKER" inspect --format='{{.Name}}' "$CID")
if [[ "${NAME}" != /RUN_TEST ]]; then
failed "${TEST_NUM}"
fi
passed "${TEST_NUM}"
TEST_NUM=2
rc=0
${ATOMIC} run -n RUN_TEST atomic-test-1 date 1>/dev/null || rc=$?
if [[ ${rc} != 1 ]]; then
# Test failed
fail "${TEST_NUM}"
fi
passed "${TEST_NUM}"
TEST_NUM=3
${ATOMIC} run --replace -n RUN_TEST atomic-test-1 date
NEW_CID=$("$DOCKER" ps -alq)
NAME=$("$DOCKER" inspect --format='{{.Name}}' "$NEW_CID")
if [[ "${NAME}" != /RUN_TEST ]]; then
failed "${TEST_NUM}"
fi
if [[ "${NEW_CID}" == "${CID}" ]]; then
failed "${TEST_NUM}"
fi
passed "${TEST_NUM}"