def setUp(self):
        self.context = chaincontext.ChainContext(
            template=troposphere.Template(), instance_name='justtestin')
        self.context.metadata[META_PIPELINE_BUCKET_POLICY_REF] = "blah"

        self.pipeline_name = "ThatPipeline"
        self.deploy_stage_name = "DeployIt"
        TestCloudFormationAction._add_pipeline_and_stage_to_template(
            self.context.template, self.pipeline_name, self.deploy_stage_name)
Esempio n. 2
0
    def create_template(self):
        t = self.template
        t.add_description("Acceptance Tests for cumulus scaling groups")

        # TODO fix
        # instance = self.name + self.context.environment['env']
        instance = "someinstance"
        # TODO: give to builder
        the_chain = chain.Chain()

        the_chain.add(ingress_rule.IngressRule(
            port_to_open="22",
            cidr="10.0.0.0/8"
        ))

        instance_profile_name = "InstanceProfile" + self.name

        the_chain.add(InstanceProfileRole(
            instance_profile_name=instance_profile_name,
            role=iam.Role(
                "SomeRoleName1",
                AssumeRolePolicyDocument=Policy(
                    Statement=[
                        Statement(
                            Effect=Allow,
                            Action=[AssumeRole],
                            Principal=Principal("Service", ["ec2.amazonaws.com", "s3.amazonaws.com"])
                        )
                    ]
                ),
            )))

        launchConfigName = 'lc' + self.name

        the_chain.add(launch_config.LaunchConfig(asg_name=self.name,
                                                 launch_config_name=launchConfigName,
                                                 meta_data=self.get_metadata(),
                                                 instance_profile_name=instance_profile_name), )

        the_chain.add(block_device_data.BlockDeviceData(ec2.BlockDeviceMapping(
            DeviceName="/dev/xvda",
            Ebs=ec2.EBSBlockDevice(
                VolumeSize="40"
            ))))

        the_chain.add(scaling_group.ScalingGroup(
            launch_config_name=launchConfigName,
        ))

        chain_context = chaincontext.ChainContext(
            template=t,
            instance_name=instance
        )

        the_chain.run(chain_context)
Esempio n. 3
0
    def create_template(self):
        t = self.template
        t.add_description("Acceptance Tests for cumulus scaling groups")

        the_chain = chain.Chain()

        application_port = "8000"

        the_chain.add(
            launch_config.LaunchConfig(prefix='websitesimple',
                                       vpc_id=Ref('VpcId'),
                                       meta_data=self.get_metadata(),
                                       bucket_name=self.context.bucket_name))

        the_chain.add(
            ingress_rule.IngressRule(port_to_open="22", cidr="10.0.0.0/8"))

        the_chain.add(
            ingress_rule.IngressRule(port_to_open=application_port,
                                     cidr="10.0.0.0/8"))

        the_chain.add(
            block_device_data.BlockDeviceData(
                ec2.BlockDeviceMapping(
                    DeviceName="/dev/xvda",
                    Ebs=ec2.EBSBlockDevice(VolumeSize="40"))))

        the_chain.add(
            target_group.TargetGroup(port=application_port,
                                     vpc_id=Ref("VpcId")))

        the_chain.add(scaling_group.ScalingGroup())

        the_chain.add(
            dns.Dns(base_domain=Ref("BaseDomain"),
                    hosted_zone_id=Ref("AlbCanonicalHostedZoneID"),
                    target=Ref("AlbDNSName"),
                    dns_name=troposphere.Join('', [
                        self.context.namespace,
                        "-websitesimple",
                    ])))

        the_chain.add(alb_port.AlbPort(port_to_open=application_port, ))

        the_chain.add(
            listener_rule.ListenerRule(base_domain_name=Ref("BaseDomain"),
                                       alb_listener_rule=Ref("IAlbListener"),
                                       path_pattern="/*",
                                       priority="2"))

        chain_context = chaincontext.ChainContext(template=t, )

        the_chain.run(chain_context)
    def test_should_build_template_with_required_parameters_added_automatically(
            self):
        the_chain = chain.Chain()
        mock_step = MockStepWithRequiredParam()
        the_chain.add(mock_step)

        self.context = chaincontext.ChainContext(
            template=troposphere.Template(),
            instance_name='will_generate_parameters',
            auto_param_creation=True)

        the_chain.run(self.context)
