blob: c1ed39d7765fbacc034e6d7ba54e84b3ed54c538 [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001import os
2import re
3import subprocess
4from oeqa.utils.httpserver import HTTPService
5
6from oeqa.runtime.case import OERuntimeTestCase
7from oeqa.core.decorator.depends import OETestDepends
8from oeqa.core.decorator.oeid import OETestID
9from oeqa.core.decorator.data import skipIfNotDataVar, skipIfNotFeature
10from oeqa.runtime.decorator.package import OEHasPackage
11
12class 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
21class 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
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'),
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080058 cls.tc.target.server_ip, logger=cls.tc.logger)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050059 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
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080070 output = self.dnf(" ".join(cmdlinerepoopts) + " --nogpgcheck " + command)
71 return output
Brad Bishop6e60e8b2018-02-01 10:27:11 -050072
73 @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
74 @OETestID(1744)
75 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'])
85 @OETestID(1746)
86 def test_dnf_repoinfo(self):
87 self.dnf_with_repo('repoinfo')
88
89 @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
90 @OETestID(1740)
91 def test_dnf_install(self):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080092 output = self.dnf_with_repo('list run-postinsts-dev')
93 if 'Installed Packages' in output:
94 self.dnf_with_repo('remove -y run-postinsts-dev')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050095 self.dnf_with_repo('install -y run-postinsts-dev')
96
97 @OETestDepends(['dnf.DnfRepoTest.test_dnf_install'])
98 @OETestID(1741)
99 def test_dnf_install_dependency(self):
100 self.dnf_with_repo('remove -y run-postinsts')
101 self.dnf_with_repo('install -y run-postinsts-dev')
102
103 @OETestDepends(['dnf.DnfRepoTest.test_dnf_install_dependency'])
104 @OETestID(1742)
105 def test_dnf_install_from_disk(self):
106 self.dnf_with_repo('remove -y run-postinsts-dev')
107 self.dnf_with_repo('install -y --downloadonly run-postinsts-dev')
108 status, output = self.target.run('find /var/cache/dnf -name run-postinsts-dev*rpm', 1500)
109 self.assertEqual(status, 0, output)
110 self.dnf_with_repo('install -y %s' % output)
111
112 @OETestDepends(['dnf.DnfRepoTest.test_dnf_install_from_disk'])
113 @OETestID(1743)
114 def test_dnf_install_from_http(self):
115 output = subprocess.check_output('%s %s -name run-postinsts-dev*' % (bb.utils.which(os.getenv('PATH'), "find"),
116 os.path.join(self.tc.td['WORKDIR'], 'oe-testimage-repo')), shell=True).decode("utf-8")
117 rpm_path = output.split("/")[-2] + "/" + output.split("/")[-1]
118 url = 'http://%s:%s/%s' %(self.target.server_ip, self.repo_server.port, rpm_path)
119 self.dnf_with_repo('remove -y run-postinsts-dev')
120 self.dnf_with_repo('install -y %s' % url)
121
122 @OETestDepends(['dnf.DnfRepoTest.test_dnf_install'])
123 @OETestID(1745)
124 def test_dnf_reinstall(self):
125 self.dnf_with_repo('reinstall -y run-postinsts-dev')
126
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800127 @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
128 @OETestID(1771)
129 def test_dnf_installroot(self):
130 rootpath = '/home/root/chroot/test'
131 #Copy necessary files to avoid errors with not yet installed tools on
132 #installroot directory.
133 self.target.run('mkdir -p %s/etc' % rootpath, 1500)
134 self.target.run('mkdir -p %s/bin %s/sbin %s/usr/bin %s/usr/sbin' % (rootpath, rootpath, rootpath, rootpath), 1500)
135 self.target.run('mkdir -p %s/dev' % rootpath, 1500)
136 #Handle different architectures lib dirs
137 self.target.run('mkdir -p %s/lib' % rootpath, 1500)
138 self.target.run('mkdir -p %s/libx32' % rootpath, 1500)
139 self.target.run('mkdir -p %s/lib64' % rootpath, 1500)
140 self.target.run('cp /lib/libtinfo.so.5 %s/lib' % rootpath, 1500)
141 self.target.run('cp /libx32/libtinfo.so.5 %s/libx32' % rootpath, 1500)
142 self.target.run('cp /lib64/libtinfo.so.5 %s/lib64' % rootpath, 1500)
143 self.target.run('cp -r /etc/rpm %s/etc' % rootpath, 1500)
144 self.target.run('cp -r /etc/dnf %s/etc' % rootpath, 1500)
145 self.target.run('cp /bin/sh %s/bin' % rootpath, 1500)
146 self.target.run('mount -o bind /dev %s/dev/' % rootpath, 1500)
147 self.dnf_with_repo('install --installroot=%s -v -y --rpmverbosity=debug busybox run-postinsts' % rootpath)
148 status, output = self.target.run('test -e %s/var/cache/dnf' % rootpath, 1500)
149 self.assertEqual(0, status, output)
150 status, output = self.target.run('test -e %s/bin/busybox' % rootpath, 1500)
151 self.assertEqual(0, status, output)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500152
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800153 @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
154 @OETestID(1772)
155 def test_dnf_exclude(self):
156 excludepkg = 'curl-dev'
157 self.dnf_with_repo('install -y curl*')
158 self.dnf('list %s' % excludepkg, 0)
159 #Avoid remove dependencies to skip some errors on different archs and images
160 self.dnf_with_repo('remove --setopt=clean_requirements_on_remove=0 -y curl*')
161 #check curl-dev is not installed adter removing all curl occurrences
162 status, output = self.target.run('dnf list --installed | grep %s'% excludepkg, 1500)
163 self.assertEqual(1, status, "%s was not removed, is listed as installed"%excludepkg)
164 self.dnf_with_repo('install -y --exclude=%s --exclude=curl-staticdev curl*' % excludepkg)
165 #check curl-dev is not installed after being excluded
166 status, output = self.target.run('dnf list --installed | grep %s'% excludepkg , 1500)
167 self.assertEqual(1, status, "%s was not excluded, is listed as installed"%excludepkg)