Skip to content

Commit

Permalink
DEVOPS-7811: added logging of instance names
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhang committed Oct 4, 2016
1 parent 9cd9126 commit 90a3b01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion License2Deploy/rolling_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class RollingDeploy(object):

MAX_RETRIES = 10
INSTANCE_NAME = "{0}-{1}{2}-{3}" #e.g. aw1-dnbi-cirrus107-qa

def __init__(self,
env=None,
Expand All @@ -28,6 +29,7 @@ def __init__(self,
only_new_wait=[10, 30]):
self.env = env
self.session = session
self.project_full_name = project
self.project = project.replace('-','')
self.build_number = build_number
self.ami_id = ami_id
Expand All @@ -53,6 +55,11 @@ def __init__(self,
self.only_new_wait = only_new_wait
self.existing_instance_ids = []
self.new_desired_capacity = None

def format_instance_name(self, ip):
region_short = 'aw1' if self.regions_conf == 'us-west-1' else 'ae1'
ip_end = ip.split(".")[-1]
return self.INSTANCE_NAME.format(region_short, self.project_full_name, ip_end, self.env)

def get_ami_id_state(self, ami_id):
try:
Expand Down Expand Up @@ -159,7 +166,9 @@ def get_instance_ip_addrs(self, id_list=[]):
try:
instance_data = [ids for instInfo in self.get_instance_info(id_list) for ids in instInfo.instances]
for instance in instance_data:
ip_dict[instance.id] = instance.private_ip_address
ip = instance.private_ip_address
instance_name = self.format_instance_name(ip)
ip_dict[instance.id] = (ip, instance_name)
return ip_dict
except Exception as e:
logging.error("Unable to get IP Addresses for instances: {0}".format(e))
Expand Down
5 changes: 5 additions & 0 deletions tests/rolling_deploy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ def test_double_autoscale_instance_count(self):

def test_decrease_autoscale_instance_count(self):
self.assertEqual(self.rolling_deploy.decrease_autoscale_instance_count(4), 2)

def test_format_instance_name(self):
expected_instance_name = "ae1-server-gms-extender50-stg"
actual_instance_name = self.rolling_deploy.format_instance_name("10.32.10.50")
self.assertEqual(expected_instance_name, actual_instance_name)

def main():
unittest.main()
Expand Down

0 comments on commit 90a3b01

Please sign in to comment.