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 ===")
77 blockdev_create(vm, { 'driver': 'ssh',
91 iotests.img_info_log(remote_path)
94 blockdev_create(vm, { 'driver': 'ssh',
102 'mode': 'known_hosts'
108 iotests.img_info_log(remote_path)
110 keys = subprocess.check_output(
111 'ssh-keyscan 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' +
113 shell=True).rstrip().decode('ascii').split('\n')
115 # Mappings of base64 representations to digests
120 md5_keys[key] = subprocess.check_output(
121 'echo %s | base64 -d | md5sum -b | cut -d" " -f1' % key,
122 shell=True).rstrip().decode('ascii')
124 sha1_keys[key] = subprocess.check_output(
125 'echo %s | base64 -d | sha1sum -b | cut -d" " -f1' % key,
126 shell=True).rstrip().decode('ascii')
130 # Find correct key first
133 result = vm.qmp('blockdev-add',
134 driver='ssh', node_name='node0', path=disk_path,
141 'hash': md5_keys[key],
144 if 'error' not in result:
145 vm.qmp('blockdev-del', node_name='node0')
149 if matching_key is None:
151 iotests.notrun('Did not find a key that fits 127.0.0.1')
153 blockdev_create(vm, { 'driver': 'ssh',
167 blockdev_create(vm, { 'driver': 'ssh',
177 'hash': md5_keys[matching_key],
183 iotests.img_info_log(remote_path)
186 blockdev_create(vm, { 'driver': 'ssh',
200 blockdev_create(vm, { 'driver': 'ssh',
210 'hash': sha1_keys[matching_key],
216 iotests.img_info_log(remote_path)
219 # Invalid path and user
221 iotests.log("=== Invalid path and user ===")
225 blockdev_create(vm, { 'driver': 'ssh',
227 'path': '/this/is/not/an/existing/path',
237 blockdev_create(vm, { 'driver': 'ssh',
240 'user': 'invalid user',