Skip to content

Commit

Permalink
CASMPET-6723 reformat printed strings
Browse files Browse the repository at this point in the history
  • Loading branch information
leliasen-hpe committed Aug 10, 2023
1 parent 4543649 commit 51176e8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
26 changes: 13 additions & 13 deletions libcsm/bss/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def get_bss_bootparams(self, xname: str) -> str:
raise requests.exceptions.RequestException(f'ERROR exception: \
{type(ex).__name__} when trying to get bootparameters')
if bss_response.status_code != http.HTTPStatus.OK:
raise requests.exceptions.RequestException(f'ERROR Failed to get BSS \
bootparameters for {xname}. Recieved http response:\
{bss_response.status_code} from BSS.')
raise requests.exceptions.RequestException(f'ERROR Failed to get BSS' \
f'bootparameters for {xname}. Recieved http response:' \
f'{bss_response.status_code} from BSS.')
return bss_response.json()[0]


Expand All @@ -79,9 +79,9 @@ def patch_bss_bootparams(self, xname : str, bss_json) -> None:
raise requests.exceptions.RequestException(f'ERROR exception: \
{type(ex).__name__} when trying to patch bootparameters')
if patch_response.status_code != http.HTTPStatus.OK:
raise requests.exceptions.RequestException(f'ERROR Failed to patch BSS \
bootparameters for {xname}. Recieved {patch_response.status_code} \
from as BSS response.')
raise requests.exceptions.RequestException(f'ERROR Failed to patch BSS' \
f'bootparameters for {xname}. Recieved {patch_response.status_code}' \
f'from as BSS response.')
print('BSS entry patched')

def set_bss_image(self, xname: str, image_dict: dict) -> None:
Expand All @@ -93,23 +93,23 @@ def set_bss_image(self, xname: str, image_dict: dict) -> None:
"""

if 'initrd' not in image_dict or 'kernel' not in image_dict or 'rootfs' not in image_dict:
raise ValueError(f"ERROR set_bss_image has inputs 'xname' and 'image_dictonary' where \
'image_dictionary' is a dictionary containing values for 'initrd', 'kernel', and \
'rootfs'. The inputs recieved were xname:{xname}, image_dictionary:{image_dict}")
raise ValueError(f"ERROR set_bss_image has inputs 'xname' and 'image_dictonary' where" \
f"'image_dictionary' is a dictionary containing values for 'initrd', 'kernel', and" \
f"'rootfs'. The inputs recieved were xname:{xname}, image_dictionary:{image_dict}")

bss_json = self.get_bss_bootparams(xname)
if 'initrd' not in bss_json or 'kernel' not in bss_json:
raise KeyError(f"BSS bootparams did not have the expected keys 'initrd' or 'kernel'. \
Boot parameters recieved: {bss_json}")
raise KeyError(f"BSS bootparams did not have the expected keys 'initrd' or 'kernel'." \
f"Boot parameters recieved: {bss_json}")
# set new images
bss_json['initrd'] = image_dict['initrd']
bss_json['kernel'] = image_dict['kernel']
params = bss_json['params']
try:
current_rootfs = params.split("metal.server=", 1)[1].split(" ",1)[0]
except Exception as exc:
raise KeyError(f"ERROR could not find current metal.server image in {xname} \
bss params") from exc
raise KeyError(f"ERROR could not find current metal.server image in {xname}" \
f"bss params") from exc

bss_json['params'] = params.replace(current_rootfs, image_dict['rootfs'])

Expand Down
12 changes: 6 additions & 6 deletions libcsm/hsm/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def get_components(role_subrole: str, api_gateway_address="api-gw-service-nmn.lo
auth = api.Auth()
auth.refresh_token()
session = get_session()
hsm_components_url = f'https://{api_gateway_address}/\
apis/smd/hsm/v2/State/Components'
hsm_components_url = f'https://{api_gateway_address}/'\
f'apis/smd/hsm/v2/State/Components'
# get components
if role_subrole not in ROLE_SUBROLES:
raise KeyError(f'ERROR {role_subrole} is not a valid role_subrole')
Expand All @@ -51,9 +51,9 @@ def get_components(role_subrole: str, api_gateway_address="api-gw-service-nmn.lo
f'?role=Management&subrole={subrole}',
headers={'Authorization': f'Bearer {auth.token}'})
except requests.exceptions.RequestException as ex:
raise requests.exceptions.RequestException(f'ERROR exception: \
{type(ex).__name__} when trying to get components')
raise requests.exceptions.RequestException(f'ERROR exception:' \
f'{type(ex).__name__} when trying to get components')
if components_response.status_code != http.HTTPStatus.OK:
raise requests.exceptions.RequestException(f'ERROR Failed \
to get components with subrole {subrole}')
raise requests.exceptions.RequestException(f'ERROR Failed' \
f'to get components with subrole {subrole}')
return components_response
28 changes: 14 additions & 14 deletions libcsm/sls/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def get_management_components_from_sls(self) -> requests.Response:
'search/hardware?extra_properties.Role=Management',
headers={'Authorization': f'Bearer {self._auth.token}'})
except requests.exceptions.RequestException as ex:
raise requests.exceptions.RequestException(f'ERROR exception: {type(ex).__name__} \
when trying to get management components from SLS') from ex
raise requests.exceptions.RequestException(f'ERROR exception: {type(ex).__name__}' \
f'when trying to get management components from SLS') from ex
if components_response.status_code != http.HTTPStatus.OK:
raise requests.exceptions.RequestException(f'ERROR Bad response \
recieved from SLS. Recived: {components_response}')
raise requests.exceptions.RequestException(f'ERROR Bad response' \
f'recieved from SLS. Recived: {components_response}')

return components_response

Expand All @@ -69,17 +69,17 @@ def get_xname(self, hostname: str) -> str:
try:
components_response = (self.get_management_components_from_sls()).json()
except ValueError as error:
raise ValueError(f'ERROR did not get valid json for management components \
from sls. {error}') from error
raise ValueError(f'ERROR did not get valid json for management components' \
f'from sls. {error}') from error

for node in components_response:
try:
if hostname in node['ExtraProperties']['Aliases']:
return node['Xname']
except KeyError as error:
raise KeyError(f'ERROR [ExtraProperties][Aliases] was not in the \
response from sls. These fields are expected in the json response. \
The response was {components_response}') from error
raise KeyError(f'ERROR [ExtraProperties][Aliases] was not in the' \
f'response from sls. These fields are expected in the json response.' \
f'The response was {components_response}') from error
raise ValueError(f'ERROR hostname:{hostname} was not found in management nodes.')

def get_hostname(self, xname: str) -> str:
Expand All @@ -89,16 +89,16 @@ def get_hostname(self, xname: str) -> str:
try:
components_response = (self.get_management_components_from_sls()).json()
except ValueError as error:
raise ValueError(f'ERROR did not get valid json for management components \
from sls. {error}') from error
raise ValueError(f'ERROR did not get valid json for management components' \
f'from sls. {error}') from error

for node in components_response:
try:
if xname == node['Xname']:
# assumes the hostname is the first entry in ['ExtraProperties']['Aliases']
return node['ExtraProperties']['Aliases'][0]
except KeyError as error:
raise KeyError(f'ERROR [ExtraProperties][Aliases] was not in the \
response from sls. These fields are expected in the json response. \
The response was {components_response}') from error
raise KeyError(f'ERROR [ExtraProperties][Aliases] was not in the' \
f'response from sls. These fields are expected in the json response.' \
f'The response was {components_response}') from error
raise ValueError(f'ERROR xname:{xname} was not found in management nodes.')

0 comments on commit 51176e8

Please sign in to comment.