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>")
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
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
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')
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'")
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')
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'")
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')
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 `/`")
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')
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')
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')
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
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
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
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
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
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
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
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))
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
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')
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) ))
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'")
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"')
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
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)
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
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
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))