Added delete all releases option for major version

This commit adds the option --all to 'software delete' command.

Usage:
software delete --all component-MM.mm

When using this option, all releases (patch or major) from
component-MM.mm will be deleted if all of them are in available
or unavailable state.

TestCase:
PASS: 'software delete --all'
      > usage: software delete [--all] release [release ...]
PASS: 'software delete --all starlingx-24.09.1'
      > The release ID must have the pattern: component-MM.mm
PASS: 'software delete --all starlingx-24.09 wrcp-24.09'
      > --all require only one release ID
PASS: 'software delete --all starlingx-25.03'
      with no starlingx-25.03 release.
      > There are no starlingx-25.03 releases to delete.
PASS: 'software delete --all wrcp-24.09'
      with at least one release not available or unavailable,
      return a list of releases that are not ready to be deleted.
      > Releases wrcp-24.09.0,wrcp-24.09.1 not ready to delete
PASS: 'software delete --all starlingx-24.09'
      with all releases available or unavailable
      > starlingx-24.09.0 has been deleted
      > starlingx-24.09.1 has been deleted
      > starlingx-24.09.2 has been deleted

Story: 2010676
Task: 50732

Change-Id: I37e9df297cdaa22653e8ad431a88a3c2dc18a643
Signed-off-by: Lindley Vieira <lindley.vieira@windriver.com>
This commit is contained in:
Lindley Vieira 2024-08-01 18:47:50 -03:00
parent bd16773cd8
commit 8e6445085e
2 changed files with 48 additions and 3 deletions

View File

@ -5,6 +5,7 @@
#
import os
import re
import signal
import sys
import textwrap
@ -267,7 +268,45 @@ class ReleaseManager(base.Manager):
path = "/v1/deploy_host/install_local"
return self._post(path, body=body)
def release_delete(self, release_id):
release_ids = "/".join(release_id)
def release_delete(self, release_id_list, delete_all):
if delete_all:
if len(release_id_list) != 1:
print("--all require only one release ID")
return 1
pattern = r"^([a-zA-Z]+)-(\d{2}\.\d{2})$"
match = re.match(pattern, release_id_list[0])
if not match:
print("The release ID must have the pattern: component-MM.mm")
return 1
component = match.group(1)
sw_version = match.group(2)
# Get a list of all patches from sw_version (MM.mm)
url = "/v1/release?show=patch&release=%s" % sw_version
resp, body = self._list(url, "")
patch_list = []
if resp.status_code == 200:
data = body
else:
print("Could not fetch the releases from %s-%s version" % (component, sw_version))
return 1
# filter patches by component
for release in data:
if release["component"] == component:
patch_list.append(release["release_id"])
if len(patch_list) == 0:
print("There are no %s-%s releases to delete." % (component, sw_version))
return 0
# pass all releases, software will check if can be deleted
release_ids = "/".join(patch_list)
else:
release_ids = "/".join(release_id_list)
path = '/v1/release/%s' % release_ids
return self._delete(path)

View File

@ -213,12 +213,18 @@ def do_upload_dir(cc, args):
return utils.check_rc(resp, data)
# --all is an optional argument
@utils.arg('--all',
action='store_true',
required=False,
help='Delete all patches and major releases related '
'to the given major release ID')
@utils.arg('release',
nargs="+", # accepts a list
help='Release ID to delete')
def do_delete(cc, args):
"""Delete the software release"""
resp, data = cc.release.release_delete(args.release)
resp, data = cc.release.release_delete(args.release, args.all)
if args.debug:
utils.print_result_debug(resp, data)