From cadc0ee3912c6095247f3006dd356070bbf7c8aa Mon Sep 17 00:00:00 2001 From: Ben Swartzlander Date: Mon, 30 Jan 2017 10:26:54 -0500 Subject: [PATCH] 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 --- README | 4 ++-- common-files/etc/init.d/S99metadata | 4 ++-- conf/busybox.config | 6 +++--- test-image.sh | 28 +++++++++++++++++++++++----- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/README b/README index 2d819b6..18228cf 100644 --- a/README +++ b/README @@ -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 == diff --git a/common-files/etc/init.d/S99metadata b/common-files/etc/init.d/S99metadata index cef1ad2..b3f2b8b 100755 --- a/common-files/etc/init.d/S99metadata +++ b/common-files/etc/init.d/S99metadata @@ -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 & diff --git a/conf/busybox.config b/conf/busybox.config index 49c5611..521f411 100644 --- a/conf/busybox.config +++ b/conf/busybox.config @@ -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 diff --git a/test-image.sh b/test-image.sh index 9d92b76..c26d111 100755 --- a/test-image.sh +++ b/test-image.sh @@ -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