def create_given_step_implementer(
        self,
        step_implementer,
        step_config={},
        step_name='',
        environment=None,
        implementer='',
        workflow_result=None,
        parent_work_dir_path='',
    ):
        config = Config({
            Config.CONFIG_KEY: {
                step_name: [{
                    'implementer': implementer,
                    'config': step_config
                }]
            }
        })
        step_config = config.get_step_config(step_name)
        sub_step_config = step_config.get_sub_step(implementer)

        if not workflow_result:
            workflow_result = WorkflowResult()

        step_implementer = step_implementer(
            workflow_result=workflow_result,
            parent_work_dir_path=parent_work_dir_path,
            config=sub_step_config,
            environment=environment)

        return step_implementer
예제 #2
0
    def create_given_step_implementer(
        self,
        step_implementer,
        step_config={},
        step_name='',
        environment=None,
        implementer='',
        results_dir_path='',
        results_file_name='',
        work_dir_path='',
    ):
        config = Config({
            Config.CONFIG_KEY: {
                step_name: [{
                    'implementer': implementer,
                    'config': step_config
                }]
            }
        })
        step_config = config.get_step_config(step_name)
        sub_step_config = step_config.get_sub_step(implementer)

        step_implementer = step_implementer(
            results_dir_path=results_dir_path,
            results_file_name=results_file_name,
            work_dir_path=work_dir_path,
            config=sub_step_config,
            environment=environment)

        return step_implementer
예제 #3
0
    def __init__(self,
                 config,
                 results_file_name='step-runner-results.yml',
                 work_dir_path='step-runner-working'):
        if isinstance(config, Config):
            self.__config = config
        else:
            self.__config = Config(config)

        self.__results_file_name = results_file_name
        self.__work_dir_path = work_dir_path

        self.__workflow_result = None
예제 #4
0
    def test_use_object_property_with_config_value(self):
        workflow_result = WorkflowResult()
        parent_work_dir_path = '/fake/path'
        step_config = {'tox-env': 'config-value-fake-env'}
        config = Config({
            Config.CONFIG_KEY: {
                'foo': [{
                    'implementer': 'ToxGeneric',
                    'config': step_config
                }]
            }
        })

        step_implementer = ToxGeneric(
            workflow_result=workflow_result,
            parent_work_dir_path=parent_work_dir_path,
            config=config,
            tox_env='object-property-fake-env')

        self.assertEqual(step_implementer.tox_env, 'object-property-fake-env')
    def test_use_object_property_with_config_value(self):
        workflow_result = WorkflowResult()
        parent_work_dir_path = '/fake/path'
        step_config = {'maven-phases-and-goals': ['config-value-fake-phase']}
        config = Config({
            Config.CONFIG_KEY: {
                'foo': [{
                    'implementer': 'MavenGeneric',
                    'config': step_config
                }]
            }
        })

        step_implementer = MavenGeneric(
            workflow_result=workflow_result,
            parent_work_dir_path=parent_work_dir_path,
            config=config,
            maven_phases_and_goals=['object-property-fake-phase'])

        self.assertEqual(step_implementer.maven_phases_and_goals,
                         ['object-property-fake-phase'])
예제 #6
0
    def test_use_object_property_with_config_value(self):
        workflow_result = WorkflowResult()
        parent_work_dir_path = '/fake/path'
        step_config = {'npm-args': ['config-value-fake-arg']}
        config = Config({
            Config.CONFIG_KEY: {
                'foo': [{
                    'implementer': 'NpmGeneric',
                    'config': step_config
                }]
            }
        })

        step_implementer = NpmGeneric(
            workflow_result=workflow_result,
            parent_work_dir_path=parent_work_dir_path,
            config=config,
            npm_args=['object-property-fake-arg'])

        self.assertEqual(step_implementer.npm_args,
                         ['object-property-fake-arg'])
def main(argv=None):
    """Main entry point for Ploigos step runner.
    """
    parser = argparse.ArgumentParser(description='Ploigos Step Runner (psr)')
    parser.add_argument('-s',
                        '--step',
                        required=True,
                        help='Workflow step to run')
    parser.add_argument('-e',
                        '--environment',
                        required=False,
                        help='The environment to run this step against.')
    parser.add_argument(
        '-c',
        '--config',
        required=True,
        nargs='+',
        help=
        'Workflow configuration files, or directories containing files, in yml or json'
    )
    parser.add_argument(
        '--step-config',
        metavar='STEP_CONFIG_KEY=STEP_CONFIG_VALUE',
        nargs='+',
        help=
        'Override step config provided by the given config-file with these arguments.',
        action=ParseKeyValueArge)
    args = parser.parse_args(argv)

    obfuscated_stdout = TextIOSelectiveObfuscator(sys.stdout)
    obfuscated_stderr = TextIOSelectiveObfuscator(sys.stderr)
    DecryptionUtils.register_obfuscation_stream(obfuscated_stdout)
    DecryptionUtils.register_obfuscation_stream(obfuscated_stderr)

    with redirect_stdout(obfuscated_stdout), redirect_stderr(
            obfuscated_stderr):
        # validate args
        for config_file in args.config:
            if not os.path.exists(config_file) or os.stat(
                    config_file).st_size == 0:
                print_error(
                    'specified -c/--config must exist and not be empty')
                sys.exit(101)

        try:
            config = Config(args.config)
        except (ValueError, AssertionError) as error:
            print_error(
                f"specified -c/--config is invalid configuration: {error}")
            sys.exit(102)

        config.set_step_config_overrides(args.step, args.step_config)
        # it is VERY important that the working dir be an absolute path because some
        # commands (looking at you maven) will change the context of relative paths on you
        step_runner = StepRunner(
            config=config,
            work_dir_path=os.path.abspath('step-runner-working'))

        try:
            if not step_runner.run_step(args.step, args.environment):
                print_error(f"Step {args.step} not successful")
                sys.exit(200)

        except Exception as error:  # pylint: disable=broad-except
            print_error(
                f"Fatal error calling step ({args.step}): {str(error)}")
            track = traceback.format_exc()
            print(track)
            sys.exit(300)