-
- Notifications
You must be signed in to change notification settings - Fork 1
Add test scenario templating to operators #110
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
8 commits Select commit Hold shift + click to select a range
59e1a9e Add test templating framework and documentation.
soenkeliebau c1efa03 Adds documentation.
soenkeliebau e1c0395 Remove accidentally committed test-definition.yaml , change extension…
soenkeliebau ce9fd1d Apply suggestions from code review
soenkeliebau 263aae6 Linter warnings
soenkeliebau 200a13a more linter warnings
soenkeliebau 9f1ce08 Apply suggestions from code review by Razvan
soenkeliebau fcf1d38 Merge branch 'main' into feat/test-templating
soenkeliebau 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| tests/ansible/roles/ | ||
| tests/_work/ | ||
| debug/ | ||
| target/ | ||
| **/*.rs.bk | ||
| | ||
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,29 @@ | ||
| #!/usr/bin/env bash | ||
| set -e | ||
| | ||
| # Register absolute paths to pass to Ansible so the location of the role is irrelevant | ||
| # for the run | ||
| TESTDIR="$(pwd)/tests" | ||
| WORKDIR="$(pwd)/tests/_work" | ||
| | ||
| # Create dirs | ||
| mkdir -p tests/ansible/roles | ||
| mkdir -p "$WORKDIR" | ||
| | ||
| # Install Ansible role if needed | ||
| pushd tests/ansible | ||
| ansible-galaxy role install -r requirements.yaml -p ./roles | ||
| | ||
| # TODO: create pipenv in files for script thingy | ||
| | ||
| # Funnel via JSON to ensure that values are escaped properly | ||
| echo '{}' | jq '{work_dir: $WORKDIR, test_dir: $TESTDIR}' --arg WORKDIR "$WORKDIR" --arg TESTDIR "$TESTDIR" > "${WORKDIR}"/vars.json | ||
| | ||
| # Run playbook to generate test scenarios | ||
| ansible-playbook playbook.yaml --extra-vars "@${WORKDIR}/vars.json" | ||
| popd | ||
| | ||
| # Run tests | ||
| pushd tests/_work | ||
| kubectl kuttl test | ||
| popd |
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,82 @@ | ||
| # Test Scenario Templating | ||
| | ||
| ## Introduction | ||
| | ||
| The tests in this directory are designed to be expanded into multiple test scenarios based on test dimensions that can be defined in a dimensions file. | ||
| | ||
| ## Defining Test Dimensions | ||
| | ||
| The dimensions file currently has to be named `test-definition.yaml` and reside in the same directory as the `kuttl-test.yaml.jinja2` file. | ||
| | ||
| An example of a minimal folder structure will be given further down in this file. | ||
| | ||
| An example of the content for the test definition file is shown here: | ||
| | ||
| ````yaml | ||
| dimensions: | ||
| - name: spark | ||
| values: | ||
| - 3.2.1 | ||
| - 3.2.2 | ||
| - 3.2.3 | ||
| - name: hadoop | ||
| values: | ||
| - 3.1.0 | ||
| - 3.2.0 | ||
| - name: aws | ||
| - abc | ||
| - xyz | ||
| tests: | ||
| - name: spark-pi-public-s3 | ||
| dimensions: | ||
| - spark | ||
| - hadoop | ||
| ```` | ||
| | ||
| This file defines three dimensions for this test to be considered. | ||
| It also defines one test case named _spark-pi-public-s3_ and the dimensions that this test case should use. | ||
| In this example the test case uses only two of the three dimensions defined, so a run of this test case would be expanded into the following test structure: | ||
| | ||
| ````text | ||
| └── spark-pi-public-s3 | ||
| ├── spark-3.2.1_hadoop-3.1.0 | ||
| ├── spark-3.2.1_hadoop-3.2.0 | ||
| ├── spark-3.2.2_hadoop-3.1.0 | ||
| ├── spark-3.2.2_hadoop-3.2.0 | ||
| ├── spark-3.2.3_hadoop-3.1.0 | ||
| └── spark-3.2.3_hadoop-3.2.0 | ||
| ```` | ||
| | ||
| The name of a test case defined under `tests` in this file has to refer back to a directory in the `templates/kuttl` directory, which will be used to create the test scenarios. | ||
| | ||
| Given the example of a test-definition.yaml shown above, the following folder structure would create the test scenarios shown above. | ||
| | ||
| ````text | ||
| tests | ||
| ├── kuttl-test.yaml.j2 | ||
| ├── templates | ||
| │ └── kuttl | ||
| │ └── spark-pi-public-s3 | ||
| └── test-definition.yaml | ||
| ```` | ||
| | ||
| The `kuttl-test.yaml.jinja2` cannot currently be edited, as it comes from the operator templating and any changes would be overwritten again. | ||
| This should be fairly easy to solve and we can look at this as soon as it becomes necessary. | ||
| | ||
| ## Using | ||
| | ||
| ### Requirements | ||
| | ||
| To run tests locally you need the following things installed: | ||
| | ||
| - python3 | ||
| - pyyaml library installed | ||
| - ansible | ||
| | ||
| ### Running | ||
| | ||
| To run tests please execute the following command from the gitroot of the operator repository: | ||
| | ||
| `scripts/run_tests.sh` | ||
| | ||
| This will install the necessarry ansible role into `tests/ansible/roles`, expand the test templates into all defined test scenarios and execute kuttl to test these scenarios. | ||
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,6 @@ | ||
| --- | ||
| - name: Expand test templates into test scenarios by applying input dimensions | ||
| hosts: localhost | ||
| connection: local | ||
| roles: | ||
| - expand-tests |
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,4 @@ | ||
| --- | ||
| - name: expand-tests | ||
| src: https://github.com/stackabletech/expand-tests.git | ||
| scm: git |
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,10 @@ | ||
| --- | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestSuite | ||
| testDirs: | ||
| {% for testcase in testinput.tests %} | ||
| - ./tests/{{ testcase.name }} | ||
| {% endfor %} | ||
| | ||
| startKIND: false | ||
| suppress: ["events"] |
Empty file.
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.