Exemple #1
0
    def run_flow(self, project_config, org_config):
        # Add the repo root to syspath to allow for custom tasks and flows in
        # the repo
        sys.path.append(project_config.repo_root)

        flow = getattr(project_config, 'flows__{}'.format(self.flow))
        if not flow:
            raise FlowNotFoundError('Flow not found: {}'.format(self.flow))
        flow_config = FlowConfig(flow)

        if settings.METACI_FLOW_SUBCLASS_ENABLED:
            class_path = 'metaci.build.flows.MetaCIFlow'
        else:
            # Get the class to look up options
            class_path = flow_config.config.get(
                'class_path', 'cumulusci.core.flows.BaseFlow')

        flow_class = import_class(class_path)

        # Create the flow and handle initialization exceptions
        self.flow_instance = flow_class(project_config,
                                        flow_config,
                                        org_config,
                                        name=self.flow)

        if settings.METACI_FLOW_SUBCLASS_ENABLED:
            self.flow_instance.buildflow_id = self.pk

        # Run the flow
        res = self.flow_instance()

        return res
 def get_flow(self, name):
     """ Returns a FlowConfig """
     config = getattr(self, "flows__{}".format(name))
     if not config:
         error_msg = "Flow not found: {}".format(name)
         suggestion = self.get_suggested_name(name, self.flows)
         raise FlowNotFoundError(error_msg + suggestion)
     return FlowConfig(config)
Exemple #3
0
    def run_flow(self, project_config, org_config):
        flow = getattr(project_config, 'flows__{}'.format(self.flow))
        if not flow:
            raise FlowNotFoundError('Flow not found: {}'.format(flow_name))
        flow_config = FlowConfig(flow)

        # Get the class to look up options
        class_path = flow_config.config.get('class_path',
                                            'cumulusci.core.flows.BaseFlow')
        flow_class = import_class(class_path)

        # Create the flow and handle initialization exceptions
        self.flow_instance = flow_class(project_config, flow_config,
                                        org_config)
        res = self.flow_instance()
Exemple #4
0
    def run_flow(self, project_config, org_config):
        # Add the repo root to syspath to allow for custom tasks and flows in
        # the repo
        sys.path.append(project_config.repo_root)

        flow = getattr(project_config, 'flows__{}'.format(self.flow))
        if not flow:
            raise FlowNotFoundError('Flow not found: {}'.format(self.flow))
        flow_config = FlowConfig(flow)

        callbacks = None
        if settings.METACI_FLOW_CALLBACK_ENABLED:
            from metaci.build.flows import MetaCIFlowCallback
            callbacks = MetaCIFlowCallback(buildflow_id=self.pk)

        # Create the flow and handle initialization exceptions
        self.flow_instance = FlowCoordinator(project_config,
                                             flow_config,
                                             name=self.flow,
                                             callbacks=callbacks)

        # Run the flow
        return self.flow_instance.run(org_config)
 def get_flow(self, name):
     """ Returns a FlowConfig """
     config = getattr(self, "flows__{}".format(name))
     if not config:
         raise FlowNotFoundError("Flow not found: {}".format(name))
     return FlowConfig(config)
