Example #1
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 #2
0
    def test_handle_erratum_with_link(self, mock_link):
        # Setup
        unit_key = {'id': 'test-erratum'}
        metadata = {'a': 'a'}
        config = PluginCallConfiguration({}, {})
        mock_repo = mock.MagicMock()

        mock_conduit = mock.MagicMock()
        inited_unit = Unit(models.Errata.TYPE, unit_key, metadata, None)
        saved_unit = Unit(models.Errata.TYPE, unit_key, metadata, None)
        saved_unit.id = 'ihaveanidnow'
        mock_conduit.init_unit.return_value = inited_unit
        mock_conduit.save_unit.return_value = saved_unit

        # Test
        upload._handle_erratum(mock_repo, models.Errata.TYPE, unit_key, metadata, None,
                               mock_conduit, config)

        # Verify
        mock_conduit.init_unit.assert_called_once_with(models.Errata.TYPE, unit_key,
                                                       metadata, None)
        mock_conduit.save_unit.assert_called_once_with(inited_unit)

        mock_link.assert_called_once()
        self.assertEqual(mock_link.call_args[0][0], mock_conduit)
        self.assertTrue(isinstance(mock_link.call_args[0][1], models.Errata))
        # it is very important that this is the saved_unit, and not the inited_unit,
        # because the underlying link logic requires it to have an "id".
        self.assertTrue(mock_link.call_args[0][2] is saved_unit)
Example #3
0
def to_plugin_unit(pulp_unit, type_def):
    """
    Parses the raw dictionary of a content unit into its plugin representation.

    @param pulp_unit: raw dictionary of unit metadata
    @type  pulp_unit: dict

    @param type_def: Pulp stored definition for the unit type
    @type  type_def: pulp.server.db.model.content.ContentType

    @return: plugin unit representation of the given unit
    @rtype:  pulp.plugins.model.Unit
    """

    # Copy so we don't mangle the original unit
    pulp_unit = dict(pulp_unit)

    key_list = type_def['unit_key']

    unit_key = {}

    for k in key_list:
        unit_key[k] = pulp_unit.pop(k)

    storage_path = pulp_unit.pop('_storage_path', None)
    unit_id = pulp_unit.pop('_id', None)

    u = Unit(type_def['id'], unit_key, pulp_unit, storage_path)
    u.id = unit_id

    return u
Example #4
0
    def test_link_unit(self, mock_link):
        # Setup
        from_unit = Unit('t1', {'k' : 'v1'}, {'m' : 'm'}, 'p')
        from_unit.id = 'from-unit'
        to_unit = Unit('t2', {'k' : 'v2'}, {'m' : 'm'}, 'p')
        to_unit.id = 'to-unit'

        # Test
        self.mixin.link_unit(from_unit, to_unit)

        # Verify
        self.assertEqual(1, mock_link.call_count)
        self.assertEqual(mock_link.call_args[0][0], from_unit.type_id)
        self.assertEqual(mock_link.call_args[0][1], from_unit.id)
        self.assertEqual(mock_link.call_args[0][2], to_unit.type_id)
        self.assertEqual(mock_link.call_args[0][3], [to_unit.id])
Example #5
0
def to_plugin_unit(pulp_unit, type_def):
    """
    Parses the raw dictionary of a content unit into its plugin representation.

    @param pulp_unit: raw dictionary of unit metadata
    @type  pulp_unit: dict

    @param type_def: Pulp stored definition for the unit type
    @type  type_def: pulp.server.db.model.content.ContentType

    @return: plugin unit representation of the given unit
    @rtype:  pulp.plugins.model.Unit
    """

    # Copy so we don't mangle the original unit
    pulp_unit = dict(pulp_unit)

    key_list = type_def['unit_key']

    unit_key = {}

    for k in key_list:
        unit_key[k] = pulp_unit.pop(k)

    storage_path = pulp_unit.pop('_storage_path', None)
    unit_id = pulp_unit.pop('_id', None)

    u = Unit(type_def['id'], unit_key, pulp_unit, storage_path)
    u.id = unit_id

    return u
Example #6
0
    def test_link_unit(self, mock_link):
        # Setup
        from_unit = Unit('t1', {'k': 'v1'}, {'m': 'm'}, 'p')
        from_unit.id = 'from-unit'
        to_unit = Unit('t2', {'k': 'v2'}, {'m': 'm'}, 'p')
        to_unit.id = 'to-unit'

        # Test
        self.mixin.link_unit(from_unit, to_unit)

        # Verify
        self.assertEqual(1, mock_link.call_count)
        self.assertEqual(mock_link.call_args[0][0], from_unit.type_id)
        self.assertEqual(mock_link.call_args[0][1], from_unit.id)
        self.assertEqual(mock_link.call_args[0][2], to_unit.type_id)
        self.assertEqual(mock_link.call_args[0][3], [to_unit.id])
Example #7
0
def to_plugin_unit(pulp_unit, unit_type_id, unit_key_fields):
    """
    Parses the raw dictionary of a content unit into its plugin representation.

    :param pulp_unit: raw dictionary of unit metadata
    :type  pulp_unit: dict
    :param unit_type_id: unique identifier for the type of unit
    :type  unit_type_id: str
    :param unit_key_fields: collection of keys required for the type's unit key
    :type  unit_key_fields: list or tuple

    :return: plugin unit representation of the given unit
    :rtype:  pulp.plugins.model.Unit
    """

    # Copy so we don't mangle the original unit
    pulp_unit = dict(pulp_unit)

    unit_key = {}

    for k in unit_key_fields:
        unit_key[k] = pulp_unit.pop(k)

    storage_path = pulp_unit.pop('_storage_path', None)
    unit_id = pulp_unit.pop('_id', None)

    u = Unit(unit_type_id, unit_key, pulp_unit, storage_path)
    u.id = unit_id

    return u
