Skip to contentSkip to conversation

testimage: TEST_SERVER_IP isn't mandatory

PATCH In review Ross Burton 1 participant 8 messages Sep 10, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 testimage: TEST_SERVER_IP isn't mandatory

When using the simpleremote test target, TEST_SERVER_IP doesn't have to be configured as the code will detect the host's IP if it isn't set.

---
 meta/classes/testimage.bbclass | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
meta/classes/testimage.bbclass +2 -5
index 3c689aec913..8bf6b17af8a 100644
@@ -143,11 +143,8 @@ do_testimage[depends] += "${TESTIMAGEDEPENDS}"
 do_testimage[lockfiles] += "${TESTIMAGELOCK}"
 
 def testimage_sanity(d):
-    if (d.getVar('TEST_TARGET') == 'simpleremote'
-        and (not d.getVar('TEST_TARGET_IP')
-             or not d.getVar('TEST_SERVER_IP'))):
-        bb.fatal('When TEST_TARGET is set to "simpleremote" '
-                 'TEST_TARGET_IP and TEST_SERVER_IP are needed too.')
+    if d.getVar('TEST_TARGET') == 'simpleremote' and not d.getVar('TEST_TARGET_IP'):
+        bb.fatal('When TEST_TARGET is set to "simpleremote" TEST_TARGET_IP must be set.')
 
 def get_testimage_configuration(d, test_type, machine):
     import platform
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/7 testimage: pass the base image name to the target class

Also pass the the base image name to the target class. This is the full path to the deploy directory and the image name without any extensions, so makes it easier to find ancillary files.

---
 meta/classes/testimage.bbclass | 1 +
 1 file changed, 1 insertion(+)
meta/classes/testimage.bbclass +1 -0
index 8bf6b17af8a..d139df9925f 100644
@@ -309,6 +309,7 @@ def testimage_main(d):
                       'serial_ports': len(d.getVar("SERIAL_CONSOLES").split()),
                       'ovmf'        : ovmf,
                       'tmpfsdir'    : d.getVar("RUNQEMU_TMPFS_DIR"),
+                      'image_name'  : image_name
                     }
 
     if d.getVar("TESTIMAGE_BOOT_PATTERNS"):
Signature · 1 line
2.25.1
#2 lore raw

PATCH 3/7 oeqa/core/target: remove abstract decorations

In reply to Ross Burton

There's no need to inherit from object in Python 3, and marking the methods as abstract is overkill considering the type hierarchy.

---
 meta/lib/oeqa/core/target/__init__.py | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
meta/lib/oeqa/core/target/__init__.py +1 -8
index 1382aa9b523..3da66038342 100644
@@ -4,33 +4,26 @@
 # SPDX-License-Identifier: MIT
 #
 
-from abc import abstractmethod
 
-class OETarget(object):
+class OETarget:
 
     def __init__(self, logger, *args, **kwargs):
         self.logger = logger
 
-    @abstractmethod
     def start(self):
         pass
 
-    @abstractmethod
     def stop(self):
         pass
 
-    @abstractmethod
     def run(self, cmd, timeout=None):
         pass
 
-    @abstractmethod
     def copyTo(self, localSrc, remoteDst):
         pass
 
-    @abstractmethod
     def copyFrom(self, remoteSrc, localDst):
         pass
 
-    @abstractmethod
     def copyDirTo(self, localSrc, remoteDst):
         pass
Signature · 1 line
2.25.1
#3 lore raw

PATCH 4/7 oeqa/core/target: move server_ip to superclass

In reply to Ross Burton

Move towards a consistent interface across OETarget subclasses by moving server_ip to the superclass.

---
 meta/lib/oeqa/core/target/__init__.py | 3 ++-
 meta/lib/oeqa/core/target/qemu.py     | 4 +---
 meta/lib/oeqa/core/target/ssh.py      | 3 +--
 3 files changed, 4 insertions(+), 6 deletions(-)
meta/lib/oeqa/core/target/__init__.py +2 -1
index 3da66038342..aff02ecc439 100644
@@ -7,7 +7,8 @@
 
 class OETarget:
 
