summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-02-16 16:53:59 +0000
committerGerrit Code Review <review@openstack.org>2022-02-16 16:53:59 +0000
commit8452de687efe14a335fd93784b528c8eeea4db10 (patch)
tree7afcd12c282c0eff04c48fceb15f48bcde4c3b2a
parentdb808f6d333115e3008d46f36114c54e5a6ff7bf (diff)
parentbbceca562e0b552cd2fc33b2833931ab3cbbfce5 (diff)
downloadironic-8452de687efe14a335fd93784b528c8eeea4db10.tar.gz
Merge "CI: use a custom cirros partition image instead of the default"
-rw-r--r--bindep.txt6
-rw-r--r--devstack/files/bindep.txt4
-rw-r--r--devstack/lib/ironic49
-rwxr-xr-xdevstack/tools/ironic/scripts/cirros-partition.sh69
-rw-r--r--zuul.d/ironic-jobs.yaml6
5 files changed, 128 insertions, 6 deletions
diff --git a/bindep.txt b/bindep.txt
index 863787763..16adeecda 100644
--- a/bindep.txt
+++ b/bindep.txt
@@ -86,9 +86,13 @@ apparmor [platform:dpkg imagebuild]
gnupg [imagebuild]
squashfs-tools [platform:dpkg platform:redhat imagebuild]
squashfs [platform:suse imagebuild]
+# For custom partition images
+kpartx [devstack]
libguestfs0 [platform:dpkg imagebuild]
-libguestfs [platform:rpm imagebuild]
+libguestfs [platform:rpm imagebuild devstack]
+libguestfs-tools [platform:dpkg devstack]
python-guestfs [platform:dpkg imagebuild]
+qemu-img [platform:rpm devstack]
# for TinyIPA build
wget [imagebuild]
python-pip [imagebuild]
diff --git a/devstack/files/bindep.txt b/devstack/files/bindep.txt
index 8c386349a..820f9b8b0 100644
--- a/devstack/files/bindep.txt
+++ b/devstack/files/bindep.txt
@@ -87,9 +87,13 @@ apparmor [platform:dpkg imagebuild]
gnupg [imagebuild]
squashfs-tools [platform:dpkg platform:redhat imagebuild]
squashfs [platform:suse imagebuild]
+# For custom partition images
+kpartx
libguestfs0 [platform:dpkg imagebuild]
libguestfs [platform:rpm imagebuild]
+libguestfs-tools [platform:dpkg]
python-guestfs [platform:dpkg imagebuild]
+qemu-img [platform:rpm]
# for TinyIPA build
wget [imagebuild]
python-pip [imagebuild]
diff --git a/devstack/lib/ironic b/devstack/lib/ironic
index 228229d2a..fa563ddb5 100644
--- a/devstack/lib/ironic
+++ b/devstack/lib/ironic
@@ -2852,6 +2852,44 @@ function build_ipa_dib_ramdisk {
rm -rf $tempdir
}
+function upload_image_if_needed {
+ if [[ "$IRONIC_PARTITIONED_IMAGE_NAME" =~ cirros ]] \
+ && [[ "$IRONIC_DEFAULT_BOOT_OPTION" == local ]] \
+ && is_service_enabled glance; then
+ echo Building a Cirros image suitable for local boot
+
+ local dest
+ IRONIC_PARTITIONED_IMAGE_NAME=cirros-${CIRROS_VERSION}-x86_64-partition
+ dest="$IRONIC_DATA_DIR/$IRONIC_PARTITIONED_IMAGE_NAME.img"
+
+ # Export some variables that the script is using.
+ CIRROS_ARCH=$CIRROS_ARCH CIRROS_VERSION=$CIRROS_VERSION \
+ IRONIC_TTY_DEV=$IRONIC_TTY_DEV VERBOSE=$VERBOSE \
+ $IRONIC_SCRIPTS_DIR/cirros-partition.sh "$dest"
+
+ # TODO(dtantsur): stop uploading kernel/ramdisk when image_type support
+ # lands.
+ local kernel_id
+ kernel_id=$(openstack image list -f value -c ID -c Name \
+ | awk '/cirros.*kernel/ { print $1; exit 0; }')
+ die_if_not_set $LINENO kernel_id "Cannot find cirros kernel"
+
+ local ramdisk_id
+ ramdisk_id=$(openstack image list -f value -c ID -c Name \
+ | awk '/cirros.*ramdisk/ { print $1; exit 0; }')
+ die_if_not_set $LINENO ramdisk_id "Cannot find cirros ramdisk"
+
+ openstack image create $IRONIC_PARTITIONED_IMAGE_NAME \
+ --public --disk-format raw --container-format bare \
+ --property kernel_id=$kernel_id --property ramdisk_id=$ramdisk_id \
+ --file "$dest"
+
+ if [[ "$IRONIC_TEMPEST_WHOLE_DISK_IMAGE" != True ]]; then
+ IRONIC_IMAGE_NAME=$IRONIC_PARTITIONED_IMAGE_NAME
+ fi
+ fi
+}
+
# download EFI boot loader image and upload it to glance
# this function sets ``IRONIC_EFIBOOT_ID``
function upload_baremetal_ironic_efiboot {
@@ -3030,6 +3068,8 @@ function prepare_baremetal_basic_ops {
upload_baremetal_ironic_efiboot
fi
+ upload_image_if_needed
+
configure_tftpd
configure_iptables
}
@@ -3152,6 +3192,13 @@ function ironic_configure_tempest {
iniset $TEMPEST_CONFIG baremetal partition_image_ref $image_uuid
fi
+ # Our cirros images cannot do local boot in legacy mode.
+ if [[ "${IRONIC_PARTITIONED_IMAGE_NAME}" =~ cirros && "${IRONIC_BOOT_MODE}" == "bios" ]]; then
+ iniset $TEMPEST_CONFIG baremetal partition_netboot True
+ else
+ iniset $TEMPEST_CONFIG baremetal partition_netboot False
+ fi
+
if [[ "$IRONIC_IP_VERSION" == "6" ]]; then
iniset $TEMPEST_CONFIG baremetal whole_disk_image_url "http://$IRONIC_HOST_IPV6:$IRONIC_HTTP_PORT/${IRONIC_WHOLEDISK_IMAGE_NAME}.img"
else
@@ -3174,6 +3221,8 @@ function ironic_configure_tempest {
# Driver for API tests
iniset $TEMPEST_CONFIG baremetal driver fake-hardware
+ iniset $TEMPEST_CONFIG baremetal default_boot_option $IRONIC_DEFAULT_BOOT_OPTION
+
local adjusted_root_disk_size_gb
if [[ "$IRONIC_IS_HARDWARE" == "False" ]]; then
adjusted_root_disk_size_gb=$(( ${IRONIC_VM_SPECS_DISK} - ${IRONIC_VM_EPHEMERAL_DISK} ))
diff --git a/devstack/tools/ironic/scripts/cirros-partition.sh b/devstack/tools/ironic/scripts/cirros-partition.sh
new file mode 100755
index 000000000..40c87b19e
--- /dev/null
+++ b/devstack/tools/ironic/scripts/cirros-partition.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+set -eu -o pipefail
+
+VERBOSE=${VERBOSE:-True}
+if [[ "$VERBOSE" == True ]]; then
+ set -x
+ guestfish_args="--verbose"
+fi
+
+CIRROS_VERSION=${CIRROS_VERSION:-0.5.2}
+CIRROS_ARCH=${CIRROS_ARCH:-x86_64}
+# TODO(dtantsur): use the image cached on infra images in the CI
+DISK_URL=http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-disk.img
+OUT=$(realpath ${1:-rootfs.img})
+
+IRONIC_TTY_DEV=${IRONIC_TTY_DEV:-ttyS0,115200}
+# rdroot : boot from the ramdisk present on the root partition instead of
+# mounting the root partition.
+# dslist : disable Nova metadata support, it takes a long time on boot.
+KARGS=${KARGS:-nofb nomodeset vga=normal console=${IRONIC_TTY_DEV} rdroot dslist=configdrive}
+
+workdir=$(mktemp -d)
+root_mp=$workdir/root
+efi_mp=$workdir/efi
+dest=$workdir/dest
+
+cd $workdir
+
+curl -Lf -o disk.qcow2 $DISK_URL
+qemu-img convert -O raw disk.qcow2 disk.img
+rm disk.qcow2
+
+# kpartx automatically allocates loop devices for all partitions in the image
+device=$(sudo kpartx -av disk.img | grep -oE 'loop[0-9]+p' | head -1)
+
+function clean_up {
+ set +e
+ sudo umount $efi_mp
+ sudo umount $root_mp
+ sudo kpartx -d $workdir/disk.img
+ sudo rm -rf $workdir
+}
+trap clean_up EXIT
+
+# TODO(dtantsur): some logic instead of hardcoding numbers 1 and 15?
+rootdev=/dev/mapper/${device}1
+efidev=/dev/mapper/${device}15
+
+mkdir -p $root_mp $efi_mp $dest/boot/efi
+sudo mount $rootdev $root_mp
+sudo mount $efidev $efi_mp
+
+sudo cp -aR $root_mp/* $dest/
+sudo cp -aR $efi_mp/EFI $dest/boot/efi/
+
+# These locations are required by IPA even when it does not really run
+# grub-install.
+sudo mkdir -p $dest/{dev,proc,run,sys}
+
+# The default arguments don't work for us, update grub configuration.
+sudo sed -i "/^ *linux /s/\$/ $KARGS/" $dest/boot/efi/EFI/ubuntu/grub.cfg
+
+LIBGUESTFS_BACKEND=direct sudo -E \
+ virt-make-fs --size +50M --type ext3 --label cirros-rootfs \
+ ${guestfish_args:-} "$dest" "$OUT"
+
+sudo chown $USER "$OUT"
+qemu-img info "$OUT"
diff --git a/zuul.d/ironic-jobs.yaml b/zuul.d/ironic-jobs.yaml
index a5a8f9b50..41100963e 100644
--- a/zuul.d/ironic-jobs.yaml
+++ b/zuul.d/ironic-jobs.yaml
@@ -248,9 +248,6 @@
IRONIC_ENABLED_POWER_INTERFACES: redfish
IRONIC_ENABLED_MANAGEMENT_INTERFACES: redfish
IRONIC_AUTOMATED_CLEAN_ENABLED: False
- # TODO(TheJulia): We need to excise netboot from
- # jobs at some point.
- IRONIC_DEFAULT_BOOT_OPTION: netboot
IRONIC_ENABLED_BOOT_INTERFACES: redfish-virtual-media
SWIFT_ENABLE_TEMPURLS: True
SWIFT_TEMPURL_KEY: secretkey
@@ -276,6 +273,7 @@
tempest_test_regex: test_baremetal_introspection
devstack_localrc:
IRONIC_BOOT_MODE: bios
+ IRONIC_DEFAULT_BOOT_OPTION: netboot
IRONIC_INSPECTOR_MANAGED_BOOT: True
IRONIC_INSPECTOR_NODE_NOT_FOUND_HOOK: ''
IRONIC_AUTOMATED_CLEAN_ENABLED: False
@@ -343,7 +341,6 @@
vars:
devstack_localrc:
IRONIC_AUTOMATED_CLEAN_ENABLED: False
- IRONIC_DEFAULT_BOOT_OPTION: netboot
- job:
name: ironic-tempest-partition-bios-ipmi-pxe
@@ -676,7 +673,6 @@
IRONIC_IPXE_ENABLED: False
IRONIC_RAMDISK_TYPE: tinyipa
IRONIC_AUTOMATED_CLEAN_ENABLED: False
- IRONIC_DEFAULT_BOOT_OPTION: netboot
IRONIC_VM_SPECS_RAM: 4096
- job: