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