Skip to content

Commit

Permalink
Merge branch 'handle_missing_launchtemplate' of github.com:JSainsbury…
Browse files Browse the repository at this point in the history
…PLC/eks-rolling-update into JSainsburyPLC-handle_missing_launchtemplate
  • Loading branch information
Craig Huber committed Jun 11, 2021
2 parents 4db3331 + ee8b548 commit 1f46b84
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion eksrollup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def main(args=None):
filtered_asgs = get_asgs(args.cluster_name)
run_mode = app_config['RUN_MODE']
# perform a dry run on mode 4 for older nodes
if args.plan or app_config['DRY_RUN'] and (run_mode == 4):
if (args.plan or app_config['DRY_RUN']) and (run_mode == 4):
plan_asgs_older_nodes(filtered_asgs)
# perform a dry run on main mode
elif args.plan or app_config['DRY_RUN']:
Expand Down
8 changes: 6 additions & 2 deletions eksrollup/lib/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,12 @@ def instance_outdated_launchtemplate(instance_obj, asg_lt_name, asg_lt_version):
describe_launch_templates boto3 method (wrapped in get_launch_template).
"""
instance_id = instance_obj['InstanceId']
lt_name = instance_obj['LaunchTemplate']['LaunchTemplateName']
lt_version = int(instance_obj['LaunchTemplate']['Version'])
try:
lt_name = instance_obj['LaunchTemplate']['LaunchTemplateName']
lt_version = int(instance_obj['LaunchTemplate']['Version'])
except KeyError:
logger.info("Instance id {} missing launch template does not match asg launch template of '{}'".format(instance_id, asg_lt_name))
return True

if lt_name != asg_lt_name:
logger.info("Instance id {} launch template of '{}' does not match asg launch template of '{}'".format(instance_id, lt_name, asg_lt_name))
Expand Down
13 changes: 13 additions & 0 deletions tests/test_aws_launchtemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def setUp(self):
self.aws_response_mock_latest = json.load(file)
with open(f"{current_dir}/fixtures/get_launch_template.json", "r") as file:
self.mock_get_launch_template = json.load(file)
with open(f"{current_dir}/fixtures/aws_response.json", "r") as file:
self.aws_response_mock_no_launch_template = json.load(file)


def test_is_instance_outdated(self):
response = self.aws_response_mock
Expand Down Expand Up @@ -77,3 +80,13 @@ def test_is_instance_outdated_fail_version_latest(self):
with patch('eksrollup.lib.aws.get_launch_template') as get_launch_template_mock:
get_launch_template_mock.return_value = self.mock_get_launch_template
self.assertTrue(instance_outdated_launchtemplate(instances[2], 'mock-lt-01', '$Latest'))

def test_is_instance_outdated_fail_no_launch_template(self):
response = self.aws_response_mock_no_launch_template
asgs = response['AutoScalingGroups']
for asg in asgs:
instances = asg['Instances']
with patch('eksrollup.lib.aws.get_launch_template') as get_launch_template_mock:
get_launch_template_mock.return_value = self.mock_get_launch_template
self.assertTrue(instance_outdated_launchtemplate(instances[0], 'mock-lt-01', '$Latest'))

0 comments on commit 1f46b84

Please sign in to comment.