Example #1
0
    def test_rpms_applicable_to_consumer(self):
        errata_rpms = []
        prof = YumProfiler()
        applicable_rpms, old_rpms = prof._rpms_applicable_to_consumer(
            Consumer("test", {}), errata_rpms)
        self.assertEqual(applicable_rpms, [])
        self.assertEqual(old_rpms, {})

        # Get rpm dictionaries embedded in an errata
        errata_obj = self.get_test_errata_object()
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]},
                           errata_obj, None)
        errata_rpms = prof._get_rpms_from_errata(errata_unit)
        # Test with 2 newer RPMs in the test errata
        # The consumer has already been configured with a profile containing 'emoticons' and
        # 'patb' rpms
        applicable_rpms, old_rpms = prof._rpms_applicable_to_consumer(
            self.test_consumer, errata_rpms)
        self.assertTrue(applicable_rpms)
        self.assertTrue(old_rpms)
        self.assertEqual(len(applicable_rpms), 2)
        self.assertTrue("emoticons x86_64" in old_rpms)
        self.assertEqual("emoticons",
                         old_rpms["emoticons x86_64"]["installed"]["name"])
        self.assertEqual("0.1",
                         old_rpms["emoticons x86_64"]["installed"]["version"])
 def test_install_units(self):
     repo_id = "test_repo_id"
     errata_obj = self.get_test_errata_object()
     errata_unit = Unit(TYPE_ID_ERRATA, {"id":errata_obj["id"]}, errata_obj, None)
     existing_units = [errata_unit]
     test_repo = profiler_mocks.get_repo(repo_id)
     conduit = profiler_mocks.get_profiler_conduit(existing_units=existing_units,
                                                   repo_bindings=[test_repo])
     example_errata = {"unit_key":errata_unit.unit_key, "type_id":TYPE_ID_ERRATA}
     prof = YumProfiler()
     translated_units  = prof.install_units(self.test_consumer, [example_errata], None, None,
                                            conduit)
     # check repo_id passed to the conduit get_units()
     self.assertEqual(conduit.get_units.call_args[0][0].id, repo_id)
     # check unit association criteria passed to the conduit get_units()
     self.assertEqual(conduit.get_units.call_args[0][1].type_ids, [TYPE_ID_ERRATA])
     self.assertEqual(conduit.get_units.call_args[0][1].unit_filters, errata_unit.unit_key)
     # validate translated units
     self.assertEqual(len(translated_units), 2)
     expected = []
     for r in prof._get_rpms_from_errata(errata_unit):
         expected_name = "%s-%s:%s-%s.%s" % (r["name"], r["epoch"], r["version"], r["release"],
                                             r["arch"])
         expected.append(expected_name)
     for u in translated_units:
         rpm_name = u["unit_key"]["name"]
         self.assertTrue(rpm_name in expected)
Example #3
0
    def test_update_profile_presorted_profile(self):
        """
        Test the update_profile() method with a presorted profile. It should not alter it at all.
        """
        profile = [
            {'name': 'Package A', 'epoch': 0, 'version': '1.0.1', 'release': '2.el6',
             'arch': 'x86_64', 'vendor': 'Red Hat, Inc.'},
            {'name': 'Package A', 'epoch': 0, 'version': '1.1.0', 'release': '1.el6',
             'arch': 'x86_64', 'vendor': 'Red Hat, Inc.'},
            {'name': 'Package B', 'epoch': 0, 'version': '2.3.9', 'release': '1.el6',
             'arch': 'x86_64', 'vendor': 'Red Hat, Inc.'},
            {'name': 'Package B', 'epoch': 1, 'version': '1.2.1', 'release': '8.el6',
             'arch': 'x86_64', 'vendor': 'Red Hat, Inc.'},
            {'name': 'Package C', 'epoch': 0, 'version': '1.0.0', 'release': '1.el6',
             'arch': 'x86_64', 'vendor': 'Red Hat, Inc.'},
            {'name': 'Package C', 'epoch': 0, 'version': '1.0.0', 'release': '2.el6',
             'arch': 'x86_64', 'vendor': 'Red Hat, Inc.'},
        ]
        profiler = YumProfiler()

        # The update_profile() method doesn't use any of the args except for profile and
        # content_type, so we'll just pass in strings for the others
        new_profile = profiler.update_profile('consumer', TYPE_ID_RPM, deepcopy(profile), 'config')

        self.assertEqual(new_profile, profile)
Example #4
0
    def test_unit_applicable(self):
        # Errata refers to RPMs which ARE part of our test consumer's profile,
        # AND in the repo.
        errata_obj = self.get_test_errata_object()
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]},
                           errata_obj, None)
        errata_unit.id = 'an_errata'

        rpm_unit_key = self.create_profile_entry("emoticons", 0, "0.1", "2",
                                                 "x86_64", "Test Vendor")
        rpm_unit = Unit(TYPE_ID_RPM, rpm_unit_key, {}, None)
        # Let's give it an id, so we can assert for it later
        rpm_unit.id = 'a_test_id'

        test_repo = profiler_mocks.get_repo("test_repo_id")

        prof = YumProfiler()
        errata_rpms = prof._get_rpms_from_errata(errata_unit)
        conduit = profiler_mocks.get_profiler_conduit(
            repo_units=[errata_unit, rpm_unit],
            repo_bindings=[test_repo],
            errata_rpms=errata_rpms)
        unit_profile = self.test_consumer.profiles[TYPE_ID_RPM]
        bound_repo_id = "test_repo_id"
        report_list = prof.calculate_applicable_units(unit_profile,
                                                      bound_repo_id, None,
                                                      conduit)
        self.assertEqual(report_list, {
            TYPE_ID_RPM: ['a_test_id'],
            TYPE_ID_ERRATA: ['an_errata']
        })
Example #5
0
    def test_install_units_with_rpms(self):
        """
        Make sure install_units() can handle being given RPMs.
        """
        rpms = [{"name": "rpm_1", "type_id": TYPE_ID_RPM}, {"name": "rpm_2", "type_id": TYPE_ID_RPM}]
        profiler = YumProfiler()

        translated_units = profiler.install_units("consumer", deepcopy(rpms), None, None, "conduit")

        # The RPMs should be unaltered
        self.assertEqual(translated_units, rpms)
Example #6
0
    def test_unit_applicable_false(self):
        rpm_unit_key = self.create_profile_entry("bla-bla", 0, "0.1", "2", "x86_64", "Test Vendor")
        rpm_unit = Unit(TYPE_ID_RPM, rpm_unit_key, {}, None)
        test_repo = profiler_mocks.get_repo("test_repo_id")
        conduit = profiler_mocks.get_profiler_conduit(repo_units=[rpm_unit], repo_bindings=[test_repo])

        prof = YumProfiler()
        unit_profile = self.test_consumer.profiles[TYPE_ID_RPM]
        bound_repo_id = "test_repo_id"
        report_list = prof.calculate_applicable_units(unit_profile, bound_repo_id, None, conduit)
        self.assertEqual(report_list, {TYPE_ID_RPM: [], TYPE_ID_ERRATA: []})
Example #7
0
    def test_rpm_applicable_to_consumer(self):
        rpm = {}
        prof = YumProfiler()
        applicable = prof._is_rpm_applicable(rpm, {})
        self.assertEqual(applicable, False)

        # Test with newer RPM
        # The consumer has already been configured with a profile containing 'emoticons'
        rpm = self.create_profile_entry("emoticons", 0, "0.1", "2", "x86_64", "Test Vendor")
        applicable = prof._is_rpm_applicable(rpm, self.test_consumer_lookup)
        self.assertTrue(applicable)
Example #8
0
    def test_install_units(self):
        """
        Verify that all available packages in the erratum are installed

        In this test, there are two packages in the erratum, and both are
        available to the consumer. Thus, both should be installed.
        """
        repo_id = "test_repo_id"
        errata_obj = self.get_test_errata_object()
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]},
                           errata_obj, None)
        existing_units = [errata_unit]
        test_repo = profiler_mocks.get_repo(repo_id)

        # create two RPM units that match what is in the erratum
        rpm_units = []
        rpm_unit_key_1 = self.create_profile_entry("emoticons", 0, "0.1", "2",
                                                   "x86_64", "Test Vendor")
        rpm_units.append(Unit(TYPE_ID_RPM, rpm_unit_key_1, {}, None))

        rpm_unit_key_2 = self.create_profile_entry("patb", 0, "0.1", "2",
                                                   "x86_64", "Test Vendor")
        rpm_units.append(Unit(TYPE_ID_RPM, rpm_unit_key_2, {}, None))

        existing_units += rpm_units

        conduit = profiler_mocks.get_profiler_conduit(
            existing_units=existing_units,
            repo_bindings=[test_repo],
            repo_units=rpm_units)

        example_errata = {
            "unit_key": errata_unit.unit_key,
            "type_id": TYPE_ID_ERRATA
        }
        prof = YumProfiler()
        translated_units = prof.install_units(self.test_consumer,
                                              [example_errata], None, None,
                                              conduit)
        # check repo_id passed to the conduit get_units()
        self.assertEqual(conduit.get_units.call_args[0][0].id, repo_id)
        # check unit association criteria passed to the conduit get_units()
        self.assertEqual(conduit.get_units.call_args_list[0][0][1].type_ids,
                         [TYPE_ID_ERRATA])
        self.assertEqual(
            conduit.get_units.call_args_list[0][0][1].unit_filters,
            errata_unit.unit_key)
        # validate translated units
        self.assertEqual(len(translated_units), 2)
        expected = prof._get_rpms_from_errata(errata_unit)
        for u in translated_units:
            rpm_unit_key = u["unit_key"]
            self.assertTrue(rpm_unit_key in expected)
Example #9
0
    def test_rpm_applicable_to_consumer(self):
        rpm = {}
        prof = YumProfiler()
        applicable = prof._is_rpm_applicable(rpm, {})
        self.assertEqual(applicable, False)

        # Test with newer RPM
        # The consumer has already been configured with a profile containing 'emoticons'
        rpm = self.create_profile_entry("emoticons", 0, "0.1", "2", "x86_64",
                                        "Test Vendor")
        applicable = prof._is_rpm_applicable(rpm, self.test_consumer_lookup)
        self.assertTrue(applicable)
Example #10
0
    def test_update_profile_with_errata(self):
        """
        Test the update_profile() method with a presorted profile. It should not alter it at all.
        """
        profile = ["one_errata", "two_errata", "three_errata", "four_errata"]
        profiler = YumProfiler()

        # The update_profile() method doesn't use any of the args except for profile and
        # content_type, so we'll just pass in strings for the others
        # This test just asserts that the profile is returned unaltered
        new_profile = profiler.update_profile("consumer", TYPE_ID_ERRATA, deepcopy(profile), "config")

        self.assertEqual(new_profile, profile)
Example #11
0
    def test_unit_applicable_true(self):
        rpm_unit_key = self.create_profile_entry("emoticons", 0, "0.1", "2", "x86_64", "Test Vendor")
        rpm_unit = Unit(TYPE_ID_RPM, rpm_unit_key, {}, None)
        # Let's give it an id, so we can assert for it later
        rpm_unit.id = "a_test_id"
        test_repo = profiler_mocks.get_repo("test_repo_id")
        conduit = profiler_mocks.get_profiler_conduit(repo_units=[rpm_unit], repo_bindings=[test_repo])

        prof = YumProfiler()
        unit_profile = self.test_consumer.profiles[TYPE_ID_RPM]
        bound_repo_id = "test_repo_id"
        report_list = prof.calculate_applicable_units(unit_profile, bound_repo_id, None, conduit)
        self.assertEqual(report_list, {TYPE_ID_RPM: [rpm_unit.id], TYPE_ID_ERRATA: []})
Example #12
0
    def test_install_units_with_rpms(self):
        """
        Make sure install_units() can handle being given RPMs.
        """
        rpms = [{'name': 'rpm_1', 'type_id': TYPE_ID_RPM},
                {'name': 'rpm_2', 'type_id': TYPE_ID_RPM}]
        profiler = YumProfiler()

        translated_units = profiler.install_units('consumer', deepcopy(rpms), None, None,
                                                  'conduit')

        # The RPMs should be unaltered
        self.assertEqual(translated_units, rpms)
Example #13
0
    def test_update_profile_with_errata(self):
        """
        Test the update_profile() method with a presorted profile. It should not alter it at all.
        """
        profile = ['one_errata', 'two_errata', 'three_errata', 'four_errata']
        profiler = YumProfiler()

        # The update_profile() method doesn't use any of the args except for profile and
        # content_type, so we'll just pass in strings for the others
        # This test just asserts that the profile is returned unaltered
        new_profile = profiler.update_profile('consumer', TYPE_ID_ERRATA,
                                              deepcopy(profile), 'config')

        self.assertEqual(new_profile, profile)
Example #14
0
    def test_unit_applicable_false(self):
        rpm_unit_key = self.create_profile_entry("bla-bla", 0, "0.1", "2",
                                                 "x86_64", "Test Vendor")
        rpm_unit = Unit(TYPE_ID_RPM, rpm_unit_key, {}, None)
        test_repo = profiler_mocks.get_repo("test_repo_id")
        conduit = profiler_mocks.get_profiler_conduit(
            repo_units=[rpm_unit], repo_bindings=[test_repo])

        prof = YumProfiler()
        unit_profile = self.test_consumer.profiles[TYPE_ID_RPM]
        bound_repo_id = "test_repo_id"
        report_list = prof.calculate_applicable_units(unit_profile,
                                                      bound_repo_id, None,
                                                      conduit)
        self.assertEqual(report_list, {TYPE_ID_RPM: [], TYPE_ID_ERRATA: []})
Example #15
0
    def test_unit_applicable_false(self):
        # Errata refers to RPMs which are NOT part of our test consumer's profile
        errata_obj = self.get_test_errata_object_unrelated()
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]}, errata_obj, None)
        test_repo = profiler_mocks.get_repo("test_repo_id")

        prof = YumProfiler()
        errata_rpms = prof._get_rpms_from_errata(errata_unit)
        conduit = profiler_mocks.get_profiler_conduit(repo_units=[errata_unit],
                                                      repo_bindings=[test_repo],
                                                      errata_rpms=errata_rpms)
        unit_profile = self.test_consumer.profiles[TYPE_ID_RPM]
        bound_repo_id = "test_repo_id"
        report_list = prof.calculate_applicable_units(unit_profile, bound_repo_id, None, conduit)
        self.assertEqual(report_list, {TYPE_ID_ERRATA: [], TYPE_ID_RPM: []})
Example #16
0
 def test_rpm_applicable_with_profile_containing_duplicate_packages(self):
     """
     If a consumer profile contains multiple rpms with same name and arch (eg. in case of
     kernel rpms), make sure that the applicability calculations take into consideration
     the newest rpm installed.
     """
     consumer_profile = self.get_test_profile_with_duplicate_packages()
     test_consumer_lookup = YumProfiler._form_lookup_table(consumer_profile[TYPE_ID_RPM])
     rpm = self.create_profile_entry("patb", 0, "0.0.2", "1", "x86_64", "Test Vendor")
     yum_profiler = YumProfiler()
     applicable = yum_profiler._is_rpm_applicable(rpm, test_consumer_lookup)
     self.assertFalse(applicable)
     newer_rpm = self.create_profile_entry("patb", 0, "0.0.3", "1", "x86_64", "Test Vendor")
     applicable = yum_profiler._is_rpm_applicable(newer_rpm, test_consumer_lookup)
     self.assertTrue(applicable)
Example #17
0
    def test_unit_applicable_updated_rpm_already_installed(self):
        # Errata refers to RPMs already installed, i.e. the consumer has these exact NEVRA already
        errata_obj = self.get_test_errata_object()
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]}, errata_obj, None)
        test_repo = profiler_mocks.get_repo("test_repo_id")

        prof = YumProfiler()
        errata_rpms = prof._get_rpms_from_errata(errata_unit)
        conduit = profiler_mocks.get_profiler_conduit(repo_units=[errata_unit],
                                                      repo_bindings=[test_repo],
                                                      errata_rpms=errata_rpms)
        unit_profile = self.test_consumer_been_updated.profiles[TYPE_ID_RPM]
        bound_repo_id = "test_repo_id"
        report_list = prof.calculate_applicable_units(unit_profile, bound_repo_id, None, conduit)
        self.assertEqual(report_list, {TYPE_ID_RPM: [], TYPE_ID_ERRATA: []})
Example #18
0
    def test__translate_erratum_returns_unit_keys(
            self, _rpms_applicable_to_consumer):
        """
        The agent handler is expecting to be given a unit key, and we had a bug[0] wherein it was
        being given only 'name' in the unit key, with all of the other "EVRA" fields being written
        into it. This test asserts that the first element of the return value of the
        _translate_erratum() method has full unit keys.

        [0] https://bugzilla.redhat.com/show_bug.cgi?id=1097434
        """
        unit = mock.MagicMock()
        repo_ids = ['repo_1', 'repo_2']
        consumer = mock.MagicMock()
        conduit = mock.MagicMock()
        # Mock there being an applicable RPM
        applicable_unit_key = {
            'name': 'a_name',
            'epoch': '0',
            'version': '2.0.1',
            'release': '2',
            'arch': 'x86_64'
        }
        _rpms_applicable_to_consumer.return_value = ([applicable_unit_key],
                                                     mock.MagicMock())

        rpms, details = YumProfiler._translate_erratum(unit, repo_ids,
                                                       consumer, conduit)

        expected_rpms = [{
            'unit_key': applicable_unit_key,
            'type_id': TYPE_ID_RPM
        }]
        self.assertEqual(rpms, expected_rpms)
Example #19
0
    def test_unit_applicable_same_name_diff_arch(self):
        # Errata refers to RPMs that are x86_64, the test consumer is i386
        # the rpms installed share the same name as the errata, but the client arch is different
        # so this errata is marked as unapplicable
        errata_obj = self.get_test_errata_object()
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]}, errata_obj, None)
        test_repo = profiler_mocks.get_repo("test_repo_id")

        prof = YumProfiler()
        errata_rpms = prof._get_rpms_from_errata(errata_unit)
        conduit = profiler_mocks.get_profiler_conduit(repo_units=[errata_unit],
                                                      repo_bindings=[test_repo],
                                                      errata_rpms=errata_rpms)
        unit_profile = self.test_consumer_i386.profiles[TYPE_ID_RPM]
        bound_repo_id = "test_repo_id"
        report_list = prof.calculate_applicable_units(unit_profile, bound_repo_id, None, conduit)
        self.assertEqual(report_list, {TYPE_ID_RPM: [], TYPE_ID_ERRATA: []})
Example #20
0
    def test_install_units_with_rpms(self):
        """
        Make sure install_units() can handle being given RPMs.
        """
        rpms = [{
            'name': 'rpm_1',
            'type_id': TYPE_ID_RPM
        }, {
            'name': 'rpm_2',
            'type_id': TYPE_ID_RPM
        }]
        profiler = YumProfiler()

        translated_units = profiler.install_units('consumer', deepcopy(rpms),
                                                  None, None, 'conduit')

        # The RPMs should be unaltered
        self.assertEqual(translated_units, rpms)
Example #21
0
    def test_install_units(self):
        """
        Verify that all available packages in the erratum are installed

        In this test, there are two packages in the erratum, and both are
        available to the consumer. Thus, both should be installed.
        """
        repo_id = "test_repo_id"
        errata_obj = self.get_test_errata_object()
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]}, errata_obj, None)
        existing_units = [errata_unit]
        test_repo = profiler_mocks.get_repo(repo_id)

        # create two RPM units that match what is in the erratum
        rpm_units = []
        rpm_unit_key_1 = self.create_profile_entry("emoticons", 0, "0.1", "2", "x86_64",
                                                   "Test Vendor")
        rpm_units.append(Unit(TYPE_ID_RPM, rpm_unit_key_1, {}, None))

        rpm_unit_key_2 = self.create_profile_entry("patb", 0, "0.1", "2", "x86_64", "Test Vendor")
        rpm_units.append(Unit(TYPE_ID_RPM, rpm_unit_key_2, {}, None))

        existing_units += rpm_units

        conduit = profiler_mocks.get_profiler_conduit(existing_units=existing_units,
                                                      repo_bindings=[test_repo],
                                                      repo_units=rpm_units)

        example_errata = {"unit_key": errata_unit.unit_key, "type_id": TYPE_ID_ERRATA}
        prof = YumProfiler()
        translated_units = prof.install_units(self.test_consumer, [example_errata], None, None,
                                              conduit)
        # check repo_id passed to the conduit get_units()
        self.assertEqual(conduit.get_units.call_args[0][0].id, repo_id)
        # check unit association criteria passed to the conduit get_units()
        self.assertEqual(conduit.get_units.call_args_list[0][0][1].type_ids, [TYPE_ID_ERRATA])
        self.assertEqual(conduit.get_units.call_args_list[0][0][1].unit_filters,
                         errata_unit.unit_key)
        # validate translated units
        self.assertEqual(len(translated_units), 2)
        expected = prof._get_rpms_from_errata(errata_unit)
        for u in translated_units:
            rpm_unit_key = u["unit_key"]
            self.assertTrue(rpm_unit_key in expected)
Example #22
0
    def test_unit_applicable_false(self):
        # Errata refers to RPMs which are NOT part of our test consumer's profile
        errata_obj = self.get_test_errata_object_unrelated()
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]},
                           errata_obj, None)
        test_repo = profiler_mocks.get_repo("test_repo_id")

        prof = YumProfiler()
        errata_rpms = prof._get_rpms_from_errata(errata_unit)
        conduit = profiler_mocks.get_profiler_conduit(
            repo_units=[errata_unit],
            repo_bindings=[test_repo],
            errata_rpms=errata_rpms)
        unit_profile = self.test_consumer.profiles[TYPE_ID_RPM]
        bound_repo_id = "test_repo_id"
        report_list = prof.calculate_applicable_units(unit_profile,
                                                      bound_repo_id, None,
                                                      conduit)
        self.assertEqual(report_list, {TYPE_ID_ERRATA: [], TYPE_ID_RPM: []})
Example #23
0
    def test_unit_applicable_updated_rpm_already_installed(self):
        # Errata refers to RPMs already installed, i.e. the consumer has these exact NEVRA already
        errata_obj = self.get_test_errata_object()
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]},
                           errata_obj, None)
        test_repo = profiler_mocks.get_repo("test_repo_id")

        prof = YumProfiler()
        errata_rpms = prof._get_rpms_from_errata(errata_unit)
        conduit = profiler_mocks.get_profiler_conduit(
            repo_units=[errata_unit],
            repo_bindings=[test_repo],
            errata_rpms=errata_rpms)
        unit_profile = self.test_consumer_been_updated.profiles[TYPE_ID_RPM]
        bound_repo_id = "test_repo_id"
        report_list = prof.calculate_applicable_units(unit_profile,
                                                      bound_repo_id, None,
                                                      conduit)
        self.assertEqual(report_list, {TYPE_ID_RPM: [], TYPE_ID_ERRATA: []})
Example #24
0
 def test_form_lookup_table(self):
     """
     Test that form_lookup_table creates a table with the latest rpm in the profile as a value
     corresponding to the rpm name and arch.
     """
     test_profile = self.get_test_profile_with_duplicate_packages()
     consumer_lookup = YumProfiler._form_lookup_table(test_profile[TYPE_ID_RPM])
     self.assertEqual(len(consumer_lookup), 2)
     self.assertEqual(consumer_lookup['patb x86_64'],
                      self.create_profile_entry("patb", 0, "0.0.2", "1", "x86_64", "Test Vendor"))
