def test_repomd_file_creation(self):

        path = os.path.join(self.metadata_file_dir, REPO_DATA_DIR_NAME, REPOMD_FILE_NAME)

        context = RepomdXMLFileContext(self.metadata_file_dir)
        context._open_metadata_file_handle()
        context._close_metadata_file_handle()

        self.assertTrue(os.path.exists(path))
    def test_repomd_opening_closing_tags(self):

        path = os.path.join(self.metadata_file_dir, REPO_DATA_DIR_NAME, REPOMD_FILE_NAME)

        context = RepomdXMLFileContext(self.metadata_file_dir)
        context._open_metadata_file_handle()

        self.assertRaises(NotImplementedError, context._write_root_tag_close)

        try:
            context._write_root_tag_open()

        except Exception, e:
            self.fail(e.message)
Beispiel #3
0
    def process_main(self, unit=None):
        wd = self.get_working_dir()
        total = len(self.parent.publish_msi.units +
                    self.parent.publish_msm.units)
        checksum_type = 'sha256'
        with PrimaryXMLFileContext(wd, total, checksum_type) as primary:
            units = itertools.chain(self.parent.publish_msi.units,
                                    self.parent.publish_msm.units)
            for unit in units:
                primary.add_unit_metadata(unit)
        with FilelistsXMLFileContext(wd, checksum_type) as filelists:
            for unit in units:
                filelists.add_unit_metadata(unit)
        with OtherXMLFileContext(wd, checksum_type) as other:
            for unit in units:
                other.add_unit_metadata(unit)

        with RepomdXMLFileContext(wd, checksum_type) as repomd:
            repomd.add_metadata_file_metadata('primary',
                                              primary.metadata_file_path,
                                              primary.checksum)
            repomd.add_metadata_file_metadata('filelists',
                                              filelists.metadata_file_path,
                                              filelists.checksum)
            repomd.add_metadata_file_metadata('other',
                                              other.metadata_file_path,
                                              other.checksum)
Beispiel #4
0
    def test_repomd_metadata_file_metadata(self):

        path = os.path.join(self.metadata_file_dir,
                            REPO_DATA_DIR_NAME,
                            REPOMD_FILE_NAME)

        test_metadata_file_name = 'metadata.gz'
        test_metadata_file_path = os.path.join(self.metadata_file_dir,
                                               REPO_DATA_DIR_NAME,
                                               test_metadata_file_name)
        test_metadata_content = 'The quick brown fox jumps over the lazy dog'

        os.makedirs(os.path.dirname(test_metadata_file_path))
        test_metadata_file_handle = gzip.open(test_metadata_file_path, 'w')
        test_metadata_file_handle.write(test_metadata_content)
        test_metadata_file_handle.close()

        context = RepomdXMLFileContext(self.metadata_file_dir)
        context._open_metadata_file_handle()
        context.add_metadata_file_metadata('metadata', test_metadata_file_path)
        context._close_metadata_file_handle()

        with open(path, 'r') as repomd_handle:

            content = repomd_handle.read()

            self.assertEqual(content.count('<data type="metadata"'), 1)
            self.assertEqual(content.count('<location href="%s/%s"' %
                                           (REPO_DATA_DIR_NAME, test_metadata_file_name)), 1)
            self.assertEqual(content.count('<timestamp>'), 1)
            self.assertEqual(content.count('<size>'), 1)
            self.assertEqual(content.count('<checksum type="sha256">'), 1)
            self.assertEqual(content.count('<open-size>%s</open-size>' % len(test_metadata_content)), 1)
            self.assertEqual(content.count('<open-checksum type="sha256">'), 1)
Beispiel #5
0
    def test_repomd_file_creation(self):

        path = os.path.join(self.metadata_file_dir, REPO_DATA_DIR_NAME,
                            REPOMD_FILE_NAME)

        context = RepomdXMLFileContext(self.metadata_file_dir)
        context._open_metadata_file_handle()
        context._close_metadata_file_handle()

        self.assertTrue(os.path.exists(path))
