Esempio n. 1
0
 def test_error(self):
     msg = 'test message'
     try:
         utils.error(object(), msg)
     except exceptions.PropertyException, e:
         assert_equals(e.message, "Error in resource properties: " + msg +
                                  " in type <unknown type>")
Esempio n. 2
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()
        if self.properties.get('HealthCheckType', None):
            if self.properties['HealthCheckType'] not in ['ELB', 'EC2']:
                error(self, "HealthCheckType must be one of `ELB' or `EC2'")

        valid_policies = set([
            'Default',
            'OldestInstance',
            'NewestInstance',
            'OldestLaunchConfiguration',
            'ClosestToNextInstanceHour',
        ])

        if self.properties.get('TerminationPolicies'):
            invalid_policies = set(self.properties['TerminationPolicies']) -\
                valid_policies
            if len(invalid_policies) > 0:
                raise ValueError(
                    "Invalid TerminationPolicy declaration: "
                    "%s not valid" % invalid_policies)

        return True
Esempio n. 3
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        iops = int(self.properties.get('Iops', 0))
        size = self.properties.get('Size')

        if self.properties.get('VolumeType') == 'io1':
            if iops < 100 or iops > 4000:
                error(self, 'iops property not in range 100-4000')
        elif self.properties.get('VolumeType') == 'gp2':
            if self.properties.get('Iops'):
                error(self, 'iops property not allowed on volumes '
                            'of type gp2')
        else:
            self.properties['VolumeType'] = 'standard'
            if self.properties.get('Iops'):
                error(self, 'iops property not allowed on volumes '
                            'of type standard')
        if size:
            if self.properties.get('SnapshotId'):
                error(self, 'Cannot set Size and SnapshotId')
            if iops > 0:
                if iops > (int(size) * 10):
                    error(self, 'Size must be at least 10 times iops')

        return True
Esempio n. 4
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()
        if self.properties.get('Type') != 'ipsec.1':
            error(self, 'Type must be ipsec.1')
Esempio n. 5
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()
        if not self.properties.get('Family'):
            error(self, "Must specify `Family'")
Esempio n. 6
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()
        if not self.properties.get('RouteTableIds'):
            error(self, 'Resource RouteTableIds required')
Esempio n. 7
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()
        if len(set(self.properties.keys()).intersection(
                set(['Ebs', 'VirtualName']))) != 1:
            error(self, "Need to specify one of `Ebs', `VirtualName'")
Esempio n. 8
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        if 'PolicyName' not in self.properties.keys():
            error(self, 'Need unique PolicyName')
Esempio n. 9
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()
        if self.properties.get('Path'):
            if not (self.properties['Path'].startswith('/') and
                    self.properties['Path'].endswith('/')):
                error(self, "Path must begin and end with `/`")
Esempio n. 10
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        if len(set(self.properties.keys()).intersection(
                set(['InternetGatewayId', 'VpnGatewayId']))) != 1:
            error(self, 'InternetGatewayId or VpnGatewayId are required')
Esempio n. 11
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        if len(set(self.properties.keys()).intersection(
               set(['AvailabilityZones', 'Subnets']))) > 1:
            error(self, 'Can not specify both Subnets and AvailabilityZones')
Esempio n. 12
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        if len(set(self.propnames).intersection(self.properties.keys())) > 0:
            return True
        error(self, 'Need at least one property')
Esempio n. 13
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()
        if len(set(['HostedZoneId', 'HostedZoneName']).intersection(
                set(self.properties.keys()))) != 1:
            error(self, 'Must set one of HostedZoneId or HostedZoneName')

        return True
Esempio n. 14
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()
        if self.properties.get('Status'):
            if self.properties['Status'] not in ["Active", "Inactive"]:
                error(self, 'Status %s not valid' % self.properties['Status'])

        return True
Esempio n. 15
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        if len(set(self.properties.keys()).intersection(
                set(['Ebs', 'VirtualName']))) != 1:
            error(self, 'One of Ebs or VirtualName required')

        return True
Esempio n. 16
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        if len(set(self.properties.keys()).intersection(
                set(['From', 'To']))) != 2:
            error(self, 'From and To are required')

        return True
Esempio n. 17
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        if len(set(self.properties.keys()).intersection(
                set(['NetworkInterfaceId', 'SubnetId']))) != 1:
            error(self, 'One of NetworkInterfaceId or SubnetId required')

        return True
Esempio n. 18
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        if len(set(self.properties.keys()).intersection(
                set(['CidrIp', 'DestinationSecurityGroupId']))) != 1:
            error(self, 'CidrIp or DestinationSecurityGroupId are required')

        return True
Esempio n. 19
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()
        if len(set(self.properties.keys()).intersection(
                set(['GatewayId', 'InstanceId',
                     'NetworkInterfaceId', 'VpcPeeringConnectionId']))) != 1:
            error(self, 'One of GatewayId, InstanceId, or NetworkInterfaceId '
                        'are required')

        return True
Esempio n. 20
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()
        valid_adj_types = [
            'ChangeInCapacity',
            'ExactCapacity',
            'PercentChangeInCapacity',
        ]
        if self.properties['AdjustmentType'] not in valid_adj_types:
            error(self, 'AdjustmentType must be one of %s' %
                  ', '.join(valid_adj_types))
