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'])
30 def filter_hash(qmsg
):
31 def _filter(key
, value
):
32 if key
== 'hash' and re
.match('[0-9a-f]+', value
):
35 return iotests
.filter_qmp(qmsg
, _filter
)
37 def blockdev_create(vm
, options
):
38 result
= vm
.qmp_log('blockdev-create', job_id
='job0', options
=options
,
39 filters
=[iotests
.filter_qmp_testfiles
, filter_hash
])
41 if 'return' in result
:
42 assert result
['return'] == {}
46 with iotests
.FilePath('t.img') as disk_path
, \
49 remote_path
= iotests
.remote_filename(disk_path
)
52 # Successful image creation (defaults)
54 iotests
.log("=== Successful image creation (defaults) ===")
58 blockdev_create(vm
, { 'driver': 'ssh',
69 iotests
.img_info_log(remote_path
)
71 iotests
.img_info_log(disk_path
)
74 # Test host-key-check options
76 iotests
.log("=== Test host-key-check options ===")
80 blockdev_create(vm
, { 'driver': 'ssh',
94 iotests
.img_info_log(remote_path
)
97 blockdev_create(vm
, { 'driver': 'ssh',
105 'mode': 'known_hosts'
111 iotests
.img_info_log(remote_path
)
113 keys
= subprocess
.check_output(
114 'ssh-keyscan 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' +
116 shell
=True).rstrip().decode('ascii').split('\n')
118 # Mappings of base64 representations to digests
123 md5_keys
[key
] = subprocess
.check_output(
124 'echo %s | base64 -d | md5sum -b | cut -d" " -f1' % key
,
125 shell
=True).rstrip().decode('ascii')
127 sha1_keys
[key
] = subprocess
.check_output(
128 'echo %s | base64 -d | sha1sum -b | cut -d" " -f1' % key
,
129 shell
=True).rstrip().decode('ascii')
133 # Find correct key first
136 result
= vm
.qmp('blockdev-add',
137 driver
='ssh', node_name
='node0', path
=disk_path
,
144 'hash': md5_keys
[key
],
147 if 'error' not in result
:
148 vm
.qmp('blockdev-del', node_name
='node0')
152 if matching_key
is None:
154 iotests
.notrun('Did not find a key that fits 127.0.0.1')
156 blockdev_create(vm
, { 'driver': 'ssh',
170 blockdev_create(vm
, { 'driver': 'ssh',
180 'hash': md5_keys
[matching_key
],
186 iotests
.img_info_log(remote_path
)
189 blockdev_create(vm
, { 'driver': 'ssh',
203 blockdev_create(vm
, { 'driver': 'ssh',
213 'hash': sha1_keys
[matching_key
],
219 iotests
.img_info_log(remote_path
)
222 # Invalid path and user
224 iotests
.log("=== Invalid path and user ===")
228 blockdev_create(vm
, { 'driver': 'ssh',
230 'path': '/this/is/not/an/existing/path',
240 blockdev_create(vm
, { 'driver': 'ssh',
243 'user': 'invalid user',