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 vm.blockdev_create(options, filters=[iotests.filter_qmp_testfiles, filter_hash])
40 with iotests.FilePath('t.img') as disk_path, \
43 remote_path = iotests.remote_filename(disk_path)
46 # Successful image creation (defaults)
48 iotests.log("=== Successful image creation (defaults) ===")
52 blockdev_create(vm, { 'driver': 'ssh',
63 iotests.img_info_log(remote_path)
65 iotests.img_info_log(disk_path)
68 # Test host-key-check options
70 iotests.log("=== Test host-key-check options ===")
74 blockdev_create(vm, { 'driver': 'ssh',
88 iotests.img_info_log(remote_path)
91 blockdev_create(vm, { 'driver': 'ssh',
105 iotests.img_info_log(remote_path)
107 keys = subprocess.check_output(
108 'ssh-keyscan 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' +
110 shell=True).rstrip().decode('ascii').split('\n')
112 # Mappings of base64 representations to digests
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')
127 # Find correct key first
130 result = vm.qmp('blockdev-add',
131 driver='ssh', node_name='node0', path=disk_path,
138 'hash': md5_keys[key],
141 if 'error' not in result:
142 vm.qmp('blockdev-del', node_name='node0')
146 if matching_key is None:
148 iotests.notrun('Did not find a key that fits 127.0.0.1')
150 blockdev_create(vm, { 'driver': 'ssh',
164 blockdev_create(vm, { 'driver': 'ssh',
174 'hash': md5_keys[matching_key],
180 iotests.img_info_log(remote_path)
183 blockdev_create(vm, { 'driver': 'ssh',
197 blockdev_create(vm, { 'driver': 'ssh',
207 'hash': sha1_keys[matching_key],
213 iotests.img_info_log(remote_path)
216 # Invalid path and user
218 iotests.log("=== Invalid path and user ===")
222 blockdev_create(vm, { 'driver': 'ssh',
224 'path': '/this/is/not/an/existing/path',
234 blockdev_create(vm, { 'driver': 'ssh',
237 'user': 'invalid user',