Skip to content

Commit 7a6ec0e

Browse files
committedJul 18, 2024
test: add rootless integration tests
1 parent f7313bd commit 7a6ec0e

File tree

15 files changed

+165
-0
lines changed

15 files changed

+165
-0
lines changed
 

‎cmd/containeragent/initialize/package_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func (*importSuite) TestImports(c *gc.C) {
9696
"rpc/jsoncodec",
9797
"rpc/params",
9898
"service/common",
99+
"service/pebble/identity",
99100
"service/pebble/plan",
100101
"service/snap",
101102
"service/systemd",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
status-set maintenance "Setup..."
5+
juju-log "charm=$UID"
6+
juju-log "sudo=$(sudo -n echo yes || echo no)"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -e
3+
4+
export PEBBLE_SOCKET=/charm/containers/rootful/pebble.socket
5+
juju-log "rootful=$(/charm/bin/pebble exec -- bash -c 'echo $UID')"
6+
7+
touch /charm/containers/rootful/ready
8+
if [ -f "/charm/containers/rootless/ready" ]; then
9+
status-set active "Ready."
10+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -e
3+
4+
export PEBBLE_SOCKET=/charm/containers/rootless/pebble.socket
5+
juju-log "rootless=$(/charm/bin/pebble exec -- bash -c 'echo $UID')"
6+
7+
touch /charm/containers/rootless/ready
8+
if [ -f "/charm/containers/rootful/ready" ]; then
9+
status-set active "Ready."
10+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
status-set maintenance "Setup..."
5+
juju-log "charm=$UID"
6+
juju-log "sudo=$(sudo -n echo yes || echo no)"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bases:
2+
- name: ubuntu
3+
channel: 22.04/stable
4+
architectures:
5+
- amd64
6+
- arm64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: sidecar-non-root
2+
summary: sidecar charm with rootless charm and workloads
3+
description: ""
4+
containers:
5+
rootful:
6+
resource: ubuntu
7+
rootless:
8+
resource: ubuntu
9+
uid: 10000
10+
gid: 10000
11+
resources:
12+
ubuntu:
13+
type: oci-image
14+
description: OCI image used for test containers
15+
charm-user: non-root
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
status-set maintenance "Setup..."
5+
juju-log "charm=$UID"
6+
juju-log "sudo=$(sudo -n echo yes || echo no)"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -e
3+
4+
export PEBBLE_SOCKET=/charm/containers/rootful/pebble.socket
5+
juju-log "rootful=$(/charm/bin/pebble exec -- bash -c 'echo $UID')"
6+
7+
touch /charm/containers/rootful/ready
8+
if [ -f "/charm/containers/rootless/ready" ]; then
9+
status-set active "Ready."
10+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -e
3+
4+
export PEBBLE_SOCKET=/charm/containers/rootless/pebble.socket
5+
juju-log "rootless=$(/charm/bin/pebble exec -- bash -c 'echo $UID')"
6+
7+
touch /charm/containers/rootless/ready
8+
if [ -f "/charm/containers/rootful/ready" ]; then
9+
status-set active "Ready."
10+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
status-set maintenance "Setup..."
5+
juju-log "charm=$UID"
6+
juju-log "sudo=$(sudo -n echo yes || echo no)"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bases:
2+
- name: ubuntu
3+
channel: 22.04/stable
4+
architectures:
5+
- amd64
6+
- arm64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: sidecar-sudoer
2+
summary: sidecar charm with rootless charm and workloads
3+
description: ""
4+
containers:
5+
rootful:
6+
resource: ubuntu
7+
rootless:
8+
resource: ubuntu
9+
uid: 10000
10+
gid: 10000
11+
resources:
12+
ubuntu:
13+
type: oci-image
14+
description: OCI image used for test containers
15+
charm-user: sudoer

‎tests/suites/sidecar/rootless.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
run_non_root_charm() {
2+
echo
3+
4+
file="${TEST_DIR}/test-rootless-non-root-charm.log"
5+
6+
ensure "test-rootless-non-root-charm" "${file}"
7+
8+
juju deploy ./testcharms/charms/sidecar-non-root --resource ubuntu=public.ecr.aws/ubuntu/ubuntu:22.04
9+
10+
wait_for "sidecar-non-root" "$(idle_condition "sidecar-non-root" 0 0)"
11+
sleep 10 # wait for logs
12+
13+
output=$(juju debug-log --replay)
14+
check_contains "$output" "charm=170"
15+
check_contains "$output" "sudo=no"
16+
check_contains "$output" "rootless=10000"
17+
check_contains "$output" "rootful=0"
18+
19+
destroy_model "test-rootless-non-root-charm"
20+
}
21+
22+
run_sudoer_charm() {
23+
echo
24+
25+
file="${TEST_DIR}/test-rootless-sudoer-charm.log"
26+
27+
ensure "test-rootless-sudoer-charm" "${file}"
28+
29+
juju deploy ./testcharms/charms/sidecar-sudoer --resource ubuntu=public.ecr.aws/ubuntu/ubuntu:22.04
30+
31+
wait_for "sidecar-sudoer" "$(idle_condition "sidecar-sudoer" 0 0)"
32+
sleep 10 # wait for logs
33+
34+
output=$(juju debug-log --replay)
35+
check_contains "$output" "charm=171"
36+
check_contains "$output" "sudo=yes"
37+
check_contains "$output" "rootless=10000"
38+
check_contains "$output" "rootful=0"
39+
40+
destroy_model "test-rootless-sudoer-charm"
41+
}
42+
43+
test_rootless() {
44+
if [ "$(skip 'test_rootless')" ]; then
45+
echo "==> TEST SKIPPED: test_rootless"
46+
return
47+
fi
48+
49+
(
50+
set_verbosity
51+
52+
cd .. || exit
53+
54+
run "run_non_root_charm"
55+
run "run_sudoer_charm"
56+
)
57+
}

‎tests/suites/sidecar/task.sh

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ test_sidecar() {
1212
test_deploy_and_force_remove_application
1313
test_pebble_notices
1414
test_pebble_checks
15+
test_rootless
1516
;;
1617
*)
1718
echo "==> TEST SKIPPED: sidecar charm tests, not a k8s provider"

0 commit comments

Comments
 (0)
test: add rootless integration tests · JoseFMP/juju@7a6ec0e · GitHub