blob: 629b9af3ed152b2f720fb43502f0914a0902035d [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishop6e60e8b2018-02-01 10:27:11 -05005import os
6import re
7import subprocess
8from oeqa.utils.httpserver import HTTPService
9
10from oeqa.runtime.case import OERuntimeTestCase
11from oeqa.core.decorator.depends import OETestDepends
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012from oeqa.core.decorator.data import skipIfNotDataVar, skipIfNotFeature
13from oeqa.runtime.decorator.package import OEHasPackage
14
15class DnfTest(OERuntimeTestCase):
16
17 def dnf(self, command, expected = 0):
18 command = 'dnf %s' % command
19 status, output = self.target.run(command, 1500)
20 message = os.linesep.join([command, output])
21 self.assertEqual(status, expected, message)
22 return output
23
24class DnfBasicTest(DnfTest):
25
26 @skipIfNotFeature('package-management',
27 'Test requires package-management to be in IMAGE_FEATURES')
28 @skipIfNotDataVar('IMAGE_PKGTYPE', 'rpm',
29 'RPM is not the primary package manager')
30 @OEHasPackage(['dnf'])
31 @OETestDepends(['ssh.SSHTest.test_ssh'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032 def test_dnf_help(self):
33 self.dnf('--help')
34
35 @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036 def test_dnf_version(self):
37 self.dnf('--version')
38
39 @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040 def test_dnf_info(self):
41 self.dnf('info dnf')
42
43 @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050044 def test_dnf_search(self):
45 self.dnf('search dnf')
46
47 @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050048 def test_dnf_history(self):
49 self.dnf('history')
50
51class DnfRepoTest(DnfTest):
52
53 @classmethod
54 def setUpClass(cls):
55 cls.repo_server = HTTPService(os.path.join(cls.tc.td['WORKDIR'], 'oe-testimage-repo'),
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080056 cls.tc.target.server_ip, logger=cls.tc.logger)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050057 cls.repo_server.start()
58
59 @classmethod
60 def tearDownClass(cls):
61 cls.repo_server.stop()
62
63 def dnf_with_repo(self, command):
64 pkgarchs = os.listdir(os.path.join(self.tc.td['WORKDIR'], 'oe-testimage-repo'))
65 deploy_url = 'http://%s:%s/' %(self.target.server_ip, self.repo_server.port)
66 cmdlinerepoopts = ["--repofrompath=oe-testimage-repo-%s,%s%s" %(arch, deploy_url, arch) for arch in pkgarchs]
67
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080068 output = self.dnf(" ".join(cmdlinerepoopts) + " --nogpgcheck " + command)
69 return output
Brad Bishop6e60e8b2018-02-01 10:27:11 -050070
71 @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050072 def test_dnf_makecache(self):
73 self.dnf_with_repo('makecache')
74
75
76# Does not work when repo is specified on the command line
77# @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
78# def test_dnf_repolist(self):
79# self.dnf_with_repo('repolist')
80
81 @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050082 def test_dnf_repoinfo(self):
83 self.dnf_with_repo('repoinfo')
84
85 @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050086 def test_dnf_install(self):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080087 output = self.dnf_with_repo('list run-postinsts-dev')
88 if 'Installed Packages' in output:
89 self.dnf_with_repo('remove -y run-postinsts-dev')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050090 self.dnf_with_repo('install -y run-postinsts-dev')
91
92 @OETestDepends(['dnf.DnfRepoTest.test_dnf_install'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050093 def test_dnf_install_dependency(self):
94 self.dnf_with_repo('remove -y run-postinsts')
95 self.dnf_with_repo('install -y run-postinsts-dev')
96
97 @OETestDepends(['dnf.DnfRepoTest.test_dnf_install_dependency'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050098 def test_dnf_install_from_disk(self):
99 self.dnf_with_repo('remove -y run-postinsts-dev')
100 self.dnf_with_repo('install -y --downloadonly run-postinsts-dev')
101 status, output = self.target.run('find /var/cache/dnf -name run-postinsts-dev*rpm', 1500)
102 self.assertEqual(status, 0, output)
103 self.dnf_with_repo('install -y %s' % output)
104
105 @OETestDepends(['dnf.DnfRepoTest.test_dnf_install_from_disk'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500106 def test_dnf_install_from_http(self):
107 output = subprocess.check_output('%s %s -name run-postinsts-dev*' % (bb.utils.which(os.getenv('PATH'), "find"),
108 os.path.join(self.tc.td['WORKDIR'], 'oe-testimage-repo')), shell=True).decode("utf-8")
109 rpm_path = output.split("/")[-2] + "/" + output.split("/")[-1]
110 url = 'http://%s:%s/%s' %(self.target.server_ip, self.repo_server.port, rpm_path)
111 self.dnf_with_repo('remove -y run-postinsts-dev')
112 self.dnf_with_repo('install -y %s' % url)
113
114 @OETestDepends(['dnf.DnfRepoTest.test_dnf_install'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500115 def test_dnf_reinstall(self):
116 self.dnf_with_repo('reinstall -y run-postinsts-dev')
117
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800118 @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800119 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)
137 self.dnf_with_repo('install --installroot=%s -v -y --rpmverbosity=debug busybox run-postinsts' % rootpath)
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 Bishop6e60e8b2018-02-01 10:27:11 -0500142
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800143 @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800144 def test_dnf_exclude(self):
145 excludepkg = 'curl-dev'
146 self.dnf_with_repo('install -y curl*')
147 self.dnf('list %s' % excludepkg, 0)
148 #Avoid remove dependencies to skip some errors on different archs and images
149 self.dnf_with_repo('remove --setopt=clean_requirements_on_remove=0 -y curl*')
150 #check curl-dev is not installed adter removing all curl occurrences
151 status, output = self.target.run('dnf list --installed | grep %s'% excludepkg, 1500)
152 self.assertEqual(1, status, "%s was not removed, is listed as installed"%excludepkg)
153 self.dnf_with_repo('install -y --exclude=%s --exclude=curl-staticdev curl*' % excludepkg)
154 #check curl-dev is not installed after being excluded
155 status, output = self.target.run('dnf list --installed | grep %s'% excludepkg , 1500)
156 self.assertEqual(1, status, "%s was not excluded, is listed as installed"%excludepkg)