Esempio n. 5
0
    def setUp(self):
        self.context = chaincontext.ChainContext(
            template=troposphere.Template(), instance_name='justtestin')
        self.context.metadata[META_PIPELINE_BUCKET_POLICY_REF] = "blah"
        self.context.metadata[META_PIPELINE_BUCKET_NAME] = troposphere.Ref(
            "notabucket")

        self.pipeline_name = "ThatPipeline"
        self.deploy_stage_name = "DeployIt"
        self.source_stage_name = "SourceIt"

        TestCodeBuildAction._add_pipeline_and_stage_to_template(
            self.context.template, self.pipeline_name, self.deploy_stage_name)
Esempio n. 6
0
 def setUp(self):
     self.context = chaincontext.ChainContext(
         template=troposphere.Template(),
         instance_name='justtestin',
     )
     self.environment = codebuild.Environment(
         ComputeType='BUILD_GENERAL1_SMALL',
         Image='aws/codebuild/python:2.7.12',
         Type='LINUX_CONTAINER',
         EnvironmentVariables=[{
             'Name': 'TEST_VAR',
             'Value': 'demo'
         }],
     )
Esempio n. 7
0
    def create_template(self):

        t = self.template
        t.add_description("Acceptance Tests for cumulus scaling groups")

        instance = self.context.environment['namespace'] + self.context.environment['env']

        the_chain = chain.Chain()

        the_chain.add(alb.Alb())

        chain_context = chaincontext.ChainContext(
            template=t,
            instance_name=instance
        )

        the_chain.run(chain_context)
    def test_should_build_template_with_required_parameters_added_externally(
            self):
        the_chain = chain.Chain()
        mock_step = MockStepWithRequiredParam()
        the_chain.add(mock_step)

        self.context = chaincontext.ChainContext(
            template=troposphere.Template(),
            instance_name='wont_generate_parameters',
            auto_param_creation=False)

        self.context.template.add_parameter(
            troposphere.Parameter("NumberOfMinions", Type="String"))

        self.context.template.add_parameter(
            troposphere.Parameter("NumberOfEyeballs", Type="String"))

        the_chain.run(self.context)
    def create_template(self):
        t = self.template
        t.add_description("Acceptance Tests for cumulus scaling groups")

        # TODO fix
        # instance = self.name + self.context.environment['env']
        # TODO: give to builder
        the_chain = chain.Chain()

        application_port = "8000"

        instance_profile_name = "InstanceProfile" + self.name

        the_chain.add(
            InstanceProfileRole(
                instance_profile_name=instance_profile_name,
                role=iam.Role(
                    "SomeRoleName1",
                    AssumeRolePolicyDocument=Policy(Statement=[
                        Statement(Effect=Allow,
                                  Action=[AssumeRole],
                                  Principal=Principal("Service", [
                                      "ec2.amazonaws.com", "s3.amazonaws.com"
                                  ]))
                    ]),
                )))

        the_chain.add(
            launch_config.LaunchConfig(meta_data=self.get_metadata(),
                                       vpc_id=Ref("VpcId")))

        the_chain.add(
            block_device_data.BlockDeviceData(
                ec2.BlockDeviceMapping(
                    DeviceName="/dev/xvda",
                    Ebs=ec2.EBSBlockDevice(VolumeSize="40"))))

        the_chain.add(
            target_group.TargetGroup(port=application_port,
                                     vpc_id=Ref("VpcId")))

        the_chain.add(scaling_group.ScalingGroup())

        the_chain.add(
            ingress_rule.IngressRule(port_to_open="22", cidr="10.0.0.0/8"))

        the_chain.add(
            ingress_rule.IngressRule(port_to_open=application_port,
                                     cidr="10.0.0.0/8"))

        the_chain.add(
            dns.Dns(
                base_domain=Ref("BaseDomain"),
                hosted_zone_id=Ref("AlbCanonicalHostedZoneID"),
                dns_name=Ref("AlbDNSName"),
            ))

        the_chain.add(
            alb_port.AlbPort(
                port_to_open=application_port,
                alb_sg_name="AlbSg",
            ))

        the_chain.add(
            listener_rule.ListenerRule(base_domain_name=Ref("BaseDomain"),
                                       alb_listener_rule=Ref("IAlbListener"),
                                       path_pattern="/*",
                                       priority="2"))

        chain_context = chaincontext.ChainContext(
            template=t, instance_name=instance_profile_name)

        the_chain.run(chain_context)
