Esempio n. 1
0
    def test_updateinfo_unit_metadata(self):

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

        handle = open(os.path.join(DATA_DIR, 'updateinfo.xml'), 'r')
        generator = packages.package_list_generator(
            handle, 'update', updateinfo.process_package_element)

        erratum_unit = next(generator)

        # just checking
        self.assertEqual(erratum_unit.unit_key['errata_id'], 'RHEA-2010:9999')

        context = UpdateinfoXMLFileContext(self.metadata_file_dir)
        context._open_metadata_file_handle()
        context.add_unit_metadata(erratum_unit)
        context._close_metadata_file_handle()

        self.assertNotEqual(os.path.getsize(path), 0)

        updateinfo_handle = gzip.open(path, 'r')
        content = updateinfo_handle.read()
        updateinfo_handle.close()

        self.assertEqual(content.count('from="*****@*****.**"'), 1)
        self.assertEqual(content.count('status="final"'), 1)
        self.assertEqual(content.count('type="enhancements"'), 1)
        self.assertEqual(content.count('version="1"'), 1)
        self.assertEqual(content.count('<id>RHEA-2010:9999</id>'), 1)
        self.assertEqual(content.count('<collection short="F13PTP">'), 1)
        self.assertEqual(content.count('<package'), 2)
        self.assertEqual(
            content.count(
                '<sum type="md5">f3c197a29d9b66c5b65c5d62b25db5b4</sum>'), 1)
Esempio n. 2
0
 def setUp(self, mock_parent_open_file_handle):
     nevra_in_repo = set([('pulp-test-package', '0', '0.3.1', '1.fc22',
                           'x86_64')])
     self.context = UpdateinfoXMLFileContext('/foo',
                                             nevra_in_repo,
                                             checksum_type='sha256')
     self.context.metadata_file_handle = StringIO()
     self.context._open_metadata_file_handle()
Esempio n. 3
0
    def test_updateinfo_file_creation(self):

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

        context = UpdateinfoXMLFileContext(self.metadata_file_dir)

        context._open_metadata_file_handle()
        context._close_metadata_file_handle()

        self.assertTrue(os.path.exists(path))
Esempio n. 4
0
    def test_updateinfo_unit_metadata_with_repo(self,
                                                mock__get_repo_unit_nevra):

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

        handle = open(os.path.join(DATA_DIR, 'updateinfo.xml'), 'r')
        generator = packages.package_list_generator(
            handle, 'update', updateinfo.process_package_element)

        # mock out the repo/unit nevra matcher so that only one unit in the referenced errata
        # is included in the output updateinfo XML
        mock__get_repo_unit_nevra.return_value = [
            {
                'name': 'patb',
                'epoch': '0',
                'version': '0.1',
                'release': '2',
                'arch': 'x86_64'
            },
        ]

        erratum_unit = next(generator)

        # just checking
        self.assertEqual(erratum_unit.unit_key['errata_id'], 'RHEA-2010:9999')

        mock_conduit = Mock()
        mock_conduit.repo_id = 'mock_conduit_repo'
        context = UpdateinfoXMLFileContext(self.metadata_file_dir,
                                           set(),
                                           conduit=mock_conduit,
                                           checksum_type='md5')
        context._open_metadata_file_handle()
        context.add_unit_metadata(erratum_unit)
        context._close_metadata_file_handle()

        self.assertNotEqual(os.path.getsize(path), 0)

        updateinfo_handle = gzip.open(path, 'r')
        content = updateinfo_handle.read()
        updateinfo_handle.close()

        self.assertEqual(content.count('from="*****@*****.**"'), 1)
        self.assertEqual(content.count('status="final"'), 1)
        self.assertEqual(content.count('type="enhancements"'), 1)
        self.assertEqual(content.count('version="1"'), 1)
        self.assertEqual(content.count('<id>RHEA-2010:9999</id>'), 1)
        self.assertEqual(content.count('<collection short="F13PTP">'), 1)
        self.assertEqual(content.count('<package'), 1)
        self.assertEqual(
            content.count(
                '<sum type="md5">f3c197a29d9b66c5b65c5d62b25db5b4</sum>'), 1)
Esempio n. 5
0
    def test_updateinfo_opening_closing_tags(self):

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

        context = UpdateinfoXMLFileContext(self.metadata_file_dir)

        context._open_metadata_file_handle()

        self.assertRaises(NotImplementedError, context._write_root_tag_close)

        context._write_root_tag_open()

        try:
            context._write_root_tag_close()

        except Exception, e:
            self.fail(e.message)
Esempio n. 6
0
    def test_updateinfo_repo_unit_nevra_q_filter(self, mock_rpm):
        # A mongoengine "QCombination" object is used to efficiently search for units
        # by nevra. This checks that the QCombination object is properly created based
        # on the errata unit parsed from the test updateinfo XML.
        with open(os.path.join(DATA_DIR, 'updateinfo.xml'), 'r') as handle:
            generator = packages.package_list_generator(
                handle, 'update', updateinfo.process_package_element)
            erratum_unit = next(generator)

        context = UpdateinfoXMLFileContext(self.metadata_file_dir)
        context._repo_unit_nevra(erratum_unit, 'mock_repo')

        # Call 0 to mock_rpm's filter should have one arg, which should be the QCombination
        # object that is built with an OR operator, with two children (one for each package
        # in the errata unit that was passed to the method under test.
        qcombination = mock_rpm.objects.filter.call_args_list[0][0][0]
        self.assertTrue(isinstance(qcombination, QCombination))
        self.assertEqual(qcombination.operation, qcombination.OR)
        self.assertEqual(len(qcombination.children), 2)