-    def __init__(self, logger, *args, **kwargs):
+    def __init__(self, logger, server_ip):
+        self.server_ip = server_ip
         self.logger = logger
 
     def start(self):
meta/lib/oeqa/core/target/qemu.py +1 -3
index 79fd724f7d4..7c6e353edf2 100644
@@ -26,10 +26,8 @@ class OEQemuTarget(OESSHTarget):
             tmpdir='', dir_image='', boottime=60, serial_ports=2,
             boot_patterns = defaultdict(str), ovmf=False, tmpfsdir=None, **kwargs):
 
-        super(OEQemuTarget, self).__init__(logger, None, server_ip, timeout,
-                user, port)
+        super().__init__(logger, None, server_ip, timeout, user, port)
 
-        self.server_ip = server_ip
         self.server_port = 0
         self.machine = machine
         self.rootfs = rootfs
meta/lib/oeqa/core/target/ssh.py +1 -2
index 923a223b25b..4da1e4c2b2d 100644
@@ -27,9 +27,8 @@ class OESSHTarget(OETarget):
             fileHandler.setFormatter(formatter)
             logger.addHandler(fileHandler)
 
-        super(OESSHTarget, self).__init__(logger)
+        super().__init__(logger, server_ip)
         self.ip = ip
-        self.server_ip = server_ip
         self.server_port = server_port
         self.timeout = timeout
         self.user = user
Signature · 1 line
2.25.1
#4 lore raw

PATCH 5/7 oeqa/core/target: remove server port parameter

In reply to Ross Burton

Specifying a port that the test host can open sockets on isn't that useful as the package management tests will open multiple ports, so the specified port won't be used anyway. The value was never set so used the default of value, which meant the kernel picked the port.

Remove the server port parameter entirely, and let the kernel pick a free port.

---
 meta/lib/oeqa/core/target/qemu.py   | 1 -
 meta/lib/oeqa/core/target/ssh.py    | 3 +--
 meta/lib/oeqa/runtime/cases/apt.py  | 4 +---
 meta/lib/oeqa/runtime/cases/dnf.py  | 3 +--
 meta/lib/oeqa/runtime/cases/opkg.py | 4 +---
 meta/lib/oeqa/runtime/context.py    | 6 ------
 6 files changed, 4 insertions(+), 17 deletions(-)
meta/lib/oeqa/core/target/qemu.py +0 -1
index 7c6e353edf2..66551607fb9 100644
@@ -28,7 +28,6 @@ class OEQemuTarget(OESSHTarget):
 
         super().__init__(logger, None, server_ip, timeout, user, port)
 
-        self.server_port = 0
         self.machine = machine
         self.rootfs = rootfs
         self.kernel = kernel
meta/lib/oeqa/core/target/ssh.py +1 -2
index 4da1e4c2b2d..bbf621c8e38 100644
@@ -15,7 +15,7 @@ from . import OETarget
 
 class OESSHTarget(OETarget):
     def __init__(self, logger, ip, server_ip, timeout=300, user='root',
-                 port=None, server_port=0, **kwargs):
+                 port=None, **kwargs):
         if not logger:
             logger = logging.getLogger('target')
             logger.setLevel(logging.INFO)
@@ -29,7 +29,6 @@ class OESSHTarget(OETarget):
 
         super().__init__(logger, server_ip)
         self.ip = ip