Esempio n. 21
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        valid_protos = ["https", "http", "email", "email-json", "sqs"]
        super(self.__class__, self).validate()
        if self.properties['Protocol'] not in valid_protos:
            error(self, 'Protocol %s not valid. Not in %s' % (
                self.properties['Protocol'],
                valid_protos
            ))

        return True
Esempio n. 22
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        if self.properties['Protocol'] == 1:
            if not self.properties.get('Icmp'):
                error(self, 'Icmp must be specified when protocol is 1')
        elif self.properties['Protocol'] in [6, 17]:  # TCP, UDP
            if not self.properties.get('PortRange'):
                error(self, 'PortRange must be specified when protocol '
                            'protocol is 6 or 17')
Esempio n. 23
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()
        if len(set(self.properties.keys()).intersection(
                set(['SnapshotId', 'VolumeSize']))) != 1:
            error(self, "Need to specify one of `SnapshotId', `VolumeSize'")
        if 'VolumeType' in self.properties.keys():
            allowed_types = ['standard', 'io1', 'gp2']
            if self.properties['VolumeType'] not in allowed_types:
                error(self, "Bad VolumeType: `%s' - must be one of `%s'" % (
                    self.properties['VolumeType'],
                    ("', `").join(allowed_types)
                ))
Esempio n. 24
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()
        if self.properties.get('CIDRIP'):
            if len(set(self.properties.keys()).intersection(
                set(['EC2SecurityGroupId', 'EC2SecurityGroupName',
                     'EC2SecurityGroupOwnerId']))) > 0:
                error(self, "CIDRIP is only valid on its own")
        else:
            if len(set(self.properties.keys()).intersection(
                    set(['EC2SecurityGroupId', 'EC2SecurityGroupName']))) != 1:
                    error(self, "Cannot use both `EC2SecurityGroupId' and "
                                "`EC2SecurityGroupName'")
Esempio n. 25
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        if self.properties.get('EnableDnsHostnames'):
            if not self.properties.get('EnableDnsSupport'):
                error(self, 'EnableDnsSupport must be true if '
                            'EnableDnsHostnames is true')

        inst_ten = self.properties.get('InstanceTenancy')
        if inst_ten:
            if inst_ten not in ['default', 'dedicated']:
                error(self, 'InstanceTenancy must be one of "default", '
                            '"dedicated"')
Esempio n. 26
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        if self.properties['Enabled'] is False:
            return True

        if len(set(self.properties.keys()).intersection(
               set(['EmitInterval', 'S3BucketName']))) != 2:
            error(self, 'Must specify EmitInterval and S3BucketName')

        if self.properties['EmitInterval'] not in [5, 60]:
            error(self, 'EmitInterval must be either 5 or 60')

        return True
Esempio n. 27
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        policy_types = [
            'AppCookieStickinessPolicyType',
            'BackendServerAuthenticationPolicyType',
            'LBCookieStickinessPolicyType',
            'ProxyProtocolPolicyType',
            'PublicKeyPolicyType',
            'SSLNegotiationPolicyType',
        ]

        if self.properties['PolicyType'] not in policy_types:
            error(self, 'PolicyType must be one of %s' % policy_types)
Esempio n. 28
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        net_props = ['InstanceId', 'PrivateIpAddress']
        if len(set(self.properties.keys()).intersection(
                set(['AllocationId', 'EIP']))) != 1:
            error(self, 'Need to specify an EIP')

        if self.properties.get('AllocationId'):
            net_props.append('NetworkInterfaceId')

        if len(set(self.properties.keys()).intersection(set(net_props))) != 1:
            error(self, 'Need to specify associated resource')

        return True
Esempio n. 29
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()
        rr_props = ['TTL', 'SetIdentifier']
        if self.properties.get('AliasTarget'):
            if self.properties.get('ResourceRecords'):
                error(self, "Can't set both ResourceRecords and AliasTarget")

        for prop in rr_props:
            if self.properties.get(prop):
                if not self.properties.get('ResourceRecords'):
                    error(self, "Must set ResourceRecords with %s" % prop)

        if self.properties.get('ResourceRecords'):
            found = False
            for prop in rr_props:
                if self.properties.get(prop):
                    found = True
                    break
            if not found:
                error(
                    self,
                    "Must set TTL or SetIdentifier with ResourceRecords"
                )

        return True
Esempio n. 30
0
    def validate(self):
        """
        Validate properties of troposphere resource with additional checks
        """

        super(self.__class__, self).validate()

        if len(set(self.properties.keys()).intersection(
                set(['DesiredCapacity', 'MinSize', 'MaxSize']))) == 0:
            error(self, "Need to specify one of `DesiredCapacity', `MinSize', "
                        "`MaxSize'")

        tm_fmt = "%Y-%m-%dT%H:%M:%SZ"
        cron_valid = [
            range(0, 8),
            range(1, 13),
            range(1, 32),
            range(0, 24),
            range(0, 60)
        ]
        recurrence = self.properties['Recurrence'].split()
        for idx, item in enumerate(recurrence):
            if item == '*':
                continue
            if int(item) not in cron_valid[idx]:
                error(self, "Invalid cron spec: %s not in range %d-%d or *" %
                      (item, cron_valid[idx][0], cron_valid[idx][-2]))

        for item in ['StartTime', 'EndTime']:
            if self.properties.get(item):
                try:
                    time.strptime(self.properties[item], tm_fmt)
                except ValueError:
                    error(self, '%s invalid date, must match %s' %
                          (item, tm_fmt))