xref: /openbmc/qemu/tests/qemu-iotests/207 (revision d1fd31f8)
1#!/bin/bash
2#
3# Test ssh image creation
4#
5# Copyright (C) 2018 Red Hat, Inc.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#
20
21# creator
22owner=kwolf@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
27here=`pwd`
28status=1	# failure is the default!
29
30# get standard environment, filters and checks
31. ./common.rc
32. ./common.filter
33
34_supported_fmt raw
35_supported_proto ssh
36_supported_os Linux
37
38function do_run_qemu()
39{
40    echo Testing: "$@"
41    $QEMU -nographic -qmp stdio -serial none "$@"
42    echo
43}
44
45function run_qemu()
46{
47    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
48                          | _filter_qemu | _filter_imgfmt \
49                          | _filter_actual_image_size
50}
51
52echo
53echo "=== Successful image creation (defaults) ==="
54echo
55
56run_qemu <<EOF
57{ "execute": "qmp_capabilities" }
58{ "execute": "x-blockdev-create",
59  "arguments": {
60      "driver": "ssh",
61      "location": {
62          "path": "$TEST_IMG_FILE",
63          "server": {
64              "host": "127.0.0.1",
65              "port": "22"
66          }
67      },
68      "size": 4194304
69  }
70}
71{ "execute": "quit" }
72EOF
73
74_img_info | _filter_img_info
75echo
76TEST_IMG=$TEST_IMG_FILE _img_info | _filter_img_info
77
78echo
79echo "=== Test host-key-check options ==="
80echo
81
82run_qemu <<EOF
83{ "execute": "qmp_capabilities" }
84{ "execute": "x-blockdev-create",
85  "arguments": {
86      "driver": "ssh",
87      "location": {
88          "path": "$TEST_IMG_FILE",
89          "server": {
90              "host": "127.0.0.1",
91              "port": "22"
92          },
93          "host-key-check": {
94              "mode": "none"
95          }
96      },
97      "size": 8388608
98  }
99}
100{ "execute": "quit" }
101EOF
102
103_img_info | _filter_img_info
104
105run_qemu <<EOF
106{ "execute": "qmp_capabilities" }
107{ "execute": "x-blockdev-create",
108  "arguments": {
109      "driver": "ssh",
110      "location": {
111          "path": "$TEST_IMG_FILE",
112          "server": {
113              "host": "127.0.0.1",
114              "port": "22"
115          },
116          "host-key-check": {
117              "mode": "known_hosts"
118          }
119      },
120      "size": 4194304
121  }
122}
123{ "execute": "quit" }
124EOF
125
126_img_info | _filter_img_info
127
128
129key=$(ssh-keyscan -t rsa 127.0.0.1 2>/dev/null | grep -v "\\^#" |
130      cut -d" " -f3 | base64 -d | md5sum -b | cut -d" " -f1)
131
132run_qemu <<EOF
133{ "execute": "qmp_capabilities" }
134{ "execute": "x-blockdev-create",
135  "arguments": {
136      "driver": "ssh",
137      "location": {
138          "path": "$TEST_IMG_FILE",
139          "server": {
140              "host": "127.0.0.1",
141              "port": "22"
142          },
143          "host-key-check": {
144              "mode": "hash",
145              "type": "md5",
146              "hash": "wrong"
147          }
148      },
149      "size": 8388608
150  }
151}
152{ "execute": "x-blockdev-create",
153  "arguments": {
154      "driver": "ssh",
155      "location": {
156          "path": "$TEST_IMG_FILE",
157          "server": {
158              "host": "127.0.0.1",
159              "port": "22"
160          },
161          "host-key-check": {
162              "mode": "hash",
163              "type": "md5",
164              "hash": "$key"
165          }
166      },
167      "size": 8388608
168  }
169}
170{ "execute": "quit" }
171EOF
172
173_img_info | _filter_img_info
174
175
176key=$(ssh-keyscan -t rsa 127.0.0.1 2>/dev/null | grep -v "\\^#" |
177      cut -d" " -f3 | base64 -d | sha1sum -b | cut -d" " -f1)
178
179run_qemu <<EOF
180{ "execute": "qmp_capabilities" }
181{ "execute": "x-blockdev-create",
182  "arguments": {
183      "driver": "ssh",
184      "location": {
185          "path": "$TEST_IMG_FILE",
186          "server": {
187              "host": "127.0.0.1",
188              "port": "22"
189          },
190          "host-key-check": {
191              "mode": "hash",
192              "type": "sha1",
193              "hash": "wrong"
194          }
195      },
196      "size": 4194304
197  }
198}
199{ "execute": "x-blockdev-create",
200  "arguments": {
201      "driver": "ssh",
202      "location": {
203          "path": "$TEST_IMG_FILE",
204          "server": {
205              "host": "127.0.0.1",
206              "port": "22"
207          },
208          "host-key-check": {
209              "mode": "hash",
210              "type": "sha1",
211              "hash": "$key"
212          }
213      },
214      "size": 4194304
215  }
216}
217{ "execute": "quit" }
218EOF
219
220_img_info | _filter_img_info
221
222echo
223echo "=== Invalid path and user ==="
224echo
225
226run_qemu <<EOF
227{ "execute": "qmp_capabilities" }
228{ "execute": "x-blockdev-create",
229  "arguments": {
230      "driver": "ssh",
231      "location": {
232          "path": "/this/is/not/an/existing/path",
233          "server": {
234              "host": "127.0.0.1",
235              "port": "22"
236          }
237      },
238      "size": 4194304
239  }
240}
241{ "execute": "x-blockdev-create",
242  "arguments": {
243      "driver": "ssh",
244      "location": {
245          "path": "$TEST_IMG_FILE",
246          "user": "invalid user",
247          "server": {
248              "host": "127.0.0.1",
249              "port": "22"
250          }
251      },
252      "size": 4194304
253  }
254}
255{ "execute": "quit" }
256EOF
257
258# success, all done
259echo "*** done"
260rm -f $seq.full
261status=0
262