oeqa/runtime/cases: Improve test dependency information

Add the OEHasPackage decorator to a variety of tests so they determine
automatically if they should run against a given image.

To ensure tests can do this we need to move target operations such
as scp commands into the tests and out of the class startup/teardown.

(From OE-Core rev: 60d6580b85714b8960a964e775d76a7f937f5e5a)

(From OE-Core rev: 03b7658369bb7c1c8fbbaac7d9e281617cc16135)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2018-11-08 19:55:17 +00:00
parent e9055b90c0
commit d853fa2680
10 changed files with 32 additions and 25 deletions

View File

@@ -3,6 +3,7 @@ import re
from oeqa.runtime.case import OERuntimeTestCase from oeqa.runtime.case import OERuntimeTestCase
from oeqa.core.decorator.depends import OETestDepends from oeqa.core.decorator.depends import OETestDepends
from oeqa.core.decorator.oeid import OETestID from oeqa.core.decorator.oeid import OETestID
from oeqa.runtime.decorator.package import OEHasPackage
class DateTest(OERuntimeTestCase): class DateTest(OERuntimeTestCase):
@@ -18,6 +19,7 @@ class DateTest(OERuntimeTestCase):
@OETestID(211) @OETestID(211)
@OETestDepends(['ssh.SSHTest.test_ssh']) @OETestDepends(['ssh.SSHTest.test_ssh'])
@OEHasPackage(['coreutils', 'busybox'])
def test_date(self): def test_date(self):
(status, output) = self.target.run('date +"%Y-%m-%d %T"') (status, output) = self.target.run('date +"%Y-%m-%d %T"')
msg = 'Failed to get initial date, output: %s' % output msg = 'Failed to get initial date, output: %s' % output

View File

@@ -1,11 +1,13 @@
from oeqa.runtime.case import OERuntimeTestCase from oeqa.runtime.case import OERuntimeTestCase
from oeqa.core.decorator.depends import OETestDepends from oeqa.core.decorator.depends import OETestDepends
from oeqa.core.decorator.oeid import OETestID from oeqa.core.decorator.oeid import OETestID
from oeqa.runtime.decorator.package import OEHasPackage
class DfTest(OERuntimeTestCase): class DfTest(OERuntimeTestCase):
@OETestID(234) @OETestID(234)
@OETestDepends(['ssh.SSHTest.test_ssh']) @OETestDepends(['ssh.SSHTest.test_ssh'])
@OEHasPackage(['coreutils', 'busybox'])
def test_df(self): def test_df(self):
cmd = "df / | sed -n '2p' | awk '{print $4}'" cmd = "df / | sed -n '2p' | awk '{print $4}'"
(status,output) = self.target.run(cmd) (status,output) = self.target.run(cmd)

View File

@@ -16,13 +16,13 @@ class OpkgTest(OERuntimeTestCase):
class OpkgRepoTest(OpkgTest): class OpkgRepoTest(OpkgTest):
@classmethod @classmethod
def setUpClass(cls): def setUp(cls):
service_repo = os.path.join(cls.tc.td['DEPLOY_DIR_IPK'], 'all') service_repo = os.path.join(cls.tc.td['DEPLOY_DIR_IPK'], 'all')
cls.repo_server = HTTPService(service_repo, cls.tc.target.server_ip) cls.repo_server = HTTPService(service_repo, cls.tc.target.server_ip)
cls.repo_server.start() cls.repo_server.start()
@classmethod @classmethod
def tearDownClass(cls): def tearDown(cls):
cls.repo_server.stop() cls.repo_server.stop()
def setup_source_config_for_package_install(self): def setup_source_config_for_package_install(self):

View File

