From 13cd9c6c22930d9bbd38da7e8d09ee50cddc5153 Mon Sep 17 00:00:00 2001 From: liyingjun Date: Wed, 22 Apr 2015 17:23:37 +0800 Subject: [PATCH] Check delay and timeout when editing monitor Validate delay and timeout when editing monitor, make sure delay is greater than or equal to timeout. And add more detail in help message for delay input. Change-Id: I5dd16d385e85d282b5baba8b1bc0a6ed7d79ec26 Closes-bug: #1446997 --- .../dashboards/project/loadbalancers/forms.py | 14 ++++++++++++-- .../dashboards/project/loadbalancers/workflows.py | 5 +++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/openstack_dashboard/dashboards/project/loadbalancers/forms.py b/openstack_dashboard/dashboards/project/loadbalancers/forms.py index 3d67faa61f..34c30b8181 100644 --- a/openstack_dashboard/dashboards/project/loadbalancers/forms.py +++ b/openstack_dashboard/dashboards/project/loadbalancers/forms.py @@ -224,12 +224,13 @@ class UpdateMonitor(forms.SelfHandlingForm): min_value=1, label=_("Delay"), help_text=_("The minimum time in seconds between regular checks " - "of a member")) + "of a member. It must be greater than or equal to " + "timeout")) timeout = forms.IntegerField( min_value=1, label=_("Timeout"), help_text=_("The maximum time in seconds for a monitor to wait " - "for a reply")) + "for a reply. It must be less than or equal to delay")) max_retries = forms.IntegerField( max_value=10, min_value=1, label=_("Max Retries (1~10)"), @@ -244,6 +245,15 @@ class UpdateMonitor(forms.SelfHandlingForm): def __init__(self, request, *args, **kwargs): super(UpdateMonitor, self).__init__(request, *args, **kwargs) + def clean(self): + cleaned_data = super(UpdateMonitor, self).clean() + delay = cleaned_data.get('delay') + timeout = cleaned_data.get('timeout') + if not delay >= timeout: + msg = _('Delay must be greater than or equal to timeout') + self._errors['delay'] = self.error_class([msg]) + return cleaned_data + def handle(self, request, context): context['admin_state_up'] = (context['admin_state_up'] == 'True') try: diff --git a/openstack_dashboard/dashboards/project/loadbalancers/workflows.py b/openstack_dashboard/dashboards/project/loadbalancers/workflows.py index 84d00cc650..34a44d2e78 100644 --- a/openstack_dashboard/dashboards/project/loadbalancers/workflows.py +++ b/openstack_dashboard/dashboards/project/loadbalancers/workflows.py @@ -496,12 +496,13 @@ class AddMonitorAction(workflows.Action): min_value=1, label=_("Delay"), help_text=_("The minimum time in seconds between regular checks " - "of a member")) + "of a member. It must be greater than or equal to " + "timeout")) timeout = forms.IntegerField( min_value=1, label=_("Timeout"), help_text=_("The maximum time in seconds for a monitor to wait " - "for a reply")) + "for a reply. It must be less than or equal to delay")) max_retries = forms.IntegerField( max_value=10, min_value=1, label=_("Max Retries (1~10)"),