WIP Update USM Rest API

Test Plan:
- PENDING

Story: 2010676
Task: 50015

Change-Id: Ifa15b50a3d163c981a72adbaeffd462102f7c42d
Signed-off-by: Hugo Brito <hugo.brito@windriver.com>
This commit is contained in:
Hugo Brito 2024-04-30 19:39:02 -03:00
parent 0a3c96c766
commit 23fa6a1e46
4 changed files with 55 additions and 23 deletions

View File

@ -45,35 +45,49 @@ class SoftwareClient(base.DriverBase):
# The usm systemcontroller endpoint ends with a slash but the regionone
# and the subcloud endpoint don't. The slash is removed to standardize
# with the other endpoints.
self.endpoint = self.endpoint.rstrip('/') + '/v1/software'
self.endpoint = self.endpoint.rstrip('/') + '/v1'
self.token = session.get_token()
def query(self, state='all', release=None, timeout=REST_DEFAULT_TIMEOUT):
"""Query releases"""
extra_opts = ""
if release:
extra_opts = "&release=%s" % release
url = self.endpoint + '/query?show=%s%s' % (state, extra_opts)
def list(self, state='all', timeout=REST_DEFAULT_TIMEOUT):
"""List releases"""
url = self.endpoint + '/release?show=%s' % (state)
headers = {"X-Auth-Token": self.token}
response = requests.get(url, headers=headers, timeout=timeout)
if response.status_code != 200:
LOG.error("Query failed with RC: %d" % response.status_code)
raise exceptions.ApiException(endpoint="Query",
LOG.error("List failed with RC: %d" % response.status_code)
raise exceptions.ApiException(endpoint="List",
rc=response.status_code)
data = response.json()
if data.get('error'):
message = "Query failed with error: %s" % data["error"]
message = "List failed with error: %s" % data["error"]
LOG.error(message)
raise Exception(message)
return data.get('sd', [])
def show(self, releases, timeout=REST_DEFAULT_TIMEOUT):
"""Show releases"""
release_str = "/".join(releases)
url = self.endpoint + "/release/%s" % release_str
headers = {"X-Auth-Token": self.token}
response = requests.get(url, headers=headers, timeout=timeout)
if response.status_code != 200:
LOG.error("Show failed with RC: %d" % response.status_code)
raise exceptions.ApiException(endpoint="Show", rc=response.status_code)
data = response.json()
if data.get("error"):
message = "Show failed with error: %s" % data["error"]
LOG.error(message)
raise Exception(message)
return data.get("sd", [])
def delete(self, releases, timeout=REST_DEFAULT_TIMEOUT):
"""Delete"""
release_str = "/".join(releases)
url = self.endpoint + '/delete/%s' % release_str
url = self.endpoint + '/release/%s' % release_str
headers = {"X-Auth-Token": self.token}
response = requests.post(url, headers=headers, timeout=timeout)
response = requests.delete(url, headers=headers, timeout=timeout)
if response.status_code != 200:
LOG.error("Delete failed with RC: %d" % response.status_code)
@ -88,7 +102,7 @@ class SoftwareClient(base.DriverBase):
def deploy_activate(self, deployment, timeout=REST_DEFAULT_TIMEOUT):
"""Deploy activate"""
url = self.endpoint + '/deploy_activate/%s' % deployment
url = self.endpoint + '/deploy/activate/%s' % deployment
headers = {"X-Auth-Token": self.token}
response = requests.post(url, headers=headers, timeout=timeout)
@ -122,7 +136,7 @@ class SoftwareClient(base.DriverBase):
def deploy_start(self, deployment, timeout=REST_DEFAULT_TIMEOUT):
"""Deploy start"""
url = self.endpoint + '/deploy_start/%s' % deployment
url = self.endpoint + "/deploy/%s/start" % deployment
headers = {"X-Auth-Token": self.token}
response = requests.post(url, headers=headers, timeout=timeout)
@ -154,6 +168,24 @@ class SoftwareClient(base.DriverBase):
raise Exception(message)
return data.get('sd', [])
def deploy_precheck(self, deployment, timeout=REST_DEFAULT_TIMEOUT):
"""Deploy start"""
url = self.endpoint + "/deploy/%s/precheck" % deployment
headers = {"X-Auth-Token": self.token}
response = requests.post(url, headers=headers, timeout=timeout)
if response.status_code != 200:
LOG.error("Deploy start failed with RC: %d" % response.status_code)
raise exceptions.ApiException(
endpoint="Deploy start", rc=response.status_code
)
data = response.json()
if data.get("error"):
message = "Deploy start failed with error: %s" % data["error"]
LOG.error(message)
raise Exception(message)
return data.get("sd", [])
def upload_dir(self, release_dirs, timeout=REST_DEFAULT_TIMEOUT):
"""Upload dir"""
dirlist = {}
@ -196,12 +228,12 @@ class SoftwareClient(base.DriverBase):
)
enc = MultipartEncoder(fields=to_upload_files)
url = self.endpoint + '/upload'
url = self.endpoint + '/release'
headers = {"X-Auth-Token": self.token, "Content-Type": enc.content_type}
response = requests.post(url,
data=enc,
headers=headers,
timeout=timeout)
response = requests.put(url,
data=enc,
headers=headers,
timeout=timeout)
if response.status_code != 200:
LOG.error("Upload failed with RC: %d" % response.status_code)
raise exceptions.ApiException(endpoint="Upload",

View File

@ -109,7 +109,7 @@ def mocked_requests_success(*args, **kwargs):
if args[0].endswith('/query_hosts'):
response_content = json.dumps(QUERY_HOSTS_RESPONSE)
elif args[0].endswith('/query?show=all'):
elif args[0].endswith('/release?show=all'):
response_content = json.dumps(QUERY_RESPONSE)
elif any([url in args[0] for url in URLS]):
response_content = json.dumps(INFO_RESPONSE)

View File

@ -90,7 +90,7 @@ class SoftwareAudit(object):
return None
# First query RegionOne to determine what releases should be deployed
# to the system.
regionone_releases = software_client.query()
regionone_releases = software_client.list()
LOG.debug(f"regionone_releases: {regionone_releases}")
# Build lists of releases that should be deployed or committed in all
# subclouds, based on their state in RegionOne.
@ -146,7 +146,7 @@ class SoftwareAudit(object):
# Retrieve all the releases that are present in this subcloud.
try:
subcloud_releases = software_client.query()
subcloud_releases = software_client.list()
LOG.debug(f"Releases for subcloud {subcloud_name}: {subcloud_releases}")
except Exception:
LOG.warn(

View File

@ -37,7 +37,7 @@ class FinishStrategyState(BaseState):
try:
software_client = self.get_software_client(self.region_name)
subcloud_releases = software_client.query()
subcloud_releases = software_client.list()
except Exception:
message = ("Cannot retrieve subcloud releases. Please see logs for "
"details.")