Skip to content

Commit

Permalink
CRAYSAT-1923: Update sat bootsys to support CFS v2 or v3
Browse files Browse the repository at this point in the history
  • Loading branch information
annapoorna-s-alt committed Dec 11, 2024
1 parent 5eac878 commit c573d3f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ 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).

## [3.33.3] - 2024-11-26
## [3.33.4] - 2024-12-11

### Added
- Added support for using either the CFS v2 or v3 API in `sat bootsys`,
depending on the value of the `--cfs-version` command-line option or the
`cfs.api_version` config-file option.

## [3.33.3] - 2024-12-10

### Added
- Added the ability to sort reports by multiple fields

## [3.33.2] - 2024-11-26
## [3.33.2] - 2024-12-10

### Fixed
- Added error message and system exit when token file is not found.
Expand Down
3 changes: 3 additions & 0 deletions docs/man/sat-bootsys.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ These options apply to both the ``shutdown`` and ``boot`` actions.
**--bos-version BOS_VERSION**
The version of the BOS API to use when launching BOS sessions.

**--cfs-version CFS_VERSION**
The version of the CFS API to use when launching CFS sessions.

**--cle-bos-template** *CLE_BOS_TEMPLATE*
The name of the BOS session template for shutdown or boot of
COS (formerly known as CLE) compute nodes. If not specified, no
Expand Down
6 changes: 6 additions & 0 deletions sat/cli/bootsys/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ def add_bootsys_subparser(subparsers):
help='The version of the BOS API to use for BOS operations',
)

bootsys_parser.add_argument(
'--cfs-version',
choices=['v2', 'v3'],
help='The version of the CFS API to use for CFS operations',
)

actions_subparsers = bootsys_parser.add_subparsers(
metavar='action', dest='action', help='The action to perform.'
)
Expand Down
4 changes: 2 additions & 2 deletions sat/cli/bootsys/service_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ def get_active_sessions(self):
Raises:
ServiceCheckError: if unable to get the active CFS sessions.
"""
cfs_client = CFSClientBase.get_cfs_client(SATSession(), 'v2')
cfs_client = CFSClientBase.get_cfs_client(SATSession(), get_config_value('cfs.api_version'))
try:
sessions = cfs_client.get('sessions').json()
sessions = cfs_client.get_sessions()
except (APIError, ValueError) as err:
raise self.get_err(str(err))

Expand Down
30 changes: 7 additions & 23 deletions tests/cli/bootsys/test_service_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,26 +495,15 @@ def setUp(self):

# If not None, causes CFSClient().get() to raise this
self.cfs_err = None
# If not None, causes CFSClient().get().json() to raise this
self.json_err = None

def mock_cfs_get(*args):
if self.cfs_err:
raise self.cfs_err

def json():
if len(args) != 1 or args[0] != 'sessions':
self.fail('Unexpected get to CFSClient with args: {}'.format(args))
elif self.json_err:
raise self.json_err
else:
return self.cfs_sessions
return Mock(json=json)
def mock_get_sessions(*args, **kwargs):
for session in self.cfs_sessions:
yield session

patch('sat.cli.bootsys.service_activity.SATSession').start()
self.mock_cfs_client = patch(
'sat.cli.bootsys.service_activity.CFSClientBase.get_cfs_client').start()
self.mock_cfs_client.return_value.get = mock_cfs_get
self.mock_cfs_client.return_value.get_sessions = mock_get_sessions

def tearDown(self):
"""Stop mocks at the end of each unit test."""
Expand Down Expand Up @@ -553,20 +542,15 @@ def test_get_active_sessions_two_active(self):

def test_get_active_sessions_api_err(self):
"""Test get_active_sessions with an API error."""
self.mock_cfs_client.return_value.get_sessions = Mock(
side_effect=APIError('service unavailable')
)
api_err_msg = 'service unavailable'
self.cfs_err = APIError(api_err_msg)
err_regex = '^Unable to get active CFS sessions: {}'.format(api_err_msg)
with self.assertRaisesRegex(ServiceCheckError, err_regex):
self.cfs_checker.get_active_sessions()

def test_get_active_sessions_value_err(self):
"""Test get_active_sessions"""
val_err_msg = 'invalid json'
self.json_err = ValueError(val_err_msg)
err_regex = '^Unable to get active CFS sessions: {}'.format(val_err_msg)
with self.assertRaisesRegex(ServiceCheckError, err_regex):
self.cfs_checker.get_active_sessions()


class TestFirmwareActivityChecker(ExtendedTestCase):
"""Test the FirmwareActivityChecker class."""
Expand Down

0 comments on commit c573d3f

Please sign in to comment.