Example #1
0
    def test_error_changes(self):
        duplicate_resource = POSTableData(
            sample_create_resource_record_sets_error_result.xml,
            b"text/xml",
            BAD_REQUEST,
        )
        zone_id = u"1234ABCDEF"
        agent = RequestTraversalAgent(static_resource({
            b"2013-04-01": {
                b"hostedzone": {
                    zone_id.encode("ascii"): {
                        b"rrset": duplicate_resource,
                    },
                },
            },
        }))
        aws = AWSServiceRegion(access_key="abc", secret_key="def")
        client = get_route53_client(agent, aws, uncooperator())
        err = self.failureResultOf(client.change_resource_record_sets(
            zone_id=zone_id,
            changes=[create_rrset(sample_create_resource_record_sets_error_result.rrset)],
        ), Route53Error)

        expected =  {
            u'Code': 'InvalidChangeBatch',
            u'Message': "[Tried to create resource record set [name='duplicate.example.invalid.', type='CNAME'] but it already exists]",
            u'Type': 'Sender',
        }
        self.assertEqual(err.value.errors, [expected])
Example #2
0
    def test_error_changes(self):
        duplicate_resource = POSTableData(
            sample_create_resource_record_sets_error_result.xml,
            b"text/xml",
            BAD_REQUEST,
        )
        zone_id = "1234ABCDEF"
        agent = RequestTraversalAgent(
            static_resource({
                b"2013-04-01": {
                    b"hostedzone": {
                        zone_id.encode("ascii"): {
                            b"rrset": duplicate_resource,
                        },
                    },
                },
            }))
        aws = AWSServiceRegion(access_key="abc", secret_key="def")
        client = get_route53_client(agent, aws, uncooperator())
        err = self.failureResultOf(
            client.change_resource_record_sets(
                zone_id=zone_id,
                changes=[
                    create_rrset(
                        sample_create_resource_record_sets_error_result.rrset)
                ],
            ), Route53Error)

        expected = {
            'Code': 'InvalidChangeBatch',
            'Message':
            "[Tried to create resource record set [name='duplicate.example.invalid.', type='CNAME'] but it already exists]",
            'Type': 'Sender',
        }
        self.assertEqual(err.value.errors, [expected])
Example #3
0
    def get_route53_client(self):
        from txaws.route53.client import get_route53_client

        if self._agent is None:
            from twisted.web.client import Agent
            from twisted.internet import reactor
            self._agent = Agent(reactor)

        return get_route53_client(self._agent, self)
Example #4
0
    def get_route53_client(self):
        from txaws.route53.client import get_route53_client

        if self._agent is None:
            from twisted.web.client import Agent
            from twisted.internet import reactor
            self._agent = Agent(reactor)

        return get_route53_client(self._agent, self)
Example #5
0
 def test_some_zones(self):
     agent = RequestTraversalAgent(static_resource({
         b"2013-04-01": {
             b"hostedzone": Data(
                 sample_list_hosted_zones_result.xml,
                 b"text/xml",
             ),
         },
     }))
     aws = AWSServiceRegion(access_key="abc", secret_key="def")
     client = get_route53_client(agent, aws, uncooperator())
     zones = self.successResultOf(client.list_hosted_zones())
     expected = [HostedZone(**sample_list_hosted_zones_result.details)]
     self.assertEquals(expected, zones)
Example #6
0
 def _client_for_rrsets(self, zone_id, rrsets_xml):
     agent = RequestTraversalAgent(static_resource({
         b"2013-04-01": {
             b"hostedzone": {
                 zone_id: {
                     b"rrset": Data(
                         rrsets_xml,
                         b"text/xml",
                     )
                 }
             }
         }
     }))
     aws = AWSServiceRegion(access_key="abc", secret_key="def")
     return get_route53_client(agent, aws, uncooperator())
Example #7
0
 def _client_for_rrsets(self, zone_id, rrsets_xml):
     agent = RequestTraversalAgent(
         static_resource({
             b"2013-04-01": {
                 b"hostedzone": {
                     zone_id: {
                         b"rrset": Data(
                             rrsets_xml,
                             b"text/xml",
                         )
                     }
                 }
             }
         }))
     aws = AWSServiceRegion(access_key="abc", secret_key="def")
     return get_route53_client(agent, aws, uncooperator())
