Browse Source

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
changes/11/426811/3
Ben Swartzlander 2 years ago
parent
commit
cadc0ee391
4 changed files with 30 additions and 12 deletions
  1. 2
    2
      README
  2. 2
    2
      common-files/etc/init.d/S99metadata
  3. 3
    3
      conf/busybox.config
  4. 23
    5
      test-image.sh

+ 2
- 2
README View File

@@ -23,7 +23,7 @@ On Ubuntu:
23 23
      build-essential gcc-multilib
24 24
  # For test/dev
25 25
  sudo apt-get -y install bison flex texinfo gettext ncurses-dev sshpass \
26
-     qt-sdk qemu-kvm
26
+     qt-sdk qemu-kvm genisoimage
27 27
 
28 28
 On Fedora:
29 29
 
@@ -32,7 +32,7 @@ On Fedora:
32 32
      make glibc-devel.i686
33 33
  # For test/dev
34 34
  sudo dnf -y install bison flex texinfo gettext ncurses-devel sshpass \
35
-     qt-devel qemu-kvm
35
+     qt-devel qemu-kvm genisoimage
36 36
 
37 37
 == Building the images ==
38 38
 

+ 2
- 2
common-files/etc/init.d/S99metadata View File

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

+ 3
- 3
conf/busybox.config View File

@@ -572,8 +572,8 @@ CONFIG_FEATURE_MOUNT_OTHERTAB=y
572 572
 CONFIG_UEVENT=y
573 573
 # CONFIG_ACPID is not set
574 574
 # CONFIG_FEATURE_ACPID_COMPAT is not set
575
-# CONFIG_BLKID is not set
576
-# CONFIG_FEATURE_BLKID_TYPE is not set
575
+CONFIG_BLKID=y
576
+CONFIG_FEATURE_BLKID_TYPE=y
577 577
 CONFIG_DMESG=y
578 578
 CONFIG_FEATURE_DMESG_PRETTY=y
579 579
 # CONFIG_FBSET is not set
@@ -658,7 +658,7 @@ CONFIG_FEATURE_VOLUMEID_NTFS=y
658 658
 CONFIG_FEATURE_VOLUMEID_OCFS2=y
659 659
 CONFIG_FEATURE_VOLUMEID_REISERFS=y
660 660
 CONFIG_FEATURE_VOLUMEID_ROMFS=y
661
-# CONFIG_FEATURE_VOLUMEID_SQUASHFS is not set
661
+CONFIG_FEATURE_VOLUMEID_SQUASHFS=y
662 662
 CONFIG_FEATURE_VOLUMEID_SYSV=y
663 663
 CONFIG_FEATURE_VOLUMEID_UDF=y
664 664
 CONFIG_FEATURE_VOLUMEID_XFS=y

+ 23
- 5
test-image.sh View File

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

Loading…
Cancel
Save