]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/units/testsuite-25.sh
Merge pull request #18701 from bugaevc/mdns-unicast
[thirdparty/systemd.git] / test / units / testsuite-25.sh
1 #!/usr/bin/env bash
2 set -ex
3 set -o pipefail
4
5 export SYSTEMD_PAGER=cat
6
7 dd if=/dev/urandom of=/var/tmp/testimage.raw bs=$((1024*1024+7)) count=5
8
9 # Test import
10 machinectl import-raw /var/tmp/testimage.raw
11 machinectl image-status testimage
12 test -f /var/lib/machines/testimage.raw
13 cmp /var/tmp/testimage.raw /var/lib/machines/testimage.raw
14
15 # Test export
16 machinectl export-raw testimage /var/tmp/testimage2.raw
17 cmp /var/tmp/testimage.raw /var/tmp/testimage2.raw
18 rm /var/tmp/testimage2.raw
19
20 # Test compressed export (gzip)
21 machinectl export-raw testimage /var/tmp/testimage2.raw.gz
22 gunzip /var/tmp/testimage2.raw.gz
23 cmp /var/tmp/testimage.raw /var/tmp/testimage2.raw
24 rm /var/tmp/testimage2.raw
25
26 # Test clone
27 machinectl clone testimage testimage3
28 test -f /var/lib/machines/testimage3.raw
29 machinectl image-status testimage3
30 test -f /var/lib/machines/testimage.raw
31 machinectl image-status testimage
32 cmp /var/tmp/testimage.raw /var/lib/machines/testimage.raw
33 cmp /var/tmp/testimage.raw /var/lib/machines/testimage3.raw
34
35 # Test removal
36 machinectl remove testimage
37 test ! -f /var/lib/machines/testimage.raw
38 machinectl image-status testimage && { echo 'unexpected success'; exit 1; }
39
40 # Test export of clone
41 machinectl export-raw testimage3 /var/tmp/testimage3.raw
42 cmp /var/tmp/testimage.raw /var/tmp/testimage3.raw
43 rm /var/tmp/testimage3.raw
44
45 # Test rename
46 machinectl rename testimage3 testimage4
47 test -f /var/lib/machines/testimage4.raw
48 machinectl image-status testimage4
49 test ! -f /var/lib/machines/testimage3.raw
50 machinectl image-status testimage3 && { echo 'unexpected success'; exit 1; }
51 cmp /var/tmp/testimage.raw /var/lib/machines/testimage4.raw
52
53 # Test export of rename
54 machinectl export-raw testimage4 /var/tmp/testimage4.raw
55 cmp /var/tmp/testimage.raw /var/tmp/testimage4.raw
56 rm /var/tmp/testimage4.raw
57
58 # Test removal
59 machinectl remove testimage4
60 test ! -f /var/lib/machines/testimage4.raw
61 machinectl image-status testimage4 && { echo 'unexpected success'; exit 1; }
62
63 # → And now, let's test directory trees ← #
64
65 # Set up a directory we can import
66 mkdir /var/tmp/scratch
67 mv /var/tmp/testimage.raw /var/tmp/scratch/
68 touch /var/tmp/scratch/anotherfile
69 mkdir /var/tmp/scratch/adirectory
70 echo "piep" >/var/tmp/scratch/adirectory/athirdfile
71
72 # Test import-fs
73 machinectl import-fs /var/tmp/scratch/
74 test -d /var/lib/machines/scratch
75 machinectl image-status scratch
76
77 # Test export-tar
78 machinectl export-tar scratch /var/tmp/scratch.tar.gz
79 test -f /var/tmp/scratch.tar.gz
80 mkdir /var/tmp/extract
81 (cd /var/tmp/extract ; tar xzf /var/tmp/scratch.tar.gz)
82 diff -r /var/tmp/scratch/ /var/tmp/extract/
83 rm -rf /var/tmp/extract
84
85 # Test import-tar
86 machinectl import-tar /var/tmp/scratch.tar.gz scratch2
87 test -d /var/lib/machines/scratch2
88 machinectl image-status scratch2
89 diff -r /var/tmp/scratch/ /var/lib/machines/scratch2
90
91 # Test removal
92 machinectl remove scratch
93 test ! -f /var/lib/machines/scratch
94 machinectl image-status scratchi && { echo 'unexpected success'; exit 1; }
95
96 # Test clone
97 machinectl clone scratch2 scratch3
98 test -d /var/lib/machines/scratch2
99 machinectl image-status scratch2
100 test -d /var/lib/machines/scratch3
101 machinectl image-status scratch3
102 diff -r /var/tmp/scratch/ /var/lib/machines/scratch3
103
104 # Test removal
105 machinectl remove scratch2
106 test ! -f /var/lib/machines/scratch2
107 machinectl image-status scratch2 && { echo 'unexpected success'; exit 1; }
108
109 # Test rename
110 machinectl rename scratch3 scratch4
111 test -d /var/lib/machines/scratch4
112 machinectl image-status scratch4
113 test ! -f /var/lib/machines/scratch3
114 machinectl image-status scratch3 && { echo 'unexpected success'; exit 1; }
115 diff -r /var/tmp/scratch/ /var/lib/machines/scratch4
116
117 # Test removal
118 machinectl remove scratch4
119 test ! -f /var/lib/machines/scratch4
120 machinectl image-status scratch4 && { echo 'unexpected success'; exit 1; }
121
122 # Test import-tar hyphen/stdin pipe behavior
123 cat /var/tmp/scratch.tar.gz | machinectl import-tar - scratch5
124 test -d /var/lib/machines/scratch5
125 machinectl image-status scratch5
126 diff -r /var/tmp/scratch/ /var/lib/machines/scratch5
127
128 # Test export-tar hyphen/stdout pipe behavior
129 mkdir -p /var/tmp/extract
130 machinectl export-tar scratch5 - | tar xvf - -C /var/tmp/extract/
131 diff -r /var/tmp/scratch/ /var/tmp/extract/
132 rm -rf /var/tmp/extract
133
134 rm -rf /var/tmp/scratch
135
136 # Test removal
137 machinectl remove scratch5
138 test ! -f /var/lib/machines/scratch5
139 machinectl image-status scratch5 && { echo 'unexpected success'; exit 1; }
140
141 echo OK >/testok
142
143 exit 0