Skip to content

Commit

Permalink
Feature/interfaces assignments (#85)
Browse files Browse the repository at this point in the history
* first draft of converge file

* first draft of the molecule file

* fixed typo

* fixed module naming

* first draft of the utils

* added first draft of plugins/module_utils/interfaces_assignments_utils.py

* added first draft of plugins/modules/interfaces_assignments.py

* added first draft of plugins/module_utils/module_index.py

* added missing function

* updated interfaces_assignments.py

* updated converge.yml

* finished tests

* updated converge.yml

* updated interfaces_assignments_utils.py

* added verify file

* updated module_index

* updated interfaces_assignments

* removed old file

* updated tests

* updated typo in tests

* updated tests

* added docstring to Interface_assignment class

* added docstring to Interface_assignment functions

* added class- and docstring to class InterfacesSet

* updated linter errors

* updated linter errors

* updated linter errors

* some more linter erros

* fixed typo

* excluded tests from linter

* some linter changes + comparision fixed

* added full config as test xml

* fixed RETURN

* fixed RETURN

* some more linter errors

* sanity error fix

* XML Utility: elements_equal (#86)

* Drop ansible core devel python 3.7 support

* Make dict_to_etree exception more verbose

* Add elements_equal xml utility

* Lint xml utils sequence bool check

* Format changes

* initial version of the system_settings_logging module (#61)

* initial version of the system_settings_logging module

---------

Co-authored-by: KiLLuuuhh <[email protected]>

* updated linter errors

* XML Utility: elements_equal (#86)

* Drop ansible core devel python 3.7 support

* Make dict_to_etree exception more verbose

* Add elements_equal xml utility

* Lint xml utils sequence bool check

* Format changes

* updated module_index

* initial version of the system_settings_logging module (#61)

* initial version of the system_settings_logging module

---------

Co-authored-by: KiLLuuuhh <[email protected]>

* updated module_index

* added pylint: disable=duplicate-code

* updated converge tests

* updated unit tests

* changed error message

* added fail_json exceptions

* updated utils, so that local interfaces can be queried and created logic for interface update

* updated module_index

* updated test contexts

* refactored some code for the linter

* fixed list error

* black

* added some tests

* added new error

* fixed typing issue

* fixed doc issue

* added fully qualified collection names

* removed OPNSenseInterfaceNotFoundError

* applied DonGiovannis suggestions

* removed InterfaceNotFound error since it is not used

* restructured get_interfaces method to not rely on removed interfaces_list module_index entry

* removed unused entries

* removed unused interfaces_list entry

* some more module_index updates

* Update plugins/modules/interfaces_assignments.py

Co-authored-by: Fabio Bertagna <[email protected]>

* Update plugins/module_utils/interfaces_assignments_utils.py

Co-authored-by: Fabio Bertagna <[email protected]>

* Update plugins/module_utils/module_index.py

Co-authored-by: Fabio Bertagna <[email protected]>

* Update plugins/module_utils/module_index.py

Co-authored-by: Fabio Bertagna <[email protected]>

* Update plugins/module_utils/module_index.py

Co-authored-by: Fabio Bertagna <[email protected]>

* Update plugins/module_utils/module_index.py

Co-authored-by: Fabio Bertagna <[email protected]>

* updated error texts

* applied DonGiovanni suggestions

* refactored code

* reimplements configure_params

* final adjustments

* finalized module_index

* updated get_interfaces so that it uses the newly created run_command function

* updated tests

* black plugins/module_utils/interfaces_assignments_utils.py

* restructed module_index

---------

Co-authored-by: Fabio Bertagna <[email protected]>
Co-authored-by: Reto Kupferschmid <[email protected]>
  • Loading branch information
3 people authored Apr 23, 2024
1 parent aeb4bdd commit a0876cc
Show file tree
Hide file tree
Showing 7 changed files with 2,409 additions and 34 deletions.
54 changes: 54 additions & 0 deletions molecule/interfaces_assignments/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
- name: converge
hosts: all
become: true
tasks:
- name: Test interface lan, device em1 description update
puzzle.opnsense.interfaces_assignments:
identifier: "lan"
device: "em1"
description: "LAN1"

- name: Test interface wan, device update from em2 to em3
puzzle.opnsense.interfaces_assignments:
identifier: "wan"
device: "em3"
description: "wan_interface"
register: device_already_assigned_result
ignore_errors: yes

- name: "Verify that the device update failed since the device is already assigned"
ansible.builtin.assert:
that:
- device_already_assigned_result is failed
fail_msg: "This device is already assigned, please unassign this device first"
success_msg: "This device is already assigned, please unassign this device first"

- name: Test unknown identifier to used device description update
puzzle.opnsense.interfaces_assignments:
identifier: "unknown_identifier"
device: "em1"
description: "unknown_identifier"
register: unknown_identifier_result
ignore_errors: yes

- name: "Verify that the device update failed since the device is already assigned"
ansible.builtin.assert:
that:
- unknown_identifier_result is failed
fail_msg: "This device is already assigned, please unassign this device first"
success_msg: "This device is already assigned, please unassign this device first"

- name: Test interface lan, unknown_device update
puzzle.opnsense.interfaces_assignments:
identifier: "lan"
device: "unknown_device"
register: unknown_device_result
ignore_errors: yes

- name: "Verify that the device update failed due to non-existing device"
ansible.builtin.assert:
that:
- unknown_device_result is failed
fail_msg: "Interface update should fail due to non-existing device"
success_msg: "Interface update failed as expected due to non-existing device"
67 changes: 67 additions & 0 deletions molecule/interfaces_assignments/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
scenario:
name: interfaces_assignments
test_sequence:
# - dependency not relevant uless we have requirements
- destroy
- syntax
- create
- converge
- idempotence
- verify
- destroy

driver:
name: vagrant
parallel: true

platforms:
- name: "22.7"
hostname: false
box: puzzle/opnsense
box_version: "22.7"
memory: 1024
cpus: 2
instance_raw_config_args:
- 'vm.guest = :freebsd'
- 'ssh.sudo_command = "%c"'
- 'ssh.shell = "/bin/sh"'
- name: "23.1"
box: puzzle/opnsense
hostname: false
box_version: "23.1"
memory: 1024
cpus: 2
instance_raw_config_args:
- 'vm.guest = :freebsd'
- 'ssh.sudo_command = "%c"'
- 'ssh.shell = "/bin/sh"'
- name: "23.7"
box: puzzle/opnsense
hostname: false
box_version: "23.7"
memory: 1024
cpus: 2
instance_raw_config_args:
- 'vm.guest = :freebsd'
- 'ssh.sudo_command = "%c"'
- 'ssh.shell = "/bin/sh"'
- name: "24.1"
box: puzzle/opnsense
hostname: false
box_version: "24.1"
memory: 1024
cpus: 2
instance_raw_config_args:
- 'vm.guest = :freebsd'
- 'ssh.sudo_command = "%c"'
- 'ssh.shell = "/bin/sh"'

provisioner:
name: ansible
env:
ANSIBLE_VERBOSITY: 3
verifier:
name: ansible
options:
become: true
6 changes: 6 additions & 0 deletions molecule/interfaces_assignments/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Verify connectivity to server
hosts: all
tasks:
- name: Ping the server
ansible.builtin.ping:
Loading

0 comments on commit a0876cc

Please sign in to comment.