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') |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 25 | cls.repo_server = HTTPService(service_repo, cls.tc.target.server_ip, logger=cls.tc.logger) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 26 | cls.repo_server.start() |
| 27 | |
| 28 | @classmethod |
| 29 | def tearDownClass(cls): |
| 30 | cls.repo_server.stop() |
| 31 | |
| 32 | def setup_source_config_for_package_install(self): |
| 33 | apt_get_source_server = 'http://%s:%s/' % (self.tc.target.server_ip, self.repo_server.port) |
| 34 | apt_get_sourceslist_dir = '/etc/apt/' |
| 35 | self.target.run('cd %s; echo deb %s ./ > sources.list' % (apt_get_sourceslist_dir, apt_get_source_server)) |
| 36 | |
| 37 | def cleanup_source_config_for_package_install(self): |
| 38 | apt_get_sourceslist_dir = '/etc/apt/' |
| 39 | self.target.run('cd %s; rm sources.list' % (apt_get_sourceslist_dir)) |
| 40 | |
| 41 | @skipIfNotFeature('package-management', |
| 42 | 'Test requires package-management to be in IMAGE_FEATURES') |
| 43 | @skipIfNotDataVar('IMAGE_PKGTYPE', 'deb', |
| 44 | 'DEB is not the primary package manager') |
| 45 | @OEHasPackage(['apt']) |
| 46 | def test_apt_install_from_repo(self): |
| 47 | self.setup_source_config_for_package_install() |
| 48 | self.pkg('update') |
| 49 | self.pkg('remove --yes run-postinsts-dev') |
| 50 | self.pkg('install --yes --allow-unauthenticated run-postinsts-dev') |
| 51 | self.cleanup_source_config_for_package_install() |