Skip to content

Commit 7a29b29

Browse files
committed
fix(route53-wildcard.py): poll until wildcard domain is accessible
1 parent 669ab53 commit 7a29b29

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

tests/bin/route53-wildcard.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,41 @@
1616
./route53-wildcard.py create mycluster.gabrtv.io deis-elb.blah.amazonaws.com
1717
./route53-wildcard.py delete mycluster.gabrtv.io deis-elb.blah.amazonaws.com
1818
"""
19+
20+
from __future__ import print_function
21+
1922
import boto.route53
2023
import docopt
21-
import json
22-
import subprocess
24+
import socket
2325
import time
26+
import uuid
2427

2528

2629
def parse_args():
2730
return docopt.docopt(__doc__)
2831

32+
2933
def create_cname(args):
3034
conn = boto.route53.connect_to_region(args['--region'])
3135
zone = conn.get_zone(args['<zone>'])
32-
status = zone.add_cname(args['<name>'], args['<value>'], ttl=args['--ttl'])
36+
name = args['<name>']
37+
status = zone.add_cname(name, args['<value>'], ttl=args['--ttl'])
3338
print("waiting for record to sync: {}".format(status))
3439
while status.update() != "INSYNC":
3540
time.sleep(2)
3641
print(status)
42+
print('waiting for wildcard domain to become available...', end='')
43+
# AWS docs say it can take up to 30 minutes for route53 changes to happen, although
44+
# it seems to be almost immediate.
45+
for i in xrange(120):
46+
try:
47+
random_hostname = str(uuid.uuid4())[:8]
48+
if socket.gethostbyname("{}.{}".format(random_hostname, name)):
49+
print('ok')
50+
break
51+
except socket.gaierror:
52+
time.sleep(15)
53+
3754

3855
def delete_cname(args, block=False):
3956
conn = boto.route53.connect_to_region(args['--region'])

0 commit comments

Comments
 (0)