aboutsummaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/runtime/decorator/package.py
blob: 1a8bc0099e27b5ee2bbb23a56b5dcec9b2a35d44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright (C) 2016 Intel Corporation
# Released under the MIT license (see COPYING.MIT)

from oeqa.core.decorator import OETestDecorator, registerDecorator
from oeqa.core.utils.misc import strToSet

@registerDecorator
class OEHasPackage(OETestDecorator):
    """
        Checks if image has packages (un)installed.

        The argument must be a string, set, or list of packages that must be
        installed or not present in the image.

        The way to tell a package must not be in an image is using an
        exclamation point ('!') before the name of the package.

        If test depends on pkg1 or pkg2 you need to use:
        @OEHasPackage({'pkg1', 'pkg2'})

        If test depends on pkg1 and pkg2 you need to use:
        @OEHasPackage('pkg1')
        @OEHasPackage('pkg2')

        If test depends on pkg1 but pkg2 must not be present use:
        @OEHasPackage({'pkg1', '!pkg2'})
    """

    attrs = ('need_pkgs',)

    def setUpDecorator(self):
        need_pkgs = set()
        unneed_pkgs = set()
        pkgs = strToSet(self.need_pkgs)
        # Conver to multilib
        mlprefix = self.case.tc.td['MLPREFIX']
        for pkg in pkgs:
            if pkg.startswith('!'):
                pkg_name = pkg[1:]
                if mlprefix and not pkg_name.startswith(mlprefix):
                    unneed_pkgs.add('%s%s' % (mlprefix, pkg_name))
                else:
                    unneed_pkgs.add(pkg_name)
            else:
                if mlprefix and not pkg.startswith(mlprefix):
                    need_pkgs.add('%s%s' % (mlprefix, pkg))
                else:
                    need_pkgs.add(pkg)

        if unneed_pkgs:
            msg = 'Checking if %s is not installed' % ', '.join(unneed_pkgs)
            self.logger.debug(msg)
            if not self.case.tc.image_packages.isdisjoint(unneed_pkgs):
                msg = "Test can't run with %s installed" % ', or'.join(unneed_pkgs)
                self.case.skipTest(msg)

        if need_pkgs:
            msg = 'Checking if at least one of %s is installed' % ', '.join(need_pkgs)
            self.logger.debug(msg)
            if self.case.tc.image_packages.isdisjoint(need_pkgs):
                msg = "Test requires %s to be installed" % ', or'.join(need_pkgs)
                self.case.skipTest(msg)