xref: /OK3568_Linux_fs/yocto/poky/meta/lib/oeqa/runtime/cases/opkg.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#
2# SPDX-License-Identifier: MIT
3#
4
5import os
6from oeqa.utils.httpserver import HTTPService
7from oeqa.runtime.case import OERuntimeTestCase
8from oeqa.core.decorator.data import skipIfNotDataVar, skipIfNotFeature, skipIfFeature
9from oeqa.runtime.decorator.package import OEHasPackage
10
11class OpkgTest(OERuntimeTestCase):
12
13    def pkg(self, command, expected = 0):
14        command = 'opkg %s' % command
15        status, output = self.target.run(command, 1500)
16        message = os.linesep.join([command, output])
17        self.assertEqual(status, expected, message)
18        return output
19
20class OpkgRepoTest(OpkgTest):
21
22    @classmethod
23    def setUp(cls):
24        allarchfeed = 'all'
25        if cls.tc.td["MULTILIB_VARIANTS"]:
26            allarchfeed = cls.tc.td["TUNE_PKGARCH"]
27        service_repo = os.path.join(cls.tc.td['DEPLOY_DIR_IPK'], allarchfeed)
28        cls.repo_server = HTTPService(service_repo,
29                                      '0.0.0.0', port=cls.tc.target.server_port,
30                                      logger=cls.tc.logger)
31        cls.repo_server.start()
32
33    @classmethod
34    def tearDown(cls):
35        cls.repo_server.stop()
36
37    def setup_source_config_for_package_install(self):
38        apt_get_source_server = 'http://%s:%s/' % (self.tc.target.server_ip, self.repo_server.port)
39        apt_get_sourceslist_dir = '/etc/opkg/'
40        self.target.run('cd %s; echo src/gz all %s >> opkg.conf' % (apt_get_sourceslist_dir, apt_get_source_server))
41
42    def cleanup_source_config_for_package_install(self):
43        apt_get_sourceslist_dir = '/etc/opkg/'
44        self.target.run('cd %s; sed -i "/^src/d" opkg.conf' % (apt_get_sourceslist_dir))
45
46    @skipIfNotFeature('package-management',
47                      'Test requires package-management to be in IMAGE_FEATURES')
48    @skipIfNotDataVar('IMAGE_PKGTYPE', 'ipk',
49                      'IPK is not the primary package manager')
50    @skipIfFeature('read-only-rootfs',
51                   'Test does not work with read-only-rootfs in IMAGE_FEATURES')
52    @OEHasPackage(['opkg'])
53    def test_opkg_install_from_repo(self):
54        self.setup_source_config_for_package_install()
55        self.pkg('update')
56        self.pkg('remove run-postinsts-dev')
57        self.pkg('install run-postinsts-dev')
58        self.cleanup_source_config_for_package_install()
59