@@ -5,6 +5,7 @@ from oeqa.runtime.case import OERuntimeTestCase
from oeqa.core.decorator.depends import OETestDepends from oeqa.core.decorator.depends import OETestDepends
from oeqa.core.decorator.oeid import OETestID from oeqa.core.decorator.oeid import OETestID
from oeqa.core.decorator.data import skipIfNotFeature from oeqa.core.decorator.data import skipIfNotFeature
from oeqa.runtime.decorator.package import OEHasPackage
from oeqa.utils.logparser import Lparser, Result from oeqa.utils.logparser import Lparser, Result
class PtestRunnerTest(OERuntimeTestCase): class PtestRunnerTest(OERuntimeTestCase):
@@ -52,6 +53,7 @@ class PtestRunnerTest(OERuntimeTestCase):
@OETestID(1600) @OETestID(1600)
@skipIfNotFeature('ptest', 'Test requires ptest to be in DISTRO_FEATURES') @skipIfNotFeature('ptest', 'Test requires ptest to be in DISTRO_FEATURES')
@OETestDepends(['ssh.SSHTest.test_ssh']) @OETestDepends(['ssh.SSHTest.test_ssh'])
@OEHasPackage(['ptest-runner'])
@unittest.expectedFailure @unittest.expectedFailure
def test_ptestrunner(self): def test_ptestrunner(self):
status, output = self.target.run('which ptest-runner', 0) status, output = self.target.run('which ptest-runner', 0)

View File

@@ -1,16 +1,12 @@
from oeqa.runtime.case import OERuntimeTestCase from oeqa.runtime.case import OERuntimeTestCase
from oeqa.core.decorator.depends import OETestDepends from oeqa.core.decorator.depends import OETestDepends
from oeqa.core.decorator.oeid import OETestID from oeqa.core.decorator.oeid import OETestID
from oeqa.runtime.decorator.package import OEHasPackage
class PythonTest(OERuntimeTestCase): class PythonTest(OERuntimeTestCase):
@classmethod
def setUpClass(cls):
import unittest
if "python3-core" not in cls.tc.image_packages:
raise unittest.SkipTest("Python3 not on target")
@OETestID(965) @OETestID(965)
@OETestDepends(['ssh.SSHTest.test_ssh']) @OETestDepends(['ssh.SSHTest.test_ssh'])
@OEHasPackage(['python3-core'])
def test_python3(self): def test_python3(self):
cmd = "python3 -c \"import codecs; print(codecs.encode('Uryyb, jbeyq', 'rot13'))\"" cmd = "python3 -c \"import codecs; print(codecs.encode('Uryyb, jbeyq', 'rot13'))\""
status, output = self.target.run(cmd) status, output = self.target.run(cmd)

View File

