Ejemplo n.º 1
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]))
Ejemplo n.º 2
0
 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))
Ejemplo n.º 3
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")
Ejemplo n.º 4
0
class TestRepoMD(unittest.TestCase):
    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_repomd(self, md):
        intended_fields = ["location", "size", "checksum_type", "checksum"]
        actual_fields = md.keys()
        for field in intended_fields:
            self.assertTrue(field in actual_fields)
        for field in actual_fields:
            self.assertTrue(field in intended_fields)

        self.assertIsInstance(md["size"], int)

    def test_invalid_file(self):
        with self.assertRaises(FileNotFoundError):
            RepoMD("/file/does/not/exist")
        with self.assertRaises(ParseError):
            RepoMD("/dev/null")

    def test_get_primary(self):
        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):
        updateinfo1 = self.repomd.get_metadata("updateinfo")
        self._test_repomd(updateinfo1)

        # Should fail
        with self.assertRaises(RepoMDTypeNotFound):
            self.repomd_primary_only.get_metadata("updateinfo")
Ejemplo n.º 5
0
    def setUp(self):
        """Setup example files."""
        repomd = RepoMD("test_data/repodata/repomd.xml")
        primary_db = PrimaryDatabaseMD("test_data/repodata/primary_db.sqlite")
        primary = PrimaryMD("test_data/repodata/primary.xml")
        updateinfo = UpdateInfoMD("test_data/repodata/updateinfo.xml")

        self.repository = Repository("repo_url")
        self.repository.primary = primary_db
        self.repository.updateinfo = updateinfo
        self.repository_without_updateinfo = Repository("repo_url")
        self.repository_without_updateinfo.primary = primary_db
        self.repository_primary_xml = Repository("repo_url")
        self.repository_primary_xml.primary = primary
        self.repository_primary_xml.updateinfo = updateinfo
Ejemplo n.º 6
0
 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")
Ejemplo n.º 7
0
 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")
Ejemplo n.º 8
0
 def test_invalid_file(self):
     with self.assertRaises(FileNotFoundError):
         RepoMD("/file/does/not/exist")
     with self.assertRaises(ParseError):
         RepoMD("/dev/null")