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