Ejemplo n.º 1
0
    def test_construct_environment_with_valid_config(
        self, filepaths, targets, results
    ):
        with self.runner.isolated_filesystem():
            sceptre_dir = os.path.abspath('./example')
            config_dir = os.path.join(sceptre_dir, "config")
            os.makedirs(config_dir)

            for rel_path in filepaths:
                abs_path = os.path.join(config_dir, rel_path)
                dir_path = abs_path
                if abs_path.endswith(".yaml"):
                    dir_path = os.path.split(abs_path)[0]
                if not os.path.exists(dir_path):
                    try:
                        os.makedirs(dir_path)
                    except OSError as exc:
                        if exc.errno != errno.EEXIST:
                            raise

                config = {
                    "region": "region",
                    "project_code": "project_code",
                    "template_path": rel_path
                }
                with open(abs_path, 'w') as config_file:
                    yaml.safe_dump(
                        config, stream=config_file, default_flow_style=False
                    )

            config_reader = ConfigReader(sceptre_dir)

            def check_environment(environment, details):
                assert sorted(details["stacks"]) == sorted([
                    stack.name for stack in environment.stacks
                ])
                for sub_env in environment.sub_environments:
                    sub_env_details = details["environments"][sub_env.path]
                    check_environment(sub_env, sub_env_details)

            for i, target in enumerate(targets):
                environment = config_reader.construct_environment(target)
                expected = results[i]
                check_environment(environment, expected[environment.path])
Ejemplo n.º 2
0
def get_stack_or_env(ctx, path):
    """
    Parses the path to generate relevant Environment and Stack object.

    :param ctx: Cli context.
    :type ctx: click.Context
    :param path: Path to either stack config or environment folder.
    :type path: str
    """
    stack = None
    env = None

    config_reader = ConfigReader(ctx.obj["awsscripter_dir"],
                                 ctx.obj["user_variables"])

    if os.path.splitext(path)[1]:
        stack = config_reader.construct_stack(path)
    else:
        env = config_reader.construct_environment(path)

    return (stack, env)