Exemple #1
0
def mkmetadatadir(path, updateinfo=None, comps=None, source=False):
    """
    Generate package metadata for a given directory.

    If the metadata doesn't exist, then create it.

    Args:
        path (basestring): The directory to generate metadata for.
        updateinfo (basestring or None or bool): The updateinfo to insert instead of example.
            No updateinfo is inserted if False is passed. Passing True provides undefined
            behavior.
        comps (basestring or None): The comps to insert instead of example.
        source (True): If True, do not insert comps or prestodelta. Defaults to False.
    """
    compsfile = '''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
  <group>
    <id>testable</id>
    <_name>Testable</_name>
    <_description>comps group for testing</_description>
    <packagelist>
      <packagereq>testpkg</packagereq>
    </packagelist>
  </group>
</comps>'''
    updateinfofile = ''
    if not os.path.isdir(path):
        os.makedirs(path)
    if not comps and not source:
        comps = os.path.join(path, 'comps.xml')
        with open(comps, 'w') as f:
            f.write(compsfile)
    if updateinfo is None:
        updateinfo = os.path.join(path, 'updateinfo.xml')
        with open(updateinfo, 'w') as f:
            f.write(updateinfofile)

    createrepo_command = [
        'createrepo_c', '--xz', '--database', '--quiet', path
    ]

    if not source:
        for arg in ('--deltas', 'comps.xml', '--groupfile'):
            createrepo_command.insert(1, arg)

    subprocess.check_call(createrepo_command)
    if updateinfo is not False:
        metadata.insert_in_repo(createrepo_c.XZ,
                                os.path.join(path,
                                             'repodata'), 'updateinfo', 'xml',
                                os.path.join(path, 'updateinfo.xml'))
Exemple #2
0
    def test_zchunk_metadata_coverage_xz_compression(self, mock_cr):
        """
        Let's test that we skip zchunk files, because we don't want to zchunk zchunk files.

        This test makes sure we reach 100% coverage by mocking createrepo.

        cr.ZCK_COMPRESSION is only defined when createrepo_c supports zchunk, but createrepo_c's
        zchunk support is only available in createrepo_c >= 0.12.0, and it is also a build flag,
        so we can't be sure that the createrepo_c we work with has that feature.

        This function is designed to *only* make sure we reach 100% coverage and isn't meant
        to test whether zchunk is working correctly.  _test_extended_metadata will take care
        of testing both the regular and zchunked updateinfo if zchunk is enabled
        """
        mock_cr.ZCK_COMPRESSION = 99
        mock_repomd = mock.MagicMock()
        mock_repomd.xml_dump = mock.MagicMock(return_value="test data")
        mock_cr.Repomd = mock.MagicMock(return_value=mock_repomd)

        bodhi_metadata.insert_in_repo(bodhi_metadata.cr.XZ_COMPRESSION,
                                      self.tempcompdir, 'garbage', 'zck',
                                      '/dev/null', True)

        mock_cr.Repomd.assert_called_once_with(
            os.path.join(self.tempcompdir, 'repomd.xml'))
        self.assertEqual(mock_cr.RepomdRecord.mock_calls, [
            mock.call('garbage', os.path.join(self.tempcompdir,
                                              'garbage.zck')),
            mock.call().compress_and_fill(mock_cr.SHA256,
                                          mock_cr.XZ_COMPRESSION),
            mock.call().compress_and_fill().rename_file(),
            mock.call('garbage_zck',
                      os.path.join(self.tempcompdir, 'garbage.zck')),
            mock.call().compress_and_fill(mock_cr.SHA256,
                                          mock_cr.ZCK_COMPRESSION),
            mock.call().compress_and_fill().rename_file()
        ])
        rec = mock_cr.RepomdRecord.return_value
        rec_comp = rec.compress_and_fill.return_value
        # The last comp_type added is the _zck one
        self.assertEqual(rec_comp.type, 'garbage_zck')
        self.assertEqual(
            mock_cr.Repomd.return_value.set_record.mock_calls,
            [mock.call(rec_comp), mock.call(rec_comp)])

        with open(os.path.join(self.tempcompdir, 'repomd.xml')) as repomd_file:
            repomd_contents = repomd_file.read()

        self.assertEqual(repomd_contents, 'test data')
        self.assertFalse(
            os.path.exists(os.path.join(self.tempcompdir, 'garbage.zck')))
Exemple #3
0
    def test_zchunk_metadata_coverage_zchunk_unsupported(self, mock_cr):
        """
        Let's test that we skip zchunk compression when it is unsupported by createrepo_c.

        This test makes sure we reach 100% coverage by mocking createrepo.

        cr.ZCK_COMPRESSION is only defined when createrepo_c supports zchunk, but createrepo_c's
        zchunk support is only available in createrepo_c >= 0.12.0, and it is also a build flag,
        so we can't be sure that the createrepo_c we work with has that feature.

        This function is designed to *only* make sure we reach 100% coverage and isn't meant
        to test whether zchunk is working correctly.  _test_extended_metadata will take care
        of testing both the regular and zchunked updateinfo if zchunk is enabled
        """
        del mock_cr.ZCK_COMPRESSION
        mock_repomd = mock.MagicMock()
        mock_repomd.xml_dump = mock.MagicMock(return_value="test data")
        mock_cr.Repomd = mock.MagicMock(return_value=mock_repomd)

        bodhi_metadata.insert_in_repo(bodhi_metadata.cr.XZ_COMPRESSION,
                                      self.tempcompdir, 'garbage', 'xz',
                                      '/dev/null', True)

        mock_cr.Repomd.assert_called_once_with(
            os.path.join(self.tempcompdir, 'repomd.xml'))
        mock_cr.RepomdRecord.assert_called_once_with(
            'garbage', os.path.join(self.tempcompdir, 'garbage.xz'))
        rec = mock_cr.RepomdRecord.return_value
        rec.compress_and_fill.assert_called_once_with(mock_cr.SHA256,
                                                      mock_cr.XZ_COMPRESSION)
        rec_comp = rec.compress_and_fill.return_value
        rec_comp.rename_file.assert_called_once_with()
        # The last inserted type is without _zck
        assert rec_comp.type == 'garbage'
        mock_cr.Repomd.return_value.set_record.assert_called_once_with(
            rec_comp)

        with open(os.path.join(self.tempcompdir, 'repomd.xml')) as repomd_file:
            repomd_contents = repomd_file.read()

        assert repomd_contents == 'test data'
        assert not os.path.exists(os.path.join(self.tempcompdir,
                                               'garbage.zck'))