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