def test_import_config__empty_stack(self, mock_isfile, mock_open, mock_print): self.migration_environment.connection_manager\ .call.return_value = {'Stacks': [ { } ]} mock_isfile.return_value = False fake_template = Template('fake-path', []) fake_template.relative_template_path = 'fake-relative-path' config.import_config(migration_environment=self.migration_environment, aws_stack_name="fake-aws-stack-name", config_path="environment-path/fake-stack", template=fake_template) mock_open.assert_called_with( "fake-spectre-dir/config/environment-path/fake-stack.yaml", 'w') mock_print.assert_has_calls([ call("template_path: fake-relative-path", file=mock_open.return_value.__enter__.return_value), call("stack_name: fake-aws-stack-name", file=mock_open.return_value.__enter__.return_value) ], any_order=False)
def import_template(migration_environment, aws_stack_name, template_path): """ Saves a template imported from AWS CloudFormation. :param path: The absolute path to the file which stores the template. :type path: str :param body: The body of the imported template. :type region: str or dict :raises: UnsupportedTemplateFileTypeError """ abs_template_path = os.path.join( migration_environment.environment_config.sceptre_dir, template_path) logging.getLogger(__name__).debug( "%s - Preparing to Import CloudFormation to %s", os.path.basename(template_path).split(".")[0], abs_template_path) response = migration_environment.connection_manager.call( service='cloudformation', command='get_template', kwargs={ 'StackName': aws_stack_name, 'TemplateStage': 'Original' }) _write_template( abs_template_path, _normalize_template_for_write(response['TemplateBody'], os.path.splitext(template_path)[1])) template = Template(abs_template_path, []) template.relative_template_path = template_path return template