-
Notifications
You must be signed in to change notification settings - Fork 16
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
(12.1.0) INFRASYS-6779 - disable the cloud-watch_alarms while rolling deployment. #27
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ def __init__(self, env=None, project=None, buildNum=None, ami_id=None, profile_n | |
self.conn_ec2 = AWSConn.aws_conn_ec2(self.region, self.profile_name) | ||
self.conn_elb = AWSConn.aws_conn_elb(self.region, self.profile_name) | ||
self.conn_auto = AWSConn.aws_conn_auto(self.region, self.profile_name) | ||
self.conn_cloudwatch = AWSConn.aws_conn_cloudwatch(self.region, self.profile_name) | ||
self.exit_error_code = 2 | ||
self.load_balancer = self.get_lb() | ||
|
||
|
@@ -222,18 +223,55 @@ def healthcheck_new_instances(self, group_name): # pragma: no cover | |
self.wait_for_new_instances(new_instance_ids) #Wait for new instances to be up and ready | ||
self.lb_healthcheck(new_instance_ids) #Once instances are ready, healthcheck. If successful, decrease desired count. | ||
|
||
def retrieve_project_cloudwatch_alarms(self): | ||
""" Retrieve all the Cloud-Watch alarms for the given project and environment """ | ||
try: | ||
all_cloud_watch_alarms = self.conn_cloudwatch.describe_alarms() | ||
except Exception as e: | ||
logging.error("Error while retrieving the list of cloud-watch alarms. Error: {0}".format(e)) | ||
exit(self.exit_error_code) | ||
project_cloud_watch_alarms = filter(lambda alarm: self.project in alarm.name and self.env in alarm.name, all_cloud_watch_alarms) | ||
if len(project_cloud_watch_alarms) == 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is enough to do: if not project_cloud_watch_alarms: |
||
logging.info("No cloud-watch alarm found") | ||
return project_cloud_watch_alarms | ||
|
||
def disable_project_cloudwatch_alarms(self): | ||
''' Disable all the cloud watch alarms ''' | ||
project_cloud_watch_alarms = self.retrieve_project_cloudwatch_alarms() | ||
for alarm in project_cloud_watch_alarms: | ||
try: | ||
self.conn_cloudwatch.disable_alarm_actions(alarm.name) | ||
logging.info("Disabled cloud-watch alarm. {0}".format(alarm.name)) | ||
except Exception as e: | ||
logging.error("Unable to disable the cloud-watch alarm, please investigate: {0}".format(e)) | ||
exit(self.exit_error_code) | ||
|
||
def enable_project_cloudwatch_alarms(self): | ||
''' Enable all the cloud watch alarms ''' | ||
project_cloud_watch_alarms = self.retrieve_project_cloudwatch_alarms() | ||
for alarm in project_cloud_watch_alarms: | ||
logging.info("Found an alarm. {0}".format(alarm.name)) | ||
try: | ||
self.conn_cloudwatch.enable_alarm_actions(alarm.name) | ||
logging.info("Enabled cloud-watch alarm. {0}".format(alarm.name)) | ||
except Exception as e: | ||
logging.error("Unable to enable the cloud-watch alarm, please investigate: {0}".format(e)) | ||
exit(self.exit_error_code) | ||
|
||
def deploy(self): # pragma: no cover | ||
''' Rollin Rollin Rollin, Rawhide! ''' | ||
group_name = self.get_autoscale_group_name() | ||
self.wait_ami_availability(self.ami_id) | ||
logging.info("Build #: {0} ::: Autoscale Group: {1}".format(self.buildNum, group_name)) | ||
self.disable_project_cloudwatch_alarms() | ||
self.set_autoscale_instance_desired_count(self.calculate_autoscale_desired_instance_count(group_name, 'increase'), group_name) | ||
logging.info("Sleeping for 240 seconds to allow for instances to spin up") | ||
sleep(240) #Need to wait until the instances come up in the load balancer | ||
self.healthcheck_new_instances(group_name) | ||
self.set_autoscale_instance_desired_count(self.calculate_autoscale_desired_instance_count(group_name, 'decrease'), group_name) | ||
self.confirm_lb_has_only_new_instances() | ||
self.tag_ami(self.ami_id, self.env) | ||
self.enable_project_cloudwatch_alarms() | ||
logging.info("Deployment Complete!") | ||
|
||
def revert_deployment(self): #pragma: no cover | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a newline above the start of this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamjkeller Done.