Esempio n. 10
0
    def create_template(self):

        t = self.template
        t.add_description("Acceptance Tests for cumulus pipelines")

        instance = self.name + self.context.environment['env']

        # TODO: give to builder
        the_chain = chain.Chain()
        # bucket becomes: cumulus-acceptance-tests-123123-namespace
        pipeline_bucket_name = troposphere.Join('', [
            self.context.namespace, "-",
            troposphere.Ref("AWS::AccountId"), "-", "automatedtests"
        ])

        the_chain.add(
            pipeline.Pipeline(
                name=self.name,
                bucket_name=pipeline_bucket_name,
            ))

        source_stage_name = "SourceStage"
        deploy_stage_name = "DeployStage"
        service_artifact = "ServiceArtifact"

        the_chain.add(
            pipeline_stage.PipelineStage(stage_name=source_stage_name))

        the_chain.add(
            pipeline_source_action.PipelineSourceAction(
                action_name="MicroserviceSource",
                output_artifact_name=service_artifact,
                s3_bucket_name=pipeline_bucket_name,
                s3_object_key="artifact.tar.gz"))

        the_chain.add(
            pipeline_stage.PipelineStage(stage_name=deploy_stage_name, ), )

        inline_ls_url_spec = """version: 0.2
phases:
  build:
    commands:
      - ls -lah
      - env
      - curl $URL
"""

        test_env = troposphere.codebuild.Environment(
            ComputeType='BUILD_GENERAL1_SMALL',
            Image='aws/codebuild/golang:1.10',
            Type='LINUX_CONTAINER',
            EnvironmentVariables=[{
                'Name': 'URL',
                'Value': "https://google.ca"
            }],
        )

        deploy_test = code_build_action.CodeBuildAction(
            action_name="DeployMyStuff",
            stage_name_to_add=deploy_stage_name,
            input_artifact_name=service_artifact,
            environment=test_env,
            buildspec=inline_ls_url_spec,
        )

        the_chain.add(deploy_test)

        lambda1 = lambda_action.LambdaAction(
            action_name="TriggerLambda",
            input_artifact_name=service_artifact,  # TODO make optional ?
            stage_name_to_add=deploy_stage_name,
            function_name="bswift-mock-function-mock-createUser")

        the_chain.add(lambda1)

        # the_chain.add(code_build_action.CodeBuildAction(
        #     action_name="NotificationSmokeTest",
        #     stage_name_to_add=deploy_stage_name,
        #     input_artifact_name=service_artifact,
        #     environment=test_env,
        #     buildspec='buildspec_smoke_test.yml',
        # ))

        # TODO: integration tests don't confirm the below.. yet.  Do it.
        destroy_stage_name = "EchoAURL"
        the_chain.add(
            pipeline_stage.PipelineStage(stage_name=destroy_stage_name, ), )

        the_chain.add(
            ApprovalAction(action_name="ApproveDestruction",
                           stage_name_to_add=destroy_stage_name))

        the_chain.add(
            code_build_action.CodeBuildAction(
                action_name="DestroyService",
                stage_name_to_add=destroy_stage_name,
                input_artifact_name=service_artifact,
            ))

        chain_context = chaincontext.ChainContext(template=t,
                                                  instance_name=instance)

        the_chain.run(chain_context)
 def setUp(self):
     self.context = chaincontext.ChainContext(
         template=troposphere.Template(),
         instance_name='justtestin',
         auto_param_creation=False)