Beispiel #6
0
    def test_repomd_metadata_file_metadata(self, mock_getmtime):

        path = os.path.join(self.metadata_file_dir, REPO_DATA_DIR_NAME,
                            REPOMD_FILE_NAME)

        test_metadata_file_name = 'metadata.gz'
        test_metadata_file_path = os.path.join(self.metadata_file_dir,
                                               REPO_DATA_DIR_NAME,
                                               test_metadata_file_name)
        test_metadata_content = 'The quick brown fox jumps over the lazy dog'

        os.makedirs(os.path.dirname(test_metadata_file_path))
        test_metadata_file_handle = gzip.open(test_metadata_file_path, 'w')
        test_metadata_file_handle.write(test_metadata_content)
        test_metadata_file_handle.close()

        mock_getmtime.return_value = 45.5
        context = RepomdXMLFileContext(self.metadata_file_dir)
        context._open_metadata_file_handle()
        context.add_metadata_file_metadata('metadata', test_metadata_file_path)
        context._close_metadata_file_handle()

        with open(path, 'r') as repomd_handle:
            content = repomd_handle.read()
            self.assertEqual(content.count('<data type="metadata"'), 1)
            self.assertEqual(
                content.count('<location href="%s/%s"' %
                              (REPO_DATA_DIR_NAME, test_metadata_file_name)),
                1)
            self.assertEqual(content.count('<timestamp>'), 1)
            # yum does an integer conversion on the timestamp
            # integer conversion of float strings will throw an error
            # so make sure this isn't a float
            xml_element = et.fromstring(content)
            ts_value = (xml_element.findall('timestamp'))[0].text
            int(ts_value)

            self.assertEqual(content.count('<size>'), 1)
            self.assertEqual(content.count('<checksum type="sha256">'), 1)
            self.assertEqual(
                content.count('<open-size>%s</open-size>' %
                              len(test_metadata_content)), 1)
            self.assertEqual(content.count('<open-checksum type="sha256">'), 1)
Beispiel #7
0
    def test_repomd_opening_closing_tags(self):

        path = os.path.join(self.metadata_file_dir, REPO_DATA_DIR_NAME,
                            REPOMD_FILE_NAME)

        context = RepomdXMLFileContext(self.metadata_file_dir)
        context._open_metadata_file_handle()

        self.assertRaises(NotImplementedError, context._write_root_tag_close)

        try:
            context._write_root_tag_open()

        except Exception, e:
            self.fail(e.message)
Beispiel #8
0
    def test_repomd_metadata_file_metadata(self, mock_getmtime):

        path = os.path.join(self.metadata_file_dir,
                            REPO_DATA_DIR_NAME,
                            REPOMD_FILE_NAME)

        test_metadata_file_name = 'metadata.gz'
        test_metadata_file_path = os.path.join(self.metadata_file_dir,
                                               REPO_DATA_DIR_NAME,
                                               test_metadata_file_name)
        test_metadata_content = 'The quick brown fox jumps over the lazy dog'

        os.makedirs(os.path.dirname(test_metadata_file_path))
        test_metadata_file_handle = gzip.open(test_metadata_file_path, 'w')
        test_metadata_file_handle.write(test_metadata_content)
        test_metadata_file_handle.close()

        mock_getmtime.return_value = 45.5
        context = RepomdXMLFileContext(self.metadata_file_dir)
        context._open_metadata_file_handle()
        context.add_metadata_file_metadata('metadata', test_metadata_file_path)
        context._close_metadata_file_handle()

        with open(path, 'r') as repomd_handle:
            content = repomd_handle.read()
            self.assertEqual(content.count('<data type="metadata"'), 1)
            self.assertEqual(content.count('<location href="%s/%s"' %
                                           (REPO_DATA_DIR_NAME, test_metadata_file_name)), 1)
            self.assertEqual(content.count('<timestamp>'), 1)
            # yum does an integer conversion on the timestamp
            # integer conversion of float strings will throw an error
            # so make sure this isn't a float
            xml_element = et.fromstring(content)
            ts_value = (xml_element.findall('timestamp'))[0].text
            int(ts_value)

            self.assertEqual(content.count('<size>'), 1)
            self.assertEqual(content.count('<checksum type="sha256">'), 1)
            self.assertEqual(
                content.count('<open-size>%s</open-size>' % len(test_metadata_content)), 1)
            self.assertEqual(content.count('<open-checksum type="sha256">'), 1)