@@ -10,11 +10,6 @@ from oeqa.core.utils.path import findFile
class RpmBasicTest(OERuntimeTestCase): class RpmBasicTest(OERuntimeTestCase):
@classmethod
def setUpClass(cls):
if cls.tc.td['PACKAGE_CLASSES'].split()[0] != 'package_rpm':
cls.skipTest('Tests require image to be build from rpm')
@OETestID(960) @OETestID(960)
@OEHasPackage(['rpm']) @OEHasPackage(['rpm'])
@OETestDepends(['ssh.SSHTest.test_ssh']) @OETestDepends(['ssh.SSHTest.test_ssh'])
@@ -26,6 +21,9 @@ class RpmBasicTest(OERuntimeTestCase):
@OETestID(191) @OETestID(191)
@OETestDepends(['rpm.RpmBasicTest.test_rpm_help']) @OETestDepends(['rpm.RpmBasicTest.test_rpm_help'])
def test_rpm_query(self): def test_rpm_query(self):
status, output = self.target.run('ls /var/lib/rpm/')
if status != 0:
self.skipTest('No /var/lib/rpm on target')
status, output = self.target.run('rpm -q rpm') status, output = self.target.run('rpm -q rpm')
msg = 'status and output: %s and %s' % (status, output) msg = 'status and output: %s and %s' % (status, output)
self.assertEqual(status, 0, msg=msg) self.assertEqual(status, 0, msg=msg)
@@ -34,30 +32,25 @@ class RpmInstallRemoveTest(OERuntimeTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
if cls.tc.td['PACKAGE_CLASSES'].split()[0] != 'package_rpm':
cls.skipTest('Tests require image to be build from rpm')
pkgarch = cls.td['TUNE_PKGARCH'].replace('-', '_') pkgarch = cls.td['TUNE_PKGARCH'].replace('-', '_')
rpmdir = os.path.join(cls.tc.td['DEPLOY_DIR'], 'rpm', pkgarch) rpmdir = os.path.join(cls.tc.td['DEPLOY_DIR'], 'rpm', pkgarch)
# Pick base-passwd-doc as a test file to get installed, because it's small # Pick base-passwd-doc as a test file to get installed, because it's small
# and it will always be built for standard targets # and it will always be built for standard targets
rpm_doc = 'base-passwd-doc-*.%s.rpm' % pkgarch rpm_doc = 'base-passwd-doc-*.%s.rpm' % pkgarch
if not os.path.exists(rpmdir):
return
for f in fnmatch.filter(os.listdir(rpmdir), rpm_doc): for f in fnmatch.filter(os.listdir(rpmdir), rpm_doc):
test_file = os.path.join(rpmdir, f) cls.test_file = os.path.join(rpmdir, f)
dst = '/tmp/base-passwd-doc.rpm' cls.dst = '/tmp/base-passwd-doc.rpm'
cls.tc.target.copyTo(test_file, dst)
@classmethod
def tearDownClass(cls):
dst = '/tmp/base-passwd-doc.rpm'
cls.tc.target.run('rm -f %s' % dst)
@OETestID(192) @OETestID(192)
@OETestDepends(['rpm.RpmBasicTest.test_rpm_help']) @OETestDepends(['rpm.RpmBasicTest.test_rpm_query'])
def test_rpm_install(self): def test_rpm_install(self):
self.tc.target.copyTo(self.test_file, self.dst)
status, output = self.target.run('rpm -ivh /tmp/base-passwd-doc.rpm') status, output = self.target.run('rpm -ivh /tmp/base-passwd-doc.rpm')
msg = 'Failed to install base-passwd-doc package: %s' % output msg = 'Failed to install base-passwd-doc package: %s' % output
self.assertEqual(status, 0, msg=msg) self.assertEqual(status, 0, msg=msg)
self.tc.target.run('rm -f %s' % self.dst)
@OETestID(194) @OETestID(194)
@OETestDepends(['rpm.RpmInstallRemoveTest.test_rpm_install']) @OETestDepends(['rpm.RpmInstallRemoveTest.test_rpm_install'])
@@ -118,6 +111,8 @@ class RpmInstallRemoveTest(OERuntimeTestCase):
msg = 'Failed to find database files under /var/lib/rpm/ as __db.xxx' msg = 'Failed to find database files under /var/lib/rpm/ as __db.xxx'
self.assertEqual(0, status, msg=msg) self.assertEqual(0, status, msg=msg)
self.tc.target.copyTo(self.test_file, self.dst)
# Remove the package just in case # Remove the package just in case
self.target.run('rpm -e base-passwd-doc') self.target.run('rpm -e base-passwd-doc')
@@ -131,6 +126,8 @@ class RpmInstallRemoveTest(OERuntimeTestCase):
msg = 'Failed to remove base-passwd-doc package. Reason: {}'.format(output) msg = 'Failed to remove base-passwd-doc package. Reason: {}'.format(output)
self.assertEqual(0, status, msg=msg) self.assertEqual(0, status, msg=msg)
self.tc.target.run('rm -f %s' % self.dst)
# if using systemd this should ensure all entries are flushed to /var # if using systemd this should ensure all entries are flushed to /var
status, output = self.target.run("journalctl --sync") status, output = self.target.run("journalctl --sync")
# Get the amount of entries in the log file # Get the amount of entries in the log file

View File

@@ -4,6 +4,7 @@ from tempfile import mkstemp
from oeqa.runtime.case import OERuntimeTestCase from oeqa.runtime.case import OERuntimeTestCase
from oeqa.core.decorator.depends import OETestDepends from oeqa.core.decorator.depends import OETestDepends
from oeqa.core.decorator.oeid import OETestID from oeqa.core.decorator.oeid import OETestID
from oeqa.runtime.decorator.package import OEHasPackage
class ScpTest(OERuntimeTestCase): class ScpTest(OERuntimeTestCase):
@@ -20,6 +21,7 @@ class ScpTest(OERuntimeTestCase):
@OETestID(220) @OETestID(220)
@OETestDepends(['ssh.SSHTest.test_ssh']) @OETestDepends(['ssh.SSHTest.test_ssh'])
@OEHasPackage(['openssh-scp', 'dropbear'])
def test_scp_file(self): def test_scp_file(self):
dst = '/tmp/test_scp_file' dst = '/tmp/test_scp_file'

View File

@@ -1,11 +1,13 @@
from oeqa.runtime.case import OERuntimeTestCase from oeqa.runtime.case import OERuntimeTestCase
from oeqa.core.decorator.depends import OETestDepends from oeqa.core.decorator.depends import OETestDepends
from oeqa.core.decorator.oeid import OETestID from oeqa.core.decorator.oeid import OETestID
from oeqa.runtime.decorator.package import OEHasPackage
class SSHTest(OERuntimeTestCase): class SSHTest(OERuntimeTestCase):
@OETestID(224) @OETestID(224)
@OETestDepends(['ping.PingTest.test_ping']) @OETestDepends(['ping.PingTest.test_ping'])
@OEHasPackage(['dropbear', 'openssh-sshd'])
def test_ssh(self): def test_ssh(self):
(status, output) = self.target.run('uname -a') (status, output) = self.target.run('uname -a')
self.assertEqual(status, 0, msg='SSH Test failed: %s' % output) self.assertEqual(status, 0, msg='SSH Test failed: %s' % output)

View File

@@ -4,6 +4,7 @@ from oeqa.runtime.case import OERuntimeTestCase
from oeqa.core.decorator.depends import OETestDepends from oeqa.core.decorator.depends import OETestDepends
from oeqa.core.decorator.oeid import OETestID from oeqa.core.decorator.oeid import OETestID
from oeqa.core.decorator.data import skipIfNotFeature from oeqa.core.decorator.data import skipIfNotFeature
from oeqa.runtime.decorator.package import OEHasPackage
class StapTest(OERuntimeTestCase): class StapTest(OERuntimeTestCase):
@@ -22,6 +23,7 @@ class StapTest(OERuntimeTestCase):
@skipIfNotFeature('tools-profile', @skipIfNotFeature('tools-profile',
'Test requires tools-profile to be in IMAGE_FEATURES') 'Test requires tools-profile to be in IMAGE_FEATURES')
@OETestDepends(['kernelmodule.KernelModuleTest.test_kernel_module']) @OETestDepends(['kernelmodule.KernelModuleTest.test_kernel_module'])
@OEHasPackage(['systemtap'])
def test_stap(self): def test_stap(self):
cmds = [ cmds = [
'cd /usr/src/kernel && make scripts prepare', 'cd /usr/src/kernel && make scripts prepare',

View File

@@ -2,6 +2,7 @@ from oeqa.runtime.case import OERuntimeTestCase
from oeqa.core.decorator.depends import OETestDepends from oeqa.core.decorator.depends import OETestDepends
from oeqa.core.decorator.oeid import OETestID from oeqa.core.decorator.oeid import OETestID
from oeqa.core.decorator.data import skipIfNotFeature from oeqa.core.decorator.data import skipIfNotFeature
from oeqa.runtime.decorator.package import OEHasPackage
class XorgTest(OERuntimeTestCase): class XorgTest(OERuntimeTestCase):
@@ -9,6 +10,7 @@ class XorgTest(OERuntimeTestCase):
@skipIfNotFeature('x11-base', @skipIfNotFeature('x11-base',
'Test requires x11 to be in IMAGE_FEATURES') 'Test requires x11 to be in IMAGE_FEATURES')
@OETestDepends(['ssh.SSHTest.test_ssh']) @OETestDepends(['ssh.SSHTest.test_ssh'])
@OEHasPackage(['xserver-nodm-init'])
def test_xorg_running(self): def test_xorg_running(self):
cmd ='%s | grep -v xinit | grep [X]org' % self.tc.target_cmds['ps'] cmd ='%s | grep -v xinit | grep [X]org' % self.tc.target_cmds['ps']
status, output = self.target.run(cmd) status, output = self.target.run(cmd)