-
Notifications
You must be signed in to change notification settings - Fork 28
Updates to Node distribution test (#489) #558
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
06e2207
Updates to Node distribution test (#489)
cah-hbaum 300090e
Change for requested updates
cah-hbaum c71520a
Add additional test files
cah-hbaum a22b8c3
Add pytest script and more scenarios
martinmo a00f5a9
Replace masterN with control-N in test data
martinmo a7db76e
Streamline testdata
martinmo 4f363df
Small fixes to the compliant to standard
cah-hbaum 50824e9
Use yaml.safe_load(…) instead of yaml.load(…, yaml.SafeLoader)
martinmo 0854a95
PEP-8 changes (#475)
cah-hbaum 3eb16be
Update test according to change requests (#489)
cah-hbaum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| """ | ||
| Unit tests for node distribution check functions. | ||
|
|
||
| (c) Martin Morgenstern <martin.morgenstern@cloudandheat.com>, 4/2024 | ||
| (c) Hannes Baum <hannes.baum@cloudandheat.com>, 5/2024 | ||
| SPDX-License-Identifier: CC-BY-SA-4.0 | ||
| """ | ||
|
|
||
| from pathlib import Path | ||
| import yaml | ||
|
|
||
| import pytest | ||
|
|
||
| from k8s_node_distribution_check import check_nodes | ||
|
|
||
|
|
||
| HERE = Path(__file__).parent | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def load_testdata(): | ||
| with open(Path(HERE, "testdata", "scenarios.yaml")) as stream: | ||
| return yaml.safe_load(stream) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("yaml_key", ["success-1", "success-2"]) | ||
| def test_success_single_region_warning(yaml_key, caplog, load_testdata): | ||
| data = load_testdata[yaml_key] | ||
| assert check_nodes(data.values()) == 0 | ||
| assert len(caplog.records) == 2 | ||
| for record in caplog.records: | ||
| assert "no distribution across multiple regions" in record.message | ||
| assert record.levelname == "WARNING" | ||
|
|
||
|
|
||
| def test_not_enough_nodes(caplog, load_testdata): | ||
| data = load_testdata["not-enough-nodes"] | ||
| assert check_nodes(data.values()) == 2 | ||
| assert len(caplog.records) == 1 | ||
| assert "cluster only contains a single node" in caplog.records[0].message | ||
| assert caplog.records[0].levelname == "ERROR" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("yaml_key", ["no-distribution-1", "no-distribution-2"]) | ||
| def test_no_distribution(yaml_key, caplog, load_testdata): | ||
| data = load_testdata[yaml_key] | ||
| with caplog.at_level("ERROR"): | ||
| assert check_nodes(data.values()) == 2 | ||
| assert len(caplog.records) == 1 | ||
| record = caplog.records[0] | ||
| assert "distribution of nodes described in the standard couldn't be detected" in record.message | ||
| assert record.levelname == "ERROR" | ||
|
|
||
|
|
||
| def test_missing_label(caplog, load_testdata): | ||
| data = load_testdata["missing-labels"] | ||
| assert check_nodes(data.values()) == 2 | ||
| hostid_missing_records = [ | ||
| record for record in caplog.records | ||
| if "label for host-ids" in record.message | ||
| ] | ||
| assert len(hostid_missing_records) == 1 | ||
| assert hostid_missing_records[0].levelname == "ERROR" |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.