From 3157b9db5939030689371223dedf7d7690cddba2 Mon Sep 17 00:00:00 2001 From: ethanholen-hpe Date: Thu, 7 Nov 2024 09:44:25 -0700 Subject: [PATCH] CRAYSAT-1895: add empty string handling for rootfs_provider key of boot_set Add a validation method that ensures rootfs_provider and rootfs_provider_passthrough are not empty --- CHANGELOG.md | 6 ++ sat/cli/bootprep/input/session_template.py | 24 +++++ .../bootprep/input/test_session_template.py | 92 +++++++++++++++++++ 3 files changed, 122 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0760af28..5bca92f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/sat/cli/bootprep/input/session_template.py b/sat/cli/bootprep/input/session_template.py index 4fc48353..7198b5a2 100644 --- a/sat/cli/bootprep/input/session_template.py +++ b/sat/cli/bootprep/input/session_template.py @@ -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. diff --git a/tests/cli/bootprep/input/test_session_template.py b/tests/cli/bootprep/input/test_session_template.py index 26916867..0e23383b 100644 --- a/tests/cli/bootprep/input/test_session_template.py +++ b/tests/cli/bootprep/input/test_session_template.py @@ -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()