Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 7 | import os |
| 8 | from oeqa.utils.httpserver import HTTPService |
| 9 | from oeqa.runtime.case import OERuntimeTestCase |
| 10 | from oeqa.core.decorator.data import skipIfNotDataVar, skipIfNotFeature |
| 11 | from oeqa.runtime.decorator.package import OEHasPackage |
| 12 | |
| 13 | class AptTest(OERuntimeTestCase): |
| 14 | |
| 15 | def pkg(self, command, expected = 0): |
| 16 | command = 'apt-get %s' % command |
| 17 | status, output = self.target.run(command, 1500) |
| 18 | message = os.linesep.join([command, output]) |
| 19 | self.assertEqual(status, expected, message) |
| 20 | return output |
| 21 | |
| 22 | class AptRepoTest(AptTest): |
| 23 | |
| 24 | @classmethod |
| 25 | def setUpClass(cls): |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 26 | service_repo = os.path.join(cls.tc.td['DEPLOY_DIR_DEB'], '') |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 27 | cls.repo_server = HTTPService(service_repo, |
| 28 | '0.0.0.0', port=cls.tc.target.server_port, |
| 29 | logger=cls.tc.logger) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 30 | cls.repo_server.start() |
| 31 | |
| 32 | @classmethod |
| 33 | def tearDownClass(cls): |
| 34 | cls.repo_server.stop() |
| 35 | |
| 36 | def setup_source_config_for_package_install(self): |
| 37 | apt_get_source_server = 'http://%s:%s/' % (self.tc.target.server_ip, self.repo_server.port) |
| 38 | apt_get_sourceslist_dir = '/etc/apt/' |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 39 | self.target.run('cd %s; echo deb [ allow-insecure=yes ] %s/all ./ > sources.list' % (apt_get_sourceslist_dir, apt_get_source_server)) |
| 40 | |
| 41 | def setup_source_config_for_package_install_signed(self): |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 42 | apt_get_source_server = 'http://%s:%s' % (self.tc.target.server_ip, self.repo_server.port) |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 43 | apt_get_sourceslist_dir = '/etc/apt/' |
Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 44 | self.target.run("cd %s; cp sources.list sources.list.bak; sed -i 's|\[trusted=yes\] http://bogus_ip:bogus_port|%s|g' sources.list" % (apt_get_sourceslist_dir, apt_get_source_server)) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 45 | |
| 46 | def cleanup_source_config_for_package_install(self): |
| 47 | apt_get_sourceslist_dir = '/etc/apt/' |
| 48 | self.target.run('cd %s; rm sources.list' % (apt_get_sourceslist_dir)) |
| 49 | |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 50 | def cleanup_source_config_for_package_install_signed(self): |
| 51 | apt_get_sourceslist_dir = '/etc/apt/' |
| 52 | self.target.run('cd %s; mv sources.list.bak sources.list' % (apt_get_sourceslist_dir)) |
| 53 | |
| 54 | def setup_key(self): |
| 55 | # the key is found on the target /etc/pki/packagefeed-gpg/ |
| 56 | # named PACKAGEFEED-GPG-KEY-poky-branch |
| 57 | self.target.run('cd %s; apt-key add P*' % ('/etc/pki/packagefeed-gpg')) |
| 58 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 59 | @skipIfNotFeature('package-management', |
| 60 | 'Test requires package-management to be in IMAGE_FEATURES') |
| 61 | @skipIfNotDataVar('IMAGE_PKGTYPE', 'deb', |
| 62 | 'DEB is not the primary package manager') |
| 63 | @OEHasPackage(['apt']) |
| 64 | def test_apt_install_from_repo(self): |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 65 | if not self.tc.td.get('PACKAGE_FEED_GPG_NAME'): |
| 66 | self.setup_source_config_for_package_install() |
| 67 | self.pkg('update') |
| 68 | self.pkg('remove --yes run-postinsts-dev') |
| 69 | self.pkg('install --yes --allow-unauthenticated run-postinsts-dev') |
| 70 | self.cleanup_source_config_for_package_install() |
| 71 | else: |
| 72 | # when we are here a key has been set to sign the package feed and |
| 73 | # public key and gnupg installed on the image by test_testimage_apt |
| 74 | self.setup_source_config_for_package_install_signed() |
| 75 | self.setup_key() |
| 76 | self.pkg('update') |
| 77 | self.pkg('install --yes run-postinsts-dev') |
| 78 | self.pkg('remove --yes run-postinsts-dev') |
| 79 | self.cleanup_source_config_for_package_install_signed() |