Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVOPS-7811: added logging of instance names #36

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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