Create a config drive to test the metadata code

Because it's not possible to test the metadata service
code in an easy way, create a config drive ISO image for
test purposes.

Also speed up the metadata code to not block while waiting
for the metadata service and to exit quickly when there is
no config drive CD present.

Change-Id: If6a5565825b67de58715e3d2de1cbf69b7f9e551
This commit is contained in:
Ben Swartzlander 2017-01-30 10:26:54 -05:00
parent d341b73a9a
commit cadc0ee391
4 changed files with 30 additions and 12 deletions

4
README
View File

@ -23,7 +23,7 @@ On Ubuntu:
build-essential gcc-multilib
# For test/dev
sudo apt-get -y install bison flex texinfo gettext ncurses-dev sshpass \
qt-sdk qemu-kvm
qt-sdk qemu-kvm genisoimage
On Fedora:
@ -32,7 +32,7 @@ On Fedora:
make glibc-devel.i686
# For test/dev
sudo dnf -y install bison flex texinfo gettext ncurses-devel sshpass \
qt-devel qemu-kvm
qt-devel qemu-kvm genisoimage
== Building the images ==

View File

@ -22,7 +22,7 @@ json_metadata() {
}
check_cd() {
[ -b /dev/sr0 ] || return
blkid /dev/sr0 | grep config-2 > /dev/null || return
mkdir /tmp/cd
if mount /dev/sr0 /tmp/cd ; then
json_metadata /tmp/cd >> authorized_keys
@ -37,5 +37,5 @@ chmod 700 .
[ -f authorized_keys ] || touch authorized_keys
chmod 600 authorized_keys
check_net
check_cd
check_net &

View File

@ -572,8 +572,8 @@ CONFIG_FEATURE_MOUNT_OTHERTAB=y
CONFIG_UEVENT=y
# CONFIG_ACPID is not set
# CONFIG_FEATURE_ACPID_COMPAT is not set
# CONFIG_BLKID is not set
# CONFIG_FEATURE_BLKID_TYPE is not set
CONFIG_BLKID=y
CONFIG_FEATURE_BLKID_TYPE=y
CONFIG_DMESG=y
CONFIG_FEATURE_DMESG_PRETTY=y
# CONFIG_FBSET is not set
@ -658,7 +658,7 @@ CONFIG_FEATURE_VOLUMEID_NTFS=y
CONFIG_FEATURE_VOLUMEID_OCFS2=y
CONFIG_FEATURE_VOLUMEID_REISERFS=y
CONFIG_FEATURE_VOLUMEID_ROMFS=y
# CONFIG_FEATURE_VOLUMEID_SQUASHFS is not set
CONFIG_FEATURE_VOLUMEID_SQUASHFS=y
CONFIG_FEATURE_VOLUMEID_SYSV=y
CONFIG_FEATURE_VOLUMEID_UDF=y
CONFIG_FEATURE_VOLUMEID_XFS=y

View File

@ -1,12 +1,30 @@
#!/bin/sh
CONFIG_DIR=/tmp/configdir
CONFIG_ISO=/tmp/configdrive.iso
TEST_IMG=/tmp/client-test.qcow2
# Create config-drive ISO
mkdir -p $CONFIG_DIR/ec2/2009-04-04
(
echo -n '{"public-keys": {"0": {"openssh-key": "'
cat ~/.ssh/id_rsa.pub | tr -d '\n'
echo -n '\\n"}}}'
) > $CONFIG_DIR/ec2/2009-04-04/meta-data.json
mkisofs -R -V config-2 -o $CONFIG_ISO $CONFIG_DIR 2> /dev/null
rm -rf $CONFIG_DIR
# Create temporary overlay
qemu-img create -f qcow2 -b $(pwd)/client.qcow2 $TEST_IMG
# Test the image
KVM=kvm
if ! which $KVM 2> /dev/null ; then
KVM=qemu-kvm
fi
qemu-img create -f qcow2 -b client.qcow2 client-test.qcow2
$KVM -m 64 -monitor none -nographic \
-drive file=client-test.qcow2,if=virtio,format=qcow2 \
-netdev user,id=net0 -device virtio-net-pci,netdev=net0
rm client-test.qcow2
-drive file=$TEST_IMG,if=virtio,format=qcow2 \
-netdev user,id=net0 -device virtio-net-pci,netdev=net0 \
-cdrom $CONFIG_ISO
rm $TEST_IMG $CONFIG_ISO