def test_can_build_resource_with_single_dep(self): role = models.PreCreatedIAMRole(role_arn='foo') app = models.Application(stage='dev', resources=[role]) dep_builder = DependencyBuilder() deps = dep_builder.build_dependencies(app) assert deps == [role]
def test_no_duplicate_depedencies(self): leaf = LeafResource(name='leaf') second_parent = FooResource(name='second', leaf=leaf) first_parent = FooResource(name='first', leaf=[leaf, second_parent]) app = models.Application(stage='dev', resources=[first_parent]) dep_builder = DependencyBuilder() deps = dep_builder.build_dependencies(app) assert deps == [leaf, second_parent, first_parent]
def test_is_first_element_in_list(self): shared_leaf = LeafResource(name='leaf-resource') first_parent = FooResource(name='first', leaf=shared_leaf) app = models.Application( stage='dev', resources=[first_parent, shared_leaf], ) dep_builder = DependencyBuilder() deps = dep_builder.build_dependencies(app) assert deps == [shared_leaf, first_parent]
def test_can_build_resource_with_dag_deps(self): shared_leaf = LeafResource(name='leaf-resource') first_parent = FooResource(name='first', leaf=shared_leaf) second_parent = FooResource(name='second', leaf=shared_leaf) app = models.Application(stage='dev', resources=[first_parent, second_parent]) dep_builder = DependencyBuilder() deps = dep_builder.build_dependencies(app) assert deps == [shared_leaf, first_parent, second_parent]
def test_can_compares_with_identity_not_equality(self): first_leaf = LeafResource(name='same-name') second_leaf = LeafResource(name='same-name') first_parent = FooResource(name='first', leaf=first_leaf) second_parent = FooResource(name='second', leaf=second_leaf) app = models.Application(stage='dev', resources=[first_parent, second_parent]) dep_builder = DependencyBuilder() deps = dep_builder.build_dependencies(app) assert deps == [first_leaf, first_parent, second_leaf, second_parent]
def _create_deployer( session, # type: Session config, # type: Config ui, # type: UI executor_cls, # type: Type[BaseExecutor] recorder_cls, # type: Type[ResultsRecorder] ): # type: (...) -> Deployer client = TypedAWSClient(session) osutils = OSUtils() return Deployer( application_builder=ApplicationGraphBuilder(), deps_builder=DependencyBuilder(), build_stage=create_build_stage( osutils, UI(), TemplatedSwaggerGenerator(), ), plan_stage=PlanStage( osutils=osutils, remote_state=RemoteState( client, config.deployed_resources(config.chalice_stage)), ), sweeper=ResourceSweeper(), executor=executor_cls(client, ui), recorder=recorder_cls(osutils=osutils), )
def create_app_packager(config, package_format='cloudformation', merge_template=None): # type: (Config, str, Optional[str]) -> AppPackager osutils = OSUtils() ui = UI() application_builder = ApplicationGraphBuilder() deps_builder = DependencyBuilder() post_processors = [] # type: List[TemplatePostProcessor] generator = None # type: Union[None, TemplateGenerator] if package_format == 'cloudformation': build_stage = create_build_stage(osutils, ui, CFNSwaggerGenerator()) post_processors.extend([ SAMCodeLocationPostProcessor(osutils=osutils), TemplateMergePostProcessor(osutils=osutils, merger=TemplateDeepMerger(), merge_template=merge_template) ]) generator = SAMTemplateGenerator(config) else: build_stage = create_build_stage(osutils, ui, TerraformSwaggerGenerator()) generator = TerraformGenerator(config) post_processors.append( TerraformCodeLocationPostProcessor(osutils=osutils)) resource_builder = ResourceBuilder(application_builder, deps_builder, build_stage) return AppPackager(generator, resource_builder, CompositePostProcessor(post_processors), osutils)
def create_deletion_deployer(client, ui): # type: (TypedAWSClient, UI) -> Deployer return Deployer( application_builder=ApplicationGraphBuilder(), deps_builder=DependencyBuilder(), build_stage=BuildStage(steps=[]), plan_stage=NoopPlanner(), sweeper=ResourceSweeper(), executor=Executor(client, ui), recorder=ResultsRecorder(osutils=OSUtils()), )
def create_app_packager( config, package_format='cloudformation', template_format='json', merge_template=None): # type: (Config, str, str, Optional[str]) -> AppPackager osutils = OSUtils() ui = UI() application_builder = ApplicationGraphBuilder() deps_builder = DependencyBuilder() post_processors = [] # type: List[TemplatePostProcessor] generator = None # type: Union[None, TemplateGenerator] template_serializer = cast(TemplateSerializer, JSONTemplateSerializer()) if package_format == 'cloudformation': build_stage = create_build_stage( osutils, ui, CFNSwaggerGenerator()) use_yaml_serializer = template_format == 'yaml' if merge_template is not None and \ YAMLTemplateSerializer.is_yaml_template(merge_template): # Automatically switch the serializer to yaml if they specify # a yaml template to merge, regardless of what template format # they specify. use_yaml_serializer = True if use_yaml_serializer: template_serializer = YAMLTemplateSerializer() post_processors.extend([ SAMCodeLocationPostProcessor(osutils=osutils), TemplateMergePostProcessor( osutils=osutils, merger=TemplateDeepMerger(), template_serializer=template_serializer, merge_template=merge_template)]) generator = SAMTemplateGenerator(config) else: build_stage = create_build_stage( osutils, ui, TerraformSwaggerGenerator()) generator = TerraformGenerator(config) post_processors.append( TerraformCodeLocationPostProcessor(osutils=osutils)) resource_builder = ResourceBuilder( application_builder, deps_builder, build_stage) return AppPackager( generator, resource_builder, CompositePostProcessor(post_processors), template_serializer, osutils)