summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/PULL_REQUEST_TEMPLATE.md104
-rw-r--r--.github/dependabot.yaml10
-rw-r--r--.github/workflows/ah_token_refresh.yml14
-rw-r--r--.github/workflows/check_label.yaml11
-rw-r--r--.github/workflows/cla-check.yml15
-rw-r--r--.github/workflows/codecoverage.yml71
-rw-r--r--.github/workflows/release.yml13
-rw-r--r--.github/workflows/tests.yml52
-rw-r--r--tests/integration/targets/vyos_prefix_lists.old/aliases1
-rw-r--r--tests/integration/targets/vyos_prefix_lists.old/tasks/main.yaml144
-rw-r--r--tests/unit/modules/test_vyos_ntp_global.py22
11 files changed, 302 insertions, 155 deletions
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 0000000..9ff958d
--- /dev/null
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,104 @@
+<!-- All PR should follow this template to allow a clean and transparent review -->
+<!-- Text placed between these delimiters is considered a comment and is not rendered -->
+
+## Change Summary
+<!--- Provide a general summary of your changes in the Title above -->
+
+## Types of changes
+<!---
+What types of changes does your code introduce? Put an 'x' in all the boxes that apply.
+NOTE: Markdown requires no leading or trailing whitespace inside the [ ] for checking
+the box, please use [x]
+-->
+- [ ] Bug fix (non-breaking change which fixes an issue)
+- [ ] New feature (non-breaking change which adds functionality)
+- [ ] Code style update (formatting, renaming)
+- [ ] Refactoring (no functional changes)
+- [ ] Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
+- [ ] Other (please describe):
+
+## Related Task(s)
+<!-- optional: Link to related other tasks on Phabricator. -->
+<!-- * https://vyos.dev/Txxxx -->
+
+## Related PR(s)
+<!-- Link here any PRs in other repositories that are required by this PR -->
+
+## Component(s) name
+<!-- A rather incomplete list of components: ethernet, wireguard, bgp, mpls, ldp, l2tp, dhcp ... -->
+
+## Proposed changes
+<!--- Describe your changes in detail -->
+
+## How to test
+<!---
+Please describe in detail how you tested your changes. Include details of your testing
+environment, and the tests you ran. When pasting configs, logs, shell output, backtraces,
+and other large chunks of text, surround this text with triple backtics
+```
+like this
+```
+-->
+
+## Test results
+<!--
+Provide the output of the unit tests and confirmation of the sanity tests
+along with a description of which versions of VyOS you have tested against.
+
+Tests will be run before the PR is accepted, but do not run automatically
+on forks, so please run all of the tests with each modification of your PR
+to ensure they will pass.
+
+Unit test information can be found in the [Ansible Unit Tests](https://docs.ansible.com/ansible/latest/dev_guide/testing_units.html#testing-units)
+section of the documentation.
+
+Sanity test information can be found in the [Ansible Sanity Tests](https://docs.ansible.com/ansible/latest/dev_guide/testing_sanity.html#testing-sanity)
+section of the Ansible documentation.
+
+```
+Example:
+
+$ ansible-tests units
+============================= test session starts ==============================
+platform linux -- Python 3.12.2, pytest-8.1.1, pluggy-1.4.0
+rootdir: /root/ansible_collections/vyos/vyos
+configfile: ../../../ansible/test/lib/ansible_test/_data/pytest/config/default.ini
+plugins: xdist-3.5.0, mock-3.14.0
+created: 24/24 workers
+24 workers [244 items]
+
+........................................................................ [ 29%]
+........................................................................ [ 59%]
+........................................................................ [ 88%]
+............................ [100%]
+- generated xml file: /root/ansible_collections/vyos/vyos/tests/output/junit/python3.12-controller-units.xml -
+============================= 244 passed in 1.55s ==============================
+
+Describe the versions of VyOS that you have tested your changes
+against.
+
+```
+-->
+- [ ] Sanity tests passed
+- [ ] Unit tests passed
+
+Tested against VyOS versions:
+<!-- examples, add or delete as appropriate; if using rolling versions, please specify
+ fully
+-->
+- 1.3.8
+- 1.4-rolling-202201010100
+
+
+## Checklist:
+<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
+<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
+<!--- The entire development process is outlined here: https://docs.vyos.io/en/latest/contributing/development.html -->
+- [ ] I have read the [**CONTRIBUTING**](https://github.com/vyos/vyos-1x/blob/current/CONTRIBUTING.md) document
+- [ ] I have linked this PR to one or more Phabricator Task(s)
+- [ ] I have run the ansible sanity and unit tests
+- [ ] My commit headlines contain a valid Task id
+- [ ] My change requires a change to the documentation
+- [ ] I have updated the documentation accordingly
+- [ ] I have added unit tests to cover my changes
+- [ ] I have added a file to `changelogs/fragments` to describe the changes
diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml
new file mode 100644
index 0000000..66f19d7
--- /dev/null
+++ b/.github/dependabot.yaml
@@ -0,0 +1,10 @@
+---
+version: 2
+updates:
+ - package-ecosystem: github-actions
+ directory: /
+ schedule:
+ interval: daily
+ open-pull-requests-limit: 3
+ labels:
+ - skip-changelog
diff --git a/.github/workflows/ah_token_refresh.yml b/.github/workflows/ah_token_refresh.yml
new file mode 100644
index 0000000..09d2f9d
--- /dev/null
+++ b/.github/workflows/ah_token_refresh.yml
@@ -0,0 +1,14 @@
+name: Refresh the automation hub token
+# the token expires every 30 days, so we need to refresh it
+on:
+ schedule:
+ - cron: '0 12 1,15 * *' # run 12pm on the 1st and 15th of the month
+ workflow_dispatch:
+
+jobs:
+ refresh:
+ uses: ansible/team-devtools/.github/workflows/ah_token_refresh.yml@v26.4.0
+ with:
+ environment: release
+ secrets:
+ ah_token: ${{ secrets.AH_TOKEN }}
diff --git a/.github/workflows/check_label.yaml b/.github/workflows/check_label.yaml
new file mode 100644
index 0000000..000578b
--- /dev/null
+++ b/.github/workflows/check_label.yaml
@@ -0,0 +1,11 @@
+---
+name: Check label
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: true
+on: # yamllint disable-line rule:truthy
+ pull_request_target:
+ types: [opened, labeled, unlabeled, synchronize]
+jobs:
+ check_label:
+ uses: ansible/ansible-content-actions/.github/workflows/check_label.yaml@main
diff --git a/.github/workflows/cla-check.yml b/.github/workflows/cla-check.yml
new file mode 100644
index 0000000..da3e6ef
--- /dev/null
+++ b/.github/workflows/cla-check.yml
@@ -0,0 +1,15 @@
+name: "CLA Check"
+permissions:
+ actions: write
+ contents: read
+ pull-requests: write
+ statuses: write
+on:
+ pull_request_target:
+ types: [opened, synchronize, closed]
+ issue_comment:
+ types: [created]
+jobs:
+ call-cla-assistant:
+ uses: vyos/vyos-cla-signatures/.github/workflows/cla-reusable.yml@current
+ secrets: inherit
diff --git a/.github/workflows/codecoverage.yml b/.github/workflows/codecoverage.yml
new file mode 100644
index 0000000..8ce3af3
--- /dev/null
+++ b/.github/workflows/codecoverage.yml
@@ -0,0 +1,71 @@
+---
+name: Code Coverage
+# cloned from ansible-network/github_actions/.github/workflows/coverage_network_devices.yml@main
+# in order to deal with token issue in codecov
+
+on: # yamllint disable-line rule:truthy
+ push:
+ pull_request:
+ branches: [main]
+jobs:
+ codecoverage:
+ env:
+ PY_COLORS: "1"
+ source_directory: "./source"
+ python_version: "3.10"
+ ansible_version: "latest"
+ os: "ubuntu-latest"
+ collection_pre_install: >-
+ git+https://github.com/ansible-collections/ansible.utils.git
+ git+https://github.com/ansible-collections/ansible.netcommon.git
+ runs-on: ubuntu-latest
+ name: "Code Coverage | Python 3.10"
+ steps:
+ - name: Checkout the collection repository
+ uses: ansible-network/github_actions/.github/actions/checkout_dependency@main
+ with:
+ path: ${{ env.source_directory }}
+ ref: ${{ github.event.pull_request.head.sha }}
+ fetch-depth: "0"
+
+ - name: Set up Python ${{ env.python_version }}
+ uses: actions/setup-python@v6
+ with:
+ python-version: ${{ env.python_version }}
+
+ - name: Install ansible-core (${{ env.ansible-version }})
+ run: python3 -m pip install ansible-core pytest pytest-cov pytest-ansible-units pytest-forked pytest-xdist
+
+ - name: Read collection metadata from galaxy.yml
+ id: identify
+ uses: ansible-network/github_actions/.github/actions/identify_collection@main
+ with:
+ source_path: ${{ env.source_directory }}
+
+ - name: Build and install the collection
+ uses: ansible-network/github_actions/.github/actions/build_install_collection@main
+ with:
+ install_python_dependencies: true
+ source_path: ${{ env.source_directory }}
+ collection_path: ${{ steps.identify.outputs.collection_path }}
+ tar_file: ${{ steps.identify.outputs.tar_file }}
+
+ - name: Print the ansible version
+ run: ansible --version
+
+ - name: Print the python dependencies
+ run: python3 -m pip list
+
+ - name: Run Coverage tests
+ run: |
+ pytest tests/unit -v --cov-report xml --cov=./
+ working-directory: ${{ steps.identify.outputs.collection_path }}
+
+ - name: Upload coverage report to Codecov
+ uses: codecov/codecov-action@v6
+ with:
+ directory: ${{ steps.identify.outputs.collection_path }}
+ fail_ci_if_error: false
+ token: ${{ secrets.CODECOV_TOKEN }}
+ env:
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
new file mode 100644
index 0000000..7a2c493
--- /dev/null
+++ b/.github/workflows/release.yml
@@ -0,0 +1,13 @@
+---
+name: Release collection
+on: # yamllint disable-line rule:truthy
+ release:
+ types: [published]
+jobs:
+ release:
+ uses: ansible/ansible-content-actions/.github/workflows/release.yaml@main
+ with:
+ environment: release
+ secrets:
+ ah_token: ${{ secrets.AH_TOKEN }}
+ ansible_galaxy_api_key: ${{ secrets.ANSIBLE_GALAXY_API_KEY }}
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
new file mode 100644
index 0000000..dedbc9e
--- /dev/null
+++ b/.github/workflows/tests.yml
@@ -0,0 +1,52 @@
+---
+name: CI
+
+concurrency:
+ group: ${{ github.head_ref || github.run_id }}
+ cancel-in-progress: true
+
+on: # yamllint disable-line rule:truthy
+ pull_request:
+ branches: [main]
+ workflow_dispatch:
+ schedule:
+ - cron: 0 0 * * *
+
+jobs:
+ changelog:
+ uses: ansible/ansible-content-actions/.github/workflows/changelog.yaml@main
+ if: github.event_name == 'pull_request'
+ build-import:
+ uses: ansible/ansible-content-actions/.github/workflows/build_import.yaml@main
+ ansible-lint:
+ uses: ansible/ansible-content-actions/.github/workflows/ansible_lint.yaml@main
+ sanity:
+ uses: ansible/ansible-content-actions/.github/workflows/sanity.yaml@main
+ unit-galaxy:
+ uses: ansible/ansible-content-actions/.github/workflows/unit.yaml@main
+ unit-source:
+ uses: ansible-network/github_actions/.github/workflows/unit_source.yml@main
+ with:
+ collection_pre_install: >-
+ git+https://github.com/ansible-collections/ansible.utils.git
+ git+https://github.com/ansible-collections/ansible.netcommon.git
+ all_green:
+ if: ${{ always() }}
+ needs:
+ - changelog
+ - build-import
+ - sanity
+ - unit-galaxy
+ - unit-source
+ - ansible-lint
+ runs-on: ubuntu-latest
+ steps:
+ - run: >-
+ python -c "assert 'failure' not in
+ set([
+ '${{ needs.changelog.result }}',
+ '${{ needs.sanity.result }}',
+ '${{ needs.unit-galaxy.result }}'
+ '${{ needs.ansible-lint.result }}'
+ '${{ needs.unit-source.result }}'
+ ])"
diff --git a/tests/integration/targets/vyos_prefix_lists.old/aliases b/tests/integration/targets/vyos_prefix_lists.old/aliases
deleted file mode 100644
index cc0afef..0000000
--- a/tests/integration/targets/vyos_prefix_lists.old/aliases
+++ /dev/null
@@ -1 +0,0 @@
-network/vyos
diff --git a/tests/integration/targets/vyos_prefix_lists.old/tasks/main.yaml b/tests/integration/targets/vyos_prefix_lists.old/tasks/main.yaml
deleted file mode 100644
index e5c62cd..0000000
--- a/tests/integration/targets/vyos_prefix_lists.old/tasks/main.yaml
+++ /dev/null
@@ -1,144 +0,0 @@
----
-# tests/integration/targets/vyos_prefix_lists/tasks/main.yaml
-
-- name: TEARDOWN — delete all prefix lists before tests
- vyos.rest.vyos_prefix_lists:
- state: deleted
-
-# ------------------------------------------------------------------
-# MERGED
-# ------------------------------------------------------------------
-
-- name: MERGED — create prefix lists
- register: result
- vyos.rest.vyos_prefix_lists:
- config:
- - afi: ipv4
- prefix_lists:
- - name: AnsibleIPv4PrefixList
- description: PL configured by ansible
- entries:
- - sequence: 2
- action: permit
- prefix: 92.168.10.0/26
- le: 32
- - sequence: 3
- action: deny
- prefix: 72.168.2.0/24
- ge: 26
- - afi: ipv6
- prefix_lists:
- - name: AllowIPv6Prefix
- description: Configured by ansible for allowing IPv6 networks
- entries:
- - sequence: 5
- action: permit
- prefix: 2001:db8:8000::/35
- le: 37
- state: merged
-
-- name: ASSERT — merged changed
- assert:
- that:
- - result.changed == true
-
-- name: MERGED — idempotency check
- register: result
- vyos.rest.vyos_prefix_lists:
- config:
- - afi: ipv4
- prefix_lists:
- - name: AnsibleIPv4PrefixList
- description: PL configured by ansible
- entries:
- - sequence: 2
- action: permit
- prefix: 92.168.10.0/26
- le: 32
- - sequence: 3
- action: deny
- prefix: 72.168.2.0/24
- ge: 26
- state: merged
-
-- name: ASSERT — merged idempotent
- assert:
- that:
- - result.changed == false
- - result.commands | length == 0
-
-# ------------------------------------------------------------------
-# GATHERED
-# ------------------------------------------------------------------
-
-- name: GATHERED — read current prefix lists
- register: result
- vyos.rest.vyos_prefix_lists:
- state: gathered
-
-- name: ASSERT — gathered has ipv4 entry
- assert:
- that:
- - result.gathered | selectattr('afi','eq','ipv4') | list | length > 0
-
-# ------------------------------------------------------------------
-# REPLACED
-# ------------------------------------------------------------------
-
-- name: REPLACED — replace AnsibleIPv4PrefixList
- register: result
- vyos.rest.vyos_prefix_lists:
- config:
- - afi: ipv4
- prefix_lists:
- - name: AnsibleIPv4PrefixList
- entries:
- - sequence: 10
- action: permit
- prefix: 10.0.0.0/8
- state: replaced
-
-- name: ASSERT — replaced changed
- assert:
- that:
- - result.changed == true
-
-- name: REPLACED — idempotency check
- register: result
- vyos.rest.vyos_prefix_lists:
- config:
- - afi: ipv4
- prefix_lists:
- - name: AnsibleIPv4PrefixList
- entries:
- - sequence: 10
- action: permit
- prefix: 10.0.0.0/8
- state: replaced
-
-- name: ASSERT — replaced idempotent
- assert:
- that:
- - result.changed == false
-
-# ------------------------------------------------------------------
-# DELETED
-# ------------------------------------------------------------------
-
-- name: DELETED — remove specific prefix list
- register: result
- vyos.rest.vyos_prefix_lists:
- config:
- - afi: ipv4
- prefix_lists:
- - name: AnsibleIPv4PrefixList
- state: deleted
-
-- name: ASSERT — deleted changed
- assert:
- that:
- - result.changed == true
-
-- name: DELETED — remove all remaining
- vyos.rest.vyos_prefix_lists:
- state: deleted
diff --git a/tests/unit/modules/test_vyos_ntp_global.py b/tests/unit/modules/test_vyos_ntp_global.py
index d646b1a..9aac605 100644
--- a/tests/unit/modules/test_vyos_ntp_global.py
+++ b/tests/unit/modules/test_vyos_ntp_global.py
@@ -138,26 +138,28 @@ class TestVyOSNtpGlobalBuildCommands(unittest.TestCase):
)
def test_deleted_removes_all(self):
- want = self._want(servers={}, allow_clients=[], listen_addresses=[])
have = self._have(
servers={"time1.vyos.net": []},
allow_clients=["10.0.0.0/24"],
listen_addresses=["192.168.1.1"],
)
- cmds = build_commands(want, have, "deleted")
- paths = [c[1] for c in cmds]
- self.assertIn(["service", "ntp", "server", "time1.vyos.net"], paths)
- self.assertIn(["service", "ntp", "allow-client", "address", "10.0.0.0/24"], paths)
+ cmds = build_commands({}, have, "deleted")
+ self.assertEqual(len(cmds), 1)
+ self.assertEqual(cmds[0], ("delete", ["service", "ntp"]))
+
+ def test_deleted_idempotent_when_empty(self):
+ have = self._have(servers={}, allow_clients=[], listen_addresses=[])
+ cmds = build_commands({}, have, "deleted")
+ self.assertEqual(cmds, [])
def test_overridden_deletes_then_merges(self):
want = self._want(servers={"new.server.com": []})
have = self._have(servers={"old.server.com": []})
cmds = build_commands(want, have, "overridden")
- paths = [c[1] for c in cmds]
- # overridden deletes existing server subtree first
- self.assertIn(["service", "ntp", "server"], paths)
- # then adds new server
- self.assertIn(["service", "ntp", "server", "new.server.com"], paths)
+ ops_paths = [(c[0], c[1]) for c in cmds]
+ self.assertIn(("delete", ["service", "ntp", "server", "old.server.com"]), ops_paths)
+ self.assertIn(("set", ["service", "ntp", "server", "new.server.com"]), ops_paths)
+ self.assertNotIn(("delete", ["service", "ntp", "server"]), ops_paths)
def test_no_commands_when_already_correct(self):
state = {"allow_clients": ["10.0.0.0/24"], "listen_addresses": [], "servers": {}}