|
| 1 | +# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance |
| 4 | +# with the License. A copy of the License is located at |
| 5 | +# |
| 6 | +# http://aws.amazon.com/apache2.0/ |
| 7 | +# |
| 8 | +# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 9 | +# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and |
| 10 | +# limitations under the License. |
| 11 | +import pytest |
| 12 | + |
| 13 | +from pcluster.validators.common import FailureLevel |
| 14 | +from pcluster.validators.dev_settings_validators import ExtraChefAttributesValidator |
| 15 | +from tests.pcluster.validators.utils import assert_failure_level, assert_failure_messages |
| 16 | + |
| 17 | + |
| 18 | +@pytest.mark.parametrize( |
| 19 | + "extra_chef_attributes, expected_message, expected_failure_level", |
| 20 | + [ |
| 21 | + pytest.param(None, None, None, id="No extra chef attributes"), |
| 22 | + pytest.param('{"other_attribute": "value"}', None, None, id="in_place_update_on_fleet_enabled not set"), |
| 23 | + pytest.param( |
| 24 | + '{"cluster": {"in_place_update_on_fleet_enabled": "true"}}', |
| 25 | + None, |
| 26 | + None, |
| 27 | + id="in_place_update_true_string 'true' passes", |
| 28 | + ), |
| 29 | + pytest.param( |
| 30 | + '{"cluster": {"in_place_update_on_fleet_enabled": true}}', |
| 31 | + None, |
| 32 | + None, |
| 33 | + id="in_place_update_true_string true passes", |
| 34 | + ), |
| 35 | + pytest.param( |
| 36 | + '{"cluster": {"in_place_update_on_fleet_enabled": "false"}}', |
| 37 | + "When in-place updates are disabled, cluster updates are applied " |
| 38 | + "by replacing compute and login nodes according to the selected QueueUpdateStrategy.", |
| 39 | + FailureLevel.WARNING, |
| 40 | + id="in_place_update_true_string 'false' throws a warning", |
| 41 | + ), |
| 42 | + pytest.param( |
| 43 | + '{"cluster": {"in_place_update_on_fleet_enabled": false}}', |
| 44 | + "When in-place updates are disabled, cluster updates are applied " |
| 45 | + "by replacing compute and login nodes according to the selected QueueUpdateStrategy.", |
| 46 | + FailureLevel.WARNING, |
| 47 | + id="in_place_update_true_string false throws a warning", |
| 48 | + ), |
| 49 | + pytest.param( |
| 50 | + '{"cluster": {"in_place_update_on_fleet_enabled": "invalid"}}', |
| 51 | + "Invalid value in DevSettings/Cookbook/ExtraChefAttributes: " |
| 52 | + "attribute 'in_place_update_on_fleet_enabled' must be a boolean value.", |
| 53 | + FailureLevel.ERROR, |
| 54 | + id="in_place_update_true_string invalid (string) throws an error", |
| 55 | + ), |
| 56 | + pytest.param( |
| 57 | + '{"cluster": {"in_place_update_on_fleet_enabled": 123}}', |
| 58 | + "Invalid value in DevSettings/Cookbook/ExtraChefAttributes: " |
| 59 | + "attribute 'in_place_update_on_fleet_enabled' must be a boolean value.", |
| 60 | + FailureLevel.ERROR, |
| 61 | + id="n_place_update_true_string invalid (number) throws an error", |
| 62 | + ), |
| 63 | + ], |
| 64 | +) |
| 65 | +def test_extra_chef_attributes_validator(extra_chef_attributes, expected_message, expected_failure_level): |
| 66 | + actual_failures = ExtraChefAttributesValidator().execute(extra_chef_attributes=extra_chef_attributes) |
| 67 | + assert_failure_messages(actual_failures, expected_message) |
| 68 | + if expected_failure_level: |
| 69 | + assert_failure_level(actual_failures, expected_failure_level) |
0 commit comments