-        self.server_port = server_port
         self.timeout = timeout
         self.user = user
         ssh_options = [
meta/lib/oeqa/runtime/cases/apt.py +1 -3
index 53745df93f9..ed531a619aa 100644
@@ -22,9 +22,7 @@ class AptRepoTest(AptTest):
     @classmethod
     def setUpClass(cls):
         service_repo = os.path.join(cls.tc.td['DEPLOY_DIR_DEB'], 'all')
-        cls.repo_server = HTTPService(service_repo,
-                                      '0.0.0.0', port=cls.tc.target.server_port,
-                                      logger=cls.tc.logger)
+        cls.repo_server = HTTPService(service_repo, '0.0.0.0', logger=cls.tc.logger)
         cls.repo_server.start()
 
     @classmethod
meta/lib/oeqa/runtime/cases/dnf.py +1 -2
index f40c63026e5..937acaab597 100644
@@ -53,8 +53,7 @@ class DnfRepoTest(DnfTest):
     @classmethod
     def setUpClass(cls):
         cls.repo_server = HTTPService(os.path.join(cls.tc.td['WORKDIR'], 'oe-testimage-repo'),
-                                      '0.0.0.0', port=cls.tc.target.server_port,
-                                      logger=cls.tc.logger)
+                                      '0.0.0.0', logger=cls.tc.logger)
         cls.repo_server.start()
 
     @classmethod
meta/lib/oeqa/runtime/cases/opkg.py +1 -3
index 9cfee1cd886..581ddf58749 100644
@@ -25,9 +25,7 @@ class OpkgRepoTest(OpkgTest):
         if cls.tc.td["MULTILIB_VARIANTS"]:
             allarchfeed = cls.tc.td["TUNE_PKGARCH"]
         service_repo = os.path.join(cls.tc.td['DEPLOY_DIR_IPK'], allarchfeed)
-        cls.repo_server = HTTPService(service_repo,
-                                      '0.0.0.0', port=cls.tc.target.server_port,
-                                      logger=cls.tc.logger)
+        cls.repo_server = HTTPService(service_repo, '0.0.0.0', logger=cls.tc.logger)
         cls.repo_server.start()
 
     @classmethod
meta/lib/oeqa/runtime/context.py +0 -6
index 3826f276421..8552aa782bc 100644
@@ -99,12 +99,6 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
                 target_ip = target_ip_port[0]
                 kwargs['port'] = target_ip_port[1]
 
-        if server_ip:
-            server_ip_port = server_ip.split(':')
-            if len(server_ip_port) == 2:
-                server_ip = server_ip_port[0]
-                kwargs['server_port'] = int(server_ip_port[1])
-
         if target_type == 'simpleremote':
             target = OESSHTarget(logger, target_ip, server_ip, **kwargs)
         elif target_type == 'qemu':
Signature · 1 line
2.25.1
#5 lore raw

PATCH 6/7 oeqa/core/target: add target_ip to superclass

In reply to Ross Burton

Move towards a consistent interface across OETarget subclasses by moving target_ip to the superclass.

QemuTarget automatically determines the target IP on startup, so default that to None.

---
 meta/lib/oeqa/core/target/__init__.py | 3 ++-
 meta/lib/oeqa/core/target/qemu.py     | 4 ++--
 meta/lib/oeqa/core/target/ssh.py      | 5 ++---
 meta/lib/oeqa/runtime/context.py      | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
meta/lib/oeqa/core/target/__init__.py +2 -1
index aff02ecc439..45ed3e54b40 100644
@@ -7,8 +7,9 @@
 
 class OETarget:
 
-    def __init__(self, logger, server_ip):
+    def __init__(self, logger, server_ip, target_ip):
         self.server_ip = server_ip
+        self.ip = target_ip
         self.logger = logger
 
     def start(self):
meta/lib/oeqa/core/target/qemu.py +2 -2
index 66551607fb9..ef567939ad8 100644
@@ -20,13 +20,13 @@ from oeqa.utils.dump import TargetDumper
 supported_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic']
 
 class OEQemuTarget(OESSHTarget):
