Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRAYSAT-1941: add validation to check for existence of rootfs_provider #291

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()