Exemplo n.º 1
0
    def install(cls, conduit, units, options):
        """
        Install content unit(s).

        :param  conduit: A handler conduit
        :type   conduit: pulp.agent.gofer.pulp.Conduit
        :param  units: A list of content unit (keys)
        :type   units: list
        :param  options: Unit install options.
        :type   options: dict

        :return:    An install report.
                    "details" contains a dict with keys "errors" and "successes".
                    "errors" are any operation where the "puppet module" tool
                    returned a non-zero exit code or where the output from that
                    tool indicated an error. Everything else is in "successes".
        :rtype:     pulp.agent.lib.report.ContentReport
        """
        host = options[constants.FORGE_HOST]
        repo_id = options.get(constants.REPO_ID_OPTION)
        successes, errors, num_changes = cls._perform_operation(
            'install', units, cls._generate_forge_url(conduit, host, repo_id))
        report = ContentReport()
        report.set_succeeded({'successes': successes, 'errors': errors}, num_changes)
        return report
Exemplo n.º 2
0
    def install(cls, conduit, units, options):
        """
        Install content unit(s).

        :param  conduit: A handler conduit
        :type   conduit: pulp.agent.gofer.pulp.Conduit
        :param  units: A list of content unit (keys)
        :type   units: list
        :param  options: Unit install options.
        :type   options: dict

        :return:    An install report.
                    "details" contains a dict with keys "errors" and "successes".
                    "errors" are any operation where the "puppet module" tool
                    returned a non-zero exit code or where the output from that
                    tool indicated an error. Everything else is in "successes".
        :rtype:     pulp.agent.lib.report.ContentReport
        """
        host = options[constants.FORGE_HOST]
        repo_id = options.get(constants.REPO_ID_OPTION)
        skip_dep = options.get(constants.SKIP_DEP_OPTION)
        module_path = options.get(constants.MODULEPATH_OPTION)
        successes, errors, num_changes = cls._perform_operation(
            'install', units, cls._generate_forge_url(conduit, host, repo_id),
            skip_dep, module_path)
        report = ContentReport()
        report.set_succeeded({
            'successes': successes,
            'errors': errors
        }, num_changes)
        return report
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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)
        progress.push_step('fetch_bindings')
        bindings = RemoteBinding.fetch_all()

        strategy_name = options.setdefault('strategy', 'mirror')
        strategy_class = find_strategy(strategy_name)
        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
Exemplo n.º 5
0
    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 = RemoteBinding.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
Exemplo n.º 6
0
    def update(cls, conduit, units, options):
        """
        Update content unit(s).

        :param  conduit: A handler conduit
        :type   conduit: pulp.agent.gofer.pulp.Conduit
        :param  units: A list of content unit (keys)
        :type   units: list
        :param  options: Unit update options.
        :type   options: dict
        :return:    An update report.
                    "details" contains a dict with keys "errors" and "successes".
                    "errors" are any operation where the "puppet module" tool
                    returned a non-zero exit code or where the output from that
                    tool indicated an error. Everything else is in "successes".
        :rtype:     pulp.agent.lib.report.ContentReport
        """
        repo_id = options.get(constants.REPO_ID_OPTION)
        successes, errors, num_changes = cls._perform_operation(
            'upgrade', units, cls._generate_forge_url(conduit, repo_id))
        report = ContentReport()
        report.set_succeeded({
            'successes': successes,
            'errors': errors
        }, num_changes)
        return report
Exemplo n.º 7
0
Arquivo: handler.py Projeto: juwu/pulp
    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
Exemplo n.º 8
0
    def update(cls, conduit, units, options):
        """
        Update content unit(s).

        :param  conduit: A handler conduit
        :type   conduit: pulp.agent.gofer.pulp.Conduit
        :param  units: A list of content unit (keys)
        :type   units: list
        :param  options: Unit update options.
        :type   options: dict
        :return:    An update report.
                    "details" contains a dict with keys "errors" and "successes".
                    "errors" are any operation where the "puppet module" tool
                    returned a non-zero exit code or where the output from that
                    tool indicated an error. Everything else is in "successes".
        :rtype:     pulp.agent.lib.report.ContentReport
        """
        host = options[constants.FORGE_HOST]
        repo_id = options.get(constants.REPO_ID_OPTION)
        skip_dep = options.get(constants.SKIP_DEP_OPTION)
        module_path = options.get(constants.MODULEPATH_OPTION)
        successes, errors, num_changes = cls._perform_operation(
            "upgrade", units, cls._generate_forge_url(conduit, host, repo_id), skip_dep, module_path
        )
        report = ContentReport()
        report.set_succeeded({"successes": successes, "errors": errors}, num_changes)
        return report
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    def uninstall(cls, conduit, units, options):
        """
        Uninstall content unit(s). In case dependency conflicts cause an
        uninstall to fail, this will continue to retry the entire collection of
        failed operations until an entire pass results in no successes.

        :param  conduit: A handler conduit
        :type   conduit: pulp.agent.gofer.pulp.Conduit
        :param  units: A list of content unit (keys)
        :type   units: list
        :param  options: Unit uninstall options.
        :type   options: dict
        :return:    An uninstall report.
                    "details" contains a dict with keys "errors" and "successes".
                    "errors" are any operation where the "puppet module" tool
                    returned a non-zero exit code or where the output from that
                    tool indicated an error. Everything else is in "successes".
        :rtype:     pulp.agent.lib.report.ContentReport
        """
        module_path = options.get(constants.MODULEPATH_OPTION)
        previous_failure_count = 0
        successes, errors, num_changes = cls._perform_operation("uninstall", units, None, None, module_path)

        # need this so we can easily access original unit objects when constructing
        # new requests below
        units_by_full_name = dict(("%s/%s" % (u["author"], u["name"]), u) for u in units)

        # loop over the results, and keep trying to uninstall failed attempts as
        # a dumb but effective way of dealing with dependency-related failures.
        # keep trying until we get to an iteration where no more modules are
        # uninstalled.
        while True:
            failed_names = errors.keys()
            if len(failed_names) == 0:
                # success all around! no need to retry
                break
            elif previous_failure_count == 0 or len(failed_names) < previous_failure_count:
                previous_failure_count = len(failed_names)
                failed_units = [units_by_full_name[full_name] for full_name in failed_names]
                # retry the failed attempts
                new_successes, new_errors, new_num_changes = cls._perform_operation(
                    "uninstall", failed_units, None, None, module_path
                )
                num_changes += new_num_changes
                # move new successes from "errors" to "successes"
                successes.update(new_successes)
                for full_name in new_successes.keys():
                    del errors[full_name]
            else:
                # non-zero failure count didn't change, so it's time to give up.
                break

        report = ContentReport()
        report.set_succeeded({"successes": successes, "errors": errors}, num_changes)
        return report
