Merge remote-tracking branch 'remotes/elmarco/tags/screendump-pull-request' into...
[qemu/ar7.git] / tests / qemu-iotests / 207
blob812ab34e47b26e1a740cf2ea5fcff1d149b807c7
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(qmsg):
31 def _filter(key, value):
32 if key == 'hash' and re.match('[0-9a-f]+', value):
33 return 'HASH'
34 return value
35 return iotests.filter_qmp(qmsg, _filter)
37 def blockdev_create(vm, options):
38 vm.blockdev_create(options, filters=[iotests.filter_qmp_testfiles, filter_hash])
40 with iotests.FilePath('t.img') as disk_path, \
41 iotests.VM() as vm:
43 remote_path = iotests.remote_filename(disk_path)
46 # Successful image creation (defaults)
48 iotests.log("=== Successful image creation (defaults) ===")
49 iotests.log("")
51 vm.launch()
52 blockdev_create(vm, { 'driver': 'ssh',
53 'location': {
54 'path': disk_path,
55 'server': {
56 'host': '127.0.0.1',
57 'port': '22'
60 'size': 4194304 })
61 vm.shutdown()
63 iotests.img_info_log(remote_path)
64 iotests.log("")
65 iotests.img_info_log(disk_path)
68 # Test host-key-check options
70 iotests.log("=== Test host-key-check options ===")
71 iotests.log("")
73 vm.launch()
74 blockdev_create(vm, { 'driver': 'ssh',
75 'location': {
76 'path': disk_path,
77 'server': {
78 'host': '127.0.0.1',
79 'port': '22'
81 'host-key-check': {
82 'mode': 'none'
85 'size': 8388608 })
86 vm.shutdown()
88 iotests.img_info_log(remote_path)
90 vm.launch()
91 blockdev_create(vm, { 'driver': 'ssh',
92 'location': {
93 'path': disk_path,
94 'server': {
95 'host': '127.0.0.1',
96 'port': '22'
98 'host-key-check': {
99 'mode': 'known_hosts'
102 'size': 4194304 })
103 vm.shutdown()
105 iotests.img_info_log(remote_path)
107 keys = subprocess.check_output(
108 'ssh-keyscan 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' +
109 'cut -d" " -f3',
110 shell=True).rstrip().decode('ascii').split('\n')
112 # Mappings of base64 representations to digests
113 md5_keys = {}
114 sha1_keys = {}
116 for key in keys:
117 md5_keys[key] = subprocess.check_output(
118 'echo %s | base64 -d | md5sum -b | cut -d" " -f1' % key,
119 shell=True).rstrip().decode('ascii')
121 sha1_keys[key] = subprocess.check_output(
122 'echo %s | base64 -d | sha1sum -b | cut -d" " -f1' % key,
123 shell=True).rstrip().decode('ascii')
125 vm.launch()
127 # Find correct key first
128 matching_key = None
129 for key in keys:
130 result = vm.qmp('blockdev-add',
131 driver='ssh', node_name='node0', path=disk_path,
132 server={
133 'host': '127.0.0.1',
134 'port': '22',
135 }, host_key_check={
136 'mode': 'hash',
137 'type': 'md5',
138 'hash': md5_keys[key],
141 if 'error' not in result:
142 vm.qmp('blockdev-del', node_name='node0')
143 matching_key = key
144 break
146 if matching_key is None:
147 vm.shutdown()
148 iotests.notrun('Did not find a key that fits 127.0.0.1')
150 blockdev_create(vm, { 'driver': 'ssh',
151 'location': {
152 'path': disk_path,
153 'server': {
154 'host': '127.0.0.1',
155 'port': '22'
157 'host-key-check': {
158 'mode': 'hash',
159 'type': 'md5',
160 'hash': 'wrong',
163 'size': 2097152 })
164 blockdev_create(vm, { 'driver': 'ssh',
165 'location': {
166 'path': disk_path,
167 'server': {
168 'host': '127.0.0.1',
169 'port': '22'
171 'host-key-check': {
172 'mode': 'hash',
173 'type': 'md5',
174 'hash': md5_keys[matching_key],
177 'size': 8388608 })
178 vm.shutdown()
180 iotests.img_info_log(remote_path)
182 vm.launch()
183 blockdev_create(vm, { 'driver': 'ssh',
184 'location': {
185 'path': disk_path,
186 'server': {
187 'host': '127.0.0.1',
188 'port': '22'
190 'host-key-check': {
191 'mode': 'hash',
192 'type': 'sha1',
193 'hash': 'wrong',
196 'size': 2097152 })
197 blockdev_create(vm, { 'driver': 'ssh',
198 'location': {
199 'path': disk_path,
200 'server': {
201 'host': '127.0.0.1',
202 'port': '22'
204 'host-key-check': {
205 'mode': 'hash',
206 'type': 'sha1',
207 'hash': sha1_keys[matching_key],
210 'size': 4194304 })
211 vm.shutdown()
213 iotests.img_info_log(remote_path)
216 # Invalid path and user
218 iotests.log("=== Invalid path and user ===")
219 iotests.log("")
221 vm.launch()
222 blockdev_create(vm, { 'driver': 'ssh',
223 'location': {
224 'path': '/this/is/not/an/existing/path',
225 'server': {
226 'host': '127.0.0.1',
227 'port': '22'
229 'host-key-check': {
230 'mode': 'none'
233 'size': 4194304 })
234 blockdev_create(vm, { 'driver': 'ssh',
235 'location': {
236 'path': disk_path,
237 'user': 'invalid user',
238 'server': {
239 'host': '127.0.0.1',
240 'port': '22'
242 'host-key-check': {
243 'mode': 'none'
246 'size': 4194304 })
247 vm.shutdown()