-
-
Notifications
You must be signed in to change notification settings - Fork 215
Add tests for ansible and system manager modules #1746
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
Open
jfroche
wants to merge
34
commits into
update-nixpkgs
Choose a base branch
from
feat/ansible-testing
base: update-nixpkgs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,199
−594
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
0c6ccd8
chore: update (and refactor) flake inputs
jfroche 27f5598
chore: replace (deprecated) `substituteAll` by `replaceVars`
jfroche a18642a
chore: fix missing required `teams` meta attribute
jfroche ef8855b
chore: update old (unsupported) version of nix used in script
jfroche ed07522
fix: overlay and use our `buildPgrxExtension` function
jfroche ba09c8d
chore: `v8` has been removed from nixpkgs and replaced with `nodejs.l…
jfroche f75f757
chore: fix formatting
jfroche a0f843c
chore: bump `pgrouting` version to 3.8.0
yvan-sraka 87d5e4f
Backport tzdata fixes for postgresql 15
jfroche 6f10d04
fix: plv8 3.1 requires older v8
jfroche 588f2f2
chore: remove deprecated appl_sdk frameworks
jfroche 99adaed
chore: update cargo-pgrx 1.14.3 cargo hash
jfroche e501fbe
chore(postgresql): add isOrioleDB condition
jfroche 7676043
Fix pgregress tests
jfroche 018bf3c
fix: update schema for dbmate schema_migrations table
jfroche 9c3322f
chore: update nixpkgs flake inputs
jfroche 2614aec
chore: update fmt
jfroche e266435
Structured attributes are now required when building with separateDeb…
jfroche ca41f46
fix: pgroonga should test for all version
samrose 134e133
chore: version bump
samrose a33cf5d
fix: rebase on develop and fix code api changes from nixpkgs
samrose 4becde2
chore: bump to test
samrose 68f882a
tests: try to get passing tests
samrose ce6f5eb
feat: pin icu75 for postgres build to maintain compat with existing
samrose b1730fc
chore: remove commented out code not needed in latest changes to pg
samrose 684c4b7
chore: version bump to test
samrose ef01882
feat: add ansible task testing infrastructure based on Docker and pytest
jfroche 3c92f1c
feat: deploy nginx using system manager
jfroche 273a860
chore: simplify system manager tests
jfroche a394449
chore: formatting
jfroche a07b348
Test system manager deployment triggered by Ansible
jfroche 1e498d8
Create default system manager configuration
jfroche fc77a26
ci: make sure we cache system manager and its test dependencies
jfroche f478f94
chores: add nix run .#ansible-test and .#check-system-module to githu…
yvan-sraka 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,27 @@ | ||
| name: Ansible Test | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - feat/ansible-testing | ||
| pull_request: | ||
| branches: | ||
| - feat/ansible-testing | ||
|
|
||
| jobs: | ||
| ansible-test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout Repo | ||
| uses: supabase/postgres/.github/actions/shared-checkout@HEAD | ||
|
|
||
| - name: Install nix | ||
| uses: cachix/install-nix-action@v27 | ||
| with: | ||
| install_url: https://releases.nixos.org/nix/nix-2.29.1/install | ||
| extra_nix_config: | | ||
| substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com | ||
| trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= | ||
|
|
||
| - name: Run Ansible Test | ||
| run: nix run .#ansible-test |
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,27 @@ | ||
| name: Check System Manager | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - feat/ansible-testing | ||
| pull_request: | ||
| branches: | ||
| - feat/ansible-testing | ||
|
|
||
| jobs: | ||
| check-system-manager: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout Repo | ||
| uses: supabase/postgres/.github/actions/shared-checkout@HEAD | ||
|
|
||
| - name: Install nix | ||
| uses: cachix/install-nix-action@v27 | ||
| with: | ||
| install_url: https://releases.nixos.org/nix/nix-2.29.1/install | ||
| extra_nix_config: | | ||
| substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com | ||
| trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= | ||
|
|
||
| - name: Run check-system-manager | ||
| run: nix run .#check-system-manager |
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 @@ | ||
| ../files |
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,11 @@ | ||
| --- | ||
| - name: Check if nix is installed | ||
| ansible.builtin.command: which nix | ||
| register: nix_installed | ||
| failed_when: nix_installed.rc != 0 | ||
| ignore_errors: true | ||
|
|
||
| - name: Install nix | ||
| ansible.builtin.shell: curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install --no-confirm --extra-conf 'substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com' --extra-conf 'trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=' | ||
| when: nix_installed.rc != 0 | ||
| become: true | ||
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,7 @@ | ||
| --- | ||
| - name: Deploy system manager | ||
| ansible.builtin.shell: | | ||
| . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh | ||
| cd /tmp | ||
| nix run /flake#system-manager -- switch --flake /flake | ||
| become: true |
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,79 @@ | ||
| import pytest | ||
| import subprocess | ||
| import testinfra | ||
| from rich.console import Console | ||
|
|
||
| console = Console() | ||
|
|
||
|
|
||
| def pytest_addoption(parser): | ||
| parser.addoption( | ||
| "--flake-dir", | ||
| action="store", | ||
| help="Directory containing the current flake", | ||
| ) | ||
|
|
||
| parser.addoption( | ||
| "--docker-image", | ||
| action="store", | ||
| help="Docker image and tag to use for testing", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def host(request): | ||
| flake_dir = request.config.getoption("--flake-dir") | ||
| docker_id = ( | ||
| subprocess.check_output( | ||
| [ | ||
| "docker", | ||
| "run", | ||
| "--privileged", | ||
| "--cap-add", | ||
| "SYS_ADMIN", | ||
| "--security-opt", | ||
| "seccomp=unconfined", | ||
| "--cgroup-parent=docker.slice", | ||
| "--cgroupns", | ||
| "private", | ||
| "-v", | ||
| f"{flake_dir}:/flake", | ||
| "-d", | ||
| "ubuntu-cloudimg-with-tools:0.1", | ||
| ] | ||
| ) | ||
| .decode() | ||
| .strip() | ||
| ) | ||
| yield testinfra.get_host("docker://" + docker_id) | ||
| subprocess.check_call(["docker", "rm", "-f", docker_id], stdout=subprocess.DEVNULL) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def run_ansible_playbook(host): | ||
| def _run_playbook(playbook_name, verbose=False): | ||
| cmd = [ | ||
| "ANSIBLE_HOST_KEY_CHECKING=False", | ||
| "ansible-playbook", | ||
| "--connection=local", | ||
| ] | ||
| if verbose: | ||
| cmd.append("-vvv") | ||
| cmd.extend( | ||
| [ | ||
| "-i", | ||
| "localhost,", | ||
| "--extra-vars", | ||
| "@/flake/ansible/vars.yml", | ||
| f"/flake/ansible/tests/{playbook_name}", | ||
| ] | ||
| ) | ||
| result = host.run(" ".join(cmd)) | ||
| if result.failed: | ||
| console.log(result.stdout) | ||
| console.log(result.stderr) | ||
| raise pytest.fail( | ||
| f"Ansible playbook {playbook_name} failed with return code {result.rc}" | ||
| ) | ||
|
|
||
| return _run_playbook |
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,14 @@ | ||
| --- | ||
| - hosts: localhost | ||
| tasks: | ||
| - name: Install dependencies | ||
| apt: | ||
| pkg: | ||
| - build-essential | ||
| update_cache: yes | ||
| - import_tasks: ../tasks/setup-nginx.yml | ||
| - name: Start Nginx service | ||
| service: | ||
| name: nginx | ||
| state: started | ||
| enabled: yes |
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,5 @@ | ||
| --- | ||
| - hosts: localhost | ||
| tasks: | ||
| - import_tasks: ../tasks/setup-nix.yml | ||
| - import_tasks: ../tasks/setup-system-manager.yml |
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,11 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module", autouse=True) | ||
| def run_ansible(run_ansible_playbook): | ||
| run_ansible_playbook("nginx.yaml") | ||
|
|
||
|
|
||
| def test_nginx_service(host): | ||
| assert host.service("nginx.service").is_valid | ||
| assert host.service("nginx.service").is_running |
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,14 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module", autouse=True) | ||
| def run_ansible(run_ansible_playbook): | ||
| run_ansible_playbook("nix.yaml", verbose=True) | ||
|
|
||
|
|
||
| def test_nix_service(host): | ||
| assert host.service("nix-daemon.service").is_running | ||
|
|
||
|
|
||
| def test_envoy_service(host): | ||
| assert host.service("envoy.service").is_running |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of
ignore_errors, why not use a block/rescue