Exemple #6
0
def flow_run(config, flow_name, org, delete_org, debug, o, skip, no_prompt):
    # Check environment
    check_keychain(config)

    # Get necessary configs
    if org:
        org_config = config.project_config.get_org(org)
    else:
        org, org_config = config.project_config.keychain.get_default_org()
        if not org_config:
            raise click.UsageError(
                '`cci flow run` requires an org.'
                ' No org was specified and default org is not set.')

    org_config = check_org_expired(config, org, org_config)

    if delete_org and not org_config.scratch:
        raise click.UsageError(
            '--delete-org can only be used with a scratch org')

    flow = getattr(config.project_config, 'flows__{}'.format(flow_name))
    if not flow:
        raise FlowNotFoundError('Flow not found: {}'.format(flow_name))
    flow_config = FlowConfig(flow)
    if not flow_config.config:
        raise click.UsageError(
            'No configuration found for flow {}'.format(flow_name))

    # Get the class to look up options
    class_path = flow_config.config.get('class_path',
                                        'cumulusci.core.flows.BaseFlow')
    flow_class = import_class(class_path)

    exception = None

    # Parse command line options and add to task config
    options = {}
    if o:
        for option in o:
            options[option[0]] = option[1]

    # Create the flow and handle initialization exceptions
    try:
        flow = flow_class(config.project_config,
                          flow_config,
                          org_config,
                          options,
                          skip,
                          name=flow_name)
    except TaskRequiresSalesforceOrg as e:
        exception = click.UsageError(
            'This flow requires a salesforce org.  Use org default <name> to set a default org or pass the org name with the --org option'
        )
    except TaskOptionsError as e:
        exception = click.UsageError(e.message)
        handle_exception_debug(config, debug, e, throw_exception=exception)
    except Exception as e:
        handle_exception_debug(config, debug, e, no_prompt=no_prompt)

    if not exception:
        # Run the flow and handle exceptions
        try:
            flow()
        except TaskOptionsError as e:
            exception = click.UsageError(e.message)
            handle_exception_debug(config, debug, e, throw_exception=exception)
        except ApexTestException as e:
            exception = click.ClickException('Failed: ApexTestException')
            handle_exception_debug(config, debug, e, throw_exception=exception)
        except BrowserTestFailure as e:
            exception = click.ClickException('Failed: BrowserTestFailure')
            handle_exception_debug(config, debug, e, throw_exception=exception)
        except MetadataComponentFailure as e:
            exception = click.ClickException(
                'Failed: MetadataComponentFailure')
            handle_exception_debug(config, debug, e, throw_exception=exception)
        except MetadataApiError as e:
            exception = click.ClickException('Failed: MetadataApiError')
            handle_exception_debug(config, debug, e, throw_exception=exception)
        except ScratchOrgException as e:
            exception = click.ClickException('ScratchOrgException: {}'.format(
                e.message))
            handle_exception_debug(config, debug, e, throw_exception=exception)
        except Exception as e:
            handle_exception_debug(config, debug, e, no_prompt=no_prompt)

    # Delete the scratch org if --delete-org was set
    if delete_org:
        try:
            org_config.delete_org()
        except Exception as e:
            click.echo(
                'Scratch org deletion failed.  Ignoring the error below to complete the flow:'
            )
            click.echo(e.message)

    if exception:
        handle_sentry_event(config, no_prompt)
        raise exception
Exemple #7
0
def flow_info(config, flow_name):
    check_project_config(config)
    flow = getattr(config.project_config, 'flows__{}'.format(flow_name))
    if not flow:
        raise FlowNotFoundError('Flow not found: {}'.format(flow_name))
    click.echo(render_recursive(flow))
Exemple #8
0
def flow_run(config, flow_name, org, delete_org, debug):
    # Check environment
    check_keychain(config)

    # Get necessary configs
    if org:
        org_config = config.project_config.get_org(org)
    else:
        org, org_config = config.project_config.keychain.get_default_org()

    if delete_org and not org_config.scratch:
        raise click.UsageError(
            '--delete-org can only be used with a scratch org')

    flow = getattr(config.project_config, 'flows__{}'.format(flow_name))
    if not flow:
        raise FlowNotFoundError('Flow not found: {}'.format(flow_name))
    flow_config = FlowConfig(flow)
    if not flow_config.config:
        raise click.UsageError(
            'No configuration found for flow {}'.format(flow_name))

    # Get the class to look up options
    class_path = flow_config.config.get('class_path',
                                        'cumulusci.core.flows.BaseFlow')
    flow_class = import_class(class_path)

    exception = None

    # Create the flow and handle initialization exceptions
    try:
        flow = flow_class(config.project_config, flow_config, org_config)
    except TaskRequiresSalesforceOrg as e:
        exception = click.UsageError(
            'This flow requires a salesforce org.  Use org default <name> to set a default org or pass the org name with the --org option'
        )
    except TaskOptionsError as e:
        exception = click.UsageError(e.message)
    except Exception as e:
        if debug:
            import pdb
            import traceback
            traceback.print_exc()
            pdb.post_mortem()
        else:
            raise

    if not exception:
        # Run the flow and handle exceptions
        try:
            flow()
        except TaskOptionsError as e:
            exception = click.UsageError(e.message)
        except ApexTestException as e:
            exception = click.ClickException('Failed: ApexTestException')
        except MetadataComponentFailure as e:
            exception = click.ClickException(
                'Failed: MetadataComponentFailure')
        except MetadataApiError as e:
            exception = click.ClickException('Failed: MetadataApiError')
        except Exception as e:
            if debug:
                import pdb
                import traceback
                traceback.print_exc()
                pdb.post_mortem()
            else:
                raise

    # Delete the scratch org if --delete-org was set
    if delete_org:
        try:
            org_config.delete_org()
        except Exception as e:
            click.echo(
                'Scratch org deletion failed.  Ignoring the error below to complete the flow:'
            )
            click.echo(e.message)

    # Save the org config in case it was modified in a task
    if org and org_config:
        config.keychain.set_org(org, org_config)

    if exception:
        raise exception