Skip to content

Commit

Permalink
CRAYSAT-1941: add validation to check for existence of rootfs_provider (
Browse files Browse the repository at this point in the history
#291)

* CRAYSAT-1941: add validation to check for existence of rootfs_provider and rootfs_provider_passthrough
  • Loading branch information
ethanholen-hpe authored Nov 25, 2024
1 parent a24e0dd commit cd20601
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ 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.13] - 2024-11-25

### Fixed
- Added validation to `sat bootprep` to verify that `rootfs_provider` and
`rootfs_provider_passthrough` exist before checking for empty string values.

## [3.32.12] - 2024-11-21

### Fixed
Expand Down
5 changes: 3 additions & 2 deletions sat/cli/bootprep/input/session_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def validate_rootfs_provider_has_value(self, **_):
InputItemValidateError: if the rootfs_provider is an empty string
"""
for boot_set_name, boot_set_data in self.boot_sets.items():
if not boot_set_data['rootfs_provider']:
if 'rootfs_provider' in boot_set_data and not boot_set_data['rootfs_provider']:
raise InputItemValidateError(f'The value of rootfs_provider for boot set '
f'{boot_set_name} cannot be an empty string')

Expand All @@ -129,7 +129,8 @@ def validate_rootfs_provider_passthrough_has_value(self, **_):
InputItemValidateError: if the rootfs_provider_passthrough is an empty string
"""
for boot_set_name, boot_set_data in self.boot_sets.items():
if not boot_set_data['rootfs_provider_passthrough']:
if ('rootfs_provider_passthrough' in boot_set_data
and not boot_set_data['rootfs_provider_passthrough']):
raise InputItemValidateError(f'The value of rootfs_provider_passthrough for boot set '
f'{boot_set_name} cannot be an empty string')

Expand Down
20 changes: 20 additions & 0 deletions tests/cli/bootprep/input/test_session_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ def test_validate_rootfs_provider_multiple_bad(self):
with self.assertRaisesRegex(InputItemValidateError, err_regex):
input_session_template.validate_rootfs_provider_has_value()

def test_validate_no_rootfs_provider(self):
"""Test that validate_rootfs_provider passes with good data"""
input_data, _ = self.get_input_and_expected_bos_data()
del input_data['bos_parameters']['boot_sets']['compute']['rootfs_provider']
input_session_template = self.simplified_session_template_v2(
input_data, self.input_instance, 0, self.jinja_env,
self.bos_client, self.cfs_client, self.ims_client
)
input_session_template.validate_rootfs_provider_has_value()

def test_validate_rootfs_provider_passthrough_good(self):
"""Test that validate_rootfs_provider_passthrough passes with good data"""
input_data, _ = self.get_input_and_expected_bos_data()
Expand Down Expand Up @@ -253,6 +263,16 @@ def test_validate_rootfs_provider_passthrough_multiple_bad(self):
with self.assertRaisesRegex(InputItemValidateError, err_regex):
input_session_template.validate_rootfs_provider_passthrough_has_value()

def test_validate_no_rootfs_provider_passthrough(self):
"""Test that validate_rootfs_provider_passthrough passes with good data"""
input_data, _ = self.get_input_and_expected_bos_data()
del input_data['bos_parameters']['boot_sets']['compute']['rootfs_provider_passthrough']
input_session_template = self.simplified_session_template_v2(
input_data, self.input_instance, 0, self.jinja_env,
self.bos_client, self.cfs_client, self.ims_client
)
input_session_template.validate_rootfs_provider_passthrough_has_value()


if __name__ == '__main__':
unittest.main()

0 comments on commit cd20601

Please sign in to comment.