def update(self, conduit, units, options): """ Update the specified content units. Each unit must be of type 'repository'. Updates only the repositories specified in the unit_key by repo_id. Report format: succeeded: <bool> details: { errors: [ { error_id: <str>, details: {} }, ] repositories: [ { repo_id: <str>, action: <str>, units: { added: <int>, updated: <int>, removed: <int> } }, ] } :param conduit: A handler conduit. :type conduit: pulp.agent.lib.conduit.Conduit :param units: A list of content unit_keys. :type units: list :param options: Unit update options. :type options: dict :return: An update report. :rtype: ContentReport """ summary_report = SummaryReport() progress_report = HandlerProgress(conduit) repo_ids = [key['repo_id'] for key in units if key] bindings = BindingsOnParent.fetch(repo_ids) strategy_name = options.setdefault(constants.STRATEGY_KEYWORD, constants.MIRROR_STRATEGY) request = SyncRequest( conduit=conduit, progress=progress_report, summary=summary_report, bindings=bindings, scope=constants.REPOSITORY_SCOPE, options=options) strategy = find_strategy(strategy_name)() strategy.synchronize(request) for ne in summary_report.errors: log.error(ne) handler_report = ContentReport() if summary_report.succeeded(): handler_report.set_succeeded(summary_report.dict()) else: handler_report.set_failed(summary_report.dict()) return handler_report
def update(self, conduit, units, options): """ Update the specified content units. Each unit must be of type 'repository'. Updates only the repositories specified in the unit_key by repo_id. :param conduit: A handler conduit. :type conduit: pulp.agent.lib.conduit.Conduit :param units: A list of content unit_keys. :type units: list :param options: Unit update options. :type options: dict :return: An update report. :rtype: ContentReport """ report = SummaryReport() progress = HandlerProgress(conduit) repo_ids = [key['repo_id'] for key in units if key] bindings = BindingsOnParent.fetch(repo_ids) strategy_class = find_strategy(constants.ADDITIVE_STRATEGY) strategy = strategy_class(progress, report) progress.started(bindings) strategy.synchronize(bindings, options) handler_report = ContentReport() if report.succeeded(): handler_report.set_succeeded(report.dict()) else: handler_report.set_failed(report.dict()) return handler_report
def update(self, conduit, units, options): """ Update the specified content units. Each unit must be of type 'repository'. Updates only the repositories specified in the unit_key by repo_id. Report format: succeeded: <bool> details: { errors: [ { error_id: <str>, details: {} }, ] repositories: [ { repo_id: <str>, action: <str>, units: { added: <int>, updated: <int>, removed: <int> } }, ] } :param conduit: A handler conduit. :type conduit: pulp.agent.lib.conduit.Conduit :param units: A list of content unit_keys. :type units: list :param options: Unit update options. :type options: dict :return: An update report. :rtype: ContentReport """ summary_report = SummaryReport() progress_report = HandlerProgress(conduit) repo_ids = [key['repo_id'] for key in units if key] bindings = BindingsOnParent.fetch(repo_ids) strategy_name = options.setdefault(constants.STRATEGY_KEYWORD, constants.MIRROR_STRATEGY) request = SyncRequest( conduit=conduit, progress=progress_report, summary=summary_report, bindings=bindings, options=options) strategy = find_strategy(strategy_name)() strategy.synchronize(request) for ne in summary_report.errors: log.error(ne) handler_report = ContentReport() if summary_report.succeeded(): handler_report.set_succeeded(summary_report.dict()) else: handler_report.set_failed(summary_report.dict()) return handler_report
def test_update_rendering(self): repo_ids = ['repo_%d' % n for n in range(0, 3)] handler_report = ContentReport() summary_report = SummaryReport() summary_report.setup([{'repo_id': r} for r in repo_ids]) for r in summary_report.repository.values(): r.action = RepositoryReport.ADDED handler_report.set_succeeded(details=summary_report.dict()) renderer = UpdateRenderer(self.context.prompt, handler_report.dict()) renderer.render() self.assertEqual(len(self.recorder.lines), 32)
def test_update_rendering_with_errors(self): repo_ids = ['repo_%d' % n for n in range(0, 3)] handler_report = ContentReport() summary_report = SummaryReport() summary_report.setup([{'repo_id': r} for r in repo_ids]) for r in summary_report.repository.values(): r.action = RepositoryReport.ADDED summary_report.errors.append(UnitDownloadError('http://abc/x.rpm', repo_ids[0], dict(response_code=401))) handler_report.set_failed(details=summary_report.dict()) renderer = UpdateRenderer(self.context.prompt, handler_report.dict()) renderer.render() self.assertEqual(len(self.recorder.lines), 42)
def update(self, conduit, units, options): """ Update the specified content units. Each unit must be of type 'node'. Updates the entire child node. Report format: succeeded: <bool> details: { errors: [ { error_id: <str>, details: {} }, ] repositories: [ { repo_id: <str>, action: <str>, units: { added: <int>, updated: <int>, removed: <int> } }, ] } :param conduit: A handler conduit. :type conduit: pulp.agent.lib.conduit.Conduit :param units: A list of content unit_keys. :type units: list :param options: Unit update options. :type options: dict :return: An update report. :rtype: ContentReport """ summary_report = SummaryReport() progress_report = HandlerProgress(conduit) bindings = BindingsOnParent.fetch_all() strategy_name = options.setdefault(constants.STRATEGY_KEYWORD, constants.MIRROR_STRATEGY) strategy_class = find_strategy(strategy_name) strategy = strategy_class(progress_report, summary_report) strategy.synchronize(bindings, options) for ne in summary_report.errors: log.error(ne) handler_report = ContentReport() if summary_report.succeeded(): handler_report.set_succeeded(summary_report.dict()) else: handler_report.set_failed(summary_report.dict()) return handler_report
def test_update_rendering_with_errors(self): repo_ids = ['repo_%d' % n for n in range(0, 3)] handler_report = ContentReport() summary_report = SummaryReport() summary_report.setup([{'repo_id': r} for r in repo_ids]) for r in summary_report.repository.values(): r.action = RepositoryReport.ADDED summary_report.errors.append( UnitDownloadError('http://abc/x.rpm', repo_ids[0], dict(response_code=401))) handler_report.set_failed(details=summary_report.dict()) renderer = UpdateRenderer(self.context.prompt, handler_report.dict()) renderer.render() self.assertEqual(len(self.recorder.lines), 48)
def update(self, conduit, units, options): """ Update the specified content units. Each unit must be of type 'node'. Updates the entire child node. Report format: succeeded: <bool> details: { errors: [ { error_id: <str>, details: {} }, ] repositories: [ { repo_id: <str>, action: <str>, units: { added: <int>, updated: <int>, removed: <int> } }, ] } :param conduit: A handler conduit. :type conduit: pulp.agent.lib.conduit.Conduit :param units: A list of content unit_keys. :type units: list :param options: Unit update options. :type options: dict :return: An update report. :rtype: ContentReport """ warnings.warn(TASK_DEPRECATION_WARNING, NodeDeprecationWarning) handler_report = ContentReport() summary_report = SummaryReport() progress_report = HandlerProgress(conduit) pulp_bindings = parent_bindings(options) try: bindings = RepositoryBinding.fetch_all(pulp_bindings, conduit.consumer_id) except GetBindingsError, ne: log.error(ne) summary_report.errors.append(ne) handler_report.set_failed(summary_report.dict()) return handler_report
def test_update_rendering(self): repo_ids = ['repo_%d' % n for n in range(0, 3)] handler_report = ContentReport() summary_report = SummaryReport() summary_report.setup([{'repo_id': r} for r in repo_ids]) for r in summary_report.repository.values(): r.action = RepositoryReport.ADDED download_report = DownloadReport() download_report.downloads[PRIMARY_ID] = DownloadDetails() download_report.downloads['content-world'] = DownloadDetails() r.sources = download_report.dict() handler_report.set_succeeded(details=summary_report.dict()) renderer = UpdateRenderer(self.context.prompt, handler_report.dict()) renderer.render() self.assertEqual(len(self.recorder.lines), 59)
def request(self, cancel_on=0): conduit = TestConduit(cancel_on) progress = HandlerProgress(conduit) summary = SummaryReport() request = SyncRequest(conduit=conduit, progress=progress, summary=summary, bindings=[dict(repo_id=REPO_ID, details={})], options={}) return request
def request(self, cancel_on=0): conduit = TestConduit(cancel_on) progress = HandlerProgress(conduit) summary = SummaryReport() request = strategies.Request( conduit=conduit, progress=progress, summary=summary, bindings=[dict(repo_id=REPO_ID, details={})], scope=constants.NODE_SCOPE, options={constants.PARENT_SETTINGS: PARENT_SETTINGS}) return request
def test_synchronize_repository_reporting(self, fake_synchronization): repo_id = '1234' added = 300 updated = 0 removed = 0 errors = [ {'details': {'A': 1, 'B': 2}, 'error_id': 1}, {'details': {'A': 10, 'B': 20}, 'error_id': 2} ] sources = { 'downloads': { 'content-world': {'total_failed': 2, 'total_succeeded': 100}, 'content-galaxy': {'total_failed': 0, 'total_succeeded': 200} }, 'total_sources': 10 } fake_request = Mock() fake_request.options = {constants.SKIP_CONTENT_UPDATE_KEYWORD: False} fake_request.cancelled.return_value = False fake_request.summary = SummaryReport() fake_request.summary.repository[repo_id] = RepositoryReport(repo_id) fake_synchronization.return_value = { 'added_count': added, 'updated_count': updated, 'removed_count': removed, 'details': { 'errors': errors, 'sources': sources } } # test strategy = HandlerStrategy() strategy._synchronize_repository(fake_request, repo_id) # validation expected = { 'errors': errors, 'repositories': [ { 'repo_id': repo_id, 'action': 'pending', 'units': {'updated': updated, 'added': added, 'removed': removed}, 'sources': sources } ]} self.assertEqual(fake_request.summary.dict(), expected)