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-1895: add empty string handling for rootfs_provider key of boot_set #283

Merged
merged 1 commit into from
Nov 19, 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.11] - 2024-11-12

### Fixed
- Added validation to `sat bootprep` to prohibit empty strings in `rootfs_provider` and
`rootfs_provider_passthrough` keys of `boot_sets`

## [3.32.10] - 2024-11-04

### Fixed
Expand Down
24 changes: 24 additions & 0 deletions sat/cli/bootprep/input/session_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ def boot_sets(self):
def image_record(self):
"""dict: the image record from IMS for this session template"""

@Validatable.validation_method()
def validate_rootfs_provider_has_value(self, **_):
"""Validate that the rootfs_provider is not an empty string

Raises:
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']:
raise InputItemValidateError(f'The value of rootfs_provider for boot set '
f'{boot_set_name} cannot be an empty string')

@Validatable.validation_method()
def validate_rootfs_provider_passthrough_has_value(self, **_):
"""Validate that the rootfs_provider_passthrough is not an empty string

Raises:
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']:
raise InputItemValidateError(f'The value of rootfs_provider_passthrough for boot set '
f'{boot_set_name} cannot be an empty string')

@Validatable.validation_method()
def validate_configuration_exists(self, **_):
"""Validate that the configuration specified for this session template exists.
Expand Down
92 changes: 92 additions & 0 deletions tests/cli/bootprep/input/test_session_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,98 @@ def test_get_create_item_data_arch_per_bootset(self):
self.assertEqual(expected_bos_data,
input_session_template.get_create_item_data())

def test_validate_rootfs_provider_good(self):
"""Test that validate_rootfs_provider passes with good data"""
input_data, _ = self.get_input_and_expected_bos_data()
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_bad(self):
"""Test that validate_rootfs_provider fails with bad data"""
input_data, _ = self.get_input_and_expected_bos_data()
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
)
err_regex = 'The value of rootfs_provider for boot set compute cannot be an empty string'
with self.assertRaisesRegex(InputItemValidateError, err_regex):
input_session_template.validate_rootfs_provider_has_value()

def test_validate_rootfs_provider_multiple_good(self):
"""Test that validate_rootfs_provider passes with good data in multiple boot sets"""
input_data, _ = self.get_input_and_expected_bos_data()
compute_boot_set = input_data['bos_parameters']['boot_sets']['compute']
input_data['bos_parameters']['boot_sets']['compute_two'] = compute_boot_set
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_multiple_bad(self):
"""Test that validate_rootfs_provider fails with bad data in multiple boot sets"""
input_data, _ = self.get_input_and_expected_bos_data()
input_data['bos_parameters']['boot_sets']['compute']['rootfs_provider'] = ''
compute_boot_set = input_data['bos_parameters']['boot_sets']['compute']
input_data['bos_parameters']['boot_sets']['compute_two'] = compute_boot_set
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
)
err_regex = 'The value of rootfs_provider for boot set compute cannot be an empty string'
with self.assertRaisesRegex(InputItemValidateError, err_regex):
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()
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()

def test_validate_rootfs_provider_passthrough_bad(self):
"""Test that validate_rootfs_provider_passthrough fails with bad data"""
input_data, _ = self.get_input_and_expected_bos_data()
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
)
err_regex = 'The value of rootfs_provider_passthrough for boot set compute cannot be an empty string'
with self.assertRaisesRegex(InputItemValidateError, err_regex):
input_session_template.validate_rootfs_provider_passthrough_has_value()

def test_validate_rootfs_provider_passthrough_multiple_good(self):
"""Test that validate_rootfs_provider_passthrough passes with good data in multiple boot sets"""
input_data, _ = self.get_input_and_expected_bos_data()
compute_boot_set = input_data['bos_parameters']['boot_sets']['compute']
input_data['bos_parameters']['boot_sets']['compute_two'] = compute_boot_set
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()

def test_validate_rootfs_provider_passthrough_multiple_bad(self):
"""Test that validate_rootfs_provider_passthrough fails with bad data in multiple boot sets"""
input_data, _ = self.get_input_and_expected_bos_data()
input_data['bos_parameters']['boot_sets']['compute']['rootfs_provider_passthrough'] = ''
compute_boot_set = input_data['bos_parameters']['boot_sets']['compute']
input_data['bos_parameters']['boot_sets']['compute_two'] = compute_boot_set
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
)
err_regex = 'The value of rootfs_provider_passthrough for boot set compute cannot be an empty string'
with self.assertRaisesRegex(InputItemValidateError, err_regex):
input_session_template.validate_rootfs_provider_passthrough_has_value()


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