summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2016-05-20 11:57:44 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-06-02 08:24:01 +0100
commit3b3997174831931ea472167ba6cc854a4972ccce (patch)
tree861b0bcb54e70fbe59bf7920862954dcec40a1e8 /meta/lib/oeqa
parent52c4b7f247618f185a11dfb1cf15d0490d074379 (diff)
downloadpoky-3b3997174831931ea472167ba6cc854a4972ccce.tar.gz
classes/lib: Complete transition to python3
This patch contains all the other misc pieces of the transition to python3 which didn't make sense to be broken into individual patches. (From OE-Core rev: fcd6b38bab8517d83e1ed48eef1bca9a9a190f57) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa')
-rw-r--r--meta/lib/oeqa/controllers/masterimage.py4
-rw-r--r--meta/lib/oeqa/oetest.py10
-rw-r--r--meta/lib/oeqa/selftest/_toaster.py4
-rw-r--r--meta/lib/oeqa/selftest/recipetool.py4
-rw-r--r--meta/lib/oeqa/selftest/sstatetests.py6
-rw-r--r--meta/lib/oeqa/targetcontrol.py4
-rw-r--r--meta/lib/oeqa/utils/commands.py4
-rw-r--r--meta/lib/oeqa/utils/decorators.py17
-rw-r--r--meta/lib/oeqa/utils/dump.py2
-rw-r--r--meta/lib/oeqa/utils/httpserver.py6
-rw-r--r--meta/lib/oeqa/utils/logparser.py2
-rw-r--r--meta/lib/oeqa/utils/qemurunner.py22
-rw-r--r--meta/lib/oeqa/utils/qemutinyrunner.py2
-rw-r--r--meta/lib/oeqa/utils/targetbuild.py4
-rw-r--r--meta/lib/oeqa/utils/testexport.py2
15 files changed, 56 insertions, 37 deletions
diff --git a/meta/lib/oeqa/controllers/masterimage.py b/meta/lib/oeqa/controllers/masterimage.py
index 522f9ebd76..4cb75539ee 100644
--- a/meta/lib/oeqa/controllers/masterimage.py
+++ b/meta/lib/oeqa/controllers/masterimage.py
@@ -24,9 +24,7 @@ from oeqa.utils import CommandError
24 24
25from abc import ABCMeta, abstractmethod 25from abc import ABCMeta, abstractmethod
26 26
27class MasterImageHardwareTarget(oeqa.targetcontrol.BaseTarget): 27class MasterImageHardwareTarget(oeqa.targetcontrol.BaseTarget, metaclass=ABCMeta):
28
29 __metaclass__ = ABCMeta
30 28
31 supported_image_fstypes = ['tar.gz', 'tar.bz2'] 29 supported_image_fstypes = ['tar.gz', 'tar.bz2']
32 30
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py
index 4211ffc379..b4cf34b720 100644
--- a/meta/lib/oeqa/oetest.py
+++ b/meta/lib/oeqa/oetest.py
@@ -13,6 +13,7 @@ import inspect
13import subprocess 13import subprocess
14import signal 14import signal
15import shutil 15import shutil
16import functools
16try: 17try:
17 import bb 18 import bb
18except ImportError: 19except ImportError:
@@ -340,7 +341,14 @@ class TestContext(object):
340 for index, suite in enumerate(suites): 341 for index, suite in enumerate(suites):
341 set_suite_depth(suite) 342 set_suite_depth(suite)
342 suite.index = index 343 suite.index = index
343 suites.sort(cmp=lambda a,b: cmp((a.depth, a.index), (b.depth, b.index))) 344
345 def cmp(a, b):
346 return (a > b) - (a < b)
347
348 def cmpfunc(a, b):
349 return cmp((a.depth, a.index), (b.depth, b.index))
350
351 suites.sort(key=functools.cmp_to_key(cmpfunc))
344 352
345 self.suite = testloader.suiteClass(suites) 353 self.suite = testloader.suiteClass(suites)
346 354
diff --git a/meta/lib/oeqa/selftest/_toaster.py b/meta/lib/oeqa/selftest/_toaster.py
index c424659fdc..15ea9df9ef 100644
--- a/meta/lib/oeqa/selftest/_toaster.py
+++ b/meta/lib/oeqa/selftest/_toaster.py
@@ -2,7 +2,7 @@ import unittest
2import os 2import os
3import sys 3import sys
4import shlex, subprocess 4import shlex, subprocess
5import urllib, commands, time, getpass, re, json, shlex 5import urllib.request, urllib.parse, urllib.error, subprocess, time, getpass, re, json, shlex
6 6
7import oeqa.utils.ftools as ftools 7import oeqa.utils.ftools as ftools
8from oeqa.selftest.base import oeSelfTest 8from oeqa.selftest.base import oeSelfTest
@@ -290,7 +290,7 @@ class Toaster_DB_Tests(ToasterSetup):
290 layers = Layer.objects.values('id', 'layer_index_url') 290 layers = Layer.objects.values('id', 'layer_index_url')
291 cnt_err = [] 291 cnt_err = []
292 for layer in layers: 292 for layer in layers:
293 resp = urllib.urlopen(layer['layer_index_url']) 293 resp = urllib.request.urlopen(layer['layer_index_url'])
294 if (resp.getcode() != 200): 294 if (resp.getcode() != 200):
295 cnt_err.append(layer['id']) 295 cnt_err.append(layer['id'])
296 self.assertEqual(len(cnt_err), 0, msg = 'Errors for layer id: %s' % cnt_err) 296 self.assertEqual(len(cnt_err), 0, msg = 'Errors for layer id: %s' % cnt_err)
diff --git a/meta/lib/oeqa/selftest/recipetool.py b/meta/lib/oeqa/selftest/recipetool.py
index e72911b0aa..a93d18e275 100644
--- a/meta/lib/oeqa/selftest/recipetool.py
+++ b/meta/lib/oeqa/selftest/recipetool.py
@@ -1,7 +1,7 @@
1import os 1import os
2import logging 2import logging
3import tempfile 3import tempfile
4import urlparse 4import urllib.parse
5 5
6from oeqa.utils.commands import runCmd, bitbake, get_bb_var, create_temp_layer 6from oeqa.utils.commands import runCmd, bitbake, get_bb_var, create_temp_layer
7from oeqa.utils.decorators import testcase 7from oeqa.utils.decorators import testcase
@@ -471,7 +471,7 @@ class RecipetoolAppendsrcBase(RecipetoolBase):
471 '''Return the first file:// in SRC_URI for the specified recipe.''' 471 '''Return the first file:// in SRC_URI for the specified recipe.'''
472 src_uri = get_bb_var('SRC_URI', recipe).split() 472 src_uri = get_bb_var('SRC_URI', recipe).split()
473 for uri in src_uri: 473 for uri in src_uri:
474 p = urlparse.urlparse(uri) 474 p = urllib.parse.urlparse(uri)
475 if p.scheme == 'file': 475 if p.scheme == 'file':
476 return p.netloc + p.path 476 return p.netloc + p.path
477 477
diff --git a/meta/lib/oeqa/selftest/sstatetests.py b/meta/lib/oeqa/selftest/sstatetests.py
index cc64c6cb68..07212ac4f1 100644
--- a/meta/lib/oeqa/selftest/sstatetests.py
+++ b/meta/lib/oeqa/selftest/sstatetests.py
@@ -264,7 +264,7 @@ SDKMACHINE = "i686"
264 files2 = get_files(topdir + "/tmp-sstatesamehash2/stamps/") 264 files2 = get_files(topdir + "/tmp-sstatesamehash2/stamps/")
265 files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash").replace("i686-linux", "x86_64-linux").replace("i686" + targetvendor + "-linux", "x86_64" + targetvendor + "-linux", ) for x in files2] 265 files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash").replace("i686-linux", "x86_64-linux").replace("i686" + targetvendor + "-linux", "x86_64" + targetvendor + "-linux", ) for x in files2]
266 self.maxDiff = None 266 self.maxDiff = None
267 self.assertItemsEqual(files1, files2) 267 self.assertCountEqual(files1, files2)
268 268
269 269
270 @testcase(1271) 270 @testcase(1271)
@@ -298,7 +298,7 @@ NATIVELSBSTRING = \"DistroB\"
298 files2 = get_files(topdir + "/tmp-sstatesamehash2/stamps/") 298 files2 = get_files(topdir + "/tmp-sstatesamehash2/stamps/")
299 files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2] 299 files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2]
300 self.maxDiff = None 300 self.maxDiff = None
301 self.assertItemsEqual(files1, files2) 301 self.assertCountEqual(files1, files2)
302 302
303 @testcase(1368) 303 @testcase(1368)
304 def test_sstate_allarch_samesigs(self): 304 def test_sstate_allarch_samesigs(self):
@@ -393,7 +393,7 @@ DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
393 files2 = get_files(topdir + "/tmp-sstatesamehash2/stamps") 393 files2 = get_files(topdir + "/tmp-sstatesamehash2/stamps")
394 files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2] 394 files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2]
395 self.maxDiff = None 395 self.maxDiff = None
396 self.assertItemsEqual(files1, files2) 396 self.assertCountEqual(files1, files2)
397 397
398 398
399 def test_sstate_noop_samesigs(self): 399 def test_sstate_noop_samesigs(self):
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py
index 5422a617c4..1c57efaaef 100644
--- a/meta/lib/oeqa/targetcontrol.py
+++ b/meta/lib/oeqa/targetcontrol.py
@@ -43,9 +43,7 @@ def get_target_controller(d):
43 return controller(d) 43 return controller(d)
44 44
45 45
46class BaseTarget(object): 46class BaseTarget(object, metaclass=ABCMeta):
47
48 __metaclass__ = ABCMeta
49 47
50 supported_image_fstypes = [] 48 supported_image_fstypes = []
51 49
diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py
index 9a7c1d1375..18fe39ecfe 100644
--- a/meta/lib/oeqa/utils/commands.py
+++ b/meta/lib/oeqa/utils/commands.py
@@ -41,7 +41,7 @@ class Command(object):
41 self.data = data 41 self.data = data
42 42
43 self.options = dict(self.defaultopts) 43 self.options = dict(self.defaultopts)
44 if isinstance(self.cmd, basestring): 44 if isinstance(self.cmd, str):
45 self.options["shell"] = True 45 self.options["shell"] = True
46 if self.data: 46 if self.data:
47 self.options['stdin'] = subprocess.PIPE 47 self.options['stdin'] = subprocess.PIPE
@@ -123,7 +123,7 @@ def bitbake(command, ignore_status=False, timeout=None, postconfig=None, **optio
123 else: 123 else:
124 extra_args = "" 124 extra_args = ""
125 125
126 if isinstance(command, basestring): 126 if isinstance(command, str):
127 cmd = "bitbake " + extra_args + " " + command 127 cmd = "bitbake " + extra_args + " " + command
128 else: 128 else:
129 cmd = [ "bitbake" ] + [a for a in (command + extra_args.split(" ")) if a not in [""]] 129 cmd = [ "bitbake" ] + [a for a in (command + extra_args.split(" ")) if a not in [""]]
diff --git a/meta/lib/oeqa/utils/decorators.py b/meta/lib/oeqa/utils/decorators.py
index 6fb09db417..0b23565485 100644
--- a/meta/lib/oeqa/utils/decorators.py
+++ b/meta/lib/oeqa/utils/decorators.py
@@ -115,6 +115,8 @@ class NoParsingFilter(logging.Filter):
115 def filter(self, record): 115 def filter(self, record):
116 return record.levelno == 100 116 return record.levelno == 100
117 117
118import inspect
119
118def LogResults(original_class): 120def LogResults(original_class):
119 orig_method = original_class.run 121 orig_method = original_class.run
120 122
@@ -124,6 +126,19 @@ def LogResults(original_class):
124 logfile = os.path.join(os.getcwd(),'results-'+caller+'.'+timestamp+'.log') 126 logfile = os.path.join(os.getcwd(),'results-'+caller+'.'+timestamp+'.log')
125 linkfile = os.path.join(os.getcwd(),'results-'+caller+'.log') 127 linkfile = os.path.join(os.getcwd(),'results-'+caller+'.log')
126 128
129 def get_class_that_defined_method(meth):
130 if inspect.ismethod(meth):
131 for cls in inspect.getmro(meth.__self__.__class__):
132 if cls.__dict__.get(meth.__name__) is meth:
133 return cls
134 meth = meth.__func__ # fallback to __qualname__ parsing
135 if inspect.isfunction(meth):
136 cls = getattr(inspect.getmodule(meth),
137 meth.__qualname__.split('.<locals>', 1)[0].rsplit('.', 1)[0])
138 if isinstance(cls, type):
139 return cls
140 return None
141
127 #rewrite the run method of unittest.TestCase to add testcase logging 142 #rewrite the run method of unittest.TestCase to add testcase logging
128 def run(self, result, *args, **kws): 143 def run(self, result, *args, **kws):
129 orig_method(self, result, *args, **kws) 144 orig_method(self, result, *args, **kws)
@@ -135,7 +150,7 @@ def LogResults(original_class):
135 except AttributeError: 150 except AttributeError:
136 test_case = self._testMethodName 151 test_case = self._testMethodName
137 152
138 class_name = str(testMethod.im_class).split("'")[1] 153 class_name = str(get_class_that_defined_method(testMethod)).split("'")[1]
139 154
140 #create custom logging level for filtering. 155 #create custom logging level for filtering.
141 custom_log_level = 100 156 custom_log_level = 100
diff --git a/meta/lib/oeqa/utils/dump.py b/meta/lib/oeqa/utils/dump.py
index 63a591d366..71422a9aea 100644
--- a/meta/lib/oeqa/utils/dump.py
+++ b/meta/lib/oeqa/utils/dump.py
@@ -3,7 +3,7 @@ import sys
3import errno 3import errno
4import datetime 4import datetime
5import itertools 5import itertools
6from commands import runCmd 6from .commands import runCmd
7 7
8def get_host_dumper(d): 8def get_host_dumper(d):
9 cmds = d.getVar("testimage_dump_host", True) 9 cmds = d.getVar("testimage_dump_host", True)
diff --git a/meta/lib/oeqa/utils/httpserver.py b/meta/lib/oeqa/utils/httpserver.py
index 76518d8ef9..bd76f36468 100644
--- a/meta/lib/oeqa/utils/httpserver.py
+++ b/meta/lib/oeqa/utils/httpserver.py
@@ -1,8 +1,8 @@
1import SimpleHTTPServer 1import http.server
2import multiprocessing 2import multiprocessing
3import os 3import os
4 4
5class HTTPServer(SimpleHTTPServer.BaseHTTPServer.HTTPServer): 5class HTTPServer(http.server.HTTPServer):
6 6
7 def server_start(self, root_dir): 7 def server_start(self, root_dir):
8 import signal 8 import signal
@@ -10,7 +10,7 @@ class HTTPServer(SimpleHTTPServer.BaseHTTPServer.HTTPServer):
10 os.chdir(root_dir) 10 os.chdir(root_dir)
11 self.serve_forever() 11 self.serve_forever()
12 12
13class HTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): 13class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
14 14
15 def log_message(self, format_str, *args): 15 def log_message(self, format_str, *args):
16 pass 16 pass
diff --git a/meta/lib/oeqa/utils/logparser.py b/meta/lib/oeqa/utils/logparser.py
index 87b50354cd..b377dcd271 100644
--- a/meta/lib/oeqa/utils/logparser.py
+++ b/meta/lib/oeqa/utils/logparser.py
@@ -3,7 +3,7 @@
3import sys 3import sys
4import os 4import os
5import re 5import re
6import ftools 6from . import ftools
7 7
8 8
9# A parser that can be used to identify weather a line is a test result or a section statement. 9# A parser that can be used to identify weather a line is a test result or a section statement.
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index 3d60433cae..e408fbbf3a 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -23,8 +23,8 @@ logger = logging.getLogger("BitBake.QemuRunner")
23 23
24# Get Unicode non printable control chars 24# Get Unicode non printable control chars
25control_range = list(range(0,32))+list(range(127,160)) 25control_range = list(range(0,32))+list(range(127,160))
26control_chars = [unichr(x) for x in control_range 26control_chars = [chr(x) for x in control_range
27 if unichr(x) not in string.printable] 27 if chr(x) not in string.printable]
28re_control_char = re.compile('[%s]' % re.escape("".join(control_chars))) 28re_control_char = re.compile('[%s]' % re.escape("".join(control_chars)))
29 29
30class QemuRunner: 30class QemuRunner:
@@ -220,6 +220,7 @@ class QemuRunner:
220 stopread = False 220 stopread = False
221 qemusock = None 221 qemusock = None
222 bootlog = '' 222 bootlog = ''
223 data = b''
223 while time.time() < endtime and not stopread: 224 while time.time() < endtime and not stopread:
224 sread, swrite, serror = select.select(socklist, [], [], 5) 225 sread, swrite, serror = select.select(socklist, [], [], 5)
225 for sock in sread: 226 for sock in sread:
@@ -283,13 +284,14 @@ class QemuRunner:
283 if hasattr(self, "origchldhandler"): 284 if hasattr(self, "origchldhandler"):
284 signal.signal(signal.SIGCHLD, self.origchldhandler) 285 signal.signal(signal.SIGCHLD, self.origchldhandler)
285 if self.runqemu: 286 if self.runqemu:
286 os.kill(self.monitorpid, signal.SIGKILL) 287 if hasattr(self, "monitorpid"):
287 logger.info("Sending SIGTERM to runqemu") 288 os.kill(self.monitorpid, signal.SIGKILL)
288 try: 289 logger.info("Sending SIGTERM to runqemu")
289 os.killpg(os.getpgid(self.runqemu.pid), signal.SIGTERM) 290 try:
290 except OSError as e: 291 os.killpg(os.getpgid(self.runqemu.pid), signal.SIGTERM)
291 if e.errno != errno.ESRCH: 292 except OSError as e:
292 raise 293 if e.errno != errno.ESRCH:
294 raise
293 endtime = time.time() + self.runqemutime 295 endtime = time.time() + self.runqemutime
294 while self.runqemu.poll() is None and time.time() < endtime: 296 while self.runqemu.poll() is None and time.time() < endtime:
295 time.sleep(1) 297 time.sleep(1)
@@ -448,7 +450,7 @@ class LoggingThread(threading.Thread):
448 def stop(self): 450 def stop(self):
449 self.logger.info("Stopping logging thread") 451 self.logger.info("Stopping logging thread")
450 if self.running: 452 if self.running:
451 os.write(self.writepipe, "stop") 453 os.write(self.writepipe, bytes("stop", "utf-8"))
452 454
453 def teardown(self): 455 def teardown(self):
454 self.logger.info("Tearing down logging thread") 456 self.logger.info("Tearing down logging thread")
diff --git a/meta/lib/oeqa/utils/qemutinyrunner.py b/meta/lib/oeqa/utils/qemutinyrunner.py
index 054ab0ec5d..c823157ad6 100644
--- a/meta/lib/oeqa/utils/qemutinyrunner.py
+++ b/meta/lib/oeqa/utils/qemutinyrunner.py
@@ -13,7 +13,7 @@ import re
13import socket 13import socket
14import select 14import select
15import bb 15import bb
16from qemurunner import QemuRunner 16from .qemurunner import QemuRunner
17 17
18class QemuTinyRunner(QemuRunner): 18class QemuTinyRunner(QemuRunner):
19 19
diff --git a/meta/lib/oeqa/utils/targetbuild.py b/meta/lib/oeqa/utils/targetbuild.py
index f850d78df1..d538f6b65f 100644
--- a/meta/lib/oeqa/utils/targetbuild.py
+++ b/meta/lib/oeqa/utils/targetbuild.py
@@ -10,9 +10,7 @@ import bb.utils
10import subprocess 10import subprocess
11from abc import ABCMeta, abstractmethod 11from abc import ABCMeta, abstractmethod
12 12
13class BuildProject(): 13class BuildProject(metaclass=ABCMeta):
14
15 __metaclass__ = ABCMeta
16 14
17 def __init__(self, d, uri, foldername=None, tmpdir="/tmp/"): 15 def __init__(self, d, uri, foldername=None, tmpdir="/tmp/"):
18 self.d = d 16 self.d = d
diff --git a/meta/lib/oeqa/utils/testexport.py b/meta/lib/oeqa/utils/testexport.py
index 4fbf4bdcb3..57be2ca449 100644
--- a/meta/lib/oeqa/utils/testexport.py
+++ b/meta/lib/oeqa/utils/testexport.py
@@ -6,7 +6,7 @@
6 6
7import os, re, glob as g, shutil as sh,sys 7import os, re, glob as g, shutil as sh,sys
8from time import sleep 8from time import sleep
9from commands import runCmd 9from .commands import runCmd
10from difflib import SequenceMatcher as SM 10from difflib import SequenceMatcher as SM
11 11
12try: 12try: