Beispiel #1
0
 def _delete_units(self, request, unit_inventory):
     """
     Determine the list of units contained in the child inventory
     but are not contained in the parent inventory and un-associate them.
     :param request: A synchronization request.
     :type request: SyncRequest
     :param unit_inventory: The inventory of both parent and child content units.
     :type unit_inventory: UnitInventory
     """
     for unit in unit_inventory.units_on_child_only():
         if request.cancelled():
             return
         try:
             _unit = AssociatedUnit(
                 type_id=unit['type_id'],
                 unit_key=unit['unit_key'],
                 metadata={},
                 storage_path=None,
                 created=None,
                 updated=None)
             _unit.id = unit['unit_id']
             request.conduit.remove_unit(_unit)
         except Exception:
             _log.exception(unit['unit_id'])
             request.summary.errors.append(DeleteUnitError(request.repo_id))
Beispiel #2
0
    def setUp(self):
        path = os.path.join(DATA_PATH, 'treeinfo-rhel5')

        self.model, files = treeinfo.parse_treefile(path)
        self.unit = AssociatedUnit(models.Distribution.TYPE,
                                   self.model.unit_key.copy(),
                                   self.model.metadata.copy(), '/a/b/c/', None, None)
 def setUp(self):
     self.profiler = wholerepo.WholeRepoProfiler()
     self.consumer = Consumer('consumer1', {})
     self.units = [{
         'type_id': constants.TYPE_PUPPET_MODULE,
         'unit_key': {
             'name': 'gcc',
             'author': 'puppetlabs'
         }
     }, {
         'type_id': constants.TYPE_PUPPET_MODULE,
         'unit_key': {
             'name': 'stdlib',
             'author': 'puppetlabs',
             'version': '3.1.1'
         }
     }, {
         'type_id': constants.TYPE_PUPPET_MODULE,
         'unit_key': {
             'name': 'stdlib',
             'author': 'puppetlabs',
             'version': '3.2.0'
         }
     }]
     self.conduit = mock.MagicMock(spec=ProfilerConduit())
     self.conduit.get_units.return_value = [
         AssociatedUnit(constants.TYPE_PUPPET_MODULE, unit['unit_key'], {},
                        '', '', '', '', '') for unit in self.units
     ]
Beispiel #4
0
 def setUp(self):
     self.distributor = installdistributor.PuppetModuleInstallDistributor()
     self.uk1 = {
         'author': 'puppetlabs',
         'name': 'stdlib',
         'version': '1.2.0'
     }
     self.uk2 = {
         'author': 'puppetlabs',
         'name': 'stdlib',
         'version': '1.2.1'
     }
     self.units = [
         AssociatedUnit(constants.TYPE_PUPPET_MODULE, self.uk1, {},
                        '/a/b/x', '', '', '', ''),
         AssociatedUnit(constants.TYPE_PUPPET_MODULE, self.uk2, {},
                        '/a/b/y', '', '', '', ''),
     ]
Beispiel #5
0
 def setUp(self):
     self.distributor = installdistributor.PuppetModuleInstallDistributor()
     self.repo = Repository('repo1', '', {})
     self.conduit = RepoPublishConduit('repo1',
                                       self.distributor.metadata()['id'])
     self.uk1 = {
         'author': 'puppetlabs',
         'name': 'stdlib',
         'version': '1.2.0'
     }
     self.uk2 = {'author': 'puppetlabs', 'name': 'java', 'version': '1.3.1'}
     self.units = [
         AssociatedUnit(constants.TYPE_PUPPET_MODULE, self.uk1, {},
                        '/a/b/x', '', '', '', ''),
         AssociatedUnit(constants.TYPE_PUPPET_MODULE, self.uk2, {},
                        '/a/b/y', '', '', '', ''),
     ]
     self.conduit.get_units = mock.MagicMock(
         return_value=self.units, spec_set=self.conduit.get_units)
