Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | import os |
| 2 | import re |
| 3 | import subprocess |
| 4 | from oeqa.utils.httpserver import HTTPService |
| 5 | |
| 6 | from oeqa.runtime.case import OERuntimeTestCase |
| 7 | from oeqa.core.decorator.depends import OETestDepends |
| 8 | from oeqa.core.decorator.oeid import OETestID |
| 9 | from oeqa.core.decorator.data import skipIfNotDataVar, skipIfNotFeature |
| 10 | from oeqa.runtime.decorator.package import OEHasPackage |
| 11 | |
| 12 | class DnfTest(OERuntimeTestCase): |
| 13 | |
| 14 | def dnf(self, command, expected = 0): |
| 15 | command = 'dnf %s' % command |
| 16 | status, output = self.target.run(command, 1500) |
| 17 | message = os.linesep.join([command, output]) |
| 18 | self.assertEqual(status, expected, message) |
| 19 | return output |
| 20 | |
| 21 | class DnfBasicTest(DnfTest): |
| 22 | |
| 23 | @skipIfNotFeature('package-management', |
| 24 | 'Test requires package-management to be in IMAGE_FEATURES') |
| 25 | @skipIfNotDataVar('IMAGE_PKGTYPE', 'rpm', |
| 26 | 'RPM is not the primary package manager') |
| 27 | @OEHasPackage(['dnf']) |
| 28 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
| 29 | @OETestID(1735) |
| 30 | def test_dnf_help(self): |
| 31 | self.dnf('--help') |
| 32 | |
| 33 | @OETestDepends(['dnf.DnfBasicTest.test_dnf_help']) |
| 34 | @OETestID(1739) |
| 35 | def test_dnf_version(self): |
| 36 | self.dnf('--version') |
| 37 | |
| 38 | @OETestDepends(['dnf.DnfBasicTest.test_dnf_help']) |
| 39 | @OETestID(1737) |
| 40 | def test_dnf_info(self): |
| 41 | self.dnf('info dnf') |
| 42 | |
| 43 | @OETestDepends(['dnf.DnfBasicTest.test_dnf_help']) |
| 44 | @OETestID(1738) |
| 45 | def test_dnf_search(self): |
| 46 | self.dnf('search dnf') |
| 47 | |
| 48 | @OETestDepends(['dnf.DnfBasicTest.test_dnf_help']) |
| 49 | @OETestID(1736) |
| 50 | def test_dnf_history(self): |
| 51 | self.dnf('history') |
| 52 | |
| 53 | class DnfRepoTest(DnfTest): |
| 54 | |
| 55 | @classmethod |
| 56 | def setUpClass(cls): |
| 57 | cls.repo_server = HTTPService(os.path.join(cls.tc.td['WORKDIR'], 'oe-testimage-repo'), |
| 58 | cls.tc.target.server_ip) |
| 59 | cls.repo_server.start() |
| 60 | |
| 61 | @classmethod |
| 62 | def tearDownClass(cls): |
| 63 | cls.repo_server.stop() |
| 64 | |
| 65 | def dnf_with_repo(self, command): |
| 66 | pkgarchs = os.listdir(os.path.join(self.tc.td['WORKDIR'], 'oe-testimage-repo')) |
| 67 | deploy_url = 'http://%s:%s/' %(self.target.server_ip, self.repo_server.port) |
| 68 | cmdlinerepoopts = ["--repofrompath=oe-testimage-repo-%s,%s%s" %(arch, deploy_url, arch) for arch in pkgarchs] |
| 69 | |
| 70 | self.dnf(" ".join(cmdlinerepoopts) + " --nogpgcheck " + command) |
| 71 | |
| 72 | @OETestDepends(['dnf.DnfBasicTest.test_dnf_help']) |
| 73 | @OETestID(1744) |
| 74 | def test_dnf_makecache(self): |
| 75 | self.dnf_with_repo('makecache') |
| 76 | |
| 77 | |
| 78 | # Does not work when repo is specified on the command line |
| 79 | # @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache']) |
| 80 | # def test_dnf_repolist(self): |
| 81 | # self.dnf_with_repo('repolist') |
| 82 | |
| 83 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache']) |
| 84 | @OETestID(1746) |
| 85 | def test_dnf_repoinfo(self): |
| 86 | self.dnf_with_repo('repoinfo') |
| 87 | |
| 88 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache']) |
| 89 | @OETestID(1740) |
| 90 | def test_dnf_install(self): |
| 91 | self.dnf_with_repo('install -y run-postinsts-dev') |
| 92 | |
| 93 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_install']) |
| 94 | @OETestID(1741) |
| 95 | def test_dnf_install_dependency(self): |
| 96 | self.dnf_with_repo('remove -y run-postinsts') |
| 97 | self.dnf_with_repo('install -y run-postinsts-dev') |
| 98 | |
| 99 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_install_dependency']) |
| 100 | @OETestID(1742) |
| 101 | def test_dnf_install_from_disk(self): |
| 102 | self.dnf_with_repo('remove -y run-postinsts-dev') |
| 103 | self.dnf_with_repo('install -y --downloadonly run-postinsts-dev') |
| 104 | status, output = self.target.run('find /var/cache/dnf -name run-postinsts-dev*rpm', 1500) |
| 105 | self.assertEqual(status, 0, output) |
| 106 | self.dnf_with_repo('install -y %s' % output) |
| 107 | |
| 108 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_install_from_disk']) |
| 109 | @OETestID(1743) |
| 110 | def test_dnf_install_from_http(self): |
| 111 | output = subprocess.check_output('%s %s -name run-postinsts-dev*' % (bb.utils.which(os.getenv('PATH'), "find"), |
| 112 | os.path.join(self.tc.td['WORKDIR'], 'oe-testimage-repo')), shell=True).decode("utf-8") |
| 113 | rpm_path = output.split("/")[-2] + "/" + output.split("/")[-1] |
| 114 | url = 'http://%s:%s/%s' %(self.target.server_ip, self.repo_server.port, rpm_path) |
| 115 | self.dnf_with_repo('remove -y run-postinsts-dev') |
| 116 | self.dnf_with_repo('install -y %s' % url) |
| 117 | |
| 118 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_install']) |
| 119 | @OETestID(1745) |
| 120 | def test_dnf_reinstall(self): |
| 121 | self.dnf_with_repo('reinstall -y run-postinsts-dev') |
| 122 | |
| 123 | |