Exemplo n.º 11
0
    def uninstall(cls, conduit, units, options):
        """
        Uninstall content unit(s). In case dependency conflicts cause an
        uninstall to fail, this will continue to retry the entire collection of
        failed operations until an entire pass results in no successes.

        :param  conduit: A handler conduit
        :type   conduit: pulp.agent.gofer.pulp.Conduit
        :param  units: A list of content unit (keys)
        :type   units: list
        :param  options: Unit uninstall options.
        :type   options: dict
        :return:    An uninstall report.
                    "details" contains a dict with keys "errors" and "successes".
                    "errors" are any operation where the "puppet module" tool
                    returned a non-zero exit code or where the output from that
                    tool indicated an error. Everything else is in "successes".
        :rtype:     pulp.agent.lib.report.ContentReport
        """
        module_path = options.get(constants.MODULEPATH_OPTION)
        previous_failure_count = 0
        successes, errors, num_changes = cls._perform_operation('uninstall', units, None, None, module_path)

        # need this so we can easily access original unit objects when constructing
        # new requests below
        units_by_full_name = dict(('%s/%s'% (u['author'], u['name']), u) for u in units)

        # loop over the results, and keep trying to uninstall failed attempts as
        # a dumb but effective way of dealing with dependency-related failures.
        # keep trying until we get to an iteration where no more modules are
        # uninstalled.
        while True:
            failed_names = errors.keys()
            if len(failed_names) == 0:
                # success all around! no need to retry
                break
            elif previous_failure_count == 0 or len(failed_names) < previous_failure_count:
                previous_failure_count = len(failed_names)
                failed_units = [units_by_full_name[full_name] for full_name in failed_names]
                # retry the failed attempts
                new_successes, new_errors, new_num_changes = \
                    cls._perform_operation('uninstall', failed_units, None, None, module_path)
                num_changes += new_num_changes
                # move new successes from "errors" to "successes"
                successes.update(new_successes)
                for full_name in new_successes.keys():
                    del errors[full_name]
            else:
                # non-zero failure count didn't change, so it's time to give up.
                break

        report = ContentReport()
        report.set_succeeded({'successes': successes, 'errors': errors}, num_changes)
        return report
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 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)
Exemplo n.º 14
0
 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)
Exemplo n.º 15
0
    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
Exemplo n.º 16
0
 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)
Exemplo n.º 17
0
    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
Exemplo n.º 18
0
 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)
Exemplo n.º 19
0
 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)
Exemplo n.º 20
0
    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
Exemplo n.º 21
0
    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
Exemplo n.º 22
0
 def test_update_rendering_with_message(self):
     handler_report = ContentReport()
     handler_report.set_failed(details=dict(message='Authorization Failed'))
     renderer = UpdateRenderer(self.context.prompt, handler_report.dict())
     renderer.render()
     self.assertEqual(len(self.recorder.lines), 4)
Exemplo n.º 23
0
 def set_succeeded(self, details):
     num_changes = \
         len(details['resolved']) + \
         len(details['deps'])
     ContentReport.set_succeeded(self, details, num_changes)
Exemplo n.º 24
0
 def test_update_rendering_with_message(self):
     handler_report = ContentReport()
     handler_report.set_failed(details=dict(message='Authorization Failed'))
     renderer = UpdateRenderer(self.context.prompt, handler_report.dict())
     renderer.render()
     self.assertEqual(len(self.recorder.lines), 4)
Exemplo n.º 25
0
 def set_succeeded(self, details):
     num_changes = len(details["resolved"]) + len(details["deps"])
     ContentReport.set_succeeded(self, details, num_changes)
Exemplo n.º 26
0
 def set_succeeded(self, details):
     num_changes = \
         len(details['resolved'])+ \
         len(details['deps'])
     ContentReport.set_succeeded(self, details, num_changes)