Example #8
0
    def test_link_unit(self, mock_link):
        # Setup
        from_unit = Unit("t1", {"k": "v1"}, {"m": "m"}, "p")
        from_unit.id = "from-unit"
        to_unit = Unit("t2", {"k": "v2"}, {"m": "m"}, "p")
        to_unit.id = "to-unit"

        # Test
        self.mixin.link_unit(from_unit, to_unit)

        # Verify
        self.assertEqual(1, mock_link.call_count)
        self.assertEqual(mock_link.call_args[0][0], from_unit.type_id)
        self.assertEqual(mock_link.call_args[0][1], from_unit.id)
        self.assertEqual(mock_link.call_args[0][2], to_unit.type_id)
        self.assertEqual(mock_link.call_args[0][3], [to_unit.id])
Example #9
0
def to_plugin_unit(pulp_unit, unit_type_id, unit_key_fields):
    """
    Parses the raw dictionary of a content unit into its plugin representation.

    :param pulp_unit: raw dictionary of unit metadata
    :type  pulp_unit: dict
    :param unit_type_id: unique identifier for the type of unit
    :type  unit_type_id: str
    :param unit_key_fields: collection of keys required for the type's unit key
    :type  unit_key_fields: list or tuple

    :return: plugin unit representation of the given unit
    :rtype:  pulp.plugins.model.Unit
    """

    # Copy so we don't mangle the original unit
    pulp_unit = dict(pulp_unit)

    unit_key = {}

    for k in unit_key_fields:
        unit_key[k] = pulp_unit.pop(k)

    storage_path = pulp_unit.pop('_storage_path', None)
    unit_id = pulp_unit.pop('_id', None)

    u = Unit(unit_type_id, unit_key, pulp_unit, storage_path)
    u.id = unit_id

    return u
Example #10
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 #11
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 #12
0
    def test_link_unit_bidirectional(self, mock_link):
        # Setup
        from_unit = Unit('t1', {'k': 'v1'}, {'m': 'm'}, 'p')
        from_unit.id = 'from-unit'
        to_unit = Unit('t2', {'k': 'v2'}, {'m': 'm'}, 'p')
        to_unit.id = 'to-unit'

        # Test
        self.mixin.link_unit(from_unit, to_unit, bidirectional=True)

        # Verify
        self.assertEqual(2, mock_link.call_count)

        call_1_args = mock_link.call_args_list[0][0]
        self.assertEqual(call_1_args[0], from_unit.type_id)
        self.assertEqual(call_1_args[1], from_unit.id)
        self.assertEqual(call_1_args[2], to_unit.type_id)
        self.assertEqual(call_1_args[3], [to_unit.id])

        call_2_args = mock_link.call_args_list[1][0]
        self.assertEqual(call_2_args[0], to_unit.type_id)
        self.assertEqual(call_2_args[1], to_unit.id)
        self.assertEqual(call_2_args[2], from_unit.type_id)
        self.assertEqual(call_2_args[3], [from_unit.id])
Example #13
0
    def test_link_unit_bidirectional(self, mock_link):
        # Setup
        from_unit = Unit("t1", {"k": "v1"}, {"m": "m"}, "p")
        from_unit.id = "from-unit"
        to_unit = Unit("t2", {"k": "v2"}, {"m": "m"}, "p")
        to_unit.id = "to-unit"

        # Test
        self.mixin.link_unit(from_unit, to_unit, bidirectional=True)

        # Verify
        self.assertEqual(2, mock_link.call_count)

        call_1_args = mock_link.call_args_list[0][0]
        self.assertEqual(call_1_args[0], from_unit.type_id)
        self.assertEqual(call_1_args[1], from_unit.id)
        self.assertEqual(call_1_args[2], to_unit.type_id)
        self.assertEqual(call_1_args[3], [to_unit.id])

        call_2_args = mock_link.call_args_list[1][0]
        self.assertEqual(call_2_args[0], to_unit.type_id)
        self.assertEqual(call_2_args[1], to_unit.id)
        self.assertEqual(call_2_args[2], from_unit.type_id)
        self.assertEqual(call_2_args[3], [from_unit.id])
Example #14
0
    def test_link_unit_bidirectional(self, mock_link):
        # Setup
        from_unit = Unit('t1', {'k' : 'v1'}, {'m' : 'm'}, 'p')
        from_unit.id = 'from-unit'
        to_unit = Unit('t2', {'k' : 'v2'}, {'m' : 'm'}, 'p')
        to_unit.id = 'to-unit'

        # Test
        self.mixin.link_unit(from_unit, to_unit, bidirectional=True)

        # Verify
        self.assertEqual(2, mock_link.call_count)

        call_1_args = mock_link.call_args_list[0][0]
        self.assertEqual(call_1_args[0], from_unit.type_id)
        self.assertEqual(call_1_args[1], from_unit.id)
        self.assertEqual(call_1_args[2], to_unit.type_id)
        self.assertEqual(call_1_args[3], [to_unit.id])

        call_2_args = mock_link.call_args_list[1][0]
        self.assertEqual(call_2_args[0], to_unit.type_id)
        self.assertEqual(call_2_args[1], to_unit.id)
        self.assertEqual(call_2_args[2], from_unit.type_id)
        self.assertEqual(call_2_args[3], [from_unit.id])
Example #15
0
    def test_unit_not_applicable_not_in_repo(self):
        # 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'
        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_RPM: [], TYPE_ID_ERRATA: []})
Example #16
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 #17
0
    def test_unit_not_applicable_not_in_repo(self):
        # 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'
        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_RPM: [], TYPE_ID_ERRATA: []})