scripts: Remove deprecated imp module usage
PATCH 1/5 scripts: Remove deprecated imp module usage
The imp module is deprecated, port the code over to use importlib as recently done for bb.utils as well.
--- scripts/lib/scriptutils.py | 11 +++++------ scripts/pythondeps | 8 +++----- 2 files changed, 8 insertions(+), 11 deletions(-)
scripts/lib/scriptutils.py +5 -6
@@ -26,6 +26,8 @@ import string import subprocess import sys import tempfile +import importlib +from importlib import machinery def logger_create(name, stream=None): logger = logging.getLogger(name)
@@ -50,12 +52,9 @@ def load_plugins(logger, plugins, pluginpath): def load_plugin(name): logger.debug('Loading plugin %s' % name) - fp, pathname, description = imp.find_module(name, [pluginpath]) - try: - return imp.load_module(name, fp, pathname, description) - finally: - if fp: - fp.close() + spec = importlib.machinery.PathFinder.find_spec(name, path=[pluginpath] ) + if spec: + return spec.loader.load_module() def plugin_name(filename): return os.path.splitext(os.path.basename(filename))[0]
scripts/pythondeps +3 -5
@@ -9,7 +9,8 @@ import argparse import ast -import imp +import importlib +from importlib import machinery import logging import os.path import sys
@@ -17,10 +18,7 @@ import sys logger = logging.getLogger('pythondeps') -suffixes = [] -for triple in imp.get_suffixes(): - suffixes.append(triple[0]) - +suffixes = importlib.machinery.all_suffixes() class PythonDepError(Exception): pass
Signature · 1 line
2.17.1
PATCH 2/5 oeqa/concurrencytest: Avoid unclosed file warnings
Avoid an unclosed file per thread warning when running selftests concurrently by closing the result stream.
--- meta/lib/oeqa/core/utils/concurrencytest.py | 3 +++ 1 file changed, 3 insertions(+)
meta/lib/oeqa/core/utils/concurrencytest.py +3 -0
@@ -115,6 +115,9 @@ class ConcurrentTestSuite(unittest.TestSuite): for thread, process_result in threads.values(): process_result.stop() raise + finally: + for test in tests: + test[0]._stream.close() def _run_test(self, test, process_result, queue): try:
Signature · 1 line
2.17.1
PATCH 3/5 testimage/testsdk/selftest: Avoid platform.distro_identifier deprecation warnings
In reply to Richard PurdieUse our own lsb function instead as used elsewhere by the codebase.
--- meta/classes/testimage.bbclass | 2 +- meta/classes/testsdk.bbclass | 2 +- meta/lib/oeqa/selftest/context.py | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-)
meta/classes/testimage.bbclass +1 -1
@@ -133,7 +133,7 @@ def get_testimage_configuration(d, test_type, machine): 'IMAGE_BASENAME': d.getVar("IMAGE_BASENAME"), 'IMAGE_PKGTYPE': d.getVar("IMAGE_PKGTYPE"), 'STARTTIME': d.getVar("DATETIME"), - 'HOST_DISTRO': ('-'.join(platform.linux_distribution())).replace(' ', '-'), + 'HOST_DISTRO': oe.lsb.distro_identifier().replace(' ', '-'), 'LAYERS': get_layers(d.getVar("BBLAYERS"))} return configuration get_testimage_configuration[vardepsexclude] = "DATETIME"
meta/classes/testsdk.bbclass +1 -1
@@ -23,7 +23,7 @@ def get_sdk_configuration(d, test_type): 'IMAGE_BASENAME': d.getVar("IMAGE_BASENAME"), 'IMAGE_PKGTYPE': d.getVar("IMAGE_PKGTYPE"), 'STARTTIME': d.getVar("DATETIME"), - 'HOST_DISTRO': ('-'.join(platform.linux_distribution())).replace(' ', '-'), + 'HOST_DISTRO': oe.lsb.distro_identifier().replace(' ', '-'), 'LAYERS': get_layers(d.getVar("BBLAYERS"))} return configuration get_sdk_configuration[vardepsexclude] = "DATETIME"
meta/lib/oeqa/selftest/context.py +2 -1
@@ -11,6 +11,7 @@ from shutil import copyfile from random import choice import oeqa +import oe from oeqa.core.context import OETestContext, OETestContextExecutor from oeqa.core.exception import OEQAPreRun, OEQATestNotFound
@@ -218,7 +219,7 @@ class OESelftestTestContextExecutor(OETestContextExecutor): configuration = {'TEST_TYPE': 'oeselftest', 'STARTTIME': args.test_start_time, 'MACHINE': self.tc.td["MACHINE"], - 'HOST_DISTRO': ('-'.join(platform.linux_distribution())).replace(' ', '-'), + 'HOST_DISTRO': oe.lsb.distro_identifier().replace(' ', '-'), 'HOST_NAME': metadata['hostname'], 'LAYERS': metadata['layers']} return configuration
Signature · 1 line
2.17.1
PATCH 4/5 oeqa/utils/httpserver: Rework to avoid hangs and improve logging
In reply to Richard Purdietestimage.bbclass installs a SIGTERM handler which conflicts with the use of multiprocessing here. This is paritcularly problematic if the http service is terminated before its started and hence before its had a chance to reset the default signal handler (as the code was written).
Instead, temporarily remove testimage's handler whilst forking the http process which means the correct handler is installed and won't deadlock.
Also take the opportunity to add in some log messages about the server start and shutdown so that future debugging is easier and its clearer what the code is doing.
--- meta/lib/oeqa/runtime/cases/apt.py | 2 +- meta/lib/oeqa/runtime/cases/dnf.py | 2 +- meta/lib/oeqa/runtime/cases/opkg.py | 2 +- meta/lib/oeqa/utils/httpserver.py | 37 ++++++++++++++++++++++------- 4 files changed, 32 insertions(+), 11 deletions(-)
meta/lib/oeqa/runtime/cases/apt.py +1 -1
@@ -18,7 +18,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, cls.tc.target.server_ip) + cls.repo_server = HTTPService(service_repo, cls.tc.target.server_ip, logger=cls.tc.logger) cls.repo_server.start() @classmethod
meta/lib/oeqa/runtime/cases/dnf.py +1 -1
@@ -55,7 +55,7 @@ class DnfRepoTest(DnfTest): @classmethod def setUpClass(cls): cls.repo_server = HTTPService(os.path.join(cls.tc.td['WORKDIR'], 'oe-testimage-repo'), - cls.tc.target.server_ip) + cls.tc.target.server_ip, logger=cls.tc.logger) cls.repo_server.start() @classmethod
meta/lib/oeqa/runtime/cases/opkg.py +1 -1
@@ -21,7 +21,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, cls.tc.target.server_ip) + cls.repo_server = HTTPService(service_repo, cls.tc.target.server_ip, logger=cls.tc.logger) cls.repo_server.start() @classmethod
meta/lib/oeqa/utils/httpserver.py +29 -8
@@ -1,13 +1,13 @@ import http.server import multiprocessing import os +import traceback +import signal from socketserver import ThreadingMixIn class HTTPServer(ThreadingMixIn, http.server.HTTPServer): - def server_start(self, root_dir): - import signal - signal.signal(signal.SIGTERM, signal.SIG_DFL) + def server_start(self, root_dir, logger): os.chdir(root_dir) self.serve_forever()
@@ -18,19 +18,40 @@ class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler): class HTTPService(object): - def __init__(self, root_dir, host=''): + def __init__(self, root_dir, host='', logger=None): self.root_dir = root_dir self.host = host self.port = 0 + self.logger = logger def start(self): + if not os.path.exists(self.root_dir): + self.logger.info("Not starting HTTPService for directory %s which doesn't exist" % (self.root_dir)) + return + self.server = HTTPServer((self.host, self.port), HTTPRequestHandler) if self.port == 0: self.port = self.server.server_port - self.process = multiprocessing.Process(target=self.server.server_start, args=[self.root_dir]) + self.process = multiprocessing.Process(target=self.server.server_start, args=[self.root_dir, self.logger]) + + # The signal handler from testimage.bbclass can cause deadlocks here + # if the HTTPServer is terminated before it can restore the standard + #signal behaviour + orig = signal.getsignal(signal.SIGTERM) + signal.signal(signal.SIGTERM, signal.SIG_DFL) self.process.start() + signal.signal(signal.SIGTERM, orig) + + if self.logger: + self.logger.info("Started HTTPService on %s:%s" % (self.host, self.port)) + def stop(self): - self.server.server_close() - self.process.terminate() - self.process.join() + if hasattr(self, "server"): + self.server.server_close() + if hasattr(self, "process"): + self.process.terminate() + self.process.join() + if self.logger: + self.logger.info("Stopped HTTPService on %s:%s" % (self.host, self.port)) +
Signature · 1 line
2.17.1
PATCH 5/5 testimage: Enable autorunning of the package manager testsuites
In reply to Richard PurdieNow that the hangs in httpservice are fixed we can let these tests auto skip as appropriate.
--- meta/classes/testimage.bbclass | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
meta/classes/testimage.bbclass +1 -3
@@ -44,9 +44,7 @@ BASICTESTSUITE = "\ ping date df ssh scp python perl gi ptest parselogs \ logrotate connman systemd oe_syslog pam stap ldd xorg \ kernelmodule gcc buildcpio buildlzip buildgalculator \ - ${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'dnf rpm', '', d)} \ - ${@bb.utils.contains('IMAGE_PKGTYPE', 'ipk', 'opkg', '', d)} \ - ${@bb.utils.contains('IMAGE_PKGTYPE', 'deb', 'apt', '', d)}" + dnf rpm opkg apt" DEFAULT_TEST_SUITES = "${BASICTESTSUITE}"
Signature · 1 line
2.17.1