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

task288 - add dyndns tasks,test,handler #97

Merged
merged 5 commits into from
Sep 13, 2024
Merged

task288 - add dyndns tasks,test,handler #97

merged 5 commits into from
Sep 13, 2024

Conversation

fnateghi
Copy link
Contributor

Pull Request Description:

This pull request introduces a new task for managing Dynamic DNS (DynDNS) settings in OPNsense, along with associated handlers and tests. The changes include the ability to remove and update general DynDNS settings, apply account-specific configurations, and restart the DynDNS service automatically. Additionally, comprehensive tests have been added to ensure proper configuration handling.

Key updates:

DynDNS task for applying general and account-specific settings.
New handler for restarting the DynDNS service.
Tests to validate XML configurations for DynDNS.

@zerwes
Copy link
Collaborator

zerwes commented Sep 12, 2024

closes #95

@fnateghi fnateghi requested a review from zerwes September 12, 2024 10:11
tasks/dyndns.yml Outdated
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: /opnsense/OPNsense/DynDNS{{ item }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave this a task for opn_unset
But if you prefer to do it in the dyndns task, you should just expect a list of UUIDs in the VAR and then use

xpath: "/opnsense/OPNsense/DynDNS/accounts/account[@uuid='{{ item }}']

to remove accounts

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @fnateghi ... testing is great 👍
But ... Ough ... I think you have misunderstood the testing completely
You should test your task(s) and not write a complete playbook
That is why your wrong condition in line 40 in the task file was not breaking the test.
The test should not test himself, but should test your task and finde errors like the wrong condition above.

you must register your new test tag

diff --git a/test/test.yml b/test/test.yml
index 2e8a39b..d071f55 100644
--- a/test/test.yml
+++ b/test/test.yml
@@ -44,6 +44,7 @@
         - ipsec
         - dnsserver
         - openvpn
+        - dyndns
       when:
         - test | default(_testtask) == _testtask
     - ansible.builtin.meta: flush_handlers

and maybe add the missing handlere as a fake one here too
and then you define your VAR files for the tests as test/dyndns-test*.yml, optional some starting xml as test/dyndns-test*.xml and the expected result as test/dyndns-test*-expect.xml
and then you can run your test in the test directory using
ansible-playbook -e test=dyndns test.yml

tasks/dyndns.yml Outdated
@@ -0,0 +1,41 @@
---

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a comment with a example of the VARs here would be great

@zerwes zerwes self-assigned this Sep 12, 2024
@zerwes zerwes added enhancement New feature or request test required labels Sep 12, 2024
tasks/dyndns.yml Outdated
state: present
pretty_print: true
notify: register dyndns
loop: "{{ opn_dyndns_general }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I would prefer to use `with_items' here
as in all other tasks

tasks/dyndns.yml Outdated
- "{{ opn_dyndns_accounts }}"
- settings
when:
- opn_dyndns_accounts_ng is defined
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-    - opn_dyndns_accounts_ng is defined
+    - opn_dyndns_accounts is defined

tasks/dyndns.yml Outdated
@@ -0,0 +1,77 @@
---
#
#opn_dyndns_general:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls fix the lint errors first ...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the new dyndns-test should work pls

@fnateghi
Copy link
Contributor Author

Dear @zerwes

Thank you for your prompt response and feedback. I encountered a small issue with my Git settings, which prevented me from committing the requested configuration initially. However, I have now modified the task and added the handler and the config example in the task as requested.

That said, I believe there might still be a minor issue in my code, though I'm not entirely sure what is wrong or where the problem lies. When I run the test playbook, I receive the following error message:

TASK [fail due to diff between result and expected state for dyndns-test] ****************************************************************************************************************** task path: /.../opnsense/test/testsimpletaskgeneric.yml:46 fatal: [localhost]: FAILED! => { "changed": false, "msg": "fail due to diff between result and expected state for dyndns-test" }

the result should be the enrire settings, but in the *expect.xml file i can only see the general part of the DynDNS settings. The account part is missing somehow.
Could you please assist me in identifying where I might have gone wrong?
thanks

@zerwes
Copy link
Collaborator

zerwes commented Sep 12, 2024

Dear @zerwes

Thank you for your prompt response and feedback. I encountered a small issue with my Git settings, which prevented me from committing the requested configuration initially. However, I have now modified the task and added the handler and the config example in the task as requested.

That said, I believe there might still be a minor issue in my code, though I'm not entirely sure what is wrong or where the problem lies. When I run the test playbook, I receive the following error message:

TASK [fail due to diff between result and expected state for dyndns-test] ****************************************************************************************************************** task path: /.../opnsense/test/testsimpletaskgeneric.yml:46 fatal: [localhost]: FAILED! => { "changed": false, "msg": "fail due to diff between result and expected state for dyndns-test" }

the result should be the enrire settings, but in the *expect.xml file i can only see the general part of the DynDNS settings. The account part is missing somehow. Could you please assist me in identifying where I might have gone wrong? thanks

Hello @fnateghi
I have already pointed you th the problem in the first review
#97 (comment)

@zerwes
Copy link
Collaborator

zerwes commented Sep 12, 2024

so it might be desirable to iterate all my comments in the code review one by one

@fnateghi
Copy link
Contributor Author

Sorry @zerwes. I will fix this and commit again.

@fnateghi
Copy link
Contributor Author

I hope this time is everything correct :)

@fnateghi fnateghi requested a review from zerwes September 12, 2024 15:29
Copy link
Collaborator

@zerwes zerwes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this time is everything correct :)

nope, sadly not

tasks/dyndns.yml Outdated
- settings
when:
- opn_dyndns_accounts is defined
- item.1.key != 'enable'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


why do you exclude the enable tag here? how do you handle it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-    - item.1.key != 'enable'

test/test.yml Outdated
- name: restart dyndns
debug:
msg: fake handler - restart dyndns

Copy link
Collaborator

@zerwes zerwes Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls, do not add empty lines where there was none was before ...

Copy link
Collaborator

@zerwes zerwes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test required, not a fake

test/dyndns-test.xml Show resolved Hide resolved
Copy link
Collaborator

@zerwes zerwes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finally 👍

@zerwes
Copy link
Collaborator

zerwes commented Sep 13, 2024

due to the 2 steps back and one forward commits I will perform a squash merge to main

@zerwes zerwes merged commit 05b1d8c into main Sep 13, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request test required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants