dnf_runtime.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from oeqa.core.decorator.depends import OETestDepends
  2. from oeqa.runtime.cases.dnf import DnfTest
  3. from oeqa.utils.httpserver import HTTPService
  4. from oeqa.core.decorator.data import skipIfDataVar
  5. class DnfSelftest(DnfTest):
  6. @classmethod
  7. def setUpClass(cls):
  8. import tempfile
  9. cls.temp_dir = tempfile.TemporaryDirectory(prefix="oeqa-remotefeeds-")
  10. cls.repo_server = HTTPService(os.path.join(cls.tc.td['WORKDIR'], 'oe-rootfs-repo'),
  11. cls.tc.target.server_ip)
  12. cls.repo_server.start()
  13. @classmethod
  14. def tearDownClass(cls):
  15. cls.repo_server.stop()
  16. cls.temp_dir.cleanup()
  17. @OETestDepends(['dnf.DnfBasicTest.test_dnf_help'])
  18. @skipIfDataVar('PACKAGE_FEED_URIS', None,
  19. 'Not suitable as PACKAGE_FEED_URIS is not set')
  20. def test_verify_package_feeds(self):
  21. """
  22. Summary: Check correct setting of PACKAGE_FEED_URIS var
  23. Expected: 1. Feeds were correctly set for dnf
  24. 2. Update recovers packages from host's repo
  25. Author: Humberto Ibarra <humberto.ibarra.lopez@intel.com>
  26. Author: Alexander Kanavin <alex.kanavin@gmail.com>
  27. """
  28. # When we created an image, we had to supply fake ip and port
  29. # for the feeds. Now we can patch the real ones into the config file.
  30. temp_file = os.path.join(self.temp_dir.name, 'tmp.repo')
  31. self.tc.target.copyFrom("/etc/yum.repos.d/oe-remote-repo.repo", temp_file)
  32. fixed_config = open(temp_file, "r").read().replace("bogus_ip", self.tc.target.server_ip).replace("bogus_port", str(self.repo_server.port))
  33. with open(temp_file, "w") as f:
  34. f.write(fixed_config)
  35. self.tc.target.copyTo(temp_file, "/etc/yum.repos.d/oe-remote-repo.repo")
  36. import re
  37. # Use '-y' for non-interactive mode: automatically import the feed signing key
  38. output_makecache = self.dnf('-vy makecache')
  39. self.assertTrue(re.match(r".*Failed to synchronize cache", output_makecache, re.DOTALL) is None, msg = "dnf makecache failed to synchronize repo: %s" %(output_makecache))
  40. self.assertTrue(re.match(r".*Metadata cache created", output_makecache, re.DOTALL) is not None, msg = "dnf makecache failed: %s" %(output_makecache))
  41. output_repoinfo = self.dnf('-v repoinfo')
  42. matchobj = re.match(r".*Repo-pkgs\s*:\s*(?P<n_pkgs>[0-9]+)", output_repoinfo, re.DOTALL)
  43. self.assertTrue(matchobj is not None, msg = "Could not find the amount of packages in dnf repoinfo output: %s" %(output_repoinfo))
  44. self.assertTrue(int(matchobj.group('n_pkgs')) > 0, msg = "Amount of remote packages is not more than zero: %s\n" %(output_repoinfo))