From 829ba2c417a1c8a3daec78cf3ba868bdffc140f3 Mon Sep 17 00:00:00 2001 From: Ryan Haasken Date: Tue, 29 Oct 2024 15:14:35 -0500 Subject: [PATCH] CRAYSAT-1929: Fix CFS fields in `sat status` for CFS v3 The `CFSStatusModule` still had hard-coded property names for the properties of a CFS component, and these property names were only valid for CFS v2, so `sat status` only showed CFS fields when CFS v2 was used. Update the mapping so that it correctly maps CFS properties to the `sat status` column names for both CFS v2 and v3. Test Description: Built `cray-sat` image and tested on `noname` with both CFS versions, that is: * `sat status --cfs-version v2` * `sat status --cfs-version v3` --- CHANGELOG.md | 5 +++++ sat/cli/status/status_module.py | 34 +++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b5fc424..0cb5c1cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,11 @@ 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.32.9] - 2024-10-29 + +### Fixed +- Fix missing CFS fields in `sat status` when using CFS v3. + ## [3.32.8] - 2024-10-21 ### Fixed diff --git a/sat/cli/status/status_module.py b/sat/cli/status/status_module.py index a05a3022..9a43df0e 100644 --- a/sat/cli/status/status_module.py +++ b/sat/cli/status/status_module.py @@ -437,24 +437,30 @@ class CFSStatusModule(StatusModule): source_name = 'CFS' component_types = {'Node'} - @staticmethod - def map_heading(heading): - return { - 'id': 'xname', - 'desiredConfig': 'Desired Config', - 'configurationStatus': 'Configuration Status', - 'errorCount': 'Error Count' - }.get(heading, heading) + def __init__(self, *, session, **_): + super().__init__(session=session) + self.cfs_version = get_config_value('cfs.api_version') + self.cfs_client = CFSClientBase.get_cfs_client(self.session, self.cfs_version) + + # CFS v2 and v3 components have different property names in components, + # so generate a mapping from those field names to the row headings. It + # should be generated here rather than in `map_heading` because that method + # is called for every row. + self.heading_mapping = { + self.cfs_client.join_words(*heading.split()): heading + for heading in self.headings if heading != 'xname' + } + # This property name is the same between CFS v2 and v3 + self.heading_mapping['id'] = 'xname' + + def map_heading(self, heading): + return self.heading_mapping.get(heading, heading) @property def rows(self): - cfs_version = get_config_value('cfs.api_version') - cfs_client = CFSClientBase.get_cfs_client(self.session, cfs_version) try: - cfs_response = cfs_client.get_components() - for response in cfs_response: - yield response - + cfs_response = self.cfs_client.get_components() + yield from cfs_response except APIError as err: raise StatusModuleException(f'Failed to query CFS for component information: {err}') from err except ValueError as err: