Exemplo n.º 1
0
    def test_fills_requirement_le_true(self):
        """
        Test fills_requirement() with LE that is True.
        """
        rpm_1 = models.RPM('firefox', 0, '23.0.0', '1', 'x86_64', 'sha256', 'some_sum', {})
        rpm_2 = models.RPM('firefox', 0, '23.0.1', '1', 'x86_64', 'sha256', 'some_sum', {})
        requirement = depsolve.Requirement('firefox', 0, '23.0.1', '1', depsolve.Requirement.LE)

        self.assertEqual(requirement.fills_requirement(rpm_1), True)
        self.assertEqual(requirement.fills_requirement(rpm_2), True)
Exemplo n.º 2
0
 def setUp(self):
     self.unit = models.RPM()
     self.unit.repodata['primary'] = self.PRIMARY_EXCERPT
     self.unit.repodata['filelists'] = self.FILELISTS_EXCERPT
     self.unit.repodata['other'] = self.OTHER_EXCERPT
     self.unit.filename = 'fixed-filename.rpm'
     self.checksum = '951e0eacf3e6e6102b10acb2e689243b5866ec2c7720e783749dbd32f4a69ab3'
Exemplo n.º 3
0
    def test_render_download_step_checksum_type_error(self):
        """
        Assert correct behavior from render_download_step() when the progress report contains errors
        about checksum type being unknown. This asserts coverage on code that caused #1099771.

        https://bugzilla.redhat.com/show_bug.cgi?id=1099771
        """
        self.prompt.render_failure_message = mock.MagicMock()
        content_report = report.ContentReport()
        model = models.RPM('name', 0, '1.0.1', '2', 'x86_64',
                           'non_existing_checksum', 'checksum', {'size': 1024})
        error_report = {
            constants.NAME:
            model.unit_key['name'],
            constants.ERROR_CODE:
            constants.ERROR_CHECKSUM_TYPE_UNKNOWN,
            constants.CHECKSUM_TYPE:
            model.unit_key['checksumtype'],
            constants.ACCEPTED_CHECKSUM_TYPES:
            verification.CHECKSUM_FUNCTIONS.keys()
        }
        content_report.failure(model, error_report)
        content_report['state'] = constants.STATE_COMPLETE
        progress_report = {'yum_importer': {'content': content_report}}
        renderer = status.RpmStatusRenderer(self.context)

        renderer.render_download_step(progress_report)

        # The call above should not have failed, and the error messages asserted below should have
        # been printed for the user.
        self.assertTrue('package errors encountered' in
                        self.prompt.render_failure_message.mock_calls[0][1][0])
        self.assertTrue('invalid checksum type (non_existing_checksum)' in
                        self.prompt.render_failure_message.mock_calls[1][1][0])
Exemplo n.º 4
0
    def test_render_download_step_invalid_signature_error(self):
        """
        Assert correct behavior from render_download_step() when the progress report contains errors
        about packages that did not pass signature filtering.
        """
        self.prompt.render_failure_message = mock.MagicMock()
        content_report = report.ContentReport()
        model = models.RPM(name='name',
                           epoch=0,
                           version='1.0.1',
                           release='2',
                           arch='x86_64',
                           checksumtype='sha1',
                           checksum='abcd',
                           size=1024)
        error_report = {
            'count': 32,
            constants.ERROR_CODE: 'invalid_package_signature',
        }
        content_report.failure(model, error_report)
        content_report['state'] = constants.STATE_COMPLETE
        progress_report = {'yum_importer': {'content': content_report}}
        renderer = status.RpmStatusRenderer(self.context)

        renderer.render_download_step(progress_report)

        # The call above should not have failed, and the error messages asserted below should have
        # been printed for the user.
        self.assertTrue('package errors encountered' in
                        self.prompt.render_failure_message.mock_calls[0][1][0])
        self.assertTrue(
            '32 packages failed signature filter and were not imported.' in
            self.prompt.render_failure_message.mock_calls[1][1][0])
Exemplo n.º 5
0
 def setUp(self):
     self.unit = models.RPM()
     self.repodata = {
         'primary': self.PRIMARY_EXCERPT,
         'filelists': self.FILELISTS_EXCERPT,
         'other': self.OTHER_EXCERPT
     }
Exemplo n.º 6
0
    def test_fills_requirement_lt_false(self):
        """
        Test fills_requirement() with LT that is False.
        """
        rpm = models.RPM('firefox', 0, '23.0.2', '1', 'x86_64', 'sha256', 'some_sum', {})
        requirement = depsolve.Requirement('firefox', 0, '23.0.1', '1', depsolve.Requirement.LT)

        self.assertEqual(requirement.fills_requirement(rpm), False)
Exemplo n.º 7
0
    def test_fills_requirement_gt_true(self):
        """
        Test fills_requirement() with GT that is True.
        """
        rpm = models.RPM('firefox', 0, '23.0.2', '1', 'x86_64', 'sha256', 'some_sum', {})
        requirement = depsolve.Requirement('firefox', 0, '23.0.1', '1', depsolve.Requirement.GT)

        self.assertEqual(requirement.fills_requirement(rpm), True)
Exemplo n.º 8
0
    def test___init___sanitizes_checksum_type(self):
        """
        Ensure that __init__() calls sanitize_checksum_type correctly.
        """
        # The sha should get changed to sha1
        rpm = models.RPM('name', 'epoch', 'version', 'release', 'filename', 'sha', 'checksum', {})

        self.assertEqual(rpm.unit_key['checksumtype'], 'sha1')
Exemplo n.º 9
0
    def test_fills_requirement_eq_versioned_true(self):
        """
        Test fille_requirement() when the EQ flag is set and it is versioned for the case when the
        RPM does meet the requirement.
        """
        rpm = models.RPM('firefox', 0, '23.0', '1', 'x86_64', 'sha256', 'some_sum', {})
        requirement = depsolve.Requirement('firefox', 0, '23.0', '1', flags=depsolve.Requirement.EQ)

        self.assertEqual(requirement.fills_requirement(rpm), True)
Exemplo n.º 10
0
    def test_fills_requirement_name_match_versioned(self):
        """
        A package with the name that the unversioned Requirement specifies should meet the
        Requirement.
        """
        rpm = models.RPM('firefox', 0, '23.0', '1', 'x86_64', 'sha256', 'some_sum', {})
        requirement = depsolve.Requirement('firefox')

        self.assertEqual(requirement.fills_requirement(rpm), True)
Exemplo n.º 11
0
 def setUp(self):
     super(TestNonMetadataGetOrCalculateChecksum, self).setUp()
     self.model = models.RPM(name='foo',
                             epoch='0',
                             version='1.0.0',
                             release='2',
                             arch='noarch',
                             checksumtype='sha1',
                             checksum='abc123')
     self.model.checksums = {'sha256': 'asum'}
Exemplo n.º 12
0
    def test_fills_requirement_name_mismatch(self):
        """
        A package with a different name than the Requirement's name should not meet the Requirement.
        """
        rpm = models.RPM('firefox', 0, '23.0', '1', 'x86_64', 'sha256', 'some_sum', {})
        requirement = depsolve.Requirement('openssh-server', 0, '23.0', '1')

        # Because 'firefox' is different than 'openssh-server', the rpm doesn't satisfy the
        # requirement even though the versions are equal
        self.assertEqual(requirement.fills_requirement(rpm), False)
Exemplo n.º 13
0
    def test_handle_package(self, mock_generate, mock_nevra):
        # Setup
        unit_key = {
            'name': 'walrus',
            'epoch': '1',
            'version': '5.21',
            'release': '1',
            'arch': 'noarch',
            'checksumtype': 'sha256',
            'checksum': 'e837a635cc99f967a70f34b268baa52e0f412c1502e08e924ff5b09f1f9573f2',
        }
        metadata = {
            'filename': ''
        }
        mock_generate.return_value = unit_key, metadata

        user_unit_key = {'version': '100'}
        user_metadata = {'extra-meta': 'e'}
        config = PluginCallConfiguration({}, {})
        mock_repo = mock.MagicMock()

        mock_conduit = mock.MagicMock()
        inited_unit = Unit(models.RPM.TYPE, unit_key, metadata, self.upload_dest_filename)
        mock_conduit.init_unit.return_value = inited_unit

        # Test
        upload._handle_package(mock_repo, models.RPM.TYPE, user_unit_key, user_metadata,
                               self.upload_src_filename, mock_conduit, config)

        # Verify

        # File was moved as part of the import
        self.assertTrue(os.path.exists(self.upload_dest_filename))
        self.assertTrue(not os.path.exists(self.upload_src_filename))

        #   Mock calls
        mock_generate.assert_called_once_with(models.RPM.TYPE,
                                              self.upload_src_filename,
                                              user_metadata)

        full_unit_key = dict(unit_key)
        full_metadata = dict(metadata)

        full_unit_key.update(user_unit_key)
        full_metadata.update(user_metadata)
        expected_relative_path = models.RPM(metadata=full_metadata, **full_unit_key).relative_path

        mock_conduit.init_unit.assert_called_once_with(models.RPM.TYPE, full_unit_key,
                                                       full_metadata, expected_relative_path)

        mock_nevra.assert_called_once_with(full_unit_key, models.RPM.TYPE, mock_repo.id)

        mock_conduit.save_unit.assert_called_once()
        saved_unit = mock_conduit.save_unit.call_args[0][0]
        self.assertEqual(inited_unit, saved_unit)
Exemplo n.º 14
0
def rpm_models(num, same_name_and_arch=False):
    ret = []
    count = _rpm_counter.next()
    name = 'name-%d' % count
    for i in range(num):
        if not same_name_and_arch:
            name = 'name-%d' % count
        ret.append(
            models.RPM(name, '0', '2.1.%d' % count, '1-1', 'x86_64', 'sha256',
                       'somehash-%d' % count, {}))
        count = _rpm_counter.next()
    return ret
Exemplo n.º 15
0
 def setUp(self):
     super(TestRpmBaseRender, self).setUp()
     self.unit = models.RPM(name='cat',
                            epoch='0',
                            version='1.0',
                            release='1',
                            arch='noarch')
     self.unit.checksum = 'abc123'
     self.unit.checksumtype = 'sha1'
     self.unit.checksums = {'sha1': 'abc123'}
     self.unit.set_repodata('primary', self.PRIMARY_EXCERPT)
     self.unit.set_repodata('other', self.OTHER_EXCERPT)
     self.unit.set_repodata('filelists', self.FILELISTS_EXCERPT)
Exemplo n.º 16
0
    def test_rhel6_real_data(self):
        with open(os.path.join(DATA_DIR, 'RHBA-2010-0836.erratum.xml')) as f:
            errata = packages.package_list_generator(
                f, updateinfo.PACKAGE_TAG, updateinfo.process_package_element)
            errata = list(errata)

        self.assertEqual(len(errata), 1)
        erratum = errata[0]
        self.assertTrue(isinstance(erratum, models.Errata))
        self.assertEqual(erratum.rights, 'Copyright 2010 Red Hat Inc')
        description = """NetworkManager is a system network service that manages network devices and
connections, attempting to keep active network connectivity when available. It
manages Ethernet, wireless, mobile broadband (WWAN), and PPPoE devices, and
provides VPN integration with a variety of different VPN services.

This update fixes the following bug:

* Under certain circumstances, the "Enable Networking" and "Enable Wireless"
menu items in the panel applet may have been insensitive. This error no longer
occurs, and both options are now available as expected. (BZ#638598)

Also, this update adds the following enhancements:

* In enterprise wireless networks, the proactive key caching can now be used
along with the PEAP-GTC authentication mechanism.

* Punjabi translation of the network applet has been updated.

Users are advised to upgrade to these updated packages, which resolve this
issue, and add these enhancements.
"""
        self.assertEqual(erratum.description, description)
        self.assertTrue(erratum.summary is not None)
        self.assertEqual(erratum.errata_id, 'RHBA-2010:0836')
        self.assertEqual(erratum.type, 'bugfix')
        self.assertEqual(erratum.issued, '2010-11-10 00:00:00')
        self.assertEqual(erratum.updated, '2010-11-10 00:00:00')
        self.assertEqual(erratum.reboot_suggested, False)
        self.assertEqual(erratum.severity, '')

        rpms = erratum.rpm_search_dicts
        self.assertEqual(len(rpms), 4)
        for rpm in rpms:
            # make sure all of the correct keys are present
            model = models.RPM(**rpm)
            self.assertEqual(model.checksumtype, 'sha256')
            self.assertTrue(len(model.checksum) > 0)
            self.assertTrue(model.name.startswith('NetworkManager'))
            self.assertEqual(model.version, '0.8.1')
            self.assertEqual(model.release, '5.el6_0.1')
Exemplo n.º 17
0
    def test_download_successful_invalid_checksum_type(
            self, mock_copy, mock_verify_size, mock_validate_checksumtype,
            mock_open):
        self.config.get.return_value = True
        self.report.data = models.RPM()

        mock_validate_checksumtype.side_effect = util.InvalidChecksumType()
        content_listener = listener.PackageListener(self, self.metadata_files)

        with self.assertRaises(util.InvalidChecksumType):
            content_listener.download_succeeded(self.report)

        mock_validate_checksumtype.assert_called_once()
        self.assertFalse(self.progress_report['content'].success.called)
Exemplo n.º 18
0
    def test_fills_requirement_le_true(self):
        """
        Test fills_requirement() with LE that is True.
        """
        rpm_1 = models.RPM(name='firefox',
                           epoch=0,
                           version='23.0.0',
                           release='1',
                           arch='x86_64',
                           checksumtype='sha256',
                           checksum='some_sum')
        rpm_2 = models.RPM(name='firefox',
                           epoch=0,
                           version='23.0.1',
                           release='1',
                           arch='x86_64',
                           checksumtype='sha256',
                           checksum='some_sum')
        requirement = depsolve.Requirement('firefox', 0, '23.0.1', '1',
                                           depsolve.Requirement.LE)

        self.assertEqual(requirement.fills_requirement(rpm_1), True)
        self.assertEqual(requirement.fills_requirement(rpm_2), True)
Exemplo n.º 19
0
    def test_fills_requirement_name_match_versioned(self):
        """
        A package with the name that the unversioned Requirement specifies should meet the
        Requirement.
        """
        rpm = models.RPM(name='firefox',
                         epoch=0,
                         version='23.0',
                         release='1',
                         arch='x86_64',
                         checksumtype='sha256',
                         checksum='some_sum')
        requirement = depsolve.Requirement('firefox')

        self.assertEqual(requirement.fills_requirement(rpm), True)
Exemplo n.º 20
0
    def test_fills_requirement_lt_false(self):
        """
        Test fills_requirement() with LT that is False.
        """
        rpm = models.RPM(name='firefox',
                         epoch=0,
                         version='23.0.2',
                         release='1',
                         arch='x86_64',
                         checksumtype='sha256',
                         checksum='some_sum')
        requirement = depsolve.Requirement('firefox', 0, '23.0.1', '1',
                                           depsolve.Requirement.LT)

        self.assertEqual(requirement.fills_requirement(rpm), False)
Exemplo n.º 21
0
    def setUp(self):
        super(TestRpmBaseRender, self).setUp()
        self.unit = models.RPM(name='cat', epoch='0', version='1.0', release='1', arch='noarch')
        self.unit.checksum = 'abc123'
        self.unit.checksumtype = 'sha1'
        self.unit.checksums = {'sha1': 'abc123'}
        self.unit.repodata['filelists'] = '''
<package arch="noarch" name="cat" pkgid="{{ pkgid }}">
    <version epoch="0" rel="1" ver="1.0" />
    <file>/tmp/cat.txt</file>
</package>'''
        self.unit.repodata['other'] = '''
<package arch="noarch" name="cat" pkgid="{{ pkgid }}">
    <version epoch="0" rel="1" ver="1.0" />
</package>'''
        self.unit.repodata['primary'] = '''
Exemplo n.º 22
0
    def test_download_successful_invalid_checksum_verification(
            self, mock_copy, mock_verify_size, mock_validate_checksumtype,
            mock_verify_checksum, mock_open):
        self.config.get.return_value = True
        self.report.data = models.RPM()

        mock_verify_checksum.side_effect = verification.VerificationException(
            'bad')
        content_listener = listener.PackageListener(self, self.metadata_files)

        with self.assertRaises(verification.VerificationException) as cm:
            content_listener.download_succeeded(self.report)

        self.assertEqual(cm.exception.args[0], 'bad')
        mock_verify_checksum.assert_called_once()
        self.assertFalse(self.progress_report['content'].success.called)
Exemplo n.º 23
0
def rpm_models(num, same_name_and_arch=False):
    ret = []
    count = _rpm_counter.next()
    name = 'name-%d' % count
    for i in range(num):
        if not same_name_and_arch:
            name = 'name-%d' % count
        ret.append(
            models.RPM(name=name,
                       epoch='0',
                       version='2.1.%d' % count,
                       release='1-1',
                       arch='x86_64',
                       checksumtype='sha256',
                       checksum='somehash-%d' % count))
        count = _rpm_counter.next()
    return ret
Exemplo n.º 24
0
    def test___init___sanitizes_checksum_type(self):
        """
        Ensure that __init__() calls sanitize_checksum_type correctly.
        """
        unit_metadata = {
            'name': 'name',
            'epoch': 'epoch',
            'version': 'version',
            'release': 'release',
            'checksumtype': 'sha',
            'checksum': 'checksum'
        }

        # The sha should get changed to sha1
        rpm = models.RPM(**unit_metadata)

        self.assertEqual(rpm.checksumtype, 'sha1')
Exemplo n.º 25
0
    def test_fills_requirement_eq_versioned_true(self):
        """
        Test fille_requirement() when the EQ flag is set and it is versioned for the case when the
        RPM does meet the requirement.
        """
        rpm = models.RPM(name='firefox',
                         epoch=0,
                         version='23.0',
                         release='1',
                         arch='x86_64',
                         checksumtype='sha256',
                         checksum='some_sum')
        requirement = depsolve.Requirement('firefox',
                                           0,
                                           '23.0',
                                           '1',
                                           flags=depsolve.Requirement.EQ)

        self.assertEqual(requirement.fills_requirement(rpm), True)
Exemplo n.º 26
0
    def setUp(self):
        """
        Build some test RPMs with some dependencies.
        """
        self.rpm_0 = models.RPM(
            'firefox', '0', '23.0.0', '1', 'x86_64', 'sha256', 'some_sum',
            {'requires': [{'name': 'xulrunner', 'version': '23.0', 'release': '1',
                           'flags': depsolve.Requirement.GE}],
             'provides': [{'name': 'webbrowser'}]})
        self.rpm_1 = models.RPM(
            'firefox', '0', '23.0.2', '1', 'x86_64', 'sha256', 'some_sum',
            {'requires': [{'name': 'xulrunner', 'version': '23.0', 'release': '1',
                           'flags': depsolve.Requirement.GE}],
             'provides': [{'name': 'webbrowser'}]})
        self.rpm_2 = models.RPM(
            'xulrunner', '0', '23.0.1', '1', 'x86_64', 'sha256', 'some_sum',
            {'requires': [{'name': 'sqlite', 'version': '3.7.17',
                           'flags': depsolve.Requirement.GE}]})
        self.rpm_3 = models.RPM(
            'sqlite', '0', '3.7.17', '1', 'x86_64', 'sha256', 'some_sum',
            {'requires': []})
        # Nothing depends on this one, so it shouldn't be returned by anything
        self.rpm_4 = models.RPM(
            'gnome-calculator', '0', '3.8.2', '1', 'x86_64', 'sha256', 'some_sum',
            {'requires': [{'name': 'glib2'}],
             'provides': [{'name': 'calculator'}]})
        self.rpm_5 = models.RPM(
            'glib2', '0', '2.36.3', '3', 'x86_64', 'sha256', 'some_sum',
            {'requires': []})
        self.rpm_6 = models.RPM(
            'gcalctool', '0', '5.28.2', '3', 'x86_64', 'sha256', 'some_sum',
            {'requires': [],
             'provides': [{'name': 'calculator'}]})
        self.rpms = [getattr(self, 'rpm_%s' % i) for i in range(7)]

        self._make_units(self.rpms)

        self.mock_search = mock.MagicMock()
        self.solver = depsolve.Solver(self.mock_search)
Exemplo n.º 27
0
 def setUp(self):
     self.unit = models.RPM()
     self.unit.repodata['primary'] = self.PRIMARY_EXCERPT
     self.unit.repodata['filelists'] = self.FILELISTS_EXCERPT
     self.unit.repodata['other'] = self.OTHER_EXCERPT
Exemplo n.º 28
0
 def setUp(self):
     self.unit = models.RPM()
     self.unit.repodata['primary'] = self.PRIMARY_XML
     self.unit.filename = 'fixed-filename.rpm'
Exemplo n.º 29
0
def process_package_element(package_element):
    """
    Process a parsed primary.xml package element into a model instance.

    In addition to parsing the data, this templatizes the raw XML that gets added.

    :param package_element: parsed primary.xml package element
    :return: package information dictionary
    :rtype: pulp_rpm.plugins.db.models.RPM
    """
    # NOTE the use of deepcopy relies on cpython's very sensible policy of never
    # duplicating string literals, this may not hold up in other implementations
    # the python interpreter.
    package_info = dict()

    name_element = package_element.find(NAME_TAG)
    if name_element is not None:
        package_info['name'] = name_element.text

    arch_element = package_element.find(ARCH_TAG)
    if arch_element is not None:
        package_info['arch'] = arch_element.text

    version_element = package_element.find(VERSION_TAG)
    if version_element is not None:
        package_info['version'] = version_element.attrib['ver']
        package_info['release'] = version_element.attrib.get('rel', None)
        package_info['epoch'] = version_element.attrib.get('epoch', None)

    checksum_element = package_element.find(CHECKSUM_TAG)
    if checksum_element is not None:
        checksum_type = util.sanitize_checksum_type(checksum_element.attrib['type'])
        package_info['checksumtype'] = checksum_type
        package_info['checksum'] = checksum_element.text

        # convert these to template targets that will be rendered at publish time
        checksum_element.text = models.RpmBase.CHECKSUM_TEMPLATE
        checksum_element.attrib['type'] = models.RpmBase.CHECKSUMTYPE_TEMPLATE

    summary_element = package_element.find(SUMMARY_TAG)
    if summary_element is not None:
        package_info['summary'] = summary_element.text

    description_element = package_element.find(DESCRIPTION_TAG)
    if description_element is not None:
        package_info['description'] = description_element.text

    url_element = package_element.find(URL_TAG)
    if url_element is not None:
        package_info['url'] = url_element.text

    time_element = package_element.find(TIME_TAG)
    if time_element is not None:
        package_info['time'] = int(time_element.attrib['file'])
        package_info['build_time'] = int(time_element.attrib['build'])

    size_element = package_element.find(SIZE_TAG)
    if size_element is not None:
        package_info['size'] = int(size_element.attrib['package'])

    location_element = package_element.find(LOCATION_TAG)
    if location_element is not None:
        href = location_element.attrib['href']
        base_url = None
        for attribute, value in location_element.items():
            if attribute == 'base' or attribute.endswith('}base'):
                base_url = value
        package_info['base_url'] = base_url
        filename = os.path.basename(href)
        package_info['relativepath'] = href
        package_info['filename'] = filename
        # we don't make any attempt to preserve the original directory structure
        # this element will end up being converted back to XML and stuffed into
        # the DB on the unit object, so this  is our chance to modify it.
        location_element.attrib['href'] = filename

    format_element = package_element.find(FORMAT_TAG)
    package_info.update(_process_format_element(format_element))

    if package_info['arch'].lower() == 'src':
        model = models.SRPM(**package_info)
    else:
        model = models.RPM(**package_info)
    # add the raw XML so it can be saved in the database later
    rpm_namespace = utils.Namespace('rpm', RPM_SPEC_URL)
    model.raw_xml = utils.element_to_raw_xml(package_element, [rpm_namespace], COMMON_SPEC_URL)
    return model