test: add logging tests

The main purpose of these tests is to make sure that the log actually
contains output from the container. We don't test the timestamps or the
stream that's stated at the moment.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
Aleksa Sarai 2017-03-22 23:07:15 +11:00
parent c31f2cf0ee
commit 65527da361
No known key found for this signature in database
GPG key ID: 9E18AA267DDB8DB4
11 changed files with 203 additions and 11 deletions

View file

@ -56,8 +56,6 @@ type RootConfig struct {
// LogDir is the default log directory were all logs will go unless kubelet // LogDir is the default log directory were all logs will go unless kubelet
// tells us to put them somewhere else. // tells us to put them somewhere else.
//
// TODO: This is currently unused until the conmon logging rewrite is done.
LogDir string `toml:"log_dir"` LogDir string `toml:"log_dir"`
} }

View file

@ -99,6 +99,103 @@ function teardown() {
stop_ocid stop_ocid
} }
@test "ctr logging" {
start_ocid
run ocic pod run --config "$TESTDATA"/sandbox_config.json
echo "$output"
[ "$status" -eq 0 ]
pod_id="$output"
run ocic pod list
echo "$output"
[ "$status" -eq 0 ]
# Create a new container.
newconfig=$(mktemp --tmpdir ocid-config.XXXXXX.json)
cp "$TESTDATA"/container_config_logging.json "$newconfig"
sed -i 's|"%echooutput%"|"here", "is", "some", "output"|' "$newconfig"
run ocic ctr create --config "$newconfig" --pod "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
ctr_id="$output"
run ocic ctr start --id "$ctr_id"
echo "$output"
[ "$status" -eq 0 ]
run ocic ctr stop --id "$ctr_id"
echo "$output"
# Ignore errors on stop.
run ocic ctr status --id "$ctr_id"
[ "$status" -eq 0 ]
run ocic ctr remove --id "$ctr_id"
echo "$output"
[ "$status" -eq 0 ]
# Check that the output is what we expect.
run cat "$DEFAULT_LOG_PATH/$pod_id/$ctr_id.log"
echo "$DEFAULT_LOG_PATH/$pod_id/$ctr_id.log ::" "$output"
[ "$status" -eq 0 ]
[[ "$output" == *"here is some output" ]]
run ocic pod stop --id "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
run ocic pod remove --id "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
cleanup_ctrs
cleanup_pods
stop_ocid
}
@test "ctr logging [tty=true]" {
start_ocid
run ocic pod run --config "$TESTDATA"/sandbox_config.json
echo "$output"
[ "$status" -eq 0 ]
pod_id="$output"
run ocic pod list
echo "$output"
[ "$status" -eq 0 ]
# Create a new container.
newconfig=$(mktemp --tmpdir ocid-config.XXXXXX.json)
cp "$TESTDATA"/container_config_logging.json "$newconfig"
sed -i 's|"%echooutput%"|"here", "is", "some", "output"|' "$newconfig"
sed -i 's|"tty": false,|"tty": true,|' "$newconfig"
run ocic ctr create --config "$newconfig" --pod "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
ctr_id="$output"
run ocic ctr start --id "$ctr_id"
echo "$output"
[ "$status" -eq 0 ]
run ocic ctr stop --id "$ctr_id"
echo "$output"
# Ignore errors on stop.
run ocic ctr status --id "$ctr_id"
[ "$status" -eq 0 ]
run ocic ctr remove --id "$ctr_id"
echo "$output"
[ "$status" -eq 0 ]
# Check that the output is what we expect.
run cat "$DEFAULT_LOG_PATH/$pod_id/$ctr_id.log"
echo "$DEFAULT_LOG_PATH/$pod_id/$ctr_id.log ::" "$output"
[ "$status" -eq 0 ]
[[ "$output" == *"here is some output" ]]
run ocic pod stop --id "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
run ocic pod remove --id "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
cleanup_ctrs
cleanup_pods
stop_ocid
}
# regression test for #127 # regression test for #127
@test "ctrs status for a pod" { @test "ctrs status for a pod" {
start_ocid start_ocid

View file

@ -45,6 +45,8 @@ COPYIMG_BINARY=${COPYIMG_BINARY:-${OCID_ROOT}/cri-o/test/copyimg/copyimg}
ARTIFACTS_PATH=${ARTIFACTS_PATH:-${OCID_ROOT}/cri-o/.artifacts} ARTIFACTS_PATH=${ARTIFACTS_PATH:-${OCID_ROOT}/cri-o/.artifacts}
# Path of the checkseccomp binary. # Path of the checkseccomp binary.
CHECKSECCOMP_BINARY=${CHECKSECCOMP_BINARY:-${OCID_ROOT}/cri-o/test/checkseccomp/checkseccomp} CHECKSECCOMP_BINARY=${CHECKSECCOMP_BINARY:-${OCID_ROOT}/cri-o/test/checkseccomp/checkseccomp}
# XXX: This is hardcoded inside cri-o at the moment.
DEFAULT_LOG_PATH=/var/log/ocid/pods
TESTDIR=$(mktemp -d) TESTDIR=$(mktemp -d)
if [ -e /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then if [ -e /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
@ -75,6 +77,16 @@ if ! [ -d "$ARTIFACTS_PATH"/redis-image ]; then
fi fi
fi fi
# Make sure we have a copy of the busybox:latest image.
if ! [ -d "$ARTIFACTS_PATH"/busybox-image ]; then
mkdir -p "$ARTIFACTS_PATH"/busybox-image
if ! "$COPYIMG_BINARY" --import-from=docker://busybox --export-to=dir:"$ARTIFACTS_PATH"/busybox-image --signature-policy="$INTEGRATION_ROOT"/policy.json ; then
echo "Error pulling docker://busybox"
rm -fr "$ARTIFACTS_PATH"/busybox-image
exit 1
fi
fi
# Run ocid using the binary specified by $OCID_BINARY. # Run ocid using the binary specified by $OCID_BINARY.
# This must ONLY be run on engines created with `start_ocid`. # This must ONLY be run on engines created with `start_ocid`.
function ocid() { function ocid() {
@ -145,6 +157,11 @@ function start_ocid() {
ocic image pull redis:latest ocic image pull redis:latest
fi fi
REDIS_IMAGEID=$(ocic image status --id=redis | head -1 | sed -e "s/ID: //g") REDIS_IMAGEID=$(ocic image status --id=redis | head -1 | sed -e "s/ID: //g")
run ocic image status --id=busybox
if [ "$status" -ne 0 ] ; then
ocic image pull busybox:latest
fi
BUSYBOX_IMAGEID=$(ocic image status --id=busybox | head -1 | sed -e "s/ID: //g")
} }
function cleanup_ctrs() { function cleanup_ctrs() {

View file

@ -7,11 +7,9 @@
"image": "docker://redis:latest" "image": "docker://redis:latest"
}, },
"command": [ "command": [
"/bin/bash"
],
"args": [
"/bin/ls" "/bin/ls"
], ],
"args": [],
"working_dir": "/", "working_dir": "/",
"envs": [ "envs": [
{ {

View file

@ -41,7 +41,7 @@
}, },
"privileged": true, "privileged": true,
"readonly_rootfs": true, "readonly_rootfs": true,
"log_path": "container.log", "log_path": "",
"stdin": false, "stdin": false,
"stdin_once": false, "stdin_once": false,
"tty": false, "tty": false,

View file

@ -0,0 +1,82 @@
{
"metadata": {
"name": "container1",
"attempt": 1
},
"image": {
"image": "docker://busybox:latest"
},
"command": [
"/bin/echo"
],
"args": [
"%echooutput%"
],
"working_dir": "/",
"envs": [
{
"key": "PATH",
"value": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
},
{
"key": "TERM",
"value": "xterm"
},
{
"key": "TESTDIR",
"value": "test/dir1"
},
{
"key": "TESTFILE",
"value": "test/file1"
}
],
"labels": {
"type": "small",
"batch": "no"
},
"annotations": {
"owner": "dragon",
"daemon": "ocid"
},
"privileged": true,
"readonly_rootfs": true,
"log_path": "",
"stdin": false,
"stdin_once": false,
"tty": false,
"linux": {
"resources": {
"cpu_period": 10000,
"cpu_quota": 20000,
"cpu_shares": 512,
"memory_limit_in_bytes": 88000000,
"oom_score_adj": 30
},
"capabilities": {
"add_capabilities": [
"setuid",
"setgid"
],
"drop_capabilities": [
"audit_write",
"audit_read"
]
},
"selinux_options": {
"user": "system_u",
"role": "system_r",
"type": "container_t",
"level": "s0:c4,c5"
},
"user": {
"uid": 5,
"gid": 300,
"additional_gids": [
400,
401,
402
]
}
}
}

View file

@ -41,7 +41,7 @@
}, },
"privileged": true, "privileged": true,
"readonly_rootfs": true, "readonly_rootfs": true,
"log_path": "container.log", "log_path": "",
"stdin": false, "stdin": false,
"stdin_once": false, "stdin_once": false,
"tty": false, "tty": false,

View file

@ -15,7 +15,7 @@
} }
], ],
"readonly_rootfs": true, "readonly_rootfs": true,
"log_path": "container.log", "log_path": "",
"stdin": false, "stdin": false,
"stdin_once": false, "stdin_once": false,
"tty": false, "tty": false,

View file

@ -39,7 +39,7 @@
"pod": "podsandbox1" "pod": "podsandbox1"
}, },
"readonly_rootfs": false, "readonly_rootfs": false,
"log_path": "container.log", "log_path": "",
"stdin": false, "stdin": false,
"stdin_once": false, "stdin_once": false,
"tty": false, "tty": false,

View file

@ -6,7 +6,7 @@
"attempt": 1 "attempt": 1
}, },
"hostname": "ocic_host", "hostname": "ocic_host",
"log_directory": ".", "log_directory": "",
"dns_options": { "dns_options": {
"servers": [ "servers": [
"server1.redhat.com", "server1.redhat.com",

View file

@ -6,7 +6,7 @@
"attempt": 1 "attempt": 1
}, },
"hostname": "ocic_host", "hostname": "ocic_host",
"log_directory": ".", "log_directory": "",
"dns_options": { "dns_options": {
"servers": [ "servers": [
"server1.redhat.com", "server1.redhat.com",