From 89498d495101d7f729d0d46f2c3ce3da06aa86b6 Mon Sep 17 00:00:00 2001 From: knguyen100000010 <63071572+knguyen100000010@users.noreply.github.com> Date: Tue, 13 Feb 2024 12:43:09 -0500 Subject: [PATCH] Prevent alarm created without scaling policy (#1448) * refuse to create alarm without scaling policy * add messages --- .../deploy_board/templates/groups/asg_config.html | 10 ++++++++-- deploy-board/deploy_board/webapp/group_view.py | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/deploy-board/deploy_board/templates/groups/asg_config.html b/deploy-board/deploy_board/templates/groups/asg_config.html index 603cc4bdb1..bd50802492 100644 --- a/deploy-board/deploy_board/templates/groups/asg_config.html +++ b/deploy-board/deploy_board/templates/groups/asg_config.html @@ -16,7 +16,6 @@ {% include "groups/group_side_panel.html" %} - {% endblock %} {% block new-builds-panel %} @@ -26,7 +25,14 @@ {% block main %} - +{% if storage %} + {% for message in storage %} + + {% endfor %} +{% endif %} {% if not is_cmp %}
diff --git a/deploy-board/deploy_board/webapp/group_view.py b/deploy-board/deploy_board/webapp/group_view.py index 3374de52eb..3e952c2f39 100644 --- a/deploy-board/deploy_board/webapp/group_view.py +++ b/deploy-board/deploy_board/webapp/group_view.py @@ -20,6 +20,7 @@ from django.template.loader import render_to_string from django.http import HttpResponse from django.contrib import messages +from django.contrib.messages import get_messages import json import logging import traceback @@ -794,6 +795,13 @@ def add_alarms(request, group_name): alarm_info["metricSource"] = params["awsMetrics"] alarm_info["groupName"] = group_name + if len(alarm_info["scalingPolicies"]) == 0: + # Technically, an alarm can be created without an action (e.g. scaling policy) + # However, in the current context, an alarm must have an associated scaling policy. + # In this case, there is no scaling policy, so refuse to create new alarm. + messages.add_message(request, messages.ERROR, 'Alarm could not be created because there was no {} policy.'.format(policy_type)) + return redirect("/groups/{}/config/".format(group_name)) + autoscaling_groups_helper.add_alarm(request, group_name, [alarm_info]) return redirect("/groups/{}/config/".format(group_name)) @@ -1180,6 +1188,7 @@ def get(self, request, group_name): "pas_config": pas_config, "is_cmp": is_cmp, "disallow_autoscaling": _disallow_autoscaling(curr_image), + "storage": get_messages(request) })