def publish_repo(self, repo, conduit, config): """ Publishes the given repository. While this call may be implemented using multiple threads, its execution from the Pulp server's standpoint should be synchronous. This call should not return until the publish is complete. It is not expected that this call be atomic. Should an error occur, it is not the responsibility of the distributor to rollback any changes that have been made. :param repo: metadata describing the repository :type repo: pulp.plugins.model.Repository :param conduit: provides access to relevant Pulp functionality :type conduit: pulp.plugins.conduits.repo_publish.RepoPublishConduit :param config: plugin configuration :type config: pulp.plugins.config.PluginConfiguration :return: report describing the publish run :rtype: pulp.plugins.model.PublishReport """ nodes_conduit = NodesConduit() units = nodes_conduit.get_units(repo.id) with self.publisher(repo, config) as publisher: publisher.publish(units) publisher.commit() details = dict(unit_count=len(units)) return conduit.build_success_report('succeeded', details)
def _unit_inventory(self, request): """ Build the unit inventory. :param request: A synchronization request. :type request: SyncRequest :return: The built inventory. :rtype: UnitInventory """ # fetch child units try: conduit = NodesConduit() child_units = conduit.get_units(request.repo_id) except NodeError: raise except Exception: log.exception(request.repo_id) raise GetChildUnitsError(request.repo_id) # fetch parent units try: request.progress.begin_manifest_download() url = request.config.get(constants.MANIFEST_URL_KEYWORD) manifest = Manifest() manifest.fetch(url, request.working_dir, request.downloader) manifest.fetch_units(url, request.downloader) parent_units = manifest.get_units() except NodeError: raise except Exception: log.exception(request.repo_id) raise GetParentUnitsError(request.repo_id) return UnitInventory(parent_units, child_units)
def test_query(self): num_units = 5 units_created = populate(num_units) conduit = NodesConduit() units = conduit.get_units(REPO_ID) self.assertEqual(len(units), len(units_created)) unit_list = list(units) n = 0 for u in sorted(unit_list, key=itemgetter('unit_id')): unit_id = u['unit_id'] type_id = u['type_id'] self.assertTrue(type_id in ALL_TYPES) self.assertEqual(create_unit_id(type_id, n), unit_id) unit_key = u['unit_key'] self.assertEqual(unit_key['N'], n) self.assertEqual(u['storage_path'], create_storage_path(unit_id)) n += 1
def _unit_inventory(self, request): """ Build the unit inventory. :param request: A synchronization request. :type request: SyncRequest :return: The built inventory. :rtype: UnitInventory """ # fetch child units try: conduit = NodesConduit() child_units = conduit.get_units(request.repo_id) except NodeError: raise except Exception: _log.exception(request.repo_id) raise GetChildUnitsError(request.repo_id) # fetch parent units try: request.progress.begin_manifest_download() url = request.config.get(constants.MANIFEST_URL_KEYWORD) manifest = Manifest(request.working_dir) try: manifest.read() except IOError, e: if e.errno == errno.ENOENT: pass except ValueError: # json decoding failed pass fetched_manifest = RemoteManifest(url, request.downloader, request.working_dir) fetched_manifest.fetch() if manifest != fetched_manifest or \ not manifest.is_valid() or not manifest.has_valid_units(): fetched_manifest.write() fetched_manifest.fetch_units() manifest = fetched_manifest if not manifest.is_valid(): raise InvalidManifestError()