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 = ContentReport() progress = HandlerProgress(conduit) progress.push_step('fetch_bindings') repo_ids = [key['repo_id'] for key in units if key] bindings = ParentBinding.fetch(repo_ids) strategy_class = find_strategy('additive') strategy = strategy_class(progress) strategy_report = strategy.synchronize(bindings, options) progress.end() details = strategy_report.dict() if strategy_report.errors: report.set_failed(details) else: report.set_succeeded(details) return 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 'node'. Updates the entire child node. :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 = ContentReport() progress = HandlerProgress(conduit) bindings = ParentBinding.fetch_all() strategy_name = options.setdefault(constants.STRATEGY_KEYWORD, constants.MIRROR_STRATEGY) strategy_class = find_strategy(strategy_name) strategy = strategy_class(progress) progress.started(bindings) strategy_report = strategy.synchronize(bindings, options) progress.finished() details = strategy_report.dict() if strategy_report.errors: report.set_failed(details) else: report.set_succeeded(details) return 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, 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. 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 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
class NodeHandler(ContentHandler): 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 """ 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 strategy_name = options.setdefault(constants.STRATEGY_KEYWORD, constants.MIRROR_STRATEGY) request = Request(conduit=conduit, progress=progress_report, summary=summary_report, bindings=bindings, scope=constants.NODE_SCOPE, options=options) strategy = find_strategy(strategy_name)() strategy.synchronize(request) for ne in summary_report.errors: log.error(ne) if summary_report.succeeded(): handler_report.set_succeeded(summary_report.dict()) else: handler_report.set_failed(summary_report.dict()) return handler_report
def test_strategy_factory(self): for name, strategy in strategies.STRATEGIES.items(): self.assertEqual(strategies.find_strategy(name), strategy) self.assertRaises(strategies.StrategyUnsupported, strategies.find_strategy, '---')