Example #25
0
 def test_rpm_applicable_with_profile_containing_duplicate_packages(self):
     """
     If a consumer profile contains multiple rpms with same name and arch (eg. in case of
     kernel rpms), make sure that the applicability calculations take into consideration
     the newest rpm installed.
     """
     consumer_profile = self.get_test_profile_with_duplicate_packages()
     test_consumer_lookup = YumProfiler._form_lookup_table(
         consumer_profile[TYPE_ID_RPM])
     rpm = self.create_profile_entry("patb", 0, "0.0.2", "1", "x86_64",
                                     "Test Vendor")
     yum_profiler = YumProfiler()
     applicable = yum_profiler._is_rpm_applicable(rpm, test_consumer_lookup)
     self.assertFalse(applicable)
     newer_rpm = self.create_profile_entry("patb", 0, "0.0.3", "1",
                                           "x86_64", "Test Vendor")
     applicable = yum_profiler._is_rpm_applicable(newer_rpm,
                                                  test_consumer_lookup)
     self.assertTrue(applicable)
Example #26
0
    def test_unit_applicable_true(self):
        rpm_unit_key = self.create_profile_entry("emoticons", 0, "0.1", "2",
                                                 "x86_64", "Test Vendor")
        rpm_unit = Unit(TYPE_ID_RPM, rpm_unit_key, {}, None)
        # Let's give it an id, so we can assert for it later
        rpm_unit.id = 'a_test_id'
        test_repo = profiler_mocks.get_repo("test_repo_id")
        conduit = profiler_mocks.get_profiler_conduit(
            repo_units=[rpm_unit], repo_bindings=[test_repo])

        prof = YumProfiler()
        unit_profile = self.test_consumer.profiles[TYPE_ID_RPM]
        bound_repo_id = "test_repo_id"
        report_list = prof.calculate_applicable_units(unit_profile,
                                                      bound_repo_id, None,
                                                      conduit)
        self.assertEqual(report_list, {
            TYPE_ID_RPM: [rpm_unit.id],
            TYPE_ID_ERRATA: []
        })
Example #27
0
    def test_create_nevra(self):
        rpm = {'name': "foo",
               'epoch': 0,
               'version': '1',
               'release': '5',
               'arch': '8088',
               'extra_field': 'extra'}

        result = YumProfiler._create_nevra(rpm)
        self.assertEquals(result, {'name': 'foo', 'epoch': '0', 'version': '1',
                                   'release': '5', 'arch': '8088'})
Example #28
0
    def test_rpms_applicable_to_consumer(self):
        errata_rpms = []
        prof = YumProfiler()
        applicable_rpms, old_rpms = prof._rpms_applicable_to_consumer(Consumer("test", {}), errata_rpms)
        self.assertEqual(applicable_rpms, [])
        self.assertEqual(old_rpms, {})

        # Get rpm dictionaries embedded in an errata
        errata_obj = self.get_test_errata_object()
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]}, errata_obj, None)
        errata_rpms = prof._get_rpms_from_errata(errata_unit)
        # Test with 2 newer RPMs in the test errata
        # The consumer has already been configured with a profile containing 'emoticons' and
        # 'patb' rpms
        applicable_rpms, old_rpms = prof._rpms_applicable_to_consumer(self.test_consumer, errata_rpms)
        self.assertTrue(applicable_rpms)
        self.assertTrue(old_rpms)
        self.assertEqual(len(applicable_rpms), 2)
        self.assertTrue("emoticons x86_64" in old_rpms)
        self.assertEqual("emoticons", old_rpms["emoticons x86_64"]["installed"]["name"])
        self.assertEqual("0.1", old_rpms["emoticons x86_64"]["installed"]["version"])
Example #29
0
    def test_unit_applicable_same_name_diff_arch(self):
        # Errata refers to RPMs that are x86_64, the test consumer is i386
        # the rpms installed share the same name as the errata, but the client arch is different
        # so this errata is marked as unapplicable
        errata_obj = self.get_test_errata_object()
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]},
                           errata_obj, None)
        test_repo = profiler_mocks.get_repo("test_repo_id")

        prof = YumProfiler()
        errata_rpms = prof._get_rpms_from_errata(errata_unit)
        conduit = profiler_mocks.get_profiler_conduit(
            repo_units=[errata_unit],
            repo_bindings=[test_repo],
            errata_rpms=errata_rpms)
        unit_profile = self.test_consumer_i386.profiles[TYPE_ID_RPM]
        bound_repo_id = "test_repo_id"
        report_list = prof.calculate_applicable_units(unit_profile,
                                                      bound_repo_id, None,
                                                      conduit)
        self.assertEqual(report_list, {TYPE_ID_RPM: [], TYPE_ID_ERRATA: []})
Example #30
0
    def test_create_nevra(self):
        rpm = {
            'name': "foo",
            'epoch': 0,
            'version': '1',
            'release': '5',
            'arch': '8088',
            'extra_field': 'extra'
        }

        result = YumProfiler._create_nevra(rpm)
        self.assertEquals(result, ('foo', '0', '1', '5', '8088'))
Example #31
0
 def test_get_rpms_from_errata(self):
     errata_obj = self.get_test_errata_object()
     errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]}, errata_obj, None)
     prof = YumProfiler()
     rpms = prof._get_rpms_from_errata(errata_unit)
     # Expected data:
     # [{'src': 'xen-3.0.3-80.el5_3.3.src.rpm', 'name': 'emoticons',
     # 'sum': ('md5', '366bb5e73a5905eacb82c96e0578f92b'),
     #   'filename': 'emoticons-0.1-2.x86_64.rpm', 'epoch': '0',
     #   'version': '0.1', 'release': '2', 'arch': 'x86_64'},
     # {'src': 'xen-3.0.3-80.el5_3.3.src.rpm', 'name': 'patb',
     #   'sum': ('md5', 'f3c197a29d9b66c5b65c5d62b25db5b4'),
     #   'filename': 'patb-0.1-2.x86_64.rpm', 'epoch': '0'
     #   'version': '0.1', 'release': '2', 'arch': 'x86_64'}]
     self.assertEqual(len(rpms), 2)
     self.assertTrue(rpms[0]["name"] in ['emoticons', 'patb'])
     self.assertTrue(rpms[1]["name"] in ['emoticons', 'patb'])
     for r in rpms:
         for key in ["name", "filename", "epoch", "version", "release"]:
             self.assertTrue(key in r)
             self.assertTrue(r[key])
Example #32
0
 def test_get_rpms_from_errata(self):
     errata_obj = self.get_test_errata_object()
     errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]},
                        errata_obj, None)
     prof = YumProfiler()
     rpms = prof._get_rpms_from_errata(errata_unit)
     # Expected data:
     # [{'src': 'xen-3.0.3-80.el5_3.3.src.rpm', 'name': 'emoticons',
     # 'sum': ('md5', '366bb5e73a5905eacb82c96e0578f92b'),
     #   'filename': 'emoticons-0.1-2.x86_64.rpm', 'epoch': '0',
     #   'version': '0.1', 'release': '2', 'arch': 'x86_64'},
     # {'src': 'xen-3.0.3-80.el5_3.3.src.rpm', 'name': 'patb',
     #   'sum': ('md5', 'f3c197a29d9b66c5b65c5d62b25db5b4'),
     #   'filename': 'patb-0.1-2.x86_64.rpm', 'epoch': '0'
     #   'version': '0.1', 'release': '2', 'arch': 'x86_64'}]
     self.assertEqual(len(rpms), 2)
     self.assertTrue(rpms[0]["name"] in ['emoticons', 'patb'])
     self.assertTrue(rpms[1]["name"] in ['emoticons', 'patb'])
     for r in rpms:
         for key in ["name", "filename", "epoch", "version", "release"]:
             self.assertTrue(key in r)
             self.assertTrue(r[key])
Example #33
0
 def test_metadata(self):
     """
     Test the metadata() method.
     """
     data = YumProfiler.metadata()
     self.assertTrue("id" in data)
     self.assertEquals(data['id'], YumProfiler.TYPE_ID)
     self.assertTrue("display_name" in data)
     # Make sure the advertised types are RPM and Errata
     self.assertTrue('types' in data)
     self.assertEqual(len(data['types']), 2)
     self.assertTrue(TYPE_ID_RPM in data["types"])
     self.assertTrue(TYPE_ID_ERRATA in data["types"])