-    def __init__(self, logger, server_ip, timeout=300, user='root',
+    def __init__(self, logger, server_ip, target_ip=None, timeout=300, user='root',
             port=None, machine='', rootfs='', kernel='', kvm=False, slirp=False,
             dump_dir='', dump_host_cmds='', display='', bootlog='',
             tmpdir='', dir_image='', boottime=60, serial_ports=2,
             boot_patterns = defaultdict(str), ovmf=False, tmpfsdir=None, **kwargs):
 
-        super().__init__(logger, None, server_ip, timeout, user, port)
+        super().__init__(logger, server_ip, target_ip, timeout, user, port)
 
         self.machine = machine
         self.rootfs = rootfs
meta/lib/oeqa/core/target/ssh.py +2 -3
index bbf621c8e38..b61c7d141d9 100644
@@ -14,7 +14,7 @@ import codecs
 from . import OETarget
 
 class OESSHTarget(OETarget):
-    def __init__(self, logger, ip, server_ip, timeout=300, user='root',
+    def __init__(self, logger, server_ip, target_ip, timeout=300, user='root',
                  port=None, **kwargs):
         if not logger:
             logger = logging.getLogger('target')
@@ -27,8 +27,7 @@ class OESSHTarget(OETarget):
             fileHandler.setFormatter(formatter)
             logger.addHandler(fileHandler)
 
-        super().__init__(logger, server_ip)
-        self.ip = ip
+        super().__init__(logger, server_ip, target_ip)
         self.timeout = timeout
         self.user = user
         ssh_options = [
meta/lib/oeqa/runtime/context.py +1 -1
index 8552aa782bc..76cae4ee789 100644
@@ -100,7 +100,7 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
                 kwargs['port'] = target_ip_port[1]
 
         if target_type == 'simpleremote':
-            target = OESSHTarget(logger, target_ip, server_ip, **kwargs)
+            target = OESSHTarget(logger, server_ip, target_ip, **kwargs)
         elif target_type == 'qemu':
             target = OEQemuTarget(logger, server_ip, **kwargs)
         else:
Signature · 1 line
2.25.1
#6 lore raw

PATCH 7/7 oeqa/target/ssh: don't assume target_dumper is set

In reply to Ross Burton

The target_dumper property is only set by the QemuTarget subclass, so assign a default value and check it isn't None before calling it.

---
 meta/lib/oeqa/core/target/ssh.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
meta/lib/oeqa/core/target/ssh.py +3 -1
index b61c7d141d9..8cd2966fa38 100644
@@ -41,6 +41,7 @@ class OESSHTarget(OETarget):
             self.ssh = self.ssh + [ '-p', port ]
             self.scp = self.scp + [ '-P', port ]
         self._monitor_dumper = None
+        self.target_dumper = None
 
     def start(self, **kwargs):
         pass
@@ -99,7 +100,8 @@ class OESSHTarget(OETarget):
             if self.monitor_dumper:
                 self.monitor_dumper.dump_monitor()
         if status == 255:
-            self.target_dumper.dump_target()
+            if self.target_dumper:
+                self.target_dumper.dump_target()
             if self.monitor_dumper:
                 self.monitor_dumper.dump_monitor()
         return (status, output)
Signature · 1 line
2.25.1
#7 lore raw
In reply to Ross Burton

Hold off on this, it breaks some potential use-cases.

Ross

Quoted 33 lines · Ross Burton via lists.openembedded.org

When using the simpleremote test target, TEST_SERVER_IP doesn't have to be configured as the code will detect the host's IP if it isn't set.

---
 meta/classes/testimage.bbclass | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
meta/classes/testimage.bbclass +2 -6
index 3c689aec913..8bf6b17af8a 100644
@@ -143,11 +143,8 @@ do_testimage[depends] += "${TESTIMAGEDEPENDS}"
 do_testimage[lockfiles] += "${TESTIMAGELOCK}"
 
 def testimage_sanity(d):
-    if (d.getVar('TEST_TARGET') == 'simpleremote'
-        and (not d.getVar('TEST_TARGET_IP')
-             or not d.getVar('TEST_SERVER_IP'))):
-        bb.fatal('When TEST_TARGET is set to "simpleremote" '
-                 'TEST_TARGET_IP and TEST_SERVER_IP are needed too.')
+    if d.getVar('TEST_TARGET') == 'simpleremote' and not d.getVar('TEST_TARGET_IP'):
+        bb.fatal('When TEST_TARGET is set to "simpleremote" TEST_TARGET_IP must be set.')
 
 def get_testimage_configuration(d, test_type, machine):
     import platform
--

2.25.1