blob: a8e23e596e930cf4465d3b984e24b8d8bbbe53ca [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Brad Bishop6e60e8b2018-02-01 10:27:11 -05007import os
8import re
9import subprocess
10from oeqa.utils.httpserver import HTTPService
11
12from oeqa.runtime.case import OERuntimeTestCase
13from oeqa.core.decorator.depends import OETestDepends
Brad Bishop79641f22019-09-10 07:20:22 -040014from oeqa.core.decorator.data import skipIfNotDataVar, skipIfNotFeature, skipIfInDataVar, skipIfNotInDataVar
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015from oeqa.runtime.decorator.package import OEHasPackage
16
17class 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
26class 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 Bishop6e60e8b2018-02-01 10:27:11 -050034 def test_dnf_help(self):
35 self.dnf('--help')
36
37 @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038 def test_dnf_version(self):
39 self.dnf('--version')
40
41 @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050042 def test_dnf_info(self):
43 self.dnf('info dnf')
44
45 @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046 def test_dnf_search(self):
47 self.dnf('search dnf')
48
49 @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050050 def test_dnf_history(self):
51 self.dnf('history')
52
53class 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 Geissler82c905d2020-04-13 13:39:40 -050058 '0.0.0.0', port=cls.tc.target.server_port,
59 logger=cls.tc.logger)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050060 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 Bishop1a4b7ee2018-12-16 17:11:34 -080071 output = self.dnf(" ".join(cmdlinerepoopts) + " --nogpgcheck " + command)
72 return output
Brad Bishop6e60e8b2018-02-01 10:27:11 -050073
74 @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050075 def test_dnf_makecache(self):
76 self.dnf_with_repo('makecache')
77
78
79# Does not work when repo is specified on the command line
80# @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
81# def test_dnf_repolist(self):
82# self.dnf_with_repo('repolist')
83
84 @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050085 def test_dnf_repoinfo(self):
86 self.dnf_with_repo('repoinfo')
87
88 @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050089 def test_dnf_install(self):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080090 output = self.dnf_with_repo('list run-postinsts-dev')
91 if 'Installed Packages' in output:
92 self.dnf_with_repo('remove -y run-postinsts-dev')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050093 self.dnf_with_repo('install -y run-postinsts-dev')
94
95 @OETestDepends(['dnf.DnfRepoTest.test_dnf_install'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050096 def test_dnf_install_dependency(self):
97 self.dnf_with_repo('remove -y run-postinsts')
98 self.dnf_with_repo('install -y run-postinsts-dev')
99
100 @OETestDepends(['dnf.DnfRepoTest.test_dnf_install_dependency'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500101 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'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500109 def test_dnf_install_from_http(self):
110 output = subprocess.check_output('%s %s -name run-postinsts-dev*' % (bb.utils.which(os.getenv('PATH'), "find"),
111 os.path.join(self.tc.td['WORKDIR'], 'oe-testimage-repo')), shell=True).decode("utf-8")
112 rpm_path = output.split("/")[-2] + "/" + output.split("/")[-1]
113 url = 'http://%s:%s/%s' %(self.target.server_ip, self.repo_server.port, rpm_path)
114 self.dnf_with_repo('remove -y run-postinsts-dev')
115 self.dnf_with_repo('install -y %s' % url)
116
117 @OETestDepends(['dnf.DnfRepoTest.test_dnf_install'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500118 def test_dnf_reinstall(self):
119 self.dnf_with_repo('reinstall -y run-postinsts-dev')
120
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800121 @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
Brad Bishop79641f22019-09-10 07:20:22 -0400122 @skipIfInDataVar('DISTRO_FEATURES', 'usrmerge', 'Test run when not enable usrmerge')
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400123 @OEHasPackage('busybox')
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800124 def test_dnf_installroot(self):
125 rootpath = '/home/root/chroot/test'
126 #Copy necessary files to avoid errors with not yet installed tools on
127 #installroot directory.
128 self.target.run('mkdir -p %s/etc' % rootpath, 1500)
129 self.target.run('mkdir -p %s/bin %s/sbin %s/usr/bin %s/usr/sbin' % (rootpath, rootpath, rootpath, rootpath), 1500)
130 self.target.run('mkdir -p %s/dev' % rootpath, 1500)
131 #Handle different architectures lib dirs
132 self.target.run('mkdir -p %s/lib' % rootpath, 1500)
133 self.target.run('mkdir -p %s/libx32' % rootpath, 1500)
134 self.target.run('mkdir -p %s/lib64' % rootpath, 1500)
135 self.target.run('cp /lib/libtinfo.so.5 %s/lib' % rootpath, 1500)
136 self.target.run('cp /libx32/libtinfo.so.5 %s/libx32' % rootpath, 1500)
137 self.target.run('cp /lib64/libtinfo.so.5 %s/lib64' % rootpath, 1500)
138 self.target.run('cp -r /etc/rpm %s/etc' % rootpath, 1500)
139 self.target.run('cp -r /etc/dnf %s/etc' % rootpath, 1500)
140 self.target.run('cp /bin/sh %s/bin' % rootpath, 1500)
141 self.target.run('mount -o bind /dev %s/dev/' % rootpath, 1500)
142 self.dnf_with_repo('install --installroot=%s -v -y --rpmverbosity=debug busybox run-postinsts' % rootpath)
143 status, output = self.target.run('test -e %s/var/cache/dnf' % rootpath, 1500)
144 self.assertEqual(0, status, output)
145 status, output = self.target.run('test -e %s/bin/busybox' % rootpath, 1500)
146 self.assertEqual(0, status, output)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500147
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800148 @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
Brad Bishop79641f22019-09-10 07:20:22 -0400149 @skipIfNotInDataVar('DISTRO_FEATURES', 'usrmerge', 'Test run when enable usrmege')
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400150 @OEHasPackage('busybox')
Brad Bishop79641f22019-09-10 07:20:22 -0400151 def test_dnf_installroot_usrmerge(self):
152 rootpath = '/home/root/chroot/test'
153 #Copy necessary files to avoid errors with not yet installed tools on
154 #installroot directory.
155 self.target.run('mkdir -p %s/etc' % rootpath, 1500)
156 self.target.run('mkdir -p %s/usr/bin %s/usr/sbin' % (rootpath, rootpath), 1500)
157 self.target.run('ln -sf -r %s/usr/bin %s/bin' % (rootpath, rootpath), 1500)
158 self.target.run('ln -sf -r %s/usr/sbin %s/sbin' % (rootpath, rootpath), 1500)
159 self.target.run('mkdir -p %s/dev' % rootpath, 1500)
160 #Handle different architectures lib dirs
161 self.target.run('mkdir -p %s/usr/lib' % rootpath, 1500)
162 self.target.run('mkdir -p %s/usr/libx32' % rootpath, 1500)
163 self.target.run('mkdir -p %s/usr/lib64' % rootpath, 1500)
164 self.target.run('cp /lib/libtinfo.so.5 %s/usr/lib' % rootpath, 1500)
165 self.target.run('cp /libx32/libtinfo.so.5 %s/usr/libx32' % rootpath, 1500)
166 self.target.run('cp /lib64/libtinfo.so.5 %s/usr/lib64' % rootpath, 1500)
167 self.target.run('ln -sf -r %s/lib %s/usr/lib' % (rootpath,rootpath), 1500)
168 self.target.run('ln -sf -r %s/libx32 %s/usr/libx32' % (rootpath,rootpath), 1500)
169 self.target.run('ln -sf -r %s/lib64 %s/usr/lib64' % (rootpath,rootpath), 1500)
170 self.target.run('cp -r /etc/rpm %s/etc' % rootpath, 1500)
171 self.target.run('cp -r /etc/dnf %s/etc' % rootpath, 1500)
172 self.target.run('cp /bin/sh %s/bin' % rootpath, 1500)
173 self.target.run('mount -o bind /dev %s/dev/' % rootpath, 1500)
174 self.dnf_with_repo('install --installroot=%s -v -y --rpmverbosity=debug busybox run-postinsts' % rootpath)
175 status, output = self.target.run('test -e %s/var/cache/dnf' % rootpath, 1500)
176 self.assertEqual(0, status, output)
177 status, output = self.target.run('test -e %s/bin/busybox' % rootpath, 1500)
178 self.assertEqual(0, status, output)
179
180 @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800181 def test_dnf_exclude(self):
182 excludepkg = 'curl-dev'
183 self.dnf_with_repo('install -y curl*')
184 self.dnf('list %s' % excludepkg, 0)
185 #Avoid remove dependencies to skip some errors on different archs and images
186 self.dnf_with_repo('remove --setopt=clean_requirements_on_remove=0 -y curl*')
187 #check curl-dev is not installed adter removing all curl occurrences
188 status, output = self.target.run('dnf list --installed | grep %s'% excludepkg, 1500)
189 self.assertEqual(1, status, "%s was not removed, is listed as installed"%excludepkg)
190 self.dnf_with_repo('install -y --exclude=%s --exclude=curl-staticdev curl*' % excludepkg)
191 #check curl-dev is not installed after being excluded
192 status, output = self.target.run('dnf list --installed | grep %s'% excludepkg , 1500)
193 self.assertEqual(1, status, "%s was not excluded, is listed as installed"%excludepkg)