Skip to content

Commit

Permalink
Merge pull request #283 from Cray-HPE/CRAYSAT-1895
Browse files Browse the repository at this point in the history
CRAYSAT-1895: add empty string handling for rootfs_provider key of boot_set
  • Loading branch information
ethanholen-hpe authored Nov 19, 2024
2 parents 663015b + 3157b9d commit 6fd9641
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 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.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()

0 comments on commit 6fd9641

Please sign in to comment.