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.script_initialize(
28 supported_fmts=['raw'],
29 supported_protocols=['ssh'],
32 def filter_hash(qmsg):
33 def _filter(key, value):
34 if key == 'hash' and re.match('[0-9a-f]+', value):
37 return iotests.filter_qmp(qmsg, _filter)
39 def blockdev_create(vm, options):
40 vm.blockdev_create(options, filters=[iotests.filter_qmp_testfiles, filter_hash])
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)
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)
93 blockdev_create(vm, { 'driver': 'ssh',
101 'mode': 'known_hosts'
107 iotests.img_info_log(remote_path)
109 keys = subprocess.check_output(
110 'ssh-keyscan 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' +
112 shell=True).rstrip().decode('ascii').split('\n')
114 # Mappings of base64 representations to digests
119 md5_keys[key] = subprocess.check_output(
120 'echo %s | base64 -d | md5sum -b | cut -d" " -f1' % key,
121 shell=True).rstrip().decode('ascii')
123 sha1_keys[key] = subprocess.check_output(
124 'echo %s | base64 -d | sha1sum -b | cut -d" " -f1' % key,
125 shell=True).rstrip().decode('ascii')
129 # Find correct key first
132 result = vm.qmp('blockdev-add',
133 driver='ssh', node_name='node0', path=disk_path,
140 'hash': md5_keys[key],
143 if 'error' not in result:
144 vm.qmp('blockdev-del', node_name='node0')
148 if matching_key is None:
150 iotests.notrun('Did not find a key that fits 127.0.0.1')
152 blockdev_create(vm, { 'driver': 'ssh',
166 blockdev_create(vm, { 'driver': 'ssh',
176 'hash': md5_keys[matching_key],
182 iotests.img_info_log(remote_path)
185 blockdev_create(vm, { 'driver': 'ssh',
199 blockdev_create(vm, { 'driver': 'ssh',
209 'hash': sha1_keys[matching_key],
215 iotests.img_info_log(remote_path)
218 # Invalid path and user
220 iotests.log("=== Invalid path and user ===")
224 blockdev_create(vm, { 'driver': 'ssh',
226 'path': '/this/is/not/an/existing/path',
236 blockdev_create(vm, { 'driver': 'ssh',
239 'user': 'invalid user',