class sample_change_resource_record_sets_result(object): rrset = RRSet( label=Name(u"example.invalid."), type=u"NS", ttl=86400, records={ NS(Name(u"ns1.example.invalid.")), NS(Name(u"ns2.example.invalid.")), }, ) xml = b"""\
def check_route53(self, database, config, subscriptions, k8s_state, aws): expected_rrsets = pmap() service = k8s_state.services.item_by_name(S4_CUSTOMER_GRID_NAME) if service.status is not None and service.status.loadBalancer.ingress: # TODO: It would be slightly nicer to make this a Route53 Alias # instead of a CNAME. txAWS needs support for creating Route53 Alias # rrsets first, though. introducer = RRSetKey( label=Name( u"introducer.{domain}".format(domain=config.domain)), type=u"CNAME", ) service_ingress = RRSet( label=introducer.label, type=introducer.type, ttl=60, records={ CNAME(canonical_name=Name( service.status.loadBalancer.ingress[0].hostname, ), ), }, ) expected_rrsets = expected_rrsets.set(introducer, service_ingress) for sid in subscriptions: label = _introducer_name_for_subscription(sid, config.domain) key = RRSetKey(label=label, type=u"CNAME") cname = CNAME( Name(u"introducer.{domain}".format(domain=config.domain))) rrset = RRSet(label=label, type=u"CNAME", ttl=60, records={cname}) expected_rrsets = expected_rrsets.set(key, rrset) route53 = aws.get_route53_client() d = route53.list_resource_record_sets(self.zone.identifier) result = self.case.successResultOf(d) actual_rrsets = pmap({ key: rrset for (key, rrset) in result.iteritems() # Don't care about these infrastructure rrsets. if key.type not in (u"SOA", u"NS") }) assert_that( actual_rrsets, GoodEquals(expected_rrsets), )
class sample_list_resource_records_with_alias_result(object): normal_target = Name(u"bar.example.invalid.") normal = RRSet( label=Name(u"foo.example.invalid."), type=u"CNAME", ttl=60, records={CNAME(canonical_name=normal_target)}, ) normal_xml = u"""\ <ResourceRecordSet><Name>{label}</Name><Type>{type}</Type><TTL>{ttl}</TTL><ResourceRecords><ResourceRecord><Value>{value}</Value></ResourceRecord></ResourceRecords></ResourceRecordSet> """.format( label=normal.label, type=normal.type, ttl=normal.ttl, value=normal_target, ) alias = AliasRRSet( label=Name(u"bar.example.invalid."), type=u"A", dns_name=Name( u"dualstack.a952f315901e6b3c812e57076f5b4138-0795221525.us-east-1.elb.amazonaws.com.", ), evaluate_target_health=False, hosted_zone_id=u"ZSXD5Q7O3X7TRK", ) alias_xml = u"""\ <ResourceRecordSet><Name>{label}</Name><Type>{type}</Type><AliasTarget><HostedZoneId>{hosted_zone_id}</HostedZoneId><DNSName>{dns_name}</DNSName><EvaluateTargetHealth>{evaluate_target_health}</EvaluateTargetHealth></AliasTarget></ResourceRecordSet> """.format( label=alias.label, type=alias.type, hosted_zone_id=alias.hosted_zone_id, dns_name=alias.dns_name, evaluate_target_health=[u"false", u"true"][alias.evaluate_target_health], ) xml = u"""\ <?xml version="1.0"?>\n <ListResourceRecordSetsResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/"><ResourceRecordSets>{normal}{alias}</ResourceRecordSets><IsTruncated>false</IsTruncated><MaxItems>100</MaxItems></ListResourceRecordSetsResponse> """.format(normal=normal_xml, alias=alias_xml).encode("utf-8")
class sample_create_resource_record_sets_error_result: label = Name("duplicate.example.invalid.") type = "CNAME" cname = CNAME(canonical_name=Name("somewhere.example.invalid."), ) rrset = RRSet( label=label, type="CNAME", ttl=600, records={cname}, ) xml = """\ <?xml version="1.0"?> <ErrorResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/"><Error><Type>Sender</Type><Code>InvalidChangeBatch</Code><Message>[Tried to create resource record set [name='{label}', type='{type}'] but it already exists]</Message></Error><RequestId>9197fef4-03cc-11e9-b35f-7947070744f2</RequestId></ErrorResponse> """.format( label=label, type=type, )
def test_naptr_with_replacement(self): self._simple_record_test( u"NAPTR", NAPTR( order=3, preference=7, flag=u"SUP", service=u"E2U+sip", regexp=u"", replacement=Name(u"foo.example.test."), ), )
def test_naptr_with_regexp(self): self._simple_record_test( u"NAPTR", NAPTR( order=3, preference=7, flag=u"SUP", service=u"E2U+sip", regexp=u"!^(\\+441632960083)$!sip:\\[email protected]!", replacement=Name(u"."), ), )
def test_get_hosted_zone_by_name(self): zone = HostedZone( name=u"example.invalid", identifier=u"", rrset_count=0, reference=u"unique string", ) region = FakeAWSServiceRegion( access_key="access key id", secret_key="secret access key", ) route53 = region.get_route53_client() d = route53.create_hosted_zone(zone.reference, zone.name) self.successResultOf(d) d = get_hosted_zone_by_name(route53, Name(zone.name)) retrieved = self.successResultOf(d) self.expectThat(retrieved.zone.reference, Equals(zone.reference)) self.expectThat(retrieved.zone.name, Equals(zone.name))
def test_unknown_record_type(self): zone_id = b"ABCDEF1234" template = u"""\ <?xml version="1.0"?> <ListResourceRecordSetsResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/"> <ResourceRecordSets> <ResourceRecordSet> <Name>{label}</Name> <Type>{type}</Type> <TTL>{ttl}</TTL> <ResourceRecords> <ResourceRecord><Value>{record}</Value></ResourceRecord> </ResourceRecords> </ResourceRecordSet> </ResourceRecordSets> <IsTruncated>false</IsTruncated> <MaxItems>100</MaxItems> </ListResourceRecordSetsResponse> """ label = Name(u"foo") client = self._client_for_rrsets( zone_id, template.format( label=label, type=u"X-TXAWS-FICTIONAL", ttl=60, record=u"good luck interpreting this", ).encode("utf-8")) expected = { RRSetKey(label=label, type=u"X-TXAWS-FICTIONAL"): RRSet( label=label, type=u"X-TXAWS-FICTIONAL", ttl=60, records={UnknownRecordType(u"good luck interpreting this")}, ), } rrsets = self.successResultOf( client.list_resource_record_sets(zone_id=zone_id), ) self.assertEquals(expected, rrsets)
def _simple_record_test(self, record_type, record): zone_id = b"ABCDEF1234" template = u"""\ <?xml version="1.0"?> <ListResourceRecordSetsResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/"> <ResourceRecordSets> <ResourceRecordSet> <Name>{label}</Name> <Type>{type}</Type> <TTL>{ttl}</TTL> <ResourceRecords> <ResourceRecord><Value>{record}</Value></ResourceRecord> </ResourceRecords> </ResourceRecordSet> </ResourceRecordSets> <IsTruncated>false</IsTruncated> <MaxItems>100</MaxItems> </ListResourceRecordSetsResponse> """ label = Name(u"foo") client = self._client_for_rrsets( zone_id, template.format( label=label, type=record_type, ttl=60, record=record.to_text(), ).encode("utf-8")) expected = { RRSetKey(label=label, type=record_type): RRSet( label=label, type=record_type, ttl=60, records={record}, ), } rrsets = self.successResultOf( client.list_resource_record_sets(zone_id=zone_id), ) self.assertEquals(expected, rrsets)
class sample_list_resource_record_sets_result(object): label = Name(u"example.invalid.") soa_ttl = 60 soa = SOA( mname=Name(u"1.awsdns-1.net."), rname=Name(u"awsdns-hostmaster.amazon.com."), serial=1, refresh=7200, retry=900, expire=1209600, minimum=86400, ) ns_ttl = 120 ns1 = NS(nameserver=Name(u"ns-1.awsdns-1.net."), ) ns2 = NS(nameserver=Name(u"ns-2.awsdns-2.net."), ) cname_ttl = 180 # The existence of a CNAME record for example.invalid. is bogus # because if you have a CNAME record for a name you're not # supposed to have any other records for it - and we have soa, ns, # etc. However, noone is interpreting this data with DNS # semantics. We're just parsing it. Hope that's okay with you. cname = CNAME(canonical_name=Name(u"somewhere.example.invalid."), ) xml = u"""\ <?xml version="1.0"?> <ListResourceRecordSetsResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/"><ResourceRecordSets><ResourceRecordSet><Name>{label}</Name><Type>NS</Type><TTL>{ns_ttl}</TTL><ResourceRecords><ResourceRecord><Value>{ns1.nameserver}</Value></ResourceRecord><ResourceRecord><Value>{ns2.nameserver}</Value></ResourceRecord></ResourceRecords></ResourceRecordSet><ResourceRecordSet><Name>{label}</Name><Type>SOA</Type><TTL>{soa_ttl}</TTL><ResourceRecords><ResourceRecord><Value>{soa.mname} {soa.rname} {soa.serial} {soa.refresh} {soa.retry} {soa.expire} {soa.minimum}</Value></ResourceRecord></ResourceRecords></ResourceRecordSet><ResourceRecordSet><Name>{label}</Name><Type>CNAME</Type><TTL>{cname_ttl}</TTL><ResourceRecords><ResourceRecord><Value>{cname.canonical_name}</Value></ResourceRecord></ResourceRecords></ResourceRecordSet></ResourceRecordSets><IsTruncated>false</IsTruncated><MaxItems>100</MaxItems></ListResourceRecordSetsResponse> """.format( label=label, soa=soa, soa_ttl=soa_ttl, ns1=ns1, ns2=ns2, ns_ttl=ns_ttl, cname=cname, cname_ttl=cname_ttl, ).encode("utf-8")
def test_srv(self): self._simple_record_test( u"SRV", SRV(1, 2, 3, Name("example.test")), )
def test_ptr(self): self._simple_record_test( u"PTR", PTR(Name(u"foo.example.test")), )
def test_mx(self): self._simple_record_test( u"MX", MX(Name(u"bar"), 15), )
def test_cname(self): self._simple_record_test( u"CNAME", CNAME(Name(u"bar")), )