From 2dd7455be5bc681aae8f83663720f802f343aa85 Mon Sep 17 00:00:00 2001 From: Agustin Carranza Date: Tue, 17 May 2022 11:24:34 -0400 Subject: [PATCH] Fix for 'Apply to' and 'Force' fields behavior On 'Create Strategy' form the following fields are not usable when selecting a subcloud: * subcloud apply type * maximum parallel subclouds Now they are hidden in such case. Input element for subcloud name was changed to a dropdown list. If 'All subclouds' is selected, the strategy is applied to all subclouds and the fields mentioned are hidden. If any other subloud name is selected, such fields are shown. It was created another 'force' element for kubernetes strategy which shows a help message that is consistent with the expected behavior. The original element is left for 'upgrade' strategy only. Test Plan PASS: Build package Install package on DC with at least one subcloud Open gui on a browser and navigate to Distributed Cloud Admin -> Orchestration -> Orchestration Stragegy -> Create Strategy: * Check 'force' parameter is hidden for 'Patch' and 'Firmware' strategy types. * Check 'force' help text describes actual behavior. * Check 'subcloud' field is a dropdown menu and shows available subclouds. * Check 'subcloud apply type' and 'maximum parallel subclouds' fields are not shown when a single subcloud is selected in the dropdown menu. Closes-bug: 1973210 Closes-bug: 1973805 Signed-off-by: Agustin Carranza Change-Id: I909bb548f9b6454f6e556109165565394ec63114 --- .../dc_admin/dc_orchestration/forms.py | 74 ++++++++++++++----- 1 file changed, 56 insertions(+), 18 deletions(-) diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/dc_admin/dc_orchestration/forms.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/dc_admin/dc_orchestration/forms.py index 62540ee6..2a2d7932 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/dc_admin/dc_orchestration/forms.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/dc_admin/dc_orchestration/forms.py @@ -63,7 +63,12 @@ class CreateCloudStrategyForm(forms.SelfHandlingForm): label=_("Strategy Type"), required=True, choices=STRATEGY_TYPES, - widget=forms.Select() + widget=forms.Select( + attrs={ + 'class': 'switchable', + 'data-slug': 'strategy_types', + } + ) ) target = forms.ChoiceField( @@ -79,19 +84,19 @@ class CreateCloudStrategyForm(forms.SelfHandlingForm): ) ) - cloud_name = forms.CharField( + cloud_name = forms.ChoiceField( label=_("Subcloud"), - required=False, + required=True, help_text=_("Select subcloud to apply strategy."), - widget=forms.TextInput( + widget=forms.Select( attrs={ - 'class': 'switched', + 'class': 'switchable switched', 'data-switch-on': 'subcloud_types', - 'data-subcloud_types-cloud_name': _("Subcloud") + 'data-subcloud_types-cloud_name': _("Subcloud"), + 'data-slug': 'subcloud_name' } ) ) - subcloud_group = forms.CharField( label=_("Subcloud Group"), required=False, @@ -120,8 +125,8 @@ class CreateCloudStrategyForm(forms.SelfHandlingForm): widget=forms.Select( attrs={ 'class': 'switched', - 'data-switch-on': 'subcloud_types', - 'data-subcloud_types-cloud_name': _("Subcloud Apply Type") + 'data-switch-on': 'subcloud_name', + 'data-subcloud_name-default': _("Subcloud Apply Type") } ) ) @@ -137,8 +142,8 @@ class CreateCloudStrategyForm(forms.SelfHandlingForm): widget=forms.TextInput( attrs={ 'class': 'switched', - 'data-switch-on': 'subcloud_types', - 'data-subcloud_types-cloud_name': + 'data-switch-on': 'subcloud_name', + 'data-subcloud_name-default': _("Maximum Parallel Subclouds") } ) @@ -148,17 +153,43 @@ class CreateCloudStrategyForm(forms.SelfHandlingForm): label=_("Force"), initial=False, required=False, - help_text=_('Offline subcloud is skipped unless ' - 'force is set for Upgrade strategy'), + help_text=_('Offline subcloud is not skipped. ' + 'Applicable only when the strategy is created ' + 'to a single subcloud.'), widget=forms.CheckboxInput( attrs={ 'class': 'switched', - 'data-switch-on': 'subcloud_types', - 'data-subcloud_types-cloud_name': _("Force") + 'data-switch-on': 'strategy_types', + 'data-strategy_types-upgrade': _("Force"), } ) ) + force_kubernetes = forms.BooleanField( + label=_("Force"), + initial=False, + required=False, + help_text=_('Force Kube upgrade to a subcloud ' + 'which is in-sync with system controller'), + widget=forms.CheckboxInput( + attrs={ + 'class': 'switched', + 'data-switch-on': 'strategy_types', + 'data-strategy_types-kubernetes': _("Force") + } + ) + ) + + def __init__(self, request, *args, **kwargs): + super(CreateCloudStrategyForm, self).__init__(request, *args, + **kwargs) + subcloud_list = [('default', 'All subclouds')] + subclouds = api.dc_manager.subcloud_list(self.request) + subcloud_list.extend([(c.name, c.name) for c in subclouds]) + self.fields['cloud_name'].choices = subcloud_list + if self.initial.get('cloud_name', None): + self.fields['cloud_name'].widget.attrs['disabled'] = 'disabled' + def handle(self, request, data): try: # convert keys to use dashes @@ -168,7 +199,6 @@ class CreateCloudStrategyForm(forms.SelfHandlingForm): elif '_' in k: data[k.replace('_', '-')] = data[k] del data[k] - if data['target'] == 'subcloud_group': del data['cloud_name'] del data['force'] @@ -176,10 +206,18 @@ class CreateCloudStrategyForm(forms.SelfHandlingForm): del data['subcloud-apply-type'] else: del data['subcloud_group'] - data['force'] = str(data['force']).lower() - + if data['cloud_name'] == 'default': + del data['cloud_name'] + del data['force'] + else: + del data['max-parallel-subclouds'] + del data['subcloud-apply-type'] + data['force'] = str(data['force']).lower() del data['target'] data['stop-on-failure'] = str(data['stop-on-failure']).lower() + if data['type'] == 'kubernetes': + data['force'] = str(data['force-kubernetes']).lower() + del data['force-kubernetes'] response = api.dc_manager.strategy_create(request, data) if not response: