diff options
author | Felix Yan <felixonmars@gmail.com> | 2014-08-28 11:12:49 +0800 |
---|---|---|
committer | Felix Yan <felixonmars@gmail.com> | 2014-08-28 11:12:49 +0800 |
commit | 7281e13f404536098dc7e85937dc569d347dd5c8 (patch) | |
tree | 9781a822babc6d0f41dc6b9fee215d27c5d58dda | |
parent | ac2b311c04cb49b337ba033b1a550039c12c929d (diff) | |
download | boto-7281e13f404536098dc7e85937dc569d347dd5c8.tar.gz |
route53 module: tidy up to meet PEP8 better
-rw-r--r-- | boto/route53/connection.py | 29 | ||||
-rw-r--r-- | boto/route53/exception.py | 4 | ||||
-rw-r--r-- | boto/route53/healthcheck.py | 2 | ||||
-rw-r--r-- | boto/route53/hostedzone.py | 2 | ||||
-rw-r--r-- | boto/route53/record.py | 55 | ||||
-rw-r--r-- | boto/route53/zone.py | 2 | ||||
-rw-r--r-- | tests/integration/route53/__init__.py | 1 | ||||
-rw-r--r-- | tests/integration/route53/test_alias_resourcerecordsets.py | 2 | ||||
-rw-r--r-- | tests/integration/route53/test_health_check.py | 3 | ||||
-rw-r--r-- | tests/integration/route53/test_resourcerecordsets.py | 3 | ||||
-rw-r--r-- | tests/integration/route53/test_zone.py | 4 | ||||
-rw-r--r-- | tests/unit/route53/test_connection.py | 16 |
12 files changed, 63 insertions, 60 deletions
diff --git a/boto/route53/connection.py b/boto/route53/connection.py index 2cab2359..c33b67d8 100644 --- a/boto/route53/connection.py +++ b/boto/route53/connection.py @@ -47,7 +47,7 @@ HZXML = """<?xml version="1.0" encoding="UTF-8"?> </HostedZoneConfig> </CreateHostedZoneRequest>""" -#boto.set_stream_logger('dns') +# boto.set_stream_logger('dns') class Route53Connection(AWSAuthConnection): @@ -65,13 +65,14 @@ class Route53Connection(AWSAuthConnection): host=DefaultHost, debug=0, security_token=None, validate_certs=True, https_connection_factory=None, profile_name=None): - super(Route53Connection, self).__init__(host, - aws_access_key_id, aws_secret_access_key, - True, port, proxy, proxy_port, debug=debug, - security_token=security_token, - validate_certs=validate_certs, - https_connection_factory=https_connection_factory, - profile_name=profile_name) + super(Route53Connection, self).__init__( + host, + aws_access_key_id, aws_secret_access_key, + True, port, proxy, proxy_port, debug=debug, + security_token=security_token, + validate_certs=validate_certs, + https_connection_factory=https_connection_factory, + profile_name=profile_name) def _required_auth_capability(self): return ['route53'] @@ -84,9 +85,9 @@ class Route53Connection(AWSAuthConnection): continue pairs.append(key + '=' + urllib.parse.quote(str(val))) path += '?' + '&'.join(pairs) - return super(Route53Connection, self).make_request(action, path, - headers, data, - retry_handler=self._retry_handler) + return super(Route53Connection, self).make_request( + action, path, headers, data, + retry_handler=self._retry_handler) # Hosted Zones @@ -103,7 +104,7 @@ class Route53Connection(AWSAuthConnection): if start_marker: params = {'marker': start_marker} response = self.make_request('GET', '/%s/hostedzone' % self.Version, - params=params) + params=params) body = response.read() boto.log.debug(body) if response.status >= 300: @@ -157,7 +158,7 @@ class Route53Connection(AWSAuthConnection): hosted_zone_name += '.' all_hosted_zones = self.get_all_hosted_zones() for zone in all_hosted_zones['ListHostedZonesResponse']['HostedZones']: - #check that they gave us the FQDN for their zone + # check that they gave us the FQDN for their zone if zone['Name'] == hosted_zone_name: return self.get_hosted_zone(zone['Id'].split('/')[-1]) @@ -233,7 +234,6 @@ class Route53Connection(AWSAuthConnection): h.parse(body) return e - # Health checks POSTHCXMLBody = """<CreateHealthCheckRequest xmlns="%(xmlns)s"> @@ -327,7 +327,6 @@ class Route53Connection(AWSAuthConnection): h.parse(body) return e - # Resource Record Sets def get_all_rrsets(self, hosted_zone_id, type=None, diff --git a/boto/route53/exception.py b/boto/route53/exception.py index ba41285a..61b33b0c 100644 --- a/boto/route53/exception.py +++ b/boto/route53/exception.py @@ -15,13 +15,13 @@ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. from boto.exception import BotoServerError -class DNSServerError(BotoServerError): +class DNSServerError(BotoServerError): pass diff --git a/boto/route53/healthcheck.py b/boto/route53/healthcheck.py index 85d6919b..43fdf179 100644 --- a/boto/route53/healthcheck.py +++ b/boto/route53/healthcheck.py @@ -141,6 +141,6 @@ class HealthCheck(object): params['ip_addr_part'] = self.XMLIpAddrPart % {'ip_addr': self.ip_addr} if self.string_match is not None: - params['string_match_part'] = self.XMLStringMatchPart % {'string_match' : self.string_match} + params['string_match_part'] = self.XMLStringMatchPart % {'string_match': self.string_match} return self.POSTXMLBody % params diff --git a/boto/route53/hostedzone.py b/boto/route53/hostedzone.py index 66b79b84..fd8420c4 100644 --- a/boto/route53/hostedzone.py +++ b/boto/route53/hostedzone.py @@ -22,6 +22,7 @@ # IN THE SOFTWARE. # + class HostedZone(object): def __init__(self, id=None, name=None, owner=None, version=None, @@ -53,4 +54,3 @@ class HostedZone(object): self.caller_reference = value else: setattr(self, name, value) - diff --git a/boto/route53/record.py b/boto/route53/record.py index 664739b8..d5848e5f 100644 --- a/boto/route53/record.py +++ b/boto/route53/record.py @@ -25,6 +25,8 @@ RECORD_TYPES = ['A', 'AAAA', 'TXT', 'CNAME', 'MX', 'PTR', 'SRV', 'SPF'] from boto.resultset import ResultSet + + class ResourceRecordSets(ResultSet): """ A list of resource records. @@ -65,9 +67,9 @@ class ResourceRecordSets(ResultSet): record_list) def add_change(self, action, name, type, ttl=600, - alias_hosted_zone_id=None, alias_dns_name=None, identifier=None, - weight=None, region=None, alias_evaluate_target_health=None, - health_check=None, failover=None): + alias_hosted_zone_id=None, alias_dns_name=None, identifier=None, + weight=None, region=None, alias_evaluate_target_health=None, + health_check=None, failover=None): """ Add a change request to the set. @@ -121,10 +123,10 @@ class ResourceRecordSets(ResultSet): for the latency-based routing :type alias_evaluate_target_health: Boolean - :param alias_evaluate_target_health: *Required for alias resource record sets* Indicates - whether this Resource Record Set should respect the health status of - any health checks associated with the ALIAS target record which it is - linked to. + :param alias_evaluate_target_health: *Required for alias resource record + sets* Indicates whether this Resource Record Set should respect the + health status of any health checks associated with the ALIAS target + record which it is linked to. :type health_check: str :param health_check: Health check to associate with this record @@ -134,11 +136,11 @@ class ResourceRecordSets(ResultSet): primary or secondary resource record set. """ change = Record(name, type, ttl, - alias_hosted_zone_id=alias_hosted_zone_id, - alias_dns_name=alias_dns_name, identifier=identifier, - weight=weight, region=region, - alias_evaluate_target_health=alias_evaluate_target_health, - health_check=health_check, failover=failover) + alias_hosted_zone_id=alias_hosted_zone_id, + alias_dns_name=alias_dns_name, identifier=identifier, + weight=weight, region=region, + alias_evaluate_target_health=alias_evaluate_target_health, + health_check=health_check, failover=failover) self.changes.append([action, change]) return change @@ -189,8 +191,6 @@ class ResourceRecordSets(ResultSet): self.is_truncated = truncated - - class Record(object): """An individual ResourceRecordSet""" @@ -237,11 +237,10 @@ class Record(object): EvaluateTargetHealth = """<EvaluateTargetHealth>%s</EvaluateTargetHealth>""" - def __init__(self, name=None, type=None, ttl=600, resource_records=None, - alias_hosted_zone_id=None, alias_dns_name=None, identifier=None, - weight=None, region=None, alias_evaluate_target_health=None, - health_check=None, failover=None): + alias_hosted_zone_id=None, alias_dns_name=None, identifier=None, + weight=None, region=None, alias_evaluate_target_health=None, + health_check=None, failover=None): self.name = name self.type = type self.ttl = ttl @@ -280,9 +279,9 @@ class Record(object): else: eval_target_health = "" - body = self.AliasBody % { "hosted_zone_id": self.alias_hosted_zone_id, - "dns_name": self.alias_dns_name, - "eval_target_health": eval_target_health } + body = self.AliasBody % {"hosted_zone_id": self.alias_hosted_zone_id, + "dns_name": self.alias_dns_name, + "eval_target_health": eval_target_health} else: # Use resource record(s) records = "" @@ -298,14 +297,14 @@ class Record(object): weight = "" if self.identifier is not None and self.weight is not None: - weight = self.WRRBody % {"identifier": self.identifier, "weight": - self.weight} + weight = self.WRRBody % {"identifier": self.identifier, + "weight": self.weight} elif self.identifier is not None and self.region is not None: - weight = self.RRRBody % {"identifier": self.identifier, "region": - self.region} + weight = self.RRRBody % {"identifier": self.identifier, + "region": self.region} elif self.identifier is not None and self.failover is not None: - weight = self.FailoverBody % {"identifier": self.identifier, "failover": - self.failover} + weight = self.FailoverBody % {"identifier": self.identifier, + "failover": self.failover} health_check = "" if self.health_check is not None: @@ -329,7 +328,7 @@ class Record(object): rr += ' (EvalTarget %s)' % self.alias_evaluate_target_health else: # Show resource record(s) - rr = ",".join(self.resource_records) + rr = ",".join(self.resource_records) if self.identifier is not None and self.weight is not None: rr += ' (WRR id=%s, w=%s)' % (self.identifier, self.weight) diff --git a/boto/route53/zone.py b/boto/route53/zone.py index bb6907da..167a0891 100644 --- a/boto/route53/zone.py +++ b/boto/route53/zone.py @@ -60,7 +60,7 @@ class Zone(object): return response['ChangeResourceRecordSetsResponse']['ChangeInfo'] def _new_record(self, changes, resource_type, name, value, ttl, identifier, - comment=""): + comment=""): """ Add a CREATE change record to an existing ResourceRecordSets diff --git a/tests/integration/route53/__init__.py b/tests/integration/route53/__init__.py index 3953ad05..417a3a08 100644 --- a/tests/integration/route53/__init__.py +++ b/tests/integration/route53/__init__.py @@ -25,6 +25,7 @@ import unittest from nose.plugins.attrib import attr from boto.route53.connection import Route53Connection + @attr(route53=True) class Route53TestCase(unittest.TestCase): def setUp(self): diff --git a/tests/integration/route53/test_alias_resourcerecordsets.py b/tests/integration/route53/test_alias_resourcerecordsets.py index 88db5d82..6a753883 100644 --- a/tests/integration/route53/test_alias_resourcerecordsets.py +++ b/tests/integration/route53/test_alias_resourcerecordsets.py @@ -79,7 +79,6 @@ class TestRoute53AliasResourceRecordSets(unittest.TestCase): rrs.add_change(action="DELETE", **base_record) rrs.commit() - def test_set_alias(self): base_record = dict(name="alias.%s." % self.base_domain, type="A", @@ -95,7 +94,6 @@ class TestRoute53AliasResourceRecordSets(unittest.TestCase): delete.set_alias(self.zone.id, "target.%s" % self.base_domain, False) rrs.commit() - def test_set_alias_backwards_compatability(self): base_record = dict(name="alias.%s." % self.base_domain, type="A", diff --git a/tests/integration/route53/test_health_check.py b/tests/integration/route53/test_health_check.py index bbd5af8f..4b4d2bcf 100644 --- a/tests/integration/route53/test_health_check.py +++ b/tests/integration/route53/test_health_check.py @@ -26,6 +26,7 @@ from boto.compat import six from boto.route53.healthcheck import HealthCheck from boto.route53.record import ResourceRecordSets + class TestRoute53HealthCheck(Route53TestCase): def test_create_health_check(self): hc = HealthCheck(ip_addr="54.217.7.118", port=80, hc_type="HTTP", resource_path="/testing") @@ -124,7 +125,7 @@ class TestRoute53HealthCheck(Route53TestCase): records = ResourceRecordSets(self.conn, self.zone.id) deleted = records.add_change('DELETE', "unittest.%s." % self.base_domain, "A", ttl=30, identifier='test', - weight=1, health_check=result['CreateHealthCheckResponse']['HealthCheck']['Id']) + weight=1, health_check=result['CreateHealthCheckResponse']['HealthCheck']['Id']) deleted.add_value('54.217.7.118') records.commit() diff --git a/tests/integration/route53/test_resourcerecordsets.py b/tests/integration/route53/test_resourcerecordsets.py index 534dbac7..76a931e8 100644 --- a/tests/integration/route53/test_resourcerecordsets.py +++ b/tests/integration/route53/test_resourcerecordsets.py @@ -20,13 +20,12 @@ # IN THE SOFTWARE. # -import time from tests.compat import unittest from tests.integration.route53 import Route53TestCase -from boto.route53.connection import Route53Connection from boto.route53.record import ResourceRecordSets + class TestRoute53ResourceRecordSets(Route53TestCase): def test_add_change(self): rrs = ResourceRecordSets(self.conn, self.zone.id) diff --git a/tests/integration/route53/test_zone.py b/tests/integration/route53/test_zone.py index 2fc0b8c6..9ba9e452 100644 --- a/tests/integration/route53/test_zone.py +++ b/tests/integration/route53/test_zone.py @@ -104,7 +104,7 @@ class TestRoute53Zone(unittest.TestCase): record = self.zone.get_mx(self.base_domain) self.assertEquals(set(record.resource_records), set([u'10 mail1.%s.' % self.base_domain, - '20 mail2.%s.' % self.base_domain])) + '20 mail2.%s.' % self.base_domain])) self.assertEquals(record.ttl, u'50') def test_get_records(self): @@ -142,7 +142,7 @@ class TestRoute53Zone(unittest.TestCase): ) self.assertEquals(len(lbrs), 2) self.zone.delete_a('lbr.%s' % self.base_domain, - identifier=('bam', 'us-west-1')) + identifier=('bam', 'us-west-1')) self.zone.delete_a('lbr.%s' % self.base_domain, identifier=('baz', 'us-east-1')) diff --git a/tests/unit/route53/test_connection.py b/tests/unit/route53/test_connection.py index 16df3747..98543518 100644 --- a/tests/unit/route53/test_connection.py +++ b/tests/unit/route53/test_connection.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. # -from tests.compat import mock, unittest +from tests.compat import mock import re import xml.dom.minidom @@ -34,6 +34,7 @@ from boto.route53.zone import Zone from nose.plugins.attrib import attr from tests.unit import AWSMockServiceTestCase + @attr(route53=True) class TestRoute53Connection(AWSMockServiceTestCase): connection_class = Route53Connection @@ -88,6 +89,7 @@ class TestRoute53Connection(AWSMockServiceTestCase): # Unpatch. self.service_connection._retry_handler = orig_retry + @attr(route53=True) class TestCreateZoneRoute53(AWSMockServiceTestCase): connection_class = Route53Connection @@ -138,6 +140,7 @@ class TestCreateZoneRoute53(AWSMockServiceTestCase): self.assertEqual(response['CreateHostedZoneResponse']['DelegationSet']['NameServers'], ['ns-100.awsdns-01.com', 'ns-1000.awsdns-01.co.uk', 'ns-1000.awsdns-01.org', 'ns-900.awsdns-01.net']) + @attr(route53=True) class TestGetZoneRoute53(AWSMockServiceTestCase): connection_class = Route53Connection @@ -195,6 +198,7 @@ class TestGetZoneRoute53(AWSMockServiceTestCase): self.assertTrue(isinstance(response, Zone)) self.assertEqual(response.name, "example.com.") + @attr(route53=True) class TestGetHostedZoneRoute53(AWSMockServiceTestCase): connection_class = Route53Connection @@ -232,6 +236,7 @@ class TestGetHostedZoneRoute53(AWSMockServiceTestCase): self.assertEqual(response['GetHostedZoneResponse']['DelegationSet']['NameServers'], ['ns-1000.awsdns-40.org', 'ns-200.awsdns-30.com', 'ns-900.awsdns-50.net', 'ns-1000.awsdns-00.co.uk']) + @attr(route53=True) class TestGetAllRRSetsRoute53(AWSMockServiceTestCase): connection_class = Route53Connection @@ -321,10 +326,9 @@ class TestGetAllRRSetsRoute53(AWSMockServiceTestCase): self.set_http_response(status_code=200) response = self.service_connection.get_all_rrsets("Z1111", "A", "example.com.") - self.assertIn(self.actual_request.path, - ("/2013-04-01/hostedzone/Z1111/rrset?type=A&name=example.com.", - "/2013-04-01/hostedzone/Z1111/rrset?name=example.com.&type=A")) + ("/2013-04-01/hostedzone/Z1111/rrset?type=A&name=example.com.", + "/2013-04-01/hostedzone/Z1111/rrset?name=example.com.&type=A")) self.assertTrue(isinstance(response, ResourceRecordSets)) self.assertEqual(response.hosted_zone_id, "Z1111") @@ -371,6 +375,7 @@ class TestGetAllRRSetsRoute53(AWSMockServiceTestCase): self.assertEqual(healthcheck_record.identifier, 'latency-example-us-west-2-evaluate-health-healthcheck') self.assertEqual(healthcheck_record.alias_dns_name, 'example-123456-evaluate-health-healthcheck.us-west-2.elb.amazonaws.com.') + @attr(route53=True) class TestCreateHealthCheckRoute53IpAddress(AWSMockServiceTestCase): connection_class = Route53Connection @@ -414,6 +419,7 @@ class TestCreateHealthCheckRoute53IpAddress(AWSMockServiceTestCase): self.assertEqual(hc_resp['SearchString'], 'OK') self.assertEqual(response['CreateHealthCheckResponse']['HealthCheck']['Id'], '34778cf8-e31e-4974-bad0-b108bd1623d3') + @attr(route53=True) class TestCreateHealthCheckRoute53FQDN(AWSMockServiceTestCase): connection_class = Route53Connection @@ -455,6 +461,7 @@ class TestCreateHealthCheckRoute53FQDN(AWSMockServiceTestCase): self.assertEqual(hc_resp['ResourcePath'], '/health_check') self.assertEqual(response['CreateHealthCheckResponse']['HealthCheck']['Id'], 'f9abfe10-8d2a-4bbd-8f35-796f0f8572f2') + @attr(route53=True) class TestChangeResourceRecordSetsRoute53(AWSMockServiceTestCase): connection_class = Route53Connection @@ -569,4 +576,3 @@ class TestChangeResourceRecordSetsRoute53(AWSMockServiceTestCase): # Note: the alias XML should not include the TTL, even if it's specified in the object model self.assertEqual(actual_xml, expected_xml) - |