Skip to content

Commit

Permalink
CASMCMS-8830: Fix return type error
Browse files Browse the repository at this point in the history
When there are no nodes in a session due to them being eliminated for
one reason or another, ensure that hsm.py's get_components method
returns the expected type of object.

In the case that there are no nodes within a session to act upon,
raise an exception, so that the session is marked as having failed and
has its error attribute filled in appropriately.
  • Loading branch information
jsollom-hpe committed Oct 13, 2023
1 parent 1da3020 commit ffd36b5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Fixed
- Return the correct object from hsm's get_components call when there are no nodes in the session.

## [2.9.0] - 09-29-2023
### Changed
- Update the spire-agent path
Expand Down
4 changes: 3 additions & 1 deletion src/bos/operators/session_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def _setup_components(self):
for component_id in components:
data.append(self._operate(component_id, boot_set))
all_component_ids += components
if not all_component_ids:
raise SessionSetupException("No nodes were found to act upon.")
except Exception as err:
raise SessionSetupException(err)
else:
Expand Down Expand Up @@ -160,7 +162,7 @@ def _get_boot_set_component_list(self, boot_set) -> Set[str]:
nodes = set(hsmfilter._filter(list(nodes)))
nodes = self._apply_tenant_limit(nodes)
if not nodes:
self._log(LOGGER.warning, "No nodes were found to act on.")
self._log(LOGGER.warning, "No nodes were found to act upon.")
return nodes

def _apply_arch(self, nodes, arch):
Expand Down
43 changes: 40 additions & 3 deletions src/bos/operators/utils/clients/hsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,47 @@ def read_all_node_xnames():
raise HWStateManagerException(ke) from ke


def get_components(node_list, enabled=None):
"""Get information for all list components HSM"""
def get_components(node_list, enabled=None) -> dict[str,list[dict]]:
"""
Get information for all list components HSM
:return the HSM components
:rtype Dictionary containing a 'Components' key whose value is a list
containing each component, where each component is itself represented by a
dictionary.
Here is an example of the returned values.
{
"Components": [
{
"ID": "x3000c0s19b1n0",
"Type": "Node",
"State": "Ready",
"Flag": "OK",
"Enabled": true,
"Role": "Compute",
"NID": 1,
"NetType": "Sling",
"Arch": "X86",
"Class": "River"
},
{
"ID": "x3000c0s19b2n0",
"Type": "Node",
"State": "Ready",
"Flag": "OK",
"Enabled": true,
"Role": "Compute",
"NID": 1,
"NetType": "Sling",
"Arch": "X86",
"Class": "River"
}
]
}
"""
if not node_list:
return []
return {'Components': []}
session = requests_retry_session()
try:
payload = {'ComponentIDs': node_list}
Expand Down

0 comments on commit ffd36b5

Please sign in to comment.