aboutsummaryrefslogtreecommitdiff
path: root/test/image_remove.bats
blob: ca2017d008499c20a770dbb54b51e6f2ec600c62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bats

load helpers

IMAGE=docker.io/kubernetes/pause

function teardown() {
	cleanup_test
}

@test "image remove with multiple names, by name" {
	start_crio "" "" --no-pause-image
	# Pull the image, giving it one name.
	run crioctl image pull "$IMAGE"
	echo "$output"
	[ "$status" -eq 0 ]
	# Add a second name to the image.
	run "$COPYIMG_BINARY" --root "$TESTDIR/crio" $STORAGE_OPTIONS --runroot "$TESTDIR/crio-run" --image-name="$IMAGE":latest --add-name="$IMAGE":othertag --signature-policy="$INTEGRATION_ROOT"/policy.json
	echo "$output"
	[ "$status" -eq 0 ]
	# Get the list of image names and IDs.
	run crioctl image list
	echo "$output"
	[ "$status" -eq 0 ]
	[ "$output" != "" ]
	# Cycle through each name, removing it by name.  The image that we assigned a second
	# name to should still be around when we get to removing its second name.
	grep ^Tag: <<< "$output" | while read -r header tag ; do
		run crioctl image remove --id "$tag"
		echo "$output"
		[ "$status" -eq 0 ]
	done
	# List all images and their names.  There should be none now.
	run crioctl image list --quiet
	echo "$output"
	[ "$status" -eq 0 ]
	[ "$output" = "" ]
	printf '%s\n' "$output" | while IFS= read -r id; do
		echo "$id"
	done
	# All done.
	cleanup_images
	stop_crio
}

@test "image remove with multiple names, by ID" {
	start_crio "" "" --no-pause-image
	# Pull the image, giving it one name.
	run crioctl image pull "$IMAGE"
	echo "$output"
	[ "$status" -eq 0 ]
	# Add a second name to the image.
	run "$COPYIMG_BINARY" --root "$TESTDIR/crio" $STORAGE_OPTIONS --runroot "$TESTDIR/crio-run" --image-name="$IMAGE":latest --add-name="$IMAGE":othertag --signature-policy="$INTEGRATION_ROOT"/policy.json
	echo "$output"
	[ "$status" -eq 0 ]
	# Get the image ID of the image we just saved.
	run crioctl image status --id="$IMAGE"
	echo "$output"
	[ "$status" -eq 0 ]
	[ "$output" != "" ]
	# Try to remove the image using its ID.  That should succeed because removing by ID always works.
	grep ^ID: <<< "$output" | while read -r header id ; do
		run crioctl image remove --id "$id"
		echo "$output"
		[ "$status" -eq 0 ]
	done
	# The image should be gone.
	run crioctl image status --id="$IMAGE"
	echo "$output"
	[ "$status" -ne 0 ]
	# All done.
	cleanup_images
	stop_crio
}