Skip to content

Commit

Permalink
Only convert CNAME to alias
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcs committed Sep 23, 2016
1 parent 248be9e commit 65b8b20
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions senza/components/elastic_load_balancer.py
Expand Up @@ -6,7 +6,7 @@
from ..manaus import ClientError
from ..manaus.acm import ACM, ACMCertificate
from ..manaus.iam import IAM, IAMServerCertificate
from ..manaus.route53 import convert_domain_records_to_alias
from ..manaus.route53 import convert_cname_records_to_alias

SENZA_PROPERTIES = frozenset(['Domains', 'HealthCheckPath', 'HealthCheckPort', 'HealthCheckProtocol',
'HTTPPort', 'Name', 'SecurityGroups', 'SSLCertificateId', 'Type'])
Expand Down Expand Up @@ -104,7 +104,7 @@ def component_elastic_load_balancer(definition,

domain_name = "{0}.{1}".format(domain["Subdomain"], domain["Zone"])

convert_domain_records_to_alias(domain_name)
convert_cname_records_to_alias(domain_name)

properties = {"Type": "A",
"Name": domain_name,
Expand Down
4 changes: 2 additions & 2 deletions senza/components/elastic_load_balancer_v2.py
Expand Up @@ -3,7 +3,7 @@
from senza.components.elastic_load_balancer import ALLOWED_LOADBALANCER_SCHEMES, get_load_balancer_name, get_ssl_cert

from ..cli import AccountArguments, TemplateArguments
from ..manaus.route53 import convert_domain_records_to_alias
from ..manaus.route53 import convert_cname_records_to_alias

SENZA_PROPERTIES = frozenset(['Domains', 'HealthCheckPath', 'HealthCheckPort', 'HealthCheckProtocol',
'HTTPPort', 'Name', 'SecurityGroups', 'SSLCertificateId', 'Type'])
Expand Down Expand Up @@ -40,7 +40,7 @@ def component_elastic_load_balancer_v2(definition,

domain_name = "{0}.{1}".format(domain["Subdomain"], domain["Zone"])

convert_domain_records_to_alias(domain_name)
convert_cname_records_to_alias(domain_name)

properties = {"Type": "A",
"Name": domain_name,
Expand Down
6 changes: 3 additions & 3 deletions senza/manaus/route53.py
Expand Up @@ -281,7 +281,7 @@ def to_alias(self,
if self.alias_target is not None:
# Record is already an Alias
return deepcopy(self)
elif self.type == RecordType.CNAME:
if self.type == RecordType.CNAME:
dns_name = self.resource_records[0]['Value']
# dns name looks like lb-name-123456.aws-region-1.elb.amazonaws.com
sub_domain, _ = dns_name.split('.', maxsplit=1) # type: str
Expand Down Expand Up @@ -373,12 +373,12 @@ def get_records(cls, *,
yield record


def convert_domain_records_to_alias(domain_name: str):
def convert_cname_records_to_alias(domain_name: str):
records = Route53.get_records(name=domain_name)
converted_records = defaultdict(lambda: {'delete': [],
'upsert': []})
for record in records:
if record.type != 'A':
if record.type == RecordType.CNAME:
converted_records[record.hosted_zone]['delete'].append(record)
try:
alias_record = record.to_alias()
Expand Down
4 changes: 2 additions & 2 deletions senza/traffic.py
Expand Up @@ -11,7 +11,7 @@
from .manaus.cloudformation import CloudFormationStack, ResourceType
from .manaus.exceptions import StackNotFound, StackNotUpdated, ELBNotFound
from .manaus.route53 import (RecordType, Route53, Route53HostedZone,
convert_domain_records_to_alias)
convert_cname_records_to_alias)

PERCENT_RESOLUTION = 2
FULL_PERCENTAGE = PERCENT_RESOLUTION * 100
Expand Down Expand Up @@ -124,7 +124,7 @@ def set_new_weights(dns_names: list, identifier, lb_dns_name: str,
for idx, dns_name in enumerate(dns_names):
domain = dns_name.split('.', 1)[1]
hosted_zone = Route53HostedZone.get_by_domain_name(domain)
convert_domain_records_to_alias(dns_name)
convert_cname_records_to_alias(dns_name)

changed = False
for stack_name, percentage in new_record_weights.items():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_manaus/test_route53.py
Expand Up @@ -7,7 +7,7 @@
RecordNotFound)
from senza.manaus.route53 import (RecordType, Route53, Route53HostedZone,
Route53Record,
convert_domain_records_to_alias)
convert_cname_records_to_alias)


def test_hosted_zone_from_boto_dict():
Expand Down Expand Up @@ -438,7 +438,7 @@ def test_convert_domain_records_to_alias(monkeypatch):
mock_isatty = MagicMock(return_value=True)
monkeypatch.setattr('sys.stdin.isatty', mock_isatty)

convert_domain_records_to_alias("app1.example.com")
convert_cname_records_to_alias("app1.example.com")

mock_hz1.delete.assert_called_once_with([mock_record1],
comment='Records that will be converted to Alias')
Expand All @@ -448,7 +448,7 @@ def test_convert_domain_records_to_alias(monkeypatch):

mock_confirm.return_value = False
with pytest.raises(InvalidState):
convert_domain_records_to_alias("app1.example.com")
convert_cname_records_to_alias("app1.example.com")


def test_hosted_zone_get_by_domain_name(monkeypatch):
Expand Down

0 comments on commit 65b8b20

Please sign in to comment.