Skip to content
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

Updates inventory integration tests for 2.2 #332

Merged
merged 6 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ jobs:
- "3.9"
nautobot-version:
- "2.1"
# TODO: Change to 2.2 once it's released
# - "2.2"
ansible-version:
- "2.14"
- "2.15"
Expand All @@ -77,6 +79,8 @@ jobs:
nautobot-version:
- "2.0"
- "2.1"
# TODO: Enable 2.2 once it's released
# - "2.2"
ansible-version:
- "2.14"
- "2.15"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/trigger_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
nautobot-version:
- "2.0"
- "2.1"
# TODO: Enable 2.2 once it's released
# - "2.2"
ansible-version:
- "2.14"
- "2.15"
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions tests/integration/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
set -o pipefail

function render {
readonly template="$1"; shift
readonly content="$(cat "$template")"
template="$1"; shift
content="$(cat "$template")"

eval "echo \"$content\""
}
Expand All @@ -23,6 +23,8 @@ function main {

echo "# Rendering integration configuration"
render "./tests/integration/integration_config.tmpl.yml" > ./tests/integration/integration_config.yml
echo "# Creating inventory test config"
render "./tests/integration/targets/inventory/runme_config.template" > ./tests/integration/targets/inventory/runme_config

echo "# Checking to make sure Nautobot server is reachable.."
timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' nautobot:8000/health/)" != "200" ]]; do echo "waiting for Nautobot"; sleep 5; done' || false
Expand Down
39 changes: 39 additions & 0 deletions tests/integration/targets/inventory/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Inventory Integration Tests

This README is focused directly on the inventory integration tests

## Versioning

As Nautobot continues to move forward into new versions and add new models, the dynamic inventory that is returned can change.
In an attempt to combat this we need to incorporate a minimum and maximum version number for each test so that we can still test old versions while being able to adapt and iterate for new versions.
Currently we include the min and max versions as part of the filename to indicate which Nautobot versions the test is compatible with.

The pattern for all inventory test files should be as such: `test_{min version}-{max version}(optional extra moniker).yml`

The minimum version should be **inclusive** and the maximum version should be **exclusive**.
For example, the filename test_2-2.2.yml is for all versions greater than or equal to 2.0.0 and less than **but not equal** to 2.2.0.
Be sure to use "short" versions in the filename (`2.2` rather than `2.2.0`, `3` rather than `3.0.0`) dropping all trailing `.0`.

We use `sort` - using the `-V` flag to designate we are sorting version numbers - to do this and you can verify the validation yourself via `bash`:

```bash
# The pattern is min, current version, max
# If the sort doesn't change the order then it equates to True, but if the order changes than it equates to False.
> printf "%s\n%s\n%s\n" "2.0" "2.1.3" "2.2" | sort -V
2.0 # Minimum version got sorted to the top
2.1.3 # The current version got sorted to the middle, so this would equate to a match and run the test
2.2 # Maximum version got sorted to the bottom
>
> printf "%s\n%s\n%s\n" "2.0" "2.2.3" "2.2" | sort -V
2.0 # Minimum version got sorted to the top
2.2 # Maximum version got sorted to the middle
2.2.3 # Notice that the current version got sorted to the end, so this would equate to not a match
>
> printf "%s\n%s\n%s\n" "2.0" "2.2.0" "2.2" | sort -V
2.0 # Minimum version got sorted to the top
2.2 # Maximum version got sorted to the middle
2.2.0 # Just like in the last example, the full 2.2.0 got sorted above 2.2 so it would not match. The max version is exclusive.
>
```

> Note: We expand the **current** version to the full major.minor.patch version automatically in CI so the sorting works correctly with this pattern. If you verify with printf, make sure you use the full version number for the current version, but the short versions for the min and max to match what automation will do.
Loading
Loading