Example #34
0
 def test_metadata(self):
     """
     Test the metadata() method.
     """
     data = YumProfiler.metadata()
     self.assertTrue("id" in data)
     self.assertEquals(data['id'], YumProfiler.TYPE_ID)
     self.assertTrue("display_name" in data)
     # Make sure the advertised types are RPM and Errata
     self.assertTrue('types' in data)
     self.assertEqual(len(data['types']), 2)
     self.assertTrue(TYPE_ID_RPM in data["types"])
     self.assertTrue(TYPE_ID_ERRATA in data["types"])
Example #35
0
    def test_unit_not_applicable_not_in_repo(self, m_get_unique_pkglists):
        # Errata refers to RPMs which ARE part of our test consumer's profile,
        # but are not in the repo.
        errata_obj = self.get_test_errata_object()
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]},
                           errata_obj, None)
        errata_unit.id = 'an_errata'
        errata_rpms = errata_obj.pkglist[0]['packages']
        m_get_unique_pkglists.return_value = [[errata_rpms]]
        test_repo = profiler_mocks.get_repo("test_repo_id")

        prof = YumProfiler()
        conduit = profiler_mocks.get_profiler_conduit(
            repo_units=[errata_unit],
            repo_bindings=[test_repo],
            errata_rpms=errata_rpms)
        unit_profile = self.test_consumer.profiles[TYPE_ID_RPM]
        bound_repo_id = "test_repo_id"
        report_list = prof.calculate_applicable_units(unit_profile,
                                                      bound_repo_id, None,
                                                      conduit)
        self.assertEqual(report_list, {TYPE_ID_RPM: [], TYPE_ID_ERRATA: []})
Example #36
0
 def test_form_lookup_table(self):
     """
     Test that form_lookup_table creates a table with the latest rpm in the profile as a value
     corresponding to the rpm name and arch.
     """
     test_profile = self.get_test_profile_with_duplicate_packages()
     consumer_lookup = YumProfiler._form_lookup_table(
         test_profile[TYPE_ID_RPM])
     self.assertEqual(len(consumer_lookup), 2)
     self.assertEqual(
         consumer_lookup['patb x86_64'],
         self.create_profile_entry("patb", 0, "0.0.2", "1", "x86_64",
                                   "Test Vendor"))
Example #37
0
 def test_get_rpms_from_errata_no_epoch(self):
     """
     Test that we default to '0' for the epoch if one doesn't exist.
     """
     errata_obj = self.get_test_errata_object(eid='RHEA-2010:8888')
     errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]}, errata_obj, None)
     prof = YumProfiler()
     rpms = prof._get_rpms_from_errata(errata_unit)
     # Expected data:
     # [{'src': 'xen-3.0.3-80.el5_3.3.src.rpm', 'name': 'emoticons',
     #   'sum': ('md5', '366bb5e73a5905eacb82c96e0578f92b'),
     #   'filename': 'emoticons-0.1-2.x86_64.rpm', 'epoch': '0',
     #   'version': '0.1', 'release': '2', 'arch': 'x86_64'},
     # {'src': 'xen-3.0.3-80.el5_3.3.src.rpm', 'name': 'patb',
     #   'sum': ('md5', 'f3c197a29d9b66c5b65c5d62b25db5b4'),
     #   'filename': 'patb-0.1-2.x86_64.rpm', 'epoch': '0',
     #   'version': '0.1', 'release': '2', 'arch': 'x86_64'}]
     self.assertEqual(len(rpms), 2)
     self.assertTrue(rpms[0]["name"] in ['emoticons', 'patb'])
     self.assertTrue(rpms[1]["name"] in ['emoticons', 'patb'])
     for r in rpms:
         self.assertTrue('epoch' in r)
         self.assertTrue(r['epoch'] == '0')
Example #38
0
    def test_unit_applicable(self):
        # Errata refers to RPMs which ARE part of our test consumer's profile,
        # AND in the repo.
        errata_obj = self.get_test_errata_object()
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]}, errata_obj, None)
        errata_unit.id = "an_errata"

        rpm_unit_key = self.create_profile_entry("emoticons", 0, "0.1", "2", "x86_64", "Test Vendor")
        rpm_unit = Unit(TYPE_ID_RPM, rpm_unit_key, {}, None)
        # Let's give it an id, so we can assert for it later
        rpm_unit.id = "a_test_id"

        test_repo = profiler_mocks.get_repo("test_repo_id")

        prof = YumProfiler()
        errata_rpms = prof._get_rpms_from_errata(errata_unit)
        conduit = profiler_mocks.get_profiler_conduit(
            repo_units=[errata_unit, rpm_unit], repo_bindings=[test_repo], errata_rpms=errata_rpms
        )
        unit_profile = self.test_consumer.profiles[TYPE_ID_RPM]
        bound_repo_id = "test_repo_id"
        report_list = prof.calculate_applicable_units(unit_profile, bound_repo_id, None, conduit)
        self.assertEqual(report_list, {TYPE_ID_RPM: ["a_test_id"], TYPE_ID_ERRATA: ["an_errata"]})
Example #39
0
 def test_get_rpms_from_errata_no_epoch(self):
     """
     Test that we default to '0' for the epoch if one doesn't exist.
     """
     errata_obj = self.get_test_errata_object(eid='RHEA-2010:8888')
     errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]},
                        errata_obj, None)
     prof = YumProfiler()
     rpms = prof._get_rpms_from_errata(errata_unit)
     # Expected data:
     # [{'src': 'xen-3.0.3-80.el5_3.3.src.rpm', 'name': 'emoticons',
     #   'sum': ('md5', '366bb5e73a5905eacb82c96e0578f92b'),
     #   'filename': 'emoticons-0.1-2.x86_64.rpm', 'epoch': '0',
     #   'version': '0.1', 'release': '2', 'arch': 'x86_64'},
     # {'src': 'xen-3.0.3-80.el5_3.3.src.rpm', 'name': 'patb',
     #   'sum': ('md5', 'f3c197a29d9b66c5b65c5d62b25db5b4'),
     #   'filename': 'patb-0.1-2.x86_64.rpm', 'epoch': '0',
     #   'version': '0.1', 'release': '2', 'arch': 'x86_64'}]
     self.assertEqual(len(rpms), 2)
     self.assertTrue(rpms[0]["name"] in ['emoticons', 'patb'])
     self.assertTrue(rpms[1]["name"] in ['emoticons', 'patb'])
     for r in rpms:
         self.assertTrue('epoch' in r)
         self.assertTrue(r['epoch'] == '0')
Example #40
0
 def setUp(self):
     super(TestYumProfilerRPM, self).setUp()
     self.data_dir = DATA_DIR
     self.temp_dir = tempfile.mkdtemp()
     self.working_dir = os.path.join(self.temp_dir, "working")
     if not os.path.exists(self.working_dir):
         os.makedirs(self.working_dir)
     self.consumer_id = "test_errata_profiler_consumer_id"
     self.profiles = self.get_test_profile()
     self.test_consumer = Consumer(self.consumer_id, self.profiles)
     self.test_consumer_lookup = YumProfiler._form_lookup_table(self.profiles[TYPE_ID_RPM])
     # i386 version of consumer to test arch issues
     self.consumer_id_i386 = "%s.i386" % (self.consumer_id)
     self.profiles_i386 = self.get_test_profile(arch="i386")
     self.test_consumer_i386 = Consumer(self.consumer_id_i386, self.profiles_i386)
     # consumer has been updated, and has the updated rpms installed
     self.consumer_id_been_updated = "%s.been_updated" % (self.consumer_id)
     self.profiles_been_updated = self.get_test_profile_been_updated()
     self.test_consumer_been_updated = Consumer(self.consumer_id_been_updated, self.profiles_been_updated)
