dnf.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #
  2. # SPDX-License-Identifier: MIT
  3. #
  4. import os
  5. import re
  6. import subprocess
  7. from oeqa.utils.httpserver import HTTPService
  8. from oeqa.runtime.case import OERuntimeTestCase
  9. from oeqa.core.decorator.depends import OETestDepends
  10. from oeqa.core.decorator.data import skipIfNotDataVar, skipIfNotFeature
  11. from oeqa.runtime.decorator.package import OEHasPackage
  12. class DnfTest(OERuntimeTestCase):
  13. def dnf(self, command, expected = 0):
  14. command = 'dnf %s' % command
  15. status, output = self.target.run(command, 1500)
  16. message = os.linesep.join([command, output])
  17. self.assertEqual(status, expected, message)
  18. return output
  19. class DnfBasicTest(DnfTest):
  20. @skipIfNotFeature('package-management',
  21. 'Test requires package-management to be in IMAGE_FEATURES')
  22. @skipIfNotDataVar('IMAGE_PKGTYPE', 'rpm',
  23. 'RPM is not the primary package manager')
  24. @OEHasPackage(['dnf'])
  25. @OETestDepends(['ssh.SSHTest.test_ssh'])
  26. def test_dnf_help(self):
  27. self.dnf('--help')
  28. @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
  29. def test_dnf_version(self):
  30. self.dnf('--version')
  31. @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
  32. def test_dnf_info(self):
  33. self.dnf('info dnf')
  34. @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
  35. def test_dnf_search(self):
  36. self.dnf('search dnf')
  37. @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
  38. def test_dnf_history(self):
  39. self.dnf('history')
  40. class DnfRepoTest(DnfTest):
  41. @classmethod
  42. def setUpClass(cls):
  43. cls.repo_server = HTTPService(os.path.join(cls.tc.td['WORKDIR'], 'oe-testimage-repo'),
  44. cls.tc.target.server_ip, logger=cls.tc.logger)
  45. cls.repo_server.start()
  46. @classmethod
  47. def tearDownClass(cls):
  48. cls.repo_server.stop()
  49. def dnf_with_repo(self, command):
  50. pkgarchs = os.listdir(os.path.join(self.tc.td['WORKDIR'], 'oe-testimage-repo'))
  51. deploy_url = 'http://%s:%s/' %(self.target.server_ip, self.repo_server.port)
  52. cmdlinerepoopts = ["--repofrompath=oe-testimage-repo-%s,%s%s" %(arch, deploy_url, arch) for arch in pkgarchs]
  53. output = self.dnf(" ".join(cmdlinerepoopts) + " --nogpgcheck " + command)
  54. return output
  55. @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
  56. def test_dnf_makecache(self):
  57. self.dnf_with_repo('makecache')
  58. # Does not work when repo is specified on the command line
  59. # @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
  60. # def test_dnf_repolist(self):
  61. # self.dnf_with_repo('repolist')
  62. @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
  63. def test_dnf_repoinfo(self):
  64. self.dnf_with_repo('repoinfo')
  65. @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
  66. def test_dnf_install(self):
  67. output = self.dnf_with_repo('list run-postinsts-dev')
  68. if 'Installed Packages' in output:
  69. self.dnf_with_repo('remove -y run-postinsts-dev')
  70. self.dnf_with_repo('install -y run-postinsts-dev')
  71. @OETestDepends(['dnf.DnfRepoTest.test_dnf_install'])
  72. def test_dnf_install_dependency(self):
  73. self.dnf_with_repo('remove -y run-postinsts')
  74. self.dnf_with_repo('install -y run-postinsts-dev')
  75. @OETestDepends(['dnf.DnfRepoTest.test_dnf_install_dependency'])
  76. def test_dnf_install_from_disk(self):
  77. self.dnf_with_repo('remove -y run-postinsts-dev')
  78. self.dnf_with_repo('install -y --downloadonly run-postinsts-dev')
  79. status, output = self.target.run('find /var/cache/dnf -name run-postinsts-dev*rpm', 1500)
  80. self.assertEqual(status, 0, output)
  81. self.dnf_with_repo('install -y %s' % output)
  82. @OETestDepends(['dnf.DnfRepoTest.test_dnf_install_from_disk'])
  83. def test_dnf_install_from_http(self):
  84. output = subprocess.check_output('%s %s -name run-postinsts-dev*' % (bb.utils.which(os.getenv('PATH'), "find"),
  85. os.path.join(self.tc.td['WORKDIR'], 'oe-testimage-repo')), shell=True).decode("utf-8")
  86. rpm_path = output.split("/")[-2] + "/" + output.split("/")[-1]
  87. url = 'http://%s:%s/%s' %(self.target.server_ip, self.repo_server.port, rpm_path)
  88. self.dnf_with_repo('remove -y run-postinsts-dev')
  89. self.dnf_with_repo('install -y %s' % url)
  90. @OETestDepends(['dnf.DnfRepoTest.test_dnf_install'])
  91. def test_dnf_reinstall(self):
  92. self.dnf_with_repo('reinstall -y run-postinsts-dev')
  93. @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
  94. def test_dnf_installroot(self):
  95. rootpath = '/home/root/chroot/test'
  96. #Copy necessary files to avoid errors with not yet installed tools on
  97. #installroot directory.
  98. self.target.run('mkdir -p %s/etc' % rootpath, 1500)
  99. self.target.run('mkdir -p %s/bin %s/sbin %s/usr/bin %s/usr/sbin' % (rootpath, rootpath, rootpath, rootpath), 1500)
  100. self.target.run('mkdir -p %s/dev' % rootpath, 1500)
  101. #Handle different architectures lib dirs
  102. self.target.run('mkdir -p %s/lib' % rootpath, 1500)
  103. self.target.run('mkdir -p %s/libx32' % rootpath, 1500)
  104. self.target.run('mkdir -p %s/lib64' % rootpath, 1500)
  105. self.target.run('cp /lib/libtinfo.so.5 %s/lib' % rootpath, 1500)
  106. self.target.run('cp /libx32/libtinfo.so.5 %s/libx32' % rootpath, 1500)
  107. self.target.run('cp /lib64/libtinfo.so.5 %s/lib64' % rootpath, 1500)
  108. self.target.run('cp -r /etc/rpm %s/etc' % rootpath, 1500)
  109. self.target.run('cp -r /etc/dnf %s/etc' % rootpath, 1500)
  110. self.target.run('cp /bin/sh %s/bin' % rootpath, 1500)
  111. self.target.run('mount -o bind /dev %s/dev/' % rootpath, 1500)
  112. self.dnf_with_repo('install --installroot=%s -v -y --rpmverbosity=debug busybox run-postinsts' % rootpath)
  113. status, output = self.target.run('test -e %s/var/cache/dnf' % rootpath, 1500)
  114. self.assertEqual(0, status, output)
  115. status, output = self.target.run('test -e %s/bin/busybox' % rootpath, 1500)
  116. self.assertEqual(0, status, output)
  117. @OETestDepends(['dnf.DnfRepoTest.test_dnf_makecache'])
  118. def test_dnf_exclude(self):
  119. excludepkg = 'curl-dev'
  120. self.dnf_with_repo('install -y curl*')
  121. self.dnf('list %s' % excludepkg, 0)
  122. #Avoid remove dependencies to skip some errors on different archs and images
  123. self.dnf_with_repo('remove --setopt=clean_requirements_on_remove=0 -y curl*')
  124. #check curl-dev is not installed adter removing all curl occurrences
  125. status, output = self.target.run('dnf list --installed | grep %s'% excludepkg, 1500)
  126. self.assertEqual(1, status, "%s was not removed, is listed as installed"%excludepkg)
  127. self.dnf_with_repo('install -y --exclude=%s --exclude=curl-staticdev curl*' % excludepkg)
  128. #check curl-dev is not installed after being excluded
  129. status, output = self.target.run('dnf list --installed | grep %s'% excludepkg , 1500)
  130. self.assertEqual(1, status, "%s was not excluded, is listed as installed"%excludepkg)