software commit-patch implementation
This commit enables the command "software commit-patch <Patch-ID>" in the Debian Env. Test Plan: [PASS] software commit-patch <patch-id> Story: 2010676 Task: 48789 Change-Id: I5f8392ac71dc964f54fa02ac8f4086feab4858ee Signed-off-by: Jessica Castelino <jessica.castelino@windriver.com>
This commit is contained in:
parent
bd32299149
commit
7e7654ef54
@ -24,6 +24,26 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
class SoftwareAPIController(object):
|
class SoftwareAPIController(object):
|
||||||
|
|
||||||
|
@expose('json')
|
||||||
|
def commit_patch(self, *args):
|
||||||
|
try:
|
||||||
|
result = sc.patch_commit(list(args))
|
||||||
|
except SoftwareError as e:
|
||||||
|
return dict(error=str(e))
|
||||||
|
|
||||||
|
sc.software_sync()
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
@expose('json')
|
||||||
|
def commit_dry_run(self, *args):
|
||||||
|
try:
|
||||||
|
result = sc.patch_commit(list(args), dry_run=True)
|
||||||
|
except SoftwareError as e:
|
||||||
|
return dict(error=str(e))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
@expose('json')
|
@expose('json')
|
||||||
@expose('query.xml', content_type='application/xml')
|
@expose('query.xml', content_type='application/xml')
|
||||||
def delete(self, *args):
|
def delete(self, *args):
|
||||||
|
@ -15,11 +15,6 @@ try:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
CLI_OPT_ALL = '--all'
|
|
||||||
CLI_OPT_DRY_RUN = '--dry-run'
|
|
||||||
CLI_OPT_RECURSIVE = '--recursive'
|
|
||||||
CLI_OPT_RELEASE = '--release'
|
|
||||||
|
|
||||||
ADDRESS_VERSION_IPV4 = 4
|
ADDRESS_VERSION_IPV4 = 4
|
||||||
ADDRESS_VERSION_IPV6 = 6
|
ADDRESS_VERSION_IPV6 = 6
|
||||||
CONTROLLER_FLOATING_HOSTNAME = "controller"
|
CONTROLLER_FLOATING_HOSTNAME = "controller"
|
||||||
|
@ -349,37 +349,25 @@ def release_delete_req(args):
|
|||||||
return check_rc(req)
|
return check_rc(req)
|
||||||
|
|
||||||
|
|
||||||
def patch_commit_req(args):
|
def commit_patch_req(args):
|
||||||
print("patch_commit_req UNDER CONSTRUCTION")
|
|
||||||
|
|
||||||
# Ignore interrupts during this function
|
# Ignore interrupts during this function
|
||||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||||
|
|
||||||
dry_run = False
|
|
||||||
if constants.CLI_OPT_DRY_RUN in args:
|
|
||||||
dry_run = True
|
|
||||||
args.remove(constants.CLI_OPT_DRY_RUN)
|
|
||||||
|
|
||||||
all_patches = False
|
|
||||||
if constants.CLI_OPT_ALL in args:
|
|
||||||
all_patches = True
|
|
||||||
args.remove(constants.CLI_OPT_ALL)
|
|
||||||
|
|
||||||
# Default to running release
|
# Default to running release
|
||||||
# this all needs to be changed
|
# this all needs to be changed
|
||||||
relopt = RUNNING_SW_VERSION
|
relopt = RUNNING_SW_VERSION
|
||||||
release = args.release
|
|
||||||
|
|
||||||
headers = {}
|
headers = {}
|
||||||
append_auth_token_if_required(headers)
|
append_auth_token_if_required(headers)
|
||||||
if release and not all_patches:
|
if args.sw_version and not args.all:
|
||||||
# Disallow
|
# Disallow
|
||||||
print("Use of --release option requires --all")
|
print("Use of --sw-version option requires --all")
|
||||||
return 1
|
return 1
|
||||||
elif all_patches:
|
elif args.all:
|
||||||
# Get a list of all patches
|
# Get a list of all patches
|
||||||
extra_opts = "&release=%s" % relopt
|
extra_opts = "&release=%s" % relopt
|
||||||
url = "http://%s/software/query?show=all%s" % (api_addr, extra_opts)
|
url = "http://%s/software/query?show=patch%s" % (api_addr, extra_opts)
|
||||||
|
|
||||||
req = requests.get(url, headers=headers)
|
req = requests.get(url, headers=headers)
|
||||||
|
|
||||||
@ -398,13 +386,14 @@ def patch_commit_req(args):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
print("The following patches will be committed:")
|
print("The following patches will be committed:")
|
||||||
for release_id in patch_list:
|
for patch_id in patch_list:
|
||||||
print(" %s" % release_id)
|
print(" %s" % patch_id)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
patches = "/".join(patch_list)
|
patches = "/".join(patch_list)
|
||||||
else:
|
else:
|
||||||
patches = "/".join(args)
|
# args.patch is a list
|
||||||
|
patches = "/".join(args.patch)
|
||||||
|
|
||||||
# First, get a list of dependencies and ask for confirmation
|
# First, get a list of dependencies and ask for confirmation
|
||||||
url = "http://%s/software/query_dependencies/%s?recursive=yes" % (api_addr, patches)
|
url = "http://%s/software/query_dependencies/%s?recursive=yes" % (api_addr, patches)
|
||||||
@ -437,7 +426,7 @@ def patch_commit_req(args):
|
|||||||
print("Aborting...")
|
print("Aborting...")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if dry_run:
|
if args.dry_run:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
print()
|
print()
|
||||||
@ -451,7 +440,7 @@ def patch_commit_req(args):
|
|||||||
print("Aborting...")
|
print("Aborting...")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
url = "http://%s/software/commit/%s" % (api_addr, patches)
|
url = "http://%s/software/commit_patch/%s" % (api_addr, patches)
|
||||||
req = requests.post(url, headers=headers)
|
req = requests.post(url, headers=headers)
|
||||||
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
@ -1254,6 +1243,31 @@ def setup_argparse():
|
|||||||
commands = parser.add_subparsers(title='Commands', metavar='')
|
commands = parser.add_subparsers(title='Commands', metavar='')
|
||||||
commands.required = True
|
commands.required = True
|
||||||
|
|
||||||
|
# -- software commit-patch <release> ---------------
|
||||||
|
cmd = commands.add_parser(
|
||||||
|
'commit-patch',
|
||||||
|
help='Commit patches to free disk space. WARNING: This action is irreversible!'
|
||||||
|
)
|
||||||
|
cmd.set_defaults(cmd='commit-patch')
|
||||||
|
cmd.set_defaults(func=commit_patch_req)
|
||||||
|
cmd.add_argument('patch',
|
||||||
|
nargs="+", # accepts a list
|
||||||
|
help='Patch ID/s to commit')
|
||||||
|
# --dry-run is an optional argument
|
||||||
|
cmd.add_argument('--dry-run',
|
||||||
|
action='store_true',
|
||||||
|
required=False,
|
||||||
|
help='Check the space savings without committing the patch')
|
||||||
|
# --all is an optional argument
|
||||||
|
cmd.add_argument('--all',
|
||||||
|
action='store_true',
|
||||||
|
required=False,
|
||||||
|
help='Commit all the applied patches')
|
||||||
|
# --sw-version is an optional argument
|
||||||
|
cmd.add_argument('--sw-version',
|
||||||
|
required=False,
|
||||||
|
help='Software release version')
|
||||||
|
|
||||||
# -- software delete <release> ---------------
|
# -- software delete <release> ---------------
|
||||||
cmd = commands.add_parser(
|
cmd = commands.add_parser(
|
||||||
'delete',
|
'delete',
|
||||||
|
@ -1595,7 +1595,8 @@ class PatchController(PatchService):
|
|||||||
self.release_data.metadata[patch_id]["restart_script"])
|
self.release_data.metadata[patch_id]["restart_script"])
|
||||||
if os.path.exists(restart_script_path):
|
if os.path.exists(restart_script_path):
|
||||||
cleanup_files.add(restart_script_path)
|
cleanup_files.add(restart_script_path)
|
||||||
patch_sw_version = self.release_data.metadata[patch_id]["sw_version"]
|
patch_sw_version = utils.get_major_release_version(
|
||||||
|
self.release_data.metadata[patch_id]["sw_version"])
|
||||||
abs_ostree_tar_dir = package_dir[patch_sw_version]
|
abs_ostree_tar_dir = package_dir[patch_sw_version]
|
||||||
software_tar_path = "%s/%s-software.tar" % (abs_ostree_tar_dir, patch_id)
|
software_tar_path = "%s/%s-software.tar" % (abs_ostree_tar_dir, patch_id)
|
||||||
if os.path.exists(software_tar_path):
|
if os.path.exists(software_tar_path):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user