def step_impl(context, stack_name): sceptre_context = SceptreContext(command_path=stack_name + '.yaml', project_path=context.sceptre_dir) config_path = sceptre_context.full_config_path() template_path = sceptre_context.full_templates_path() with open(os.path.join(config_path, stack_name + '.yaml')) as config_file: stack_config = yaml.safe_load(config_file) if "template" in stack_config and stack_config["template"]["type"].lower( ) == "s3": segments = stack_config["template"]["path"].split('/') bucket = segments[0] key = "/".join(segments[1:]) source_file = f'{template_path}/{segments[-1]}' boto3.client('s3').upload_file(source_file, bucket, key) else: config_path = sceptre_context.full_config_path() with open(os.path.join(config_path, stack_name + '.yaml')) as config_file: stack_config = yaml.safe_load(config_file) sceptre_plan = SceptrePlan(sceptre_context) try: context.output = sceptre_plan.generate() except Exception as e: context.error = e
def set_template_path(context, stack_name, template_name): sceptre_context = SceptreContext(command_path=stack_name + ".yaml", project_path=context.sceptre_dir) config_path = sceptre_context.full_config_path() template_path = os.path.join(sceptre_context.project_path, sceptre_context.templates_path, template_name) with open(os.path.join(config_path, stack_name + '.yaml')) as config_file: stack_config = yaml.safe_load(config_file) if "template_path" in stack_config: stack_config["template_path"] = template_path if "template" in stack_config: template_handler_type = stack_config["template"]["type"] if template_handler_type.lower() == 's3': segments = stack_config["template"]["path"].split('/') bucket = context.TEST_ARTIFACT_BUCKET_NAME key = "/".join(segments[1:]) stack_config["template"]["path"] = f'{bucket}/{key}' else: stack_config["template"]["path"] = template_path with open(os.path.join(config_path, stack_name + '.yaml'), 'w') as config_file: yaml.safe_dump(stack_config, config_file, default_flow_style=False)
def test_full_config_path_returns_correct_path(self): context = SceptreContext(project_path="project_path", command_path=sentinel.command_path, user_variables=sentinel.user_variables, options=sentinel.options, output_format=sentinel.output_format, no_colour=sentinel.no_colour) full_config_path = path.join("project_path", self.config_path) assert context.full_config_path() == full_config_path
def step_impl(context, stack_name): sceptre_context = SceptreContext(command_path=stack_name + '.yaml', project_path=context.sceptre_dir, ignore_dependencies=True) yaml_file = Path(sceptre_context.full_config_path()) / f'{stack_name}.yaml' with yaml_file.open(mode='r') as f: loaded = yaml.load(f) original_config = deepcopy(loaded) loaded['stack_tags'] = {'NewTag': 'NewValue'} dump_stack_config(yaml_file, loaded) context.add_cleanup(dump_stack_config, yaml_file, original_config)
def test_modified_config_path_returns_correct_path(self): context = SceptreContext( project_path="project_path", config_directory="some_other_path", command_path=sentinel.command_path, user_variables=sentinel.user_variables, options=sentinel.options, output_format=sentinel.output_format, no_colour=sentinel.no_colour, ignore_dependencies=sentinel.ignore_dependencies) full_config_path = path.join("project_path", "some_other_path") assert context.full_config_path() == full_config_path
def set_template_path(context, stack_name, template_name): sceptre_context = SceptreContext(command_path=stack_name + ".yaml", project_path=context.sceptre_dir) config_path = sceptre_context.full_config_path() template_path = os.path.join(sceptre_context.project_path, sceptre_context.templates_path, template_name) with open(os.path.join(config_path, stack_name + '.yaml')) as config_file: stack_config = yaml.safe_load(config_file) stack_config["template_path"] = template_path with open(os.path.join(config_path, stack_name + '.yaml'), 'w') as config_file: yaml.safe_dump(stack_config, config_file, default_flow_style=False)