Example #41
0
    def test__translate_erratum_returns_unit_keys(self, _rpms_applicable_to_consumer):
        """
        The agent handler is expecting to be given a unit key, and we had a bug[0] wherein it was
        being given only 'name' in the unit key, with all of the other "EVRA" fields being written
        into it. This test asserts that the first element of the return value of the
        _translate_erratum() method has full unit keys.

        [0] https://bugzilla.redhat.com/show_bug.cgi?id=1097434
        """
        unit = mock.MagicMock()
        repo_ids = ["repo_1", "repo_2"]
        consumer = mock.MagicMock()
        conduit = mock.MagicMock()
        # Mock there being an applicable RPM
        applicable_unit_key = {"name": "a_name", "epoch": "0", "version": "2.0.1", "release": "2", "arch": "x86_64"}
        _rpms_applicable_to_consumer.return_value = ([applicable_unit_key], mock.MagicMock())

        rpms, details = YumProfiler._translate_erratum(unit, repo_ids, consumer, conduit)

        expected_rpms = [{"unit_key": applicable_unit_key, "type_id": TYPE_ID_RPM}]
        self.assertEqual(rpms, expected_rpms)
Example #42
0
 def setUp(self):
     super(TestYumProfilerRPM, self).setUp()
     self.data_dir = DATA_DIR
     self.temp_dir = tempfile.mkdtemp()
     self.working_dir = os.path.join(self.temp_dir, "working")
     if not os.path.exists(self.working_dir):
         os.makedirs(self.working_dir)
     self.consumer_id = "test_errata_profiler_consumer_id"
     self.profiles = self.get_test_profile()
     self.test_consumer = Consumer(self.consumer_id, self.profiles)
     self.test_consumer_lookup = YumProfiler._form_lookup_table(
         self.profiles[TYPE_ID_RPM])
     # i386 version of consumer to test arch issues
     self.consumer_id_i386 = "%s.i386" % (self.consumer_id)
     self.profiles_i386 = self.get_test_profile(arch="i386")
     self.test_consumer_i386 = Consumer(self.consumer_id_i386,
                                        self.profiles_i386)
     # consumer has been updated, and has the updated rpms installed
     self.consumer_id_been_updated = "%s.been_updated" % (self.consumer_id)
     self.profiles_been_updated = self.get_test_profile_been_updated()
     self.test_consumer_been_updated = Consumer(
         self.consumer_id_been_updated, self.profiles_been_updated)
Example #43
0
    def test_update_profile_sorts_profile(self):
        """
        Test that the update_profile() method sorts the profile.
        """
        profile = [
            {
                'name': 'Package A',
                'epoch': 0,
                'version': '1.0.1',
                'release': '2.el6',
                'arch': 'x86_64',
                'vendor': 'Red Hat, Inc.'
            },
            {
                'name': 'Package C',
                'epoch': 0,
                'version': '1.0.0',
                'release': '1.el6',
                'arch': 'x86_64',
                'vendor': 'Red Hat, Inc.'
            },
            {
                'name': 'Package C',
                'epoch': 0,
                'version': '1.0.0',
                'release': '2.el6',
                'arch': 'x86_64',
                'vendor': 'Red Hat, Inc.'
            },
            {
                'name': 'Package A',
                'epoch': 0,
                'version': '1.1.0',
                'release': '1.el6',
                'arch': 'x86_64',
                'vendor': 'Red Hat, Inc.'
            },
            {
                'name': 'Package B',
                'epoch': 1,
                'version': '1.2.1',
                'release': '8.el6',
                'arch': 'x86_64',
                'vendor': 'Red Hat, Inc.'
            },
            {
                'name': 'Package B',
                'epoch': 0,
                'version': '2.3.9',
                'release': '1.el6',
                'arch': 'x86_64',
                'vendor': 'Red Hat, Inc.'
            },
        ]
        profiler = YumProfiler()

        # The update_profile() method doesn't use any of the args except for profile and
        # content_type, so we'll just pass in strings for the others
        new_profile = profiler.update_profile('consumer', TYPE_ID_RPM,
                                              deepcopy(profile), 'config')

        expected_profile = [
            {
                'name': 'Package A',
                'epoch': 0,
                'version': '1.0.1',
                'release': '2.el6',
                'arch': 'x86_64',
                'vendor': 'Red Hat, Inc.'
            },
            {
                'name': 'Package A',
                'epoch': 0,
                'version': '1.1.0',
                'release': '1.el6',
                'arch': 'x86_64',
                'vendor': 'Red Hat, Inc.'
            },
            {
                'name': 'Package B',
                'epoch': 0,
                'version': '2.3.9',
                'release': '1.el6',
                'arch': 'x86_64',
                'vendor': 'Red Hat, Inc.'
            },
            {
                'name': 'Package B',
                'epoch': 1,
                'version': '1.2.1',
                'release': '8.el6',
                'arch': 'x86_64',
                'vendor': 'Red Hat, Inc.'
            },
            {
                'name': 'Package C',
                'epoch': 0,
                'version': '1.0.0',
                'release': '1.el6',
                'arch': 'x86_64',
                'vendor': 'Red Hat, Inc.'
            },
            {
                'name': 'Package C',
                'epoch': 0,
                'version': '1.0.0',
                'release': '2.el6',
                'arch': 'x86_64',
                'vendor': 'Red Hat, Inc.'
            },
        ]
        self.assertEqual(new_profile, expected_profile)
Example #44
0
    def test_create_nevra(self):
        rpm = {"name": "foo", "epoch": 0, "version": "1", "release": "5", "arch": "8088", "extra_field": "extra"}

        result = YumProfiler._create_nevra(rpm)
        self.assertEquals(result, ("foo", "0", "1", "5", "8088"))
Example #45
0
    def test_install_units_unit_not_in_repo(self):
        """
        This tests that if an erratum unit is requested to be installed, we do
        not attempt to install any RPM units that are not available in repos.

        For example, if an erratum contains packages for RHEL6 and RHEL7, we do
        not want to ask a RHEL6 consumer to install RHEL7 packages that are
        unavailable on that host.

        This is a related issue to errata applicability but is slightly
        different since the API caller wants to install a particular erratum, and is
        not trying to determine which errata are applicable.

        Note also that RHEA-2014:9999 has emoticons-0.1 and patb-0.1 in
        different package collections; this is atypical and would likely not be
        seen in the wild. I set it up like this to ensure the package list from
        the erratum was being flattened during comparisons.

        More detail is available in https://pulp.plan.io/issues/770
        """
        repo_id = "test_repo_id"

        # this erratum has four RPMs but only two are available
        errata_obj = self.get_test_errata_object(eid='RHEA-2014:9999')
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]}, errata_obj, None)
        existing_units = [errata_unit]
        test_repo = profiler_mocks.get_repo(repo_id)

        # create two RPM units that match what is in the erratum. There are
        # higher versioned RPMs in the erratum that are not available; these
        # should not be installed.

        rpm_units = []
        rpm_unit_key_1 = self.create_profile_entry("emoticons", 0, "0.1", "2", "x86_64",
                                                   "Test Vendor")
        rpm_units.append(Unit(TYPE_ID_RPM, rpm_unit_key_1, {}, None))

        rpm_unit_key_2 = self.create_profile_entry("patb", 0, "0.1", "2", "x86_64", "Test Vendor")
        rpm_units.append(Unit(TYPE_ID_RPM, rpm_unit_key_2, {}, None))

        existing_units += rpm_units

        conduit = profiler_mocks.get_profiler_conduit(existing_units=existing_units,
                                                      repo_bindings=[test_repo],
                                                      repo_units=rpm_units)

        def mocked_get_units(repo_id, criteria=None):
            """
            Override the default get_units in profiler_mocks.

            This method is specific to this particular unit test. The default
            get_units() in profiler_mocks only checks the criteria's type_id and not any
            other fields.

            :param repo_id: repo ID (unused)
            :type  repo_id: not used
            :param criteria: unit association criteria
            :type  criteria: pulp.server.db.model.criteria.UnitAssociationCriteria

            """
            if TYPE_ID_ERRATA in criteria.type_ids:
                return [errata_unit]
            elif criteria['unit_filters']['name'] == 'emoticons' and \
                    criteria['unit_filters']['version'] == '0.1':
                    return [rpm_units[0]]
            elif criteria['unit_filters']['name'] == 'patb' and \
                    criteria['unit_filters']['version'] == '0.1':
                    return [rpm_units[1]]
            else:
                return []

        conduit.get_units.side_effect = mocked_get_units

        example_errata = {"unit_key": errata_unit.unit_key, "type_id": TYPE_ID_ERRATA}
        prof = YumProfiler()
        translated_units = prof.install_units(self.test_consumer, [example_errata], None, None,
                                              conduit)
        # check repo_id passed to the conduit get_units()
        self.assertEqual(conduit.get_units.call_args_list[0][0][0].id, repo_id)
        # validate translated units
        self.assertEqual(len(translated_units), 2)
        self.assertEqual(translated_units[0]['unit_key']['filename'], 'patb-0.1-2.x86_64.rpm')
        self.assertEqual(translated_units[1]['unit_key']['filename'], 'emoticons-0.1-2.x86_64.rpm')
        expected = prof._get_rpms_from_errata(errata_unit)
        for u in translated_units:
            rpm_unit_key = u["unit_key"]
            self.assertTrue(rpm_unit_key in expected)
