Exemple #1
0
class TestRepoMD(unittest.TestCase):
    """Test RepoMD class."""
    def setUp(self):
        """Setup two repomd files. First with all sections. Second with primary section only."""
        self.repomd = RepoMD("test_data/repodata/repomd.xml")
        self.repomd_primary_only = RepoMD(
            "test_data/repodata/repomd_primary_only.xml")

    def test_revision(self):
        """Test getting revision timestamp."""
        self.assertIsInstance(self.repomd.get_revision(), datetime)
        self.assertIsInstance(self.repomd_primary_only.get_revision(),
                              datetime)
        self.assertEqual(self.repomd.get_revision(),
                         self.repomd_primary_only.get_revision())

    def _test_repomd(self, data):
        intended_fields = ["location", "checksum_type", "checksum"]
        optional_fields = ["open-size", "size"]
        actual_fields = data.keys()
        for field in intended_fields:
            self.assertTrue(field in actual_fields, field)
        for field in actual_fields:
            self.assertTrue(field in intended_fields or optional_fields, field)

    def test_invalid_file(self):
        """Test case when file doesn't exist or is invalid."""
        with self.assertRaises(FileNotFoundError):
            RepoMD("/file/does/not/exist")
        with self.assertRaises(ParseError):
            RepoMD("/dev/null")

    def test_get_primary(self):
        """Test getting primary metadata info."""
        primary1 = self.repomd.get_metadata("primary")
        self._test_repomd(primary1)

        primary2 = self.repomd_primary_only.get_metadata("primary")
        self._test_repomd(primary2)

    def test_get_updateinfo(self):
        """Test getting updateinfo metadata info."""
        updateinfo1 = self.repomd.get_metadata("updateinfo")
        self._test_repomd(updateinfo1)

        # Should fail
        with self.assertRaises(RepoMDTypeNotFound):
            self.repomd_primary_only.get_metadata("updateinfo")
Exemple #2
0
 def _read_repomds(self, failed):
     """Reads all downloaded repomd files. Checks if their download failed and checks if their metadata are
        newer than metadata currently in DB.
     """
     # Fetch current list of repositories from DB
     db_repositories = self.repo_store.list_repositories()
     for repository in self.repositories:
         repomd_path = os.path.join(repository.tmp_directory, "repomd.xml")
         if repomd_path not in failed:
             repomd = RepoMD(repomd_path)
             # Was repository already synced before?
             if repository.repo_label in db_repositories:
                 db_revision = db_repositories[
                     repository.repo_label]["revision"]
             else:
                 db_revision = None
             downloaded_revision = datetime.fromtimestamp(
                 repomd.get_revision(), tz=timezone.utc)
             # Repository is synced for the first time or has newer revision
             if db_revision is None or downloaded_revision > db_revision:
                 repository.repomd = repomd
             else:
                 self.logger.log(
                     "Downloaded repo %s (%s) is not newer than repo in DB (%s)."
                     % (repository.repo_label, str(downloaded_revision),
                        str(db_revision)))
         else:
             self.logger.log("Download failed: %s (HTTP CODE %d)" %
                             (urljoin(repository.repo_url,
                                      REPOMD_PATH), failed[repomd_path]))
 def _read_repomds(self):
     """Reads all downloaded repomd files. Checks if their download failed and checks if their metadata are
        newer than metadata currently in DB.
     """
     # Fetch current list of repositories from DB
     db_repositories = self.repo_store.list_repositories()
     for repository in self.repositories:
         repomd_path = os.path.join(repository.tmp_directory, "repomd.xml")
         repomd = RepoMD(repomd_path)
         # Was repository already synced before?
         repository_key = (repository.content_set, repository.basearch,
                           repository.releasever)
         if repository_key in db_repositories:
             db_revision = db_repositories[repository_key]["revision"]
         else:
             db_revision = None
         downloaded_revision = repomd.get_revision()
         # Repository is synced for the first time or has newer revision
         if db_revision is None or downloaded_revision > db_revision:
             repository.repomd = repomd
         else:
             self.logger.debug(
                 "Downloaded repo %s (%s) is not newer than repo in DB (%s).",
                 ", ".join(filter(None, repository_key)),
                 str(downloaded_revision), str(db_revision))