Esempio n. 7
0
    def test_updateinfo_repo_unit_nevra_return(self, mock_rcu, mock_rpm):
        # Build up the mock data as well as the expected returns
        nevra_fields = ('name', 'epoch', 'version', 'release', 'arch')
        unit1_nevra = ('n1', 'e1', 'v1', 'r1', 'a1')
        unit1_nevra_dict = dict(zip(nevra_fields, unit1_nevra))
        unit2_nevra = ('n2', 'e2', 'v2', 'r2', 'a2')
        unit2_nevra_dict = dict(zip(nevra_fields, unit2_nevra))

        # This is the result to the query for all units with a given nevra
        # The expected value is a list of tuples containing unit ids and nevra fields;
        mock_rpm.objects.filter().scalar.return_value = [
            ('id1', ) + unit1_nevra,
            ('id2', ) + unit2_nevra,
        ]
        # The expected value here is a list of unit IDs from the previous query that are
        # associated with our mock repo.
        mock_rcu.objects.filter().scalar.return_value = ['id1']

        # Load the updateinfo XML to get an erratum unit to process
        with open(os.path.join(DATA_DIR, 'updateinfo.xml'), 'r') as handle:
            generator = packages.package_list_generator(
                handle, 'update', updateinfo.process_package_element)
            erratum_unit = next(generator)

        context = UpdateinfoXMLFileContext(self.metadata_file_dir)
        repo_unit_nevra = context._repo_unit_nevra(erratum_unit, 'mock_repo')

        # Call 0 created the scalar mock, so we're interested in call 1. In this case, check
        # that filter was called at least once with the expected filter kwargs and values.
        mock_rcu.objects.filter.assert_any_call(unit_id__in=['id2', 'id1'],
                                                repo_id='mock_repo')

        # And finally, make sure the return value is actually good!
        # We made the RPM mock simulate two units known to pulp with the nevra seen in our errata.
        # Then, we made the RepositoryContentUnit mock simulate that only one of those units is
        # associated with the passed-in repo. The return value should be a list with only the
        # single matching unit's nevra dict in it.
        self.assertEqual(len(repo_unit_nevra), 1)
        self.assertTrue(unit1_nevra_dict in repo_unit_nevra)
        self.assertTrue(unit2_nevra_dict not in repo_unit_nevra)
Esempio n. 8
0
    def test_updateinfo_get_repo_unit_nevra_return(self):
        nevra_fields = ('name', 'epoch', 'version', 'release', 'arch')
        unit1_nevra = ('n1', 'e1', 'v1', 'r1', 'a1')
        unit1_nevra_dict = dict(zip(nevra_fields, unit1_nevra))
        unit2_nevra = ('n2', 'e2', 'v2', 'r2', 'a2')
        unit2_nevra_dict = dict(zip(nevra_fields, unit2_nevra))

        erratum_unit = Mock()
        erratum_unit.pkglist = [{
            'packages': [
                unit1_nevra_dict,
                unit2_nevra_dict,
            ]
        }]

        context = UpdateinfoXMLFileContext(self.metadata_file_dir,
                                           set([unit1_nevra]))
        repo_unit_nevra = context._get_repo_unit_nevra(erratum_unit)

        self.assertEqual(len(repo_unit_nevra), 1)
        self.assertTrue(unit1_nevra_dict in repo_unit_nevra)
        self.assertTrue(unit2_nevra_dict not in repo_unit_nevra)
Esempio n. 9
0
    def test_updateinfo_get_repo_unit_nevra_no_epoch(self):
        """
        Test that epoch defaults to 0 and corresponding erratum and RPM unit match
        """
        nevra_fields = ('name', 'epoch', 'version', 'release', 'arch')
        erratum_unit_nevra = ('n1', None, 'v1', 'r1', 'a1')
        erratum_unit_nevra_dict = dict(zip(nevra_fields, erratum_unit_nevra))
        rpm_unit_nevra = ('n1', '0', 'v1', 'r1', 'a1')
        rpm_unit_nevra_dict = dict(zip(nevra_fields, rpm_unit_nevra))

        erratum_unit = Mock()
        erratum_unit.pkglist = [{
            'packages': [
                erratum_unit_nevra_dict,
            ]
        }]

        context = UpdateinfoXMLFileContext(self.metadata_file_dir,
                                           set([rpm_unit_nevra]))
        repo_unit_nevra = context._get_repo_unit_nevra(erratum_unit)

        self.assertEqual(len(repo_unit_nevra), 1)
        self.assertTrue(rpm_unit_nevra_dict in repo_unit_nevra)
Esempio n. 10
0
 def setUp(self, mock_parent_open_file_handle):
     self.context = UpdateinfoXMLFileContext('/foo')
     self.context.metadata_file_handle = StringIO()
     self.context._open_metadata_file_handle()