Support is-available, is-deployed and is-committed software CLI

This commit enables 'software is-available', 'software is-deployed'
and 'software is-committed' CLI commands and API endpoints within
USM.

Change-Id: I9b718a2dbbbd53ce999724cfd4d549e65d680df1
Signed-off-by: Jessica Castelino <jessica.castelino@windriver.com>
This commit is contained in:
Jessica Castelino 2023-10-19 17:13:00 +00:00
parent e6744eb9f5
commit ac6768a217
3 changed files with 145 additions and 83 deletions

View File

@ -288,6 +288,72 @@ def software_command_not_implemented_yet(args):
return 1
def release_is_available_req(args):
releases = args.release
url = "http://%s/software/is_available/%s" % (api_addr, releases)
headers = {}
append_auth_token_if_required(headers)
req = requests.post(url, headers=headers)
rc = 1
if req.status_code == 200:
result = json.loads(req.text)
print(result)
if result is True:
rc = 0
elif req.status_code == 500:
print("An internal error has occurred. Please check /var/log/patching.log for details")
return rc
def release_is_deployed_req(args):
releases = args.release
url = "http://%s/patch/is_deployed/%s" % (api_addr, releases)
headers = {}
append_auth_token_if_required(headers)
req = requests.post(url, headers=headers)
rc = 1
if req.status_code == 200:
result = json.loads(req.text)
print(result)
if result is True:
rc = 0
elif req.status_code == 500:
print("An internal error has occurred. Please check /var/log/patching.log for details")
return rc
def release_is_committed_req(args):
releases = args.release
url = "http://%s/software/is_committed/%s" % (api_addr, releases)
headers = {}
append_auth_token_if_required(headers)
req = requests.post(url, headers=headers)
rc = 1
if req.status_code == 200:
result = json.loads(req.text)
print(result)
if result is True:
rc = 0
elif req.status_code == 500:
print("An internal error has occurred. Please check /var/log/patching.log for details")
return rc
def release_upload_req(args):
rc = 0
@ -919,64 +985,6 @@ def patch_del_release(args):
return check_rc(req)
def patch_is_applied_req(args):
releases = args.releases
patches = "/".join(releases)
url = "http://%s/software/is_applied/%s" % (api_addr, patches)
headers = {}
append_auth_token_if_required(headers)
req = requests.post(url, headers=headers)
rc = 1
if req.status_code == 200:
result = json.loads(req.text)
print(result)
if result is True:
rc = 0
elif req.status_code == 500:
print("An internal error has occurred. Please check /var/log/software.log for details")
else:
m = re.search("(Error message:.*)", req.text, re.MULTILINE)
if m:
print(m.group(0))
else:
print("%s %s" % (req.status_code, req.reason))
rc = 1
return rc
def patch_is_available_req(args):
releases = args.releases
patches = "/".join(releases)
url = "http://%s/software/is_available/%s" % (api_addr, patches)
headers = {}
append_auth_token_if_required(headers)
req = requests.post(url, headers=headers)
rc = 1
if req.status_code == 200:
result = json.loads(req.text)
print(result)
if result is True:
rc = 0
elif req.status_code == 500:
print("An internal error has occurred. Please check /var/log/software.log for details")
else:
m = re.search("(Error message:.*)", req.text, re.MULTILINE)
if m:
print(m.group(0))
else:
print("%s %s" % (req.status_code, req.reason))
rc = 1
return rc
def patch_report_app_dependencies_req(args): # pylint: disable=unused-argument
extra_opts = [args.app]
extra_opts_str = '?%s' % '&'.join(extra_opts)
@ -1318,6 +1326,39 @@ def setup_argparse():
cmd.set_defaults(cmd='install-local')
cmd.set_defaults(func=install_local)
# --- software is-available <release> ------
cmd = commands.add_parser(
'is-available',
help='Query Available state for list of releases. Returns True if all are Available, False otherwise.'
)
cmd.set_defaults(cmd='is-available')
cmd.set_defaults(func=release_is_available_req)
cmd.add_argument('release',
nargs="+", # accepts a list
help='List of releases')
# --- software is-committed <release> ------
cmd = commands.add_parser(
'is-committed',
help='Query Committed state for list of releases. Returns True if all are Committed, False otherwise.'
)
cmd.set_defaults(cmd='is-committed')
cmd.set_defaults(func=release_is_committed_req)
cmd.add_argument('release',
nargs="+", # accepts a list
help='List of releases')
# --- software is-deployed <release> ------
cmd = commands.add_parser(
'is-deployed',
help='Query Deployed state for list of releases. Returns True if all are Deployed, False otherwise.'
)
cmd.set_defaults(cmd='is-deployed')
cmd.set_defaults(func=release_is_deployed_req)
cmd.add_argument('release',
nargs="+", # accepts a list
help='List of releases')
# --- software list ---------------------------
cmd = commands.add_parser(
'list',

View File

@ -135,12 +135,16 @@ class SoftwareAPIController(object):
return result
@expose('json')
def is_completed(self, *args):
return sc.is_completed(list(args))
def is_available(self, *args):
return sc.is_available(list(args))
@expose('json')
def is_uploaded(self, *args):
return sc.is_uploaded(list(args))
def is_committed(self, *args):
return sc.is_committed(list(args))
@expose('json')
def is_deployed(self, *args):
return sc.is_deployed(list(args))
@expose('json')
@expose('show.xml', content_type='application/xml')

View File

@ -2409,38 +2409,55 @@ class PatchController(PatchService):
return dict(info=msg_info, warning=msg_warning, error=msg_error)
def is_completed(self, release_ids):
all_completed = True
def is_available(self, release_ids):
all_available = True
with self.release_data_lock:
for release_id in release_ids:
if release_id not in self.release_data.metadata:
all_completed = False
break
if self.release_data.metadata[release_id]["state"] != constants.DEPLOYED:
all_completed = False
break
return all_completed
def is_uploaded(self, release_ids):
all_uploaded = True
with self.release_data_lock:
for release_id in release_ids:
if release_id not in self.release_data.metadata:
all_uploaded = False
all_available = False
break
if self.release_data.metadata[release_id]["state"] != \
constants.AVAILABLE:
all_uploaded = False
all_available = False
break
return all_uploaded
return all_available
def is_deployed(self, release_ids):
all_deployed = True
with self.release_data_lock:
for release_id in release_ids:
if release_id not in self.release_data.metadata:
all_deployed = False
break
if self.release_data.metadata[release_id]["state"] != constants.DEPLOYED:
all_deployed = False
break
return all_deployed
def is_committed(self, release_ids):
all_committed = True
with self.release_data_lock:
for release_id in release_ids:
if release_id not in self.release_data.metadata:
all_committed = False
break
if self.release_data.metadata[release_id]["state"] != \
constants.COMMITTED:
all_committed = False
break
return all_committed
def report_app_dependencies(self, patch_ids, **kwargs):
"""