-
Notifications
You must be signed in to change notification settings - Fork 8
Optional facts #88
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
Optional facts #88
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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,122 @@ | ||
| """ | ||
| Unit-tests for target generation | ||
| """ | ||
|
|
||
| import click | ||
| import pytest | ||
| import commodore.cluster as cluster | ||
|
|
||
|
|
||
| cluster_obj = { | ||
| 'id': 'mycluster', | ||
| 'tenant': 'mytenant', | ||
| 'facts': { | ||
| 'distribution': 'rancher', | ||
| 'cloud': 'cloudscale', | ||
| } | ||
| } | ||
| components = ['test-component'] | ||
| catalog = 'ssh://git@git.example.com/cluster-catalogs/mycluster' | ||
|
|
||
|
|
||
| def test_render_target(): | ||
| target = cluster._full_target(cluster_obj, components, catalog) | ||
| facts = cluster_obj['facts'] | ||
| assert target != "" | ||
| all_classes = ([f"defaults.{cn}" for cn in components] + | ||
| ['global.common', | ||
| f"global.{facts['distribution']}", | ||
| f"global.{facts['cloud']}", | ||
| f"{cluster_obj['tenant']}.{cluster_obj['id']}", | ||
| ]) | ||
|
srueg marked this conversation as resolved.
|
||
| assert len(target['classes']) == len( | ||
| all_classes), "rendered target includes different amount of classes" | ||
|
srueg marked this conversation as resolved.
|
||
| # Test order of included classes | ||
| for i in range(len(all_classes)): | ||
| assert target['classes'][i] == all_classes[i] | ||
| assert target['parameters']['target_name'] == 'cluster' | ||
|
|
||
|
|
||
| def test_optional_facts(): | ||
| cluster_obj['facts']['region'] = 'rma1' | ||
| target = cluster._full_target(cluster_obj, components, catalog) | ||
| facts = cluster_obj['facts'] | ||
| assert f"global.{facts['cloud']}.{facts['region']}" in target['classes'] | ||
|
|
||
|
|
||
| def test_missing_facts(): | ||
| cl = { | ||
| 'id': 'mycluster', | ||
| 'tenant': 'mytenant', | ||
| 'facts': { | ||
| 'distribution': 'rancher', | ||
| } | ||
| } | ||
| with pytest.raises(click.ClickException): | ||
| cluster._full_target(cl, components, catalog) | ||
|
|
||
|
|
||
| def test_reconstruct_api_response(tmp_path): | ||
| targetyml = tmp_path / 'cluster.yml' | ||
| with open(targetyml, 'w') as file: | ||
| file.write('''classes: | ||
| - defaults.argocd | ||
| - global.common | ||
| - global.k3d | ||
| - global.localdev | ||
| - t-delicate-pine-3938.c-twilight-water-9032 | ||
| parameters: | ||
| cloud: | ||
| provider: localdev | ||
| region: north | ||
| cluster: | ||
| catalog_url: ssh://git@git.vshn.net/syn-dev/cluster-catalogs/srueg-k3d-int.git | ||
| dist: k3d | ||
| name: c-twilight-water-9032 | ||
| customer: | ||
| name: t-delicate-pine-3938 | ||
| target_name: cluster ''') | ||
|
|
||
| api_response = cluster.reconstruct_api_response(targetyml) | ||
| assert api_response['id'] == 'c-twilight-water-9032' | ||
| assert api_response['tenant'] == 't-delicate-pine-3938' | ||
| assert api_response['facts']['distribution'] == 'k3d' | ||
| assert api_response['facts']['region'] == 'north' | ||
|
|
||
|
|
||
| def test_reconstruct_api_response_no_region(tmp_path): | ||
| targetyml = tmp_path / 'cluster.yml' | ||
| with open(targetyml, 'w') as file: | ||
| file.write('''classes: | ||
| parameters: | ||
| cloud: | ||
| provider: localdev | ||
| cluster: | ||
| catalog_url: ssh://git@git.vshn.net/syn-dev/cluster-catalogs/srueg-k3d-int.git | ||
| dist: k3d | ||
| name: c-twilight-water-9032 | ||
| customer: | ||
| name: t-delicate-pine-3938 | ||
| target_name: cluster ''') | ||
|
|
||
| api_response = cluster.reconstruct_api_response(targetyml) | ||
| assert 'region' not in api_response['facts'] | ||
|
|
||
|
|
||
| def test_reconstruct_api_response_missing_fact(tmp_path): | ||
| targetyml = tmp_path / 'cluster.yml' | ||
| with open(targetyml, 'w') as file: | ||
| file.write('''classes: | ||
| parameters: | ||
| cloud: | ||
| region: north | ||
| cluster: | ||
| catalog_url: ssh://git@git.vshn.net/syn-dev/cluster-catalogs/srueg-k3d-int.git | ||
| dist: k3d | ||
| name: c-twilight-water-9032 | ||
| customer: | ||
| name: t-delicate-pine-3938 | ||
| target_name: cluster ''') | ||
|
|
||
| with pytest.raises(KeyError): | ||
| cluster.reconstruct_api_response(targetyml) | ||
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 |
|---|---|---|
| @@ -1,29 +1,32 @@ | ||
| .PHONY: lint_flake8 lint_pylint lint_safety lint_bandit lint_readme | ||
| .PHONY: tox lint_flake8 lint_pylint lint_safety lint_bandit lint_readme | ||
|
|
||
| TOX_COMMAND = docker run --rm -v $(PWD):/src:ro -v $(PWD)/.tox:/app/.tox docker.io/painless/tox | ||
| TOX_COMMAND = pipenv run tox | ||
|
|
||
| tox: | ||
| $(TOX_COMMAND) | ||
|
|
||
| lint_flake8: | ||
| $(TOX_COMMAND) tox -e flake8 | ||
| $(TOX_COMMAND) -e flake8 | ||
|
|
||
| lint_pylint: | ||
| $(TOX_COMMAND) tox -e pylint | ||
| $(TOX_COMMAND) -e pylint | ||
|
|
||
| lint_safety: | ||
| $(TOX_COMMAND) tox -e safety | ||
| $(TOX_COMMAND) -e safety | ||
|
|
||
| lint_bandit: | ||
| $(TOX_COMMAND) tox -e bandit | ||
| $(TOX_COMMAND) -e bandit | ||
|
|
||
| lint_readme: | ||
| $(TOX_COMMAND) tox -e readme | ||
| $(TOX_COMMAND) -e readme | ||
|
|
||
| .PHONY: test_py36 test_py37 test_py38 | ||
|
|
||
| test_py36: | ||
| $(TOX_COMMAND) tox -e py36 | ||
| $(TOX_COMMAND) -e py36 | ||
|
|
||
| test_py37: | ||
| $(TOX_COMMAND) tox -e py37 | ||
| $(TOX_COMMAND) -e py37 | ||
|
|
||
| test_py38: | ||
| $(TOX_COMMAND) tox -e py38 | ||
| $(TOX_COMMAND) -e py38 |
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.