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 | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7 | import os |
| 8 | import re |
| 9 | import subprocess |
| 10 | from oeqa.utils.httpserver import HTTPService |
| 11 | |
| 12 | from oeqa.runtime.case import OERuntimeTestCase |
| 13 | from oeqa.core.decorator.depends import OETestDepends |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 14 | from oeqa.core.decorator.data import skipIfNotDataVar, skipIfNotFeature, skipIfInDataVar, skipIfNotInDataVar |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 15 | from oeqa.runtime.decorator.package import OEHasPackage |
| 16 | |
| 17 | class DnfTest(OERuntimeTestCase): |
| 18 | |
| 19 | def dnf(self, command, expected = 0): |
| 20 | command = 'dnf %s' % command |
| 21 | status, output = self.target.run(command, 1500) |
| 22 | message = os.linesep.join([command, output]) |
| 23 | self.assertEqual(status, expected, message) |
| 24 | return output |
| 25 | |
| 26 | class DnfBasicTest(DnfTest): |
| 27 | |
| 28 | @skipIfNotFeature('package-management', |
| 29 | 'Test requires package-management to be in IMAGE_FEATURES') |
| 30 | @skipIfNotDataVar('IMAGE_PKGTYPE', 'rpm', |
| 31 | 'RPM is not the primary package manager') |
| 32 | @OEHasPackage(['dnf']) |
| 33 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 34 | def test_dnf_help(self): |
| 35 | self.dnf('--help') |
| 36 | |
| 37 | @OETestDepends(['dnf.DnfBasicTest.test_dnf_help']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 38 | def test_dnf_version(self): |
| 39 | self.dnf('--version') |
| 40 | |
| 41 | @OETestDepends(['dnf.DnfBasicTest.test_dnf_help']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 42 | def test_dnf_info(self): |
| 43 | self.dnf('info dnf') |
| 44 | |
| 45 | @OETestDepends(['dnf.DnfBasicTest.test_dnf_help']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 46 | def test_dnf_search(self): |
| 47 | self.dnf('search dnf') |
| 48 | |
| 49 | @OETestDepends(['dnf.DnfBasicTest.test_dnf_help']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 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'), |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 58 | '0.0.0.0', port=cls.tc.target.server_port, |
| 59 | logger=cls.tc.logger) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 60 | cls.repo_server.start() |
| 61 | |
| 62 | @classmethod |
| 63 | def tearDownClass(cls): |
| 64 | cls.repo_server.stop() |
| 65 | |
| 66 | def dnf_with_repo(self, command): |
| 67 | pkgarchs = os.listdir(os.path.join(self.tc.td['WORKDIR'], 'oe-testimage-repo')) |
| 68 | deploy_url = 'http://%s:%s/' %(self.target.server_ip, self.repo_server.port) |
| 69 | cmdlinerepoopts = ["--repofrompath=oe-testimage-repo-%s,%s%s" %(arch, deploy_url, arch) for arch in pkgarchs] |
| 70 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 71 | output = self.dnf(" ".join(cmdlinerepoopts) + " --nogpgcheck " + command) |
| 72 | return output |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 73 | |
| 74 | @OETestDepends(['dnf.DnfBasicTest.test_dnf_help']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 75 | def test_dnf_makecache(self): |
| 76 | self.dnf_with_repo('makecache') |
| 77 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 78 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 79 | def test_dnf_repoinfo(self): |
| 80 | self.dnf_with_repo('repoinfo') |
| 81 | |
| 82 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 83 | def test_dnf_install(self): |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 84 | self.dnf_with_repo('remove -y dnf-test-*') |
| 85 | self.dnf_with_repo('install -y dnf-test-dep') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 86 | |
| 87 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_install']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 88 | def test_dnf_install_dependency(self): |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 89 | self.dnf_with_repo('remove -y dnf-test-*') |
| 90 | self.dnf_with_repo('install -y dnf-test-main') |
| 91 | output = self.dnf('list --installed dnf-test-*') |
| 92 | self.assertIn("dnf-test-main.", output) |
| 93 | self.assertIn("dnf-test-dep.", output) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 94 | |
| 95 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_install_dependency']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 96 | def test_dnf_install_from_disk(self): |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 97 | self.dnf_with_repo('remove -y dnf-test-dep') |
| 98 | self.dnf_with_repo('install -y --downloadonly dnf-test-dep') |
| 99 | status, output = self.target.run('find /var/cache/dnf -name dnf-test-dep*rpm') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 100 | self.assertEqual(status, 0, output) |
| 101 | self.dnf_with_repo('install -y %s' % output) |
| 102 | |
| 103 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_install_from_disk']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 104 | def test_dnf_install_from_http(self): |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 105 | output = subprocess.check_output('%s %s -name dnf-test-dep*' % (bb.utils.which(os.getenv('PATH'), "find"), |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 106 | os.path.join(self.tc.td['WORKDIR'], 'oe-testimage-repo')), shell=True).decode("utf-8") |
| 107 | rpm_path = output.split("/")[-2] + "/" + output.split("/")[-1] |
| 108 | url = 'http://%s:%s/%s' %(self.target.server_ip, self.repo_server.port, rpm_path) |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 109 | self.dnf_with_repo('remove -y dnf-test-dep') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 110 | self.dnf_with_repo('install -y %s' % url) |
| 111 | |
| 112 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_install']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 113 | def test_dnf_reinstall(self): |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 114 | self.dnf_with_repo('reinstall -y dnf-test-main') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 115 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 116 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache']) |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 117 | @skipIfInDataVar('DISTRO_FEATURES', 'usrmerge', 'Test run when not enable usrmerge') |
Brad Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 118 | @OEHasPackage('busybox') |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 119 | def test_dnf_installroot(self): |
| 120 | rootpath = '/home/root/chroot/test' |
| 121 | #Copy necessary files to avoid errors with not yet installed tools on |
| 122 | #installroot directory. |
| 123 | self.target.run('mkdir -p %s/etc' % rootpath, 1500) |
| 124 | self.target.run('mkdir -p %s/bin %s/sbin %s/usr/bin %s/usr/sbin' % (rootpath, rootpath, rootpath, rootpath), 1500) |
| 125 | self.target.run('mkdir -p %s/dev' % rootpath, 1500) |
| 126 | #Handle different architectures lib dirs |
| 127 | self.target.run('mkdir -p %s/lib' % rootpath, 1500) |
| 128 | self.target.run('mkdir -p %s/libx32' % rootpath, 1500) |
| 129 | self.target.run('mkdir -p %s/lib64' % rootpath, 1500) |
| 130 | self.target.run('cp /lib/libtinfo.so.5 %s/lib' % rootpath, 1500) |
| 131 | self.target.run('cp /libx32/libtinfo.so.5 %s/libx32' % rootpath, 1500) |
| 132 | self.target.run('cp /lib64/libtinfo.so.5 %s/lib64' % rootpath, 1500) |
| 133 | self.target.run('cp -r /etc/rpm %s/etc' % rootpath, 1500) |
| 134 | self.target.run('cp -r /etc/dnf %s/etc' % rootpath, 1500) |
| 135 | self.target.run('cp /bin/sh %s/bin' % rootpath, 1500) |
| 136 | self.target.run('mount -o bind /dev %s/dev/' % rootpath, 1500) |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 137 | self.dnf_with_repo('install --installroot=%s -v -y --rpmverbosity=debug busybox' % rootpath) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 138 | status, output = self.target.run('test -e %s/var/cache/dnf' % rootpath, 1500) |
| 139 | self.assertEqual(0, status, output) |
| 140 | status, output = self.target.run('test -e %s/bin/busybox' % rootpath, 1500) |
| 141 | self.assertEqual(0, status, output) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 142 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 143 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache']) |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 144 | @skipIfNotInDataVar('DISTRO_FEATURES', 'usrmerge', 'Test run when enable usrmerge') |
Brad Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 145 | @OEHasPackage('busybox') |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 146 | def test_dnf_installroot_usrmerge(self): |
| 147 | rootpath = '/home/root/chroot/test' |
| 148 | #Copy necessary files to avoid errors with not yet installed tools on |
| 149 | #installroot directory. |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 150 | self.target.run('mkdir -p %s/etc' % rootpath) |
| 151 | self.target.run('mkdir -p %s/usr/bin %s/usr/sbin' % (rootpath, rootpath)) |
| 152 | self.target.run('ln -sf usr/bin %s/bin' % (rootpath)) |
| 153 | self.target.run('ln -sf usr/sbin %s/sbin' % (rootpath)) |
| 154 | self.target.run('mkdir -p %s/dev' % rootpath) |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 155 | #Handle different architectures lib dirs |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 156 | self.target.run("for l in /lib*; do mkdir -p %s/usr/$l; ln -s usr/$l %s/$l; done" % (rootpath, rootpath)) |
| 157 | self.target.run('cp -r /etc/rpm %s/etc' % rootpath) |
| 158 | self.target.run('cp -r /etc/dnf %s/etc' % rootpath) |
| 159 | self.target.run('cp /bin/busybox %s/bin/sh' % rootpath) |
| 160 | self.target.run('mount -o bind /dev %s/dev/' % rootpath) |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 161 | self.dnf_with_repo('install --installroot=%s -v -y --rpmverbosity=debug busybox' % rootpath) |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 162 | status, output = self.target.run('test -e %s/var/cache/dnf' % rootpath) |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 163 | self.assertEqual(0, status, output) |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 164 | status, output = self.target.run('test -e %s/bin/busybox' % rootpath) |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 165 | self.assertEqual(0, status, output) |
| 166 | |
| 167 | @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache']) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 168 | def test_dnf_exclude(self): |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 169 | self.dnf_with_repo('remove -y dnf-test-*') |
| 170 | self.dnf_with_repo('install -y --exclude=dnf-test-dep dnf-test-*') |
| 171 | output = self.dnf('list --installed dnf-test-*') |
| 172 | self.assertIn("dnf-test-main.", output) |
| 173 | self.assertNotIn("dnf-test-dev.", output) |