Example #46
0
    def test_update_profile_sorts_profile(self):
        """
        Test that the update_profile() method sorts the profile.
        """
        profile = [
            {
                "name": "Package A",
                "epoch": 0,
                "version": "1.0.1",
                "release": "2.el6",
                "arch": "x86_64",
                "vendor": "Red Hat, Inc.",
            },
            {
                "name": "Package C",
                "epoch": 0,
                "version": "1.0.0",
                "release": "1.el6",
                "arch": "x86_64",
                "vendor": "Red Hat, Inc.",
            },
            {
                "name": "Package C",
                "epoch": 0,
                "version": "1.0.0",
                "release": "2.el6",
                "arch": "x86_64",
                "vendor": "Red Hat, Inc.",
            },
            {
                "name": "Package A",
                "epoch": 0,
                "version": "1.1.0",
                "release": "1.el6",
                "arch": "x86_64",
                "vendor": "Red Hat, Inc.",
            },
            {
                "name": "Package B",
                "epoch": 1,
                "version": "1.2.1",
                "release": "8.el6",
                "arch": "x86_64",
                "vendor": "Red Hat, Inc.",
            },
            {
                "name": "Package B",
                "epoch": 0,
                "version": "2.3.9",
                "release": "1.el6",
                "arch": "x86_64",
                "vendor": "Red Hat, Inc.",
            },
        ]
        profiler = YumProfiler()

        # The update_profile() method doesn't use any of the args except for profile and
        # content_type, so we'll just pass in strings for the others
        new_profile = profiler.update_profile("consumer", TYPE_ID_RPM, deepcopy(profile), "config")

        expected_profile = [
            {
                "name": "Package A",
                "epoch": 0,
                "version": "1.0.1",
                "release": "2.el6",
                "arch": "x86_64",
                "vendor": "Red Hat, Inc.",
            },
            {
                "name": "Package A",
                "epoch": 0,
                "version": "1.1.0",
                "release": "1.el6",
                "arch": "x86_64",
                "vendor": "Red Hat, Inc.",
            },
            {
                "name": "Package B",
                "epoch": 0,
                "version": "2.3.9",
                "release": "1.el6",
                "arch": "x86_64",
                "vendor": "Red Hat, Inc.",
            },
            {
                "name": "Package B",
                "epoch": 1,
                "version": "1.2.1",
                "release": "8.el6",
                "arch": "x86_64",
                "vendor": "Red Hat, Inc.",
            },
            {
                "name": "Package C",
                "epoch": 0,
                "version": "1.0.0",
                "release": "1.el6",
                "arch": "x86_64",
                "vendor": "Red Hat, Inc.",
            },
            {
                "name": "Package C",
                "epoch": 0,
                "version": "1.0.0",
                "release": "2.el6",
                "arch": "x86_64",
                "vendor": "Red Hat, Inc.",
            },
        ]
        self.assertEqual(new_profile, expected_profile)
Example #47
0
    def test_install_units_with_superseding_versions(self):
        """
        Verify that errata installing multiple versions of a package installs the latest package

        In this test, there are three errata to install. Two provide the same package, but one
        errata has a higher version. The third errata installs two unrelated packages.

        Only the most recent package versions should be installed.
        """
        profiler = YumProfiler()

        # "older" errata is associated with lower version rpm
        errata_obj_old = self.get_test_errata_object(eid='grinder_test_2')
        errata_old = Unit(TYPE_ID_ERRATA, {"errata_id": errata_obj_old["id"]},
                          errata_obj_old, None)
        rpm_key_old = self.create_profile_entry("grinder_test_package", 0,
                                                "2.0", "1.fc14", "noarch",
                                                "Test Vendor")

        # "newer" errata is associated with higher version rpm
        errata_obj_new = self.get_test_errata_object(eid='grinder_test_3')
        errata_new = Unit(TYPE_ID_ERRATA, {"errata_id": errata_obj_new["id"]},
                          errata_obj_new, None)
        rpm_key_new = self.create_profile_entry("grinder_test_package", 0,
                                                "3.0", "1.fc14", "noarch",
                                                "Test Vendor")

        # "unrelated" errata is a different package, a control
        errata_obj_unr = self.get_test_errata_object(eid='RHEA-2010:9999')
        errata_unr = Unit(TYPE_ID_ERRATA, {"errata_id": errata_obj_unr["id"]},
                          errata_obj_unr, None)
        rpm_key_unr_1 = self.create_profile_entry("emoticons", 0, "0.1", "2",
                                                  "x86_64", "Test Vendor")
        rpm_key_unr_2 = self.create_profile_entry("patb", 0, "0.1", "2",
                                                  "x86_64", "Test Vendor")

        # units list for the conduit
        rpm_keys = [rpm_key_old, rpm_key_new, rpm_key_unr_1, rpm_key_unr_2]
        rpm_units = [
            Unit(TYPE_ID_RPM, rpm_key, {}, None) for rpm_key in rpm_keys
        ]
        existing_units = [errata_old, errata_new, errata_unr] + rpm_units

        # Set the profile to indicate that the errata apply by including fake unit keys of
        # installed packages with lower versions that need to be upgraded
        rpm_keys_installed = [
            self.create_profile_entry("grinder_test_package", 0, "1.0",
                                      "1.fc14", "noarch", "Test Vendor"),
            self.create_profile_entry("emoticons", 0, "0.0", "1", "x86_64",
                                      "Test Vendor"),
            self.create_profile_entry("patb", 0, "0.0", "2", "x86_64",
                                      "Test Vendor")
        ]
        profiles = {TYPE_ID_RPM: rpm_keys_installed}

        # put together all the args for install_units and call it
        consumer = Consumer(self.consumer_id, profiles)
        errata = [
            {
                "unit_key": errata_old.unit_key,
                "type_id": TYPE_ID_ERRATA
            },
            {
                "unit_key": errata_new.unit_key,
                "type_id": TYPE_ID_ERRATA
            },
            {
                "unit_key": errata_unr.unit_key,
                "type_id": TYPE_ID_ERRATA
            },
        ]
        test_repo = profiler_mocks.get_repo("test_repo_id")
        conduit = profiler_mocks.get_profiler_conduit(
            existing_units=existing_units,
            repo_bindings=[test_repo],
            repo_units=rpm_units)
        translated_units = profiler.install_units(consumer, errata, None, None,
                                                  conduit)

        # validate translated units:
        # - the unrelated rpms should still be present
        # - the rpm from the "newer" errata should still be present
        # - the rpm from the "older" errata should have been removed
        # - the total number of units present is 3
        translated_filenames = [
            u['unit_key']['filename'] for u in translated_units
        ]
        self.assertTrue('emoticons-0.1-2.x86_64.rpm' in translated_filenames)
        self.assertTrue('patb-0.1-2.x86_64.rpm' in translated_filenames)
        self.assertTrue('grinder_test_package-3.0-1.fc14.noarch.rpm' in
                        translated_filenames)
        self.assertTrue('grinder_test_package-2.0-1.fc14.noarch.rpm' not in
                        translated_filenames)
        self.assertEqual(len(translated_units), 3)
