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/>.
27 iotests
.verify_image_format(supported_fmts
=['raw'])
28 iotests
.verify_protocol(supported
=['ssh'])
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'] == {}
42 with iotests
.FilePath('t.img') as disk_path
, \
45 remote_path
= iotests
.remote_filename(disk_path
)
48 # Successful image creation (defaults)
50 iotests
.log("=== Successful image creation (defaults) ===")
54 blockdev_create(vm
, { 'driver': 'ssh',
65 iotests
.img_info_log(remote_path
, filter_path
=disk_path
)
67 iotests
.img_info_log(disk_path
)
70 # Test host-key-check options
72 iotests
.log("=== Test host-key-check options ===")
76 blockdev_create(vm
, { 'driver': 'ssh',
90 iotests
.img_info_log(remote_path
, filter_path
=disk_path
)
93 blockdev_create(vm
, { 'driver': 'ssh',
101 'mode': 'known_hosts'
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().decode('ascii')
115 blockdev_create(vm
, { 'driver': 'ssh',
129 blockdev_create(vm
, { 'driver': 'ssh',
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().decode('ascii')
153 blockdev_create(vm
, { 'driver': 'ssh',
167 blockdev_create(vm
, { 'driver': 'ssh',
183 iotests
.img_info_log(remote_path
, filter_path
=disk_path
)
186 # Invalid path and user
188 iotests
.log("=== Invalid path and user ===")
192 blockdev_create(vm
, { 'driver': 'ssh',
194 'path': '/this/is/not/an/existing/path',
204 blockdev_create(vm
, { 'driver': 'ssh',
207 'user': 'invalid user',