Example #8
0
 def test_some_zones(self):
     agent = RequestTraversalAgent(
         static_resource({
             b"2013-04-01": {
                 b"hostedzone":
                 Data(
                     sample_list_hosted_zones_result.xml,
                     b"text/xml",
                 ),
             },
         }))
     aws = AWSServiceRegion(access_key="abc", secret_key="def")
     client = get_route53_client(agent, aws, uncooperator())
     zones = self.successResultOf(client.list_hosted_zones())
     expected = [HostedZone(**sample_list_hosted_zones_result.details)]
     self.assertEquals(expected, zones)
Example #9
0
    def test_some_changes(self):
        change_resource = POSTableData(
            sample_change_resource_record_sets_result.xml,
            b"text/xml",
        )
        zone_id = u"ABCDEF1234"
        agent = RequestTraversalAgent(
            static_resource({
                b"2013-04-01": {
                    b"hostedzone": {
                        zone_id.encode("ascii"): {
                            b"rrset": change_resource,
                        }
                    },
                },
            }))
        aws = AWSServiceRegion(access_key="abc", secret_key="def")
        client = get_route53_client(agent, aws, uncooperator())
        self.successResultOf(
            client.change_resource_record_sets(
                zone_id=zone_id,
                changes=[
                    create_rrset(
                        sample_change_resource_record_sets_result.rrset),
                    delete_rrset(
                        sample_change_resource_record_sets_result.rrset),
                    upsert_rrset(
                        sample_change_resource_record_sets_result.rrset),
                ],
            ))
        # Ack, what a pathetic assertion.
        change_template = u"<Change><Action>{action}</Action><ResourceRecordSet><Name>example.invalid.</Name><Type>NS</Type><TTL>86400</TTL><ResourceRecords><ResourceRecord><Value>ns1.example.invalid.</Value></ResourceRecord><ResourceRecord><Value>ns2.example.invalid.</Value></ResourceRecord></ResourceRecords></ResourceRecordSet></Change>"
        changes = [
            change_template.format(action=u"CREATE"),
            change_template.format(action=u"DELETE"),
            change_template.format(action=u"UPSERT"),
        ]
        expected = u"""\
<?xml version="1.0" encoding="UTF-8"?>
<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/"><ChangeBatch><Changes>{changes}</Changes></ChangeBatch></ChangeResourceRecordSetsRequest>""".format(
            changes=u"".join(changes)).encode("utf-8")
        self.assertEqual((expected, ), change_resource.posted)
Example #10
0
    def test_some_changes(self):
        change_resource = POSTableData(
            sample_change_resource_record_sets_result.xml,
            b"text/xml",
        )
        zone_id = u"ABCDEF1234"
        agent = RequestTraversalAgent(static_resource({
            b"2013-04-01": {
                b"hostedzone": {
                    zone_id.encode("ascii"): {
                        b"rrset": change_resource,
                    }
                },
            },
        }))
        aws = AWSServiceRegion(access_key="abc", secret_key="def")
        client = get_route53_client(agent, aws, uncooperator())
        self.successResultOf(client.change_resource_record_sets(
            zone_id=zone_id,
            changes=[
                create_rrset(sample_change_resource_record_sets_result.rrset),
                delete_rrset(sample_change_resource_record_sets_result.rrset),
                upsert_rrset(sample_change_resource_record_sets_result.rrset),
            ],
        ))
        # Ack, what a pathetic assertion.
        change_template = u"<Change><Action>{action}</Action><ResourceRecordSet><Name>example.invalid.</Name><Type>NS</Type><TTL>86400</TTL><ResourceRecords><ResourceRecord><Value>ns1.example.invalid.</Value></ResourceRecord><ResourceRecord><Value>ns2.example.invalid.</Value></ResourceRecord></ResourceRecords></ResourceRecordSet></Change>"
        changes = [
            change_template.format(action=u"CREATE"),
            change_template.format(action=u"DELETE"),
            change_template.format(action=u"UPSERT"),
        ]
        expected = u"""\
<?xml version="1.0" encoding="UTF-8"?>
<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/"><ChangeBatch><Changes>{changes}</Changes></ChangeBatch></ChangeResourceRecordSetsRequest>""".format(changes=u"".join(changes)).encode("utf-8")
        self.assertEqual((expected,), change_resource.posted)