Beispiel #6
0
 def setUp(self):
     self.uk1 = {
         'author': 'puppetlabs',
         'name': 'stdlib',
         'version': '1.2.0'
     }
     self.uk2 = {'author': 'puppetlabs', 'name': 'java', 'version': '1.3.1'}
     self.uk3 = {
         'author': 'puppetlabs',
         'name': 'stdlib',
         'version': '1.3.1'
     }
     self.unit3 = AssociatedUnit(constants.TYPE_PUPPET_MODULE, self.uk3, {},
                                 '/a/b/z', '', '', '', '')
     self.units = [
         AssociatedUnit(constants.TYPE_PUPPET_MODULE, self.uk1, {},
                        '/a/b/x', '', '', '', ''),
         AssociatedUnit(constants.TYPE_PUPPET_MODULE, self.uk2, {},
                        '/a/b/y', '', '', '', ''),
     ]
     self.method = installdistributor.PuppetModuleInstallDistributor._find_duplicate_names
Beispiel #7
0
    def test_duplicate_unit_names(self):
        config = PluginCallConfiguration(
            {}, {constants.CONFIG_INSTALL_PATH: '/tmp'})
        uk3 = {'author': 'puppetlabs', 'name': 'stdlib', 'version': '1.3.1'}
        unit3 = AssociatedUnit(constants.TYPE_PUPPET_MODULE, uk3, {}, '/a/b/z',
                               '', '', '', '')
        self.units.append(unit3)

        report = self.distributor.publish_repo(self.repo, self.conduit, config)

        self.assertFalse(report.success_flag)
        self.assertTrue(isinstance(report.summary, basestring))
        self.assertEqual(len(report.details['errors']), 2)
        self.assertTrue(report.summary.find('duplicate') >= 0)
Beispiel #8
0
def to_plugin_associated_unit(pulp_unit, type_def):
    """
    Parses the raw dictionary of content unit associated to a repository into
    the plugin's object 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.AssociatedUnit
    """

    # Copy so we don't mangle the original unit
    # pymongo on RHEL6 doesn't seem to like deepcopy, so do this instead
    pulp_unit = dict(pulp_unit)
    pulp_unit['metadata'] = dict(pulp_unit['metadata'])

    key_list = type_def['unit_key']

    unit_key = {}

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

    storage_path = pulp_unit['metadata'].pop('_storage_path', None)
    unit_id = pulp_unit.pop('unit_id', None)
    created = pulp_unit.pop('created', None)
    updated = pulp_unit.pop('updated', None)
    owner_type = pulp_unit.pop('owner_type', None)
    owner_id = pulp_unit.pop('owner_id', None)

    u = AssociatedUnit(type_def['id'], unit_key, pulp_unit['metadata'],
                       storage_path, created, updated, owner_type, owner_id)
    u.id = unit_id

    return u
Beispiel #9
0
def to_plugin_associated_unit(pulp_unit, unit_type_id, unit_key_fields):
    """
    Parses the raw dictionary of content unit associated to a repository into
    the plugin's object 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.AssociatedUnit
    """

    # Copy so we don't mangle the original unit
    # pymongo on RHEL6 doesn't seem to like deepcopy, so do this instead
    pulp_unit = dict(pulp_unit)
    pulp_unit['metadata'] = dict(pulp_unit['metadata'])

    unit_key = {}

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

    storage_path = pulp_unit['metadata'].pop('_storage_path', None)
    unit_id = pulp_unit.pop('unit_id', None)
    created = pulp_unit.pop('created', None)
    updated = pulp_unit.pop('updated', None)

    u = AssociatedUnit(unit_type_id, unit_key, pulp_unit['metadata'],
                       storage_path, created, updated)
    u.id = unit_id

    return u
Beispiel #10
0
 def setUp(self):
     uk = {'author': 'puppetlabs', 'name': 'stdlib', 'version': '1.2.0'}
     self.unit = AssociatedUnit(constants.TYPE_PUPPET_MODULE, uk, {},
                                '/a/b/x', '', '', '', '')
     self.method = installdistributor.PuppetModuleInstallDistributor._rename_directory