Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 5 | import os |
| 6 | from oeqa.utils.httpserver import HTTPService |
| 7 | from oeqa.runtime.case import OERuntimeTestCase |
| 8 | from oeqa.core.decorator.data import skipIfNotDataVar, skipIfNotFeature |
| 9 | from oeqa.runtime.decorator.package import OEHasPackage |
| 10 | |
| 11 | class AptTest(OERuntimeTestCase): |
| 12 | |
| 13 | def pkg(self, command, expected = 0): |
| 14 | command = 'apt-get %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 | |
| 20 | class AptRepoTest(AptTest): |
| 21 | |
| 22 | @classmethod |
| 23 | def setUpClass(cls): |
| 24 | service_repo = os.path.join(cls.tc.td['DEPLOY_DIR_DEB'], 'all') |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 25 | cls.repo_server = HTTPService(service_repo, |
| 26 | '0.0.0.0', port=cls.tc.target.server_port, |
| 27 | logger=cls.tc.logger) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 28 | cls.repo_server.start() |
| 29 | |
| 30 | @classmethod |
| 31 | def tearDownClass(cls): |
| 32 | cls.repo_server.stop() |
| 33 | |
| 34 | def setup_source_config_for_package_install(self): |
| 35 | apt_get_source_server = 'http://%s:%s/' % (self.tc.target.server_ip, self.repo_server.port) |
| 36 | apt_get_sourceslist_dir = '/etc/apt/' |
Andrew Geissler | 4ed12e1 | 2020-06-05 18:00:41 -0500 | [diff] [blame] | 37 | self.target.run('cd %s; echo deb [ allow-insecure=yes ] %s ./ > sources.list' % (apt_get_sourceslist_dir, apt_get_source_server)) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 38 | |
| 39 | def cleanup_source_config_for_package_install(self): |
| 40 | apt_get_sourceslist_dir = '/etc/apt/' |
| 41 | self.target.run('cd %s; rm sources.list' % (apt_get_sourceslist_dir)) |
| 42 | |
| 43 | @skipIfNotFeature('package-management', |
| 44 | 'Test requires package-management to be in IMAGE_FEATURES') |
| 45 | @skipIfNotDataVar('IMAGE_PKGTYPE', 'deb', |
| 46 | 'DEB is not the primary package manager') |
| 47 | @OEHasPackage(['apt']) |
| 48 | def test_apt_install_from_repo(self): |
| 49 | self.setup_source_config_for_package_install() |
| 50 | self.pkg('update') |
| 51 | self.pkg('remove --yes run-postinsts-dev') |
| 52 | self.pkg('install --yes --allow-unauthenticated run-postinsts-dev') |
| 53 | self.cleanup_source_config_for_package_install() |