Fix to-version field on K8S Upgrade Strategy

When creating a Kubernetes Strategy, the 'to-version' field
was being sent without the 'v' prefix. This was making that the
kubernetes pre-check fails.

This change fixes this issue. Also, the default version that is
selected when the user doesn't select an item on the 'to-version'
drop-down menu will be the systemcontroller active version.

Test Plan:
PASS: Create and apply a kubernetes upgrade strategy selecting the
desired 'to-version' option. Verify the pre-check is passed and
the strategy is completed.
PASS: Create and apply a kubernetes upgrade strategy using the default
option on the drop-down menu. Verify that the version that it being
sent to dcmanager is the systemcontroller's active version.

Closes-bug: 2018611

Signed-off-by: Enzo Candotti <enzo.candotti@windriver.com>
Change-Id: Ifb76950dfdc67bdda57cbaea20433f65ebcc8aa3
This commit is contained in:
Enzo Candotti 2023-05-05 12:17:20 -03:00
parent af025a3604
commit 8c0d3f5063
1 changed files with 5 additions and 6 deletions

View File

@ -75,7 +75,8 @@ class CreateCloudStrategyForm(forms.SelfHandlingForm):
label=_("To version"),
required=False,
help_text=_("Select a version to apply the strategy. \
Otherwise, it will be updated to the available version."),
Otherwise, it will be updated to the SystemController \
active version."),
widget=forms.Select(
attrs={
'class': 'switchable switched',
@ -221,15 +222,13 @@ class CreateCloudStrategyForm(forms.SelfHandlingForm):
kube_versions = []
version = []
is_first_available = False
kube_version_list = api.sysinv.kube_version_list(self.request)
for k in kube_version_list:
if k.state == "available" and not is_first_available:
version = [(k.version[1:], '--')]
if k.state == "active":
version = [(k.version, '--')]
kube_versions[:0] = version
is_first_available = True
if k.state != "unavailable":
version = [(k.version[1:], k.version[1:] + " - " + k.state)]
version = [(k.version, k.version + " - " + k.state)]
kube_versions.extend(version)
self.fields['to_version'].choices = kube_versions