コード例 #1
0
    def test_construct_stack_group_with_valid_config(self, filepaths, targets,
                                                     results):
        with self.runner.isolated_filesystem():
            project_path = os.path.abspath('./example')
            config_dir = os.path.join(project_path, "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(project_path)

            def check_stack_group(stack_group, details):
                assert sorted(details["stacks"]) == sorted(
                    [stack.name for stack in stack_group.stacks])
                for sub_group in stack_group.sub_stack_groups:
                    sub_group_details =\
                      details["stack_groups"][sub_group.path]
                    check_stack_group(sub_group, sub_group_details)

            for i, target in enumerate(targets):
                stack_group =\
                  config_reader.construct_stack_group(target)
                expected = results[i]
                check_stack_group(stack_group, expected[stack_group.path])
コード例 #2
0
ファイル: helpers.py プロジェクト: rgitzel/sceptre
def get_stack_or_stack_group(ctx, path):
    """
    Parses the path to generate relevant Stack Group and Stack object.

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

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

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

    return (stack, stack_group)
コード例 #3
0
def get_stack_or_stack_group(context):
    """
    Parses the path to generate relevant Stack Group and Stack object.

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

    config_reader = ConfigReader(
        context.project_path, context.user_variables
    )

    if os.path.splitext(context.command_path)[1]:
        stack = config_reader.construct_stack(context.command_path)
    else:
        stack_group = config_reader.construct_stack_group(context.command_path)

    return (stack, stack_group)