Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20180615' into staging
[qemu.git] / tests / qemu-iotests / 207
blob444ae233ae3f32e108750c43ae6c86cd0a294929
1 #!/usr/bin/env python
3 # Test ssh image creation
5 # Copyright (C) 2018 Red Hat, Inc.
7 # Creator/Owner: Kevin Wolf <kwolf@redhat.com>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 import iotests
24 import subprocess
25 import re
27 iotests.verify_image_format(supported_fmts=['raw'])
28 iotests.verify_protocol(supported=['ssh'])
30 def filter_hash(msg):
31 return re.sub("'hash': '[0-9a-f]+'", "'hash': HASH", msg)
33 def blockdev_create(vm, options):
34 result = vm.qmp_log('blockdev-create', job_id='job0', options=options,
35 filters=[iotests.filter_testfiles, filter_hash])
37 if 'return' in result:
38 assert result['return'] == {}
39 vm.run_job('job0')
40 iotests.log("")
42 with iotests.FilePath('t.img') as disk_path, \
43 iotests.VM() as vm:
45 remote_path = iotests.remote_filename(disk_path)
48 # Successful image creation (defaults)
50 iotests.log("=== Successful image creation (defaults) ===")
51 iotests.log("")
53 vm.launch()
54 blockdev_create(vm, { 'driver': 'ssh',
55 'location': {
56 'path': disk_path,
57 'server': {
58 'host': '127.0.0.1',
59 'port': '22'
62 'size': 4194304 })
63 vm.shutdown()
65 iotests.img_info_log(remote_path, filter_path=disk_path)
66 iotests.log("")
67 iotests.img_info_log(disk_path)
70 # Test host-key-check options
72 iotests.log("=== Test host-key-check options ===")
73 iotests.log("")
75 vm.launch()
76 blockdev_create(vm, { 'driver': 'ssh',
77 'location': {
78 'path': disk_path,
79 'server': {
80 'host': '127.0.0.1',
81 'port': '22'
83 'host-key-check': {
84 'mode': 'none'
87 'size': 8388608 })
88 vm.shutdown()
90 iotests.img_info_log(remote_path, filter_path=disk_path)
92 vm.launch()
93 blockdev_create(vm, { 'driver': 'ssh',
94 'location': {
95 'path': disk_path,
96 'server': {
97 'host': '127.0.0.1',
98 'port': '22'
100 'host-key-check': {
101 'mode': 'known_hosts'
104 'size': 4194304 })
105 vm.shutdown()
107 iotests.img_info_log(remote_path, filter_path=disk_path)
109 md5_key = subprocess.check_output(
110 'ssh-keyscan -t rsa 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' +
111 'cut -d" " -f3 | base64 -d | md5sum -b | cut -d" " -f1',
112 shell=True).rstrip()
114 vm.launch()
115 blockdev_create(vm, { 'driver': 'ssh',
116 'location': {
117 'path': disk_path,
118 'server': {
119 'host': '127.0.0.1',
120 'port': '22'
122 'host-key-check': {
123 'mode': 'hash',
124 'type': 'md5',
125 'hash': 'wrong',
128 'size': 2097152 })
129 blockdev_create(vm, { 'driver': 'ssh',
130 'location': {
131 'path': disk_path,
132 'server': {
133 'host': '127.0.0.1',
134 'port': '22'
136 'host-key-check': {
137 'mode': 'hash',
138 'type': 'md5',
139 'hash': md5_key,
142 'size': 8388608 })
143 vm.shutdown()
145 iotests.img_info_log(remote_path, filter_path=disk_path)
147 sha1_key = subprocess.check_output(
148 'ssh-keyscan -t rsa 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' +
149 'cut -d" " -f3 | base64 -d | sha1sum -b | cut -d" " -f1',
150 shell=True).rstrip()
152 vm.launch()
153 blockdev_create(vm, { 'driver': 'ssh',
154 'location': {
155 'path': disk_path,
156 'server': {
157 'host': '127.0.0.1',
158 'port': '22'
160 'host-key-check': {
161 'mode': 'hash',
162 'type': 'sha1',
163 'hash': 'wrong',
166 'size': 2097152 })
167 blockdev_create(vm, { 'driver': 'ssh',
168 'location': {
169 'path': disk_path,
170 'server': {
171 'host': '127.0.0.1',
172 'port': '22'
174 'host-key-check': {
175 'mode': 'hash',
176 'type': 'sha1',
177 'hash': sha1_key,
180 'size': 4194304 })
181 vm.shutdown()
183 iotests.img_info_log(remote_path, filter_path=disk_path)
186 # Invalid path and user
188 iotests.log("=== Invalid path and user ===")
189 iotests.log("")
191 vm.launch()
192 blockdev_create(vm, { 'driver': 'ssh',
193 'location': {
194 'path': '/this/is/not/an/existing/path',
195 'server': {
196 'host': '127.0.0.1',
197 'port': '22'
199 'host-key-check': {
200 'mode': 'none'
203 'size': 4194304 })
204 blockdev_create(vm, { 'driver': 'ssh',
205 'location': {
206 'path': disk_path,
207 'user': 'invalid user',
208 'server': {
209 'host': '127.0.0.1',
210 'port': '22'
212 'host-key-check': {
213 'mode': 'none'
216 'size': 4194304 })
217 vm.shutdown()