]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/TEST-25-IMPORT/testsuite.sh
service: Fix typo in warning message
[thirdparty/systemd.git] / test / TEST-25-IMPORT / testsuite.sh
1 #!/bin/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
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
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
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 scratch
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
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
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
121
122 rm -rf /var/tmp/scratch
123
124 echo OK > /testok
125
126 exit 0