-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conversation
closes #95 |
tasks/dyndns.yml
Outdated
delegate_to: localhost | ||
community.general.xml: | ||
path: "{{ local_config_path }}" | ||
xpath: /opnsense/OPNsense/DynDNS{{ item }} |
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.
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
test/test-dyndn.yml
Outdated
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.
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 @@ | |||
--- | |||
|
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.
adding a comment with a example of the VARs here would be great
tasks/dyndns.yml
Outdated
state: present | ||
pretty_print: true | ||
notify: register dyndns | ||
loop: "{{ opn_dyndns_general }}" |
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.
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 |
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.
- - opn_dyndns_accounts_ng is defined
+ - opn_dyndns_accounts is defined
…dler and add fake handler
tasks/dyndns.yml
Outdated
@@ -0,0 +1,77 @@ | |||
--- | |||
# | |||
#opn_dyndns_general: |
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.
pls fix the lint errors first ...
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.
and the new dyndns-test should work pls
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:
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. |
Hello @fnateghi |
so it might be desirable to iterate all my comments in the code review one by one |
Sorry @zerwes. I will fix this and commit again. |
I hope this time is everything correct :) |
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.
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' |
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.
❓
why do you exclude the enable tag here? how do you handle it?
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.
- - item.1.key != 'enable'
test/test.yml
Outdated
- name: restart dyndns | ||
debug: | ||
msg: fake handler - restart dyndns | ||
|
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.
pls, do not add empty lines where there was none was before ...
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.
test required, not a fake
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.
finally 👍
due to the 2 steps back and one forward commits I will perform a squash merge to main |
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.