Example #48
0
    def test_install_units_with_superseding_versions(self):
        """
        Verify that errata installing multiple versions of a package installs the latest package

        In this test, there are three errata to install. Two provide the same package, but one
        errata has a higher version. The third errata installs two unrelated packages.

        Only the most recent package versions should be installed.
        """
        profiler = YumProfiler()

        # "older" errata is associated with lower version rpm
        errata_obj_old = self.get_test_errata_object(eid='grinder_test_2')
        errata_old = Unit(TYPE_ID_ERRATA, {"errata_id": errata_obj_old["id"]}, errata_obj_old, None)
        rpm_key_old = self.create_profile_entry(
            "grinder_test_package", 0, "2.0", "1.fc14", "noarch", "Test Vendor")

        # "newer" errata is associated with higher version rpm
        errata_obj_new = self.get_test_errata_object(eid='grinder_test_3')
        errata_new = Unit(TYPE_ID_ERRATA, {"errata_id": errata_obj_new["id"]}, errata_obj_new, None)
        rpm_key_new = self.create_profile_entry(
            "grinder_test_package", 0, "3.0", "1.fc14", "noarch", "Test Vendor")

        # "unrelated" errata is a different package, a control
        errata_obj_unr = self.get_test_errata_object(eid='RHEA-2010:9999')
        errata_unr = Unit(TYPE_ID_ERRATA, {"errata_id": errata_obj_unr["id"]}, errata_obj_unr, None)
        rpm_key_unr_1 = self.create_profile_entry(
            "emoticons", 0, "0.1", "2", "x86_64", "Test Vendor")
        rpm_key_unr_2 = self.create_profile_entry(
            "patb", 0, "0.1", "2", "x86_64", "Test Vendor")

        # units list for the conduit
        rpm_keys = [rpm_key_old, rpm_key_new, rpm_key_unr_1, rpm_key_unr_2]
        rpm_units = [Unit(TYPE_ID_RPM, rpm_key, {}, None) for rpm_key in rpm_keys]
        existing_units = [errata_old, errata_new, errata_unr] + rpm_units

        # Set the profile to indicate that the errata apply by including fake unit keys of
        # installed packages with lower versions that need to be upgraded
        rpm_keys_installed = [
            self.create_profile_entry(
                "grinder_test_package", 0, "1.0", "1.fc14", "noarch", "Test Vendor"),
            self.create_profile_entry(
                "emoticons", 0, "0.0", "1", "x86_64", "Test Vendor"),
            self.create_profile_entry(
                "patb", 0, "0.0", "2", "x86_64", "Test Vendor")
        ]
        profiles = {TYPE_ID_RPM: rpm_keys_installed}

        # put together all the args for install_units and call it
        consumer = Consumer(self.consumer_id, profiles)
        errata = [
            {"unit_key": errata_old.unit_key, "type_id": TYPE_ID_ERRATA},
            {"unit_key": errata_new.unit_key, "type_id": TYPE_ID_ERRATA},
            {"unit_key": errata_unr.unit_key, "type_id": TYPE_ID_ERRATA},
        ]
        test_repo = profiler_mocks.get_repo("test_repo_id")
        conduit = profiler_mocks.get_profiler_conduit(existing_units=existing_units,
                                                      repo_bindings=[test_repo],
                                                      repo_units=rpm_units)
        translated_units = profiler.install_units(consumer, errata, None, None, conduit)

        # validate translated units:
        # - the unrelated rpms should still be present
        # - the rpm from the "newer" errata should still be present
        # - the rpm from the "older" errata should have been removed
        # - the total number of units present is 3
        translated_filenames = [u['unit_key']['filename'] for u in translated_units]
        self.assertTrue('emoticons-0.1-2.x86_64.rpm' in translated_filenames)
        self.assertTrue('patb-0.1-2.x86_64.rpm' in translated_filenames)
        self.assertTrue('grinder_test_package-3.0-1.fc14.noarch.rpm' in translated_filenames)
        self.assertTrue('grinder_test_package-2.0-1.fc14.noarch.rpm' not in translated_filenames)
        self.assertEqual(len(translated_units), 3)
Example #49
0
    def test_install_units_unit_not_in_repo(self):
        """
        This tests that if an erratum unit is requested to be installed, we do
        not attempt to install any RPM units that are not available in repos.

        For example, if an erratum contains packages for RHEL6 and RHEL7, we do
        not want to ask a RHEL6 consumer to install RHEL7 packages that are
        unavailable on that host.

        This is a related issue to errata applicability but is slightly
        different since the API caller wants to install a particular erratum, and is
        not trying to determine which errata are applicable.

        Note also that RHEA-2014:9999 has emoticons-0.1 and patb-0.1 in
        different package collections; this is atypical and would likely not be
        seen in the wild. I set it up like this to ensure the package list from
        the erratum was being flattened during comparisons.

        More detail is available in https://pulp.plan.io/issues/770
        """
        repo_id = "test_repo_id"

        # this erratum has four RPMs but only two are available
        errata_obj = self.get_test_errata_object(eid='RHEA-2014:9999')
        errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]},
                           errata_obj, None)
        existing_units = [errata_unit]
        test_repo = profiler_mocks.get_repo(repo_id)

        # create two RPM units that match what is in the erratum. There are
        # higher versioned RPMs in the erratum that are not available; these
        # should not be installed.

        rpm_units = []
        rpm_unit_key_1 = self.create_profile_entry("emoticons", 0, "0.1", "2",
                                                   "x86_64", "Test Vendor")
        rpm_units.append(Unit(TYPE_ID_RPM, rpm_unit_key_1, {}, None))

        rpm_unit_key_2 = self.create_profile_entry("patb", 0, "0.1", "2",
                                                   "x86_64", "Test Vendor")
        rpm_units.append(Unit(TYPE_ID_RPM, rpm_unit_key_2, {}, None))

        existing_units += rpm_units

        conduit = profiler_mocks.get_profiler_conduit(
            existing_units=existing_units,
            repo_bindings=[test_repo],
            repo_units=rpm_units)

        def mocked_get_units(repo_id, criteria=None):
            """
            Override the default get_units in profiler_mocks.

            This method is specific to this particular unit test. The default
            get_units() in profiler_mocks only checks the criteria's type_id and not any
            other fields.

            :param repo_id: repo ID (unused)
            :type  repo_id: not used
            :param criteria: unit association criteria
            :type  criteria: pulp.server.db.model.criteria.UnitAssociationCriteria

            """
            if TYPE_ID_ERRATA in criteria.type_ids:
                return [errata_unit]
            elif criteria['unit_filters']['name'] == 'emoticons' and \
                    criteria['unit_filters']['version'] == '0.1':
                return [rpm_units[0]]
            elif criteria['unit_filters']['name'] == 'patb' and \
                    criteria['unit_filters']['version'] == '0.1':
                return [rpm_units[1]]
            else:
                return []

        conduit.get_units.side_effect = mocked_get_units

        example_errata = {
            "unit_key": errata_unit.unit_key,
            "type_id": TYPE_ID_ERRATA
        }
        prof = YumProfiler()
        translated_units = prof.install_units(self.test_consumer,
                                              [example_errata], None, None,
                                              conduit)
        # check repo_id passed to the conduit get_units()
        self.assertEqual(conduit.get_units.call_args_list[0][0][0].id, repo_id)
        # validate translated units
        self.assertEqual(len(translated_units), 2)
        self.assertEqual(translated_units[0]['unit_key']['filename'],
                         'patb-0.1-2.x86_64.rpm')
        self.assertEqual(translated_units[1]['unit_key']['filename'],
                         'emoticons-0.1-2.x86_64.rpm')
        expected = prof._get_rpms_from_errata(errata_unit)
        for u in translated_units:
            rpm_unit_key = u["unit_key"]
            self.assertTrue(rpm_unit_key in expected)