1717
1818import boto3
1919import click
20- import dns .resolver
2120import requests
2221import senza
2322import yaml
4342from .stups .piu import Piu
4443from .templates import get_template_description , get_templates
4544from .templates ._helper import get_mint_bucket_name
46- from .traffic import change_version_traffic , get_records , print_version_traffic
45+ from .traffic import change_version_traffic , get_records , print_version_traffic , resolve_to_ip_addresses
4746from .utils import (camel_case_to_underscore , ensure_keys , named_value ,
4847 pystache_render )
4948
@@ -937,7 +936,9 @@ def status(stack_ref, region, output, w, watch):
937936 for stack in sorted (get_stacks (stack_refs , region )):
938937 instance_health = get_instance_health (elb , stack .StackName )
939938
940- main_dns_resolves = False
939+ main_dns_resolves = None
940+ version_addresses = set ()
941+ main_addresses = set ()
941942 http_status = None
942943 for res in cf .Stack (stack .StackId ).resource_summaries .all ():
943944 if res .resource_type == 'AWS::Route53::RecordSet' :
@@ -946,22 +947,20 @@ def status(stack_ref, region, output, w, watch):
946947 # physical resource ID will be empty during stack creation
947948 continue
948949 if 'version' in res .logical_id .lower ():
950+ # VersionDomain -> check HTTPS reachability
951+ # (won't work for internal ELBs, but we don't care here)
949952 try :
950- requests .get ('https://{}/' .format (name ), timeout = 2 )
953+ requests .get ('https://{}/' .format (name ), timeout = 1 )
951954 http_status = 'OK'
952955 except :
953956 http_status = 'ERROR'
957+ version_addresses = resolve_to_ip_addresses (name )
954958 else :
955- try :
956- answers = dns .resolver .query (name , 'CNAME' )
957- except :
958- answers = []
959- for answer in answers :
960- target = answer .target .to_text ()
961- if isinstance (target , bytes ):
962- target = target .decode ()
963- if target .startswith ('{}-' .format (stack .StackName )):
964- main_dns_resolves = True
959+ # MainDomain -> check whether DNS resolves to this stack version
960+ main_addresses = resolve_to_ip_addresses (name )
961+
962+ if version_addresses and main_addresses :
963+ main_dns_resolves = bool (version_addresses & main_addresses )
965964
966965 instances = list (ec2 .instances .filter (Filters = [{'Name' : 'tag:aws:cloudformation:stack-id' ,
967966 'Values' : [stack .StackId ]}]))
@@ -1025,7 +1024,7 @@ def domains(stack_ref, region, output, w, watch):
10251024 if record :
10261025 row .update ({'weight' : str (record .get ('Weight' , '' )),
10271026 'type' : record .get ('Type' ),
1028- 'value' : ',' .join ([r ['Value' ] for r in record .get ('ResourceRecords' )])})
1027+ 'value' : ',' .join ([r ['Value' ] for r in record .get ('ResourceRecords' , [] )])})
10291028 rows .append (row )
10301029
10311030 with OutputFormat (output ):
0 commit comments