From 95f236f668f641224144a527279e368e98e2e6bf Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Wed, 16 Feb 2022 17:43:45 +0000 Subject: core-image-testmaster: Rename to core-image-testcontroller Rename the image, the test controller class/code/module and the underlying image sentinel file to all match the controller terminology. (From OE-Core rev: f87b32833ac5327c4659ab8c06af34e7bda83f83) Signed-off-by: Richard Purdie --- meta/conf/distro/include/distro_alias.inc | 4 +- meta/conf/distro/include/maintainers.inc | 4 +- meta/lib/oeqa/controllers/controllerimage.py | 199 +++++++++++++++++++++ meta/lib/oeqa/controllers/masterimage.py | 199 --------------------- meta/lib/oeqa/runtime/cases/ssh.py | 4 +- .../initrdscripts/files/init-install-efi-testfs.sh | 2 +- .../initrdscripts/files/init-install-testfs.sh | 2 +- .../images/core-image-testcontroller-initramfs.bb | 24 +++ .../images/core-image-testcontroller.bb | 18 ++ .../images/core-image-testmaster-initramfs.bb | 24 --- .../images/core-image-testmaster.bb | 18 -- 11 files changed, 249 insertions(+), 249 deletions(-) create mode 100644 meta/lib/oeqa/controllers/controllerimage.py delete mode 100644 meta/lib/oeqa/controllers/masterimage.py create mode 100644 meta/recipes-extended/images/core-image-testcontroller-initramfs.bb create mode 100644 meta/recipes-extended/images/core-image-testcontroller.bb delete mode 100644 meta/recipes-extended/images/core-image-testmaster-initramfs.bb delete mode 100644 meta/recipes-extended/images/core-image-testmaster.bb diff --git a/meta/conf/distro/include/distro_alias.inc b/meta/conf/distro/include/distro_alias.inc index 44bc3bf131..e43c0acd80 100644 --- a/meta/conf/distro/include/distro_alias.inc +++ b/meta/conf/distro/include/distro_alias.inc @@ -42,8 +42,8 @@ DISTRO_PN_ALIAS:pn-core-image-rt-sdk = "OE-Core" DISTRO_PN_ALIAS:pn-core-image-sato = "OE-Core" DISTRO_PN_ALIAS:pn-core-image-sato-dev = "OE-Core" DISTRO_PN_ALIAS:pn-core-image-sato-sdk = "OE-Core" -DISTRO_PN_ALIAS:pn-core-image-testmaster = "OE-Core" -DISTRO_PN_ALIAS:pn-core-image-testmaster-initramfs = "OE-Core" +DISTRO_PN_ALIAS:pn-core-image-testcontroller = "OE-Core" +DISTRO_PN_ALIAS:pn-core-image-testcontroller-initramfs = "OE-Core" DISTRO_PN_ALIAS:pn-core-image-weston = "OE-Core" DISTRO_PN_ALIAS:pn-core-image-x11 = "OE-Core" DISTRO_PN_ALIAS:pn-createrepo-c = "Fedora=createrepo_c Clear=createrepo_c" diff --git a/meta/conf/distro/include/maintainers.inc b/meta/conf/distro/include/maintainers.inc index 32ec391eb9..740e5fe55c 100644 --- a/meta/conf/distro/include/maintainers.inc +++ b/meta/conf/distro/include/maintainers.inc @@ -112,8 +112,8 @@ RECIPE_MAINTAINER:pn-core-image-ptest-all = "Richard Purdie /dev/null &") + if status != 0: + bb.error("Failed rebooting target and no power control command defined. You need to manually reset the device.\n%s" % output) + + def _wait_until_booted(self): + ''' Waits until the target device has booted (if we have just power cycled it) ''' + # Subclasses with better methods of determining boot can override this + time.sleep(120) + + def deploy(self): + # base class just sets the ssh log file for us + super(ControllerImageHardwareTarget, self).deploy() + self.controller = sshcontrol.SSHControl(ip=self.ip, logfile=self.sshlog, timeout=600, port=self.port) + status, output = self.controller.run("cat /etc/controllerimage") + if status != 0: + # We're not booted into the controller image, so try rebooting + bb.plain("%s - booting into the controller image" % self.pn) + self.power_ctl("cycle") + self._wait_until_booted() + + bb.plain("%s - deploying image on target" % self.pn) + status, output = self.controller.run("cat /etc/controllerimage") + if status != 0: + bb.fatal("No ssh connectivity or target isn't running a controller image.\n%s" % output) + if self.user_cmds: + self.deploy_cmds = self.user_cmds.split("\n") + try: + self._deploy() + except Exception as e: + bb.fatal("Failed deploying test image: %s" % e) + + @abstractmethod + def _deploy(self): + pass + + def start(self, extra_bootparams=None): + bb.plain("%s - boot test image on target" % self.pn) + self._start() + # set the ssh object for the target/test image + self.connection = sshcontrol.SSHControl(self.ip, logfile=self.sshlog, port=self.port) + bb.plain("%s - start running tests" % self.pn) + + @abstractmethod + def _start(self): + pass + + def stop(self): + bb.plain("%s - reboot/powercycle target" % self.pn) + self.power_cycle(self.controller) + + +class SystemdbootTarget(ControllerImageHardwareTarget): + + def __init__(self, d): + super(SystemdbootTarget, self).__init__(d) + # this the value we need to set in the LoaderEntryOneShot EFI variable + # so the system boots the 'test' bootloader label and not the default + # The first four bytes are EFI bits, and the rest is an utf-16le string + # (EFI vars values need to be utf-16) + # $ echo -en "test\0" | iconv -f ascii -t utf-16le | hexdump -C + # 00000000 74 00 65 00 73 00 74 00 00 00 |t.e.s.t...| + self.efivarvalue = r'\x07\x00\x00\x00\x74\x00\x65\x00\x73\x00\x74\x00\x00\x00' + self.deploy_cmds = [ + 'mount -L boot /boot', + 'mkdir -p /mnt/testrootfs', + 'mount -L testrootfs /mnt/testrootfs', + 'modprobe efivarfs', + 'mount -t efivarfs efivarfs /sys/firmware/efi/efivars', + 'cp ~/test-kernel /boot', + 'rm -rf /mnt/testrootfs/*', + 'tar xvf ~/test-rootfs.%s -C /mnt/testrootfs' % self.image_fstype, + 'printf "%s" > /sys/firmware/efi/efivars/LoaderEntryOneShot-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f' % self.efivarvalue + ] + + def _deploy(self): + # make sure these aren't mounted + self.controller.run("umount /boot; umount /mnt/testrootfs; umount /sys/firmware/efi/efivars;") + # from now on, every deploy cmd should return 0 + # else an exception will be thrown by sshcontrol + self.controller.ignore_status = False + self.controller.copy_to(self.rootfs, "~/test-rootfs." + self.image_fstype) + self.controller.copy_to(self.kernel, "~/test-kernel") + for cmd in self.deploy_cmds: + self.controller.run(cmd) + + def _start(self, params=None): + self.power_cycle(self.controller) + # there are better ways than a timeout but this should work for now + time.sleep(120) diff --git a/meta/lib/oeqa/controllers/masterimage.py b/meta/lib/oeqa/controllers/masterimage.py deleted file mode 100644 index 0bf5917e48..0000000000 --- a/meta/lib/oeqa/controllers/masterimage.py +++ /dev/null @@ -1,199 +0,0 @@ -# Copyright (C) 2014 Intel Corporation -# -# SPDX-License-Identifier: MIT -# -# This module adds support to testimage.bbclass to deploy images and run -# tests using a "master image" - this is a "known good" image that is -# installed onto the device as part of initial setup and will be booted into -# with no interaction; we can then use it to deploy the image to be tested -# to a second partition before running the tests. -# -# For an example master image, see core-image-testmaster -# (meta/recipes-extended/images/core-image-testmaster.bb) - -import os -import bb -import traceback -import time -import subprocess - -import oeqa.targetcontrol -import oeqa.utils.sshcontrol as sshcontrol -import oeqa.utils.commands as commands -from oeqa.utils import CommandError - -from abc import ABCMeta, abstractmethod - -class MasterImageHardwareTarget(oeqa.targetcontrol.BaseTarget, metaclass=ABCMeta): - - supported_image_fstypes = ['tar.gz', 'tar.bz2'] - - def __init__(self, d): - super(MasterImageHardwareTarget, self).__init__(d) - - # target ip - addr = d.getVar("TEST_TARGET_IP") or bb.fatal('Please set TEST_TARGET_IP with the IP address of the machine you want to run the tests on.') - self.ip = addr.split(":")[0] - try: - self.port = addr.split(":")[1] - except IndexError: - self.port = None - bb.note("Target IP: %s" % self.ip) - self.server_ip = d.getVar("TEST_SERVER_IP") - if not self.server_ip: - try: - self.server_ip = subprocess.check_output(['ip', 'route', 'get', self.ip ]).split("\n")[0].split()[-1] - except Exception as e: - bb.fatal("Failed to determine the host IP address (alternatively you can set TEST_SERVER_IP with the IP address of this machine): %s" % e) - bb.note("Server IP: %s" % self.server_ip) - - # test rootfs + kernel - self.image_fstype = self.get_image_fstype(d) - self.rootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), d.getVar("IMAGE_LINK_NAME") + '.' + self.image_fstype) - self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), d.getVar("KERNEL_IMAGETYPE", False) + '-' + d.getVar('MACHINE', False) + '.bin') - if not os.path.isfile(self.rootfs): - # we could've checked that IMAGE_FSTYPES contains tar.gz but the config for running testimage might not be - # the same as the config with which the image was build, ie - # you bitbake core-image-sato with IMAGE_FSTYPES += "tar.gz" - # and your autobuilder overwrites the config, adds the test bits and runs bitbake core-image-sato -c testimage - bb.fatal("No rootfs found. Did you build the image ?\nIf yes, did you build it with IMAGE_FSTYPES += \"tar.gz\" ? \ - \nExpected path: %s" % self.rootfs) - if not os.path.isfile(self.kernel): - bb.fatal("No kernel found. Expected path: %s" % self.kernel) - - # master ssh connection - self.master = None - # if the user knows what they are doing, then by all means... - self.user_cmds = d.getVar("TEST_DEPLOY_CMDS") - self.deploy_cmds = None - - # this is the name of the command that controls the power for a board - # e.g: TEST_POWERCONTROL_CMD = "/home/user/myscripts/powercontrol.py ${MACHINE} what-ever-other-args-the-script-wants" - # the command should take as the last argument "off" and "on" and "cycle" (off, on) - self.powercontrol_cmd = d.getVar("TEST_POWERCONTROL_CMD") or None - self.powercontrol_args = d.getVar("TEST_POWERCONTROL_EXTRA_ARGS", False) or "" - - self.serialcontrol_cmd = d.getVar("TEST_SERIALCONTROL_CMD") or None - self.serialcontrol_args = d.getVar("TEST_SERIALCONTROL_EXTRA_ARGS", False) or "" - - self.origenv = os.environ - if self.powercontrol_cmd or self.serialcontrol_cmd: - # the external script for controlling power might use ssh - # ssh + keys means we need the original user env - bborigenv = d.getVar("BB_ORIGENV", False) or {} - for key in bborigenv: - val = bborigenv.getVar(key) - if val is not None: - self.origenv[key] = str(val) - - if self.powercontrol_cmd: - if self.powercontrol_args: - self.powercontrol_cmd = "%s %s" % (self.powercontrol_cmd, self.powercontrol_args) - if self.serialcontrol_cmd: - if self.serialcontrol_args: - self.serialcontrol_cmd = "%s %s" % (self.serialcontrol_cmd, self.serialcontrol_args) - - def power_ctl(self, msg): - if self.powercontrol_cmd: - cmd = "%s %s" % (self.powercontrol_cmd, msg) - try: - commands.runCmd(cmd, assert_error=False, start_new_session=True, env=self.origenv) - except CommandError as e: - bb.fatal(str(e)) - - def power_cycle(self, conn): - if self.powercontrol_cmd: - # be nice, don't just cut power - conn.run("shutdown -h now") - time.sleep(10) - self.power_ctl("cycle") - else: - status, output = conn.run("sync; { sleep 1; reboot; } > /dev/null &") - if status != 0: - bb.error("Failed rebooting target and no power control command defined. You need to manually reset the device.\n%s" % output) - - def _wait_until_booted(self): - ''' Waits until the target device has booted (if we have just power cycled it) ''' - # Subclasses with better methods of determining boot can override this - time.sleep(120) - - def deploy(self): - # base class just sets the ssh log file for us - super(MasterImageHardwareTarget, self).deploy() - self.master = sshcontrol.SSHControl(ip=self.ip, logfile=self.sshlog, timeout=600, port=self.port) - status, output = self.master.run("cat /etc/masterimage") - if status != 0: - # We're not booted into the master image, so try rebooting - bb.plain("%s - booting into the master image" % self.pn) - self.power_ctl("cycle") - self._wait_until_booted() - - bb.plain("%s - deploying image on target" % self.pn) - status, output = self.master.run("cat /etc/masterimage") - if status != 0: - bb.fatal("No ssh connectivity or target isn't running a master image.\n%s" % output) - if self.user_cmds: - self.deploy_cmds = self.user_cmds.split("\n") - try: - self._deploy() - except Exception as e: - bb.fatal("Failed deploying test image: %s" % e) - - @abstractmethod - def _deploy(self): - pass - - def start(self, extra_bootparams=None): - bb.plain("%s - boot test image on target" % self.pn) - self._start() - # set the ssh object for the target/test image - self.connection = sshcontrol.SSHControl(self.ip, logfile=self.sshlog, port=self.port) - bb.plain("%s - start running tests" % self.pn) - - @abstractmethod - def _start(self): - pass - - def stop(self): - bb.plain("%s - reboot/powercycle target" % self.pn) - self.power_cycle(self.master) - - -class SystemdbootTarget(MasterImageHardwareTarget): - - def __init__(self, d): - super(SystemdbootTarget, self).__init__(d) - # this the value we need to set in the LoaderEntryOneShot EFI variable - # so the system boots the 'test' bootloader label and not the default - # The first four bytes are EFI bits, and the rest is an utf-16le string - # (EFI vars values need to be utf-16) - # $ echo -en "test\0" | iconv -f ascii -t utf-16le | hexdump -C - # 00000000 74 00 65 00 73 00 74 00 00 00 |t.e.s.t...| - self.efivarvalue = r'\x07\x00\x00\x00\x74\x00\x65\x00\x73\x00\x74\x00\x00\x00' - self.deploy_cmds = [ - 'mount -L boot /boot', - 'mkdir -p /mnt/testrootfs', - 'mount -L testrootfs /mnt/testrootfs', - 'modprobe efivarfs', - 'mount -t efivarfs efivarfs /sys/firmware/efi/efivars', - 'cp ~/test-kernel /boot', - 'rm -rf /mnt/testrootfs/*', - 'tar xvf ~/test-rootfs.%s -C /mnt/testrootfs' % self.image_fstype, - 'printf "%s" > /sys/firmware/efi/efivars/LoaderEntryOneShot-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f' % self.efivarvalue - ] - - def _deploy(self): - # make sure these aren't mounted - self.master.run("umount /boot; umount /mnt/testrootfs; umount /sys/firmware/efi/efivars;") - # from now on, every deploy cmd should return 0 - # else an exception will be thrown by sshcontrol - self.master.ignore_status = False - self.master.copy_to(self.rootfs, "~/test-rootfs." + self.image_fstype) - self.master.copy_to(self.kernel, "~/test-kernel") - for cmd in self.deploy_cmds: - self.master.run(cmd) - - def _start(self, params=None): - self.power_cycle(self.master) - # there are better ways than a timeout but this should work for now - time.sleep(120) diff --git a/meta/lib/oeqa/runtime/cases/ssh.py b/meta/lib/oeqa/runtime/cases/ssh.py index 60a5fbbfbf..e31224b3af 100644 --- a/meta/lib/oeqa/runtime/cases/ssh.py +++ b/meta/lib/oeqa/runtime/cases/ssh.py @@ -13,7 +13,7 @@ class SSHTest(OERuntimeTestCase): def test_ssh(self): (status, output) = self.target.run('uname -a') self.assertEqual(status, 0, msg='SSH Test failed: %s' % output) - (status, output) = self.target.run('cat /etc/masterimage') - msg = "This isn't the right image - /etc/masterimage " \ + (status, output) = self.target.run('cat /etc/controllerimage') + msg = "This isn't the right image - /etc/controllerimage " \ "shouldn't be here %s" % output self.assertEqual(status, 1, msg=msg) diff --git a/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh b/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh index b351985a61..1fcd29e54c 100644 --- a/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh +++ b/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh @@ -133,7 +133,7 @@ mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /rootmnt echo "Copying rootfs files..." cp -a /rootmnt/* /ssd -touch /ssd/etc/masterimage +touch /ssd/etc/controllerimage if [ -d /ssd/etc/ ] ; then # We dont want udev to mount our root device while we're booting... diff --git a/meta/recipes-core/initrdscripts/files/init-install-testfs.sh b/meta/recipes-core/initrdscripts/files/init-install-testfs.sh index ac62160528..7b49001659 100644 --- a/meta/recipes-core/initrdscripts/files/init-install-testfs.sh +++ b/meta/recipes-core/initrdscripts/files/init-install-testfs.sh @@ -158,7 +158,7 @@ mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root echo "Copying rootfs files..." cp -a /src_root/* /tgt_root -touch /tgt_root/etc/masterimage +touch /tgt_root/etc/controllerimage if [ -d /tgt_root/etc/ ] ; then echo "$bootfs /boot ext3 defaults 1 2" >> /tgt_root/etc/fstab diff --git a/meta/recipes-extended/images/core-image-testcontroller-initramfs.bb b/meta/recipes-extended/images/core-image-testcontroller-initramfs.bb new file mode 100644 index 0000000000..2bc035a538 --- /dev/null +++ b/meta/recipes-extended/images/core-image-testcontroller-initramfs.bb @@ -0,0 +1,24 @@ +DESCRIPTION = "Small image capable of booting a device with custom install scripts, \ +adding a second rootfs, used for testing." + +# use -testfs live-install scripts +PACKAGE_INSTALL = "initramfs-live-boot initramfs-live-install-testfs initramfs-live-install-efi-testfs busybox udev base-passwd ${ROOTFS_BOOTSTRAP_INSTALL}" + +# Do not pollute the initrd image with rootfs features +IMAGE_FEATURES = "" + +export IMAGE_BASENAME = "core-image-testcontroller-initramfs" +IMAGE_NAME_SUFFIX ?= "" +IMAGE_LINGUAS = "" + +LICENSE = "MIT" + +IMAGE_FSTYPES = "${INITRAMFS_FSTYPES}" +inherit core-image + +IMAGE_ROOTFS_SIZE = "8192" +IMAGE_ROOTFS_EXTRA_SPACE = "0" +BAD_RECOMMENDATIONS += "busybox-syslog" + +# Use the same restriction as initramfs-live-install-testfs +COMPATIBLE_HOST = "(i.86|x86_64).*-linux" diff --git a/meta/recipes-extended/images/core-image-testcontroller.bb b/meta/recipes-extended/images/core-image-testcontroller.bb new file mode 100644 index 0000000000..20edbd5630 --- /dev/null +++ b/meta/recipes-extended/images/core-image-testcontroller.bb @@ -0,0 +1,18 @@ +DESCRIPTION = "A test controller image to be deployed on a target useful for testing other images using the OEQA runtime tests" + +IMAGE_FEATURES += "ssh-server-openssh package-management" + +inherit core-image + +# the deploy code requires bash and +# normal linux utilities not busybox ones +IMAGE_INSTALL += "\ + bash coreutils util-linux tar gzip bzip2 kmod \ + python3-modules python3-misc \ + e2fsprogs e2fsprogs-mke2fs parted \ + " +# we need a particular initramfs for live images +# that pulls custom install scripts which take +# care of partitioning for us +INITRD_IMAGE = "core-image-testcontroller-initramfs" + diff --git a/meta/recipes-extended/images/core-image-testmaster-initramfs.bb b/meta/recipes-extended/images/core-image-testmaster-initramfs.bb deleted file mode 100644 index 1a2e0af27b..0000000000 --- a/meta/recipes-extended/images/core-image-testmaster-initramfs.bb +++ /dev/null @@ -1,24 +0,0 @@ -DESCRIPTION = "Small image capable of booting a device with custom install scripts, \ -adding a second rootfs, used for testing." - -# use -testfs live-install scripts -PACKAGE_INSTALL = "initramfs-live-boot initramfs-live-install-testfs initramfs-live-install-efi-testfs busybox udev base-passwd ${ROOTFS_BOOTSTRAP_INSTALL}" - -# Do not pollute the initrd image with rootfs features -IMAGE_FEATURES = "" - -export IMAGE_BASENAME = "core-image-testmaster-initramfs" -IMAGE_NAME_SUFFIX ?= "" -IMAGE_LINGUAS = "" - -LICENSE = "MIT" - -IMAGE_FSTYPES = "${INITRAMFS_FSTYPES}" -inherit core-image - -IMAGE_ROOTFS_SIZE = "8192" -IMAGE_ROOTFS_EXTRA_SPACE = "0" -BAD_RECOMMENDATIONS += "busybox-syslog" - -# Use the same restriction as initramfs-live-install-testfs -COMPATIBLE_HOST = "(i.86|x86_64).*-linux" diff --git a/meta/recipes-extended/images/core-image-testmaster.bb b/meta/recipes-extended/images/core-image-testmaster.bb deleted file mode 100644 index 0faf18f5a4..0000000000 --- a/meta/recipes-extended/images/core-image-testmaster.bb +++ /dev/null @@ -1,18 +0,0 @@ -DESCRIPTION = "A master image to be deployed on a target useful for testing other images" - -IMAGE_FEATURES += "ssh-server-openssh package-management" - -inherit core-image - -# the deploy code requires bash and -# normal linux utilities not busybox ones -IMAGE_INSTALL += "\ - bash coreutils util-linux tar gzip bzip2 kmod \ - python3-modules python3-misc \ - e2fsprogs e2fsprogs-mke2fs parted \ - " -# we need a particular initramfs for live images -# that pulls custom install scripts which take -# care of partitioning for us -INITRD_IMAGE = "core-image-testmaster-initramfs" - -- cgit v1.2.3-54-g00ecf