def test_should_throw_error_with_unsatisfied_required_params(self): the_chain = chain.Chain() mock_step = MockStepWithRequiredParam() the_chain.add(mock_step) self.assertRaisesRegexp(AssertionError, '.*Minions.*\n.*Eyeballs.*', 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'] 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)
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)
def test_should_validate_template_with_missing_params(self): """ This tests the same functionality as test_should_throw_error_with_unsatisfied_required_params however, it doesn't use the example code. The idea was to keep example code even though it's less of a unit test.. to show how you would use params. Tests as documentation :) :return: """ the_chain = chain.Chain() self.context.required_params.add("ImARequiredParam") self.assertRaisesRegexp(AssertionError, 'ImARequiredParam', the_chain.validate_template, self.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 test_should_validate_template_without_any_required_params(self): the_chain = chain.Chain() the_chain.run(self.context)
def test_should_call_validate_when_chain_runs(self): the_chain = chain.Chain() the_chain.validate_template = MagicMock the_chain.run(self.context) self.assertTrue(the_chain.validate_template.called)