4 # Test ssh image creation
6 # Copyright (C) 2018 Red Hat, Inc.
8 # Creator/Owner: Kevin Wolf <kwolf@redhat.com>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 iotests.script_initialize(
29 supported_fmts=['raw'],
30 supported_protocols=['ssh'],
33 def filter_hash(qmsg):
34 def _filter(key, value):
35 if key == 'hash' and re.match('[0-9a-f]+', value):
38 return iotests.filter_qmp(qmsg, _filter)
40 def blockdev_create(vm, options):
41 vm.blockdev_create(options, filters=[iotests.filter_qmp_testfiles, filter_hash])
43 with iotests.FilePath('t.img') as disk_path, \
46 remote_path = iotests.remote_filename(disk_path)
49 # Successful image creation (defaults)
51 iotests.log("=== Successful image creation (defaults) ===")
55 blockdev_create(vm, { 'driver': 'ssh',
66 iotests.img_info_log(remote_path)
68 iotests.img_info_log(disk_path)
71 # Test host-key-check options
73 iotests.log("=== Test host-key-check options ===")
76 iotests.log("--- no host key checking --")
80 blockdev_create(vm, { 'driver': 'ssh',
94 iotests.img_info_log(remote_path)
96 iotests.log("--- known_hosts key checking --")
100 blockdev_create(vm, { 'driver': 'ssh',
108 'mode': 'known_hosts'
114 iotests.img_info_log(remote_path)
116 keys = subprocess.check_output(
117 'ssh-keyscan 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' +
119 shell=True).rstrip().decode('ascii').split('\n')
121 # Mappings of base64 representations to digests
127 md5_keys[key] = subprocess.check_output(
128 'echo %s | base64 -d | md5sum -b | cut -d" " -f1' % key,
129 shell=True).rstrip().decode('ascii')
131 sha1_keys[key] = subprocess.check_output(
132 'echo %s | base64 -d | sha1sum -b | cut -d" " -f1' % key,
133 shell=True).rstrip().decode('ascii')
135 sha256_keys[key] = subprocess.check_output(
136 'echo %s | base64 -d | sha256sum -b | cut -d" " -f1' % key,
137 shell=True).rstrip().decode('ascii')
141 # Find correct key first
144 result = vm.qmp('blockdev-add',
145 driver='ssh', node_name='node0', path=disk_path,
152 'hash': md5_keys[key],
155 if 'error' not in result:
156 vm.qmp('blockdev-del', node_name='node0')
160 if matching_key is None:
162 iotests.notrun('Did not find a key that fits 127.0.0.1')
164 iotests.log("--- explicit md5 key checking --")
167 blockdev_create(vm, { 'driver': 'ssh',
182 blockdev_create(vm, { 'driver': 'ssh',
192 'hash': md5_keys[matching_key],
198 iotests.img_info_log(remote_path)
200 iotests.log("--- explicit sha1 key checking --")
204 blockdev_create(vm, { 'driver': 'ssh',
218 blockdev_create(vm, { 'driver': 'ssh',
228 'hash': sha1_keys[matching_key],
234 iotests.img_info_log(remote_path)
236 iotests.log("--- explicit sha256 key checking --")
240 blockdev_create(vm, { 'driver': 'ssh',
254 blockdev_create(vm, { 'driver': 'ssh',
264 'hash': sha256_keys[matching_key],
270 iotests.img_info_log(remote_path)
273 # Invalid path and user
275 iotests.log("=== Invalid path and user ===")
279 blockdev_create(vm, { 'driver': 'ssh',
281 'path': '/this/is/not/an/existing/path',
291 blockdev_create(vm, { 'driver': 'ssh',
294 'user': 'invalid user',