From 06ea16cffd1f58f314170908f31ea1f4157b594b Mon Sep 17 00:00:00 2001 From: Sumanth Lingappa Date: Sat, 13 Jan 2024 11:18:14 +0530 Subject: [PATCH 1/3] new state `flushed` added --- examples/dnsproxyrecords.yaml | 9 +++++++++ features_v2.md | 1 + playbook_anatomy.md | 2 +- plugins/module_utils/common.py | 2 ++ plugins/module_utils/module_executor.py | 3 ++- plugins/modules/cachecontentgroup.py | 1 + plugins/modules/cacheobject.py | 3 ++- plugins/modules/dnsproxyrecords.py | 3 ++- plugins/modules/dnssubnetcache.py | 3 ++- plugins/modules/ipsecalgsession.py | 3 ++- plugins/modules/lsnrtspalgsession.py | 3 ++- plugins/modules/lsnsession.py | 3 ++- plugins/modules/lsnsipalgcall.py | 3 ++- plugins/modules/nssimpleacl.py | 1 + plugins/modules/nssimpleacl6.py | 1 + plugins/modules/nssurgeq.py | 3 ++- plugins/modules/rnatsession.py | 3 ++- 17 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 examples/dnsproxyrecords.yaml diff --git a/examples/dnsproxyrecords.yaml b/examples/dnsproxyrecords.yaml new file mode 100644 index 000000000..45abef2e9 --- /dev/null +++ b/examples/dnsproxyrecords.yaml @@ -0,0 +1,9 @@ +--- +- name: Sample Playbook for netscaler.adc.dnsproxyrecords + hosts: localhost + gather_facts: false + tasks: + - name: Flush DNS Proxy records + delegate_to: localhost + netscaler.adc.dnsproxyrecords: + state: flushed diff --git a/features_v2.md b/features_v2.md index 9366c29d8..de0a5899a 100644 --- a/features_v2.md +++ b/features_v2.md @@ -16,6 +16,7 @@ The `netscaler.adc` collection supports 4 modes of operation. | `disabled` | Resource will be disabled on the NetScaler ADC nodes. Not all resources have disable operation | | `created` | Some of the NITRO resources support `create` operation. This state will "create" those resources on the NetScaler. Eg: `create sslcert`, `create dnskey` etc | | `imported` | Resource will be imported on the NetScaler ADC nodes | +| `flushed` | Resources will be flushed on the NetScaler ADC nodes. Eg., `flush dns proxyrecords` | | `switched` | TBD: Resource will be switched on the NetScaler ADC nodes. Eg: Partition switch | > NOTE: The `enabled`, `disabled`, `created`, `imported`, `switched` modes are supported only for the modules that have `enable`, `disable`, `create`, `import`, `switch` operations in the NetScaler ADC NITRO API. diff --git a/playbook_anatomy.md b/playbook_anatomy.md index 59e2a57f9..35ce6d0fb 100644 --- a/playbook_anatomy.md +++ b/playbook_anatomy.md @@ -32,7 +32,7 @@ This is how a typical playbook for `netscaler.adc` collection looks like: # Should the module save the config after making the changes. This is optional. Default is false. save_config: false # This can also be given via NETSCALER_SAVE_CONFIG environment variable - state: present # This is the desired state of the resource. The module will make sure that the resource is in this state. Valid values are `present`, `absent`, `enabled`, `disabled`, `imported`, `created`. However, not all modules support all the states. Refer to the module documentation for the supported states. + state: present # This is the desired state of the resource. The module will make sure that the resource is in this state. Valid values are `present`, `absent`, `enabled`, `disabled`, `imported`, `created`, `flushed`. However, not all modules support all the states. Refer to the module documentation for the supported states. # The following are the module parameters. Refer to the module documentation for the list of supported parameters. name: s1 diff --git a/plugins/module_utils/common.py b/plugins/module_utils/common.py index 1c21a7729..19d1dffd1 100644 --- a/plugins/module_utils/common.py +++ b/plugins/module_utils/common.py @@ -554,6 +554,8 @@ def get_valid_desired_states(resource_name): desired_states.add("disabled") if "create" in supported_operations: desired_states.add("created") + if "flush" in supported_operations: + desired_states.add("flushed") if "import" in supported_operations or "Import" in supported_operations: desired_states.add("imported") if "Switch" in supported_operations: diff --git a/plugins/module_utils/module_executor.py b/plugins/module_utils/module_executor.py index 00cddc41f..e4a31b5d2 100644 --- a/plugins/module_utils/module_executor.py +++ b/plugins/module_utils/module_executor.py @@ -903,10 +903,11 @@ def main(self): if "bindings" in NITRO_RESOURCE_MAP[self.resource_name].keys(): self.sync_all_bindings() - elif self.module.params["state"] in {"created", "imported"}: + elif self.module.params["state"] in {"created", "imported", "flushed"}: state_action_map = { "created": "create", "imported": "import", + "flushed": "flush", } self.act_on_resource( action=state_action_map[self.module.params["state"]] diff --git a/plugins/modules/cachecontentgroup.py b/plugins/modules/cachecontentgroup.py index bb2d1e1f8..8bc6f32d3 100644 --- a/plugins/modules/cachecontentgroup.py +++ b/plugins/modules/cachecontentgroup.py @@ -28,6 +28,7 @@ choices: - present - absent + - flushed default: present description: - The state of the resource being configured by the module on the NetScaler diff --git a/plugins/modules/cacheobject.py b/plugins/modules/cacheobject.py index de4e3eec7..7ef92e4e7 100644 --- a/plugins/modules/cacheobject.py +++ b/plugins/modules/cacheobject.py @@ -25,7 +25,8 @@ - Sumanth Lingappa (@sumanth-lingappa) options: state: - choices: [] + choices: + - flushed default: present description: - The state of the resource being configured by the module on the NetScaler diff --git a/plugins/modules/dnsproxyrecords.py b/plugins/modules/dnsproxyrecords.py index 2462530d2..dc658e0d3 100644 --- a/plugins/modules/dnsproxyrecords.py +++ b/plugins/modules/dnsproxyrecords.py @@ -25,7 +25,8 @@ - Sumanth Lingappa (@sumanth-lingappa) options: state: - choices: [] + choices: + - flushed default: present description: - The state of the resource being configured by the module on the NetScaler diff --git a/plugins/modules/dnssubnetcache.py b/plugins/modules/dnssubnetcache.py index 661d4a9b1..bdfb7a7f2 100644 --- a/plugins/modules/dnssubnetcache.py +++ b/plugins/modules/dnssubnetcache.py @@ -25,7 +25,8 @@ - Sumanth Lingappa (@sumanth-lingappa) options: state: - choices: [] + choices: + - flushed default: present description: - The state of the resource being configured by the module on the NetScaler diff --git a/plugins/modules/ipsecalgsession.py b/plugins/modules/ipsecalgsession.py index c11a44fbf..39b830517 100644 --- a/plugins/modules/ipsecalgsession.py +++ b/plugins/modules/ipsecalgsession.py @@ -25,7 +25,8 @@ - Sumanth Lingappa (@sumanth-lingappa) options: state: - choices: [] + choices: + - flushed default: present description: - The state of the resource being configured by the module on the NetScaler diff --git a/plugins/modules/lsnrtspalgsession.py b/plugins/modules/lsnrtspalgsession.py index 08007b0b4..251395188 100644 --- a/plugins/modules/lsnrtspalgsession.py +++ b/plugins/modules/lsnrtspalgsession.py @@ -25,7 +25,8 @@ - Sumanth Lingappa (@sumanth-lingappa) options: state: - choices: [] + choices: + - flushed default: present description: - The state of the resource being configured by the module on the NetScaler diff --git a/plugins/modules/lsnsession.py b/plugins/modules/lsnsession.py index a04821bb4..977522989 100644 --- a/plugins/modules/lsnsession.py +++ b/plugins/modules/lsnsession.py @@ -25,7 +25,8 @@ - Sumanth Lingappa (@sumanth-lingappa) options: state: - choices: [] + choices: + - flushed default: present description: - The state of the resource being configured by the module on the NetScaler diff --git a/plugins/modules/lsnsipalgcall.py b/plugins/modules/lsnsipalgcall.py index 478cdd3e2..c6c9350f3 100644 --- a/plugins/modules/lsnsipalgcall.py +++ b/plugins/modules/lsnsipalgcall.py @@ -25,7 +25,8 @@ - Sumanth Lingappa (@sumanth-lingappa) options: state: - choices: [] + choices: + - flushed default: present description: - The state of the resource being configured by the module on the NetScaler diff --git a/plugins/modules/nssimpleacl.py b/plugins/modules/nssimpleacl.py index 2718557f1..7cd325bb1 100644 --- a/plugins/modules/nssimpleacl.py +++ b/plugins/modules/nssimpleacl.py @@ -28,6 +28,7 @@ choices: - present - absent + - flushed default: present description: - The state of the resource being configured by the module on the NetScaler diff --git a/plugins/modules/nssimpleacl6.py b/plugins/modules/nssimpleacl6.py index 017890a29..705d5c51b 100644 --- a/plugins/modules/nssimpleacl6.py +++ b/plugins/modules/nssimpleacl6.py @@ -28,6 +28,7 @@ choices: - present - absent + - flushed default: present description: - The state of the resource being configured by the module on the NetScaler diff --git a/plugins/modules/nssurgeq.py b/plugins/modules/nssurgeq.py index 75a60e3ad..e675a4c13 100644 --- a/plugins/modules/nssurgeq.py +++ b/plugins/modules/nssurgeq.py @@ -25,7 +25,8 @@ - Sumanth Lingappa (@sumanth-lingappa) options: state: - choices: [] + choices: + - flushed default: present description: - The state of the resource being configured by the module on the NetScaler diff --git a/plugins/modules/rnatsession.py b/plugins/modules/rnatsession.py index ba7e3888c..29a934d53 100644 --- a/plugins/modules/rnatsession.py +++ b/plugins/modules/rnatsession.py @@ -25,7 +25,8 @@ - Sumanth Lingappa (@sumanth-lingappa) options: state: - choices: [] + choices: + - flushed default: present description: - The state of the resource being configured by the module on the NetScaler From 7ba336cc8a34d3cdbc8b24f46724397e54347603 Mon Sep 17 00:00:00 2001 From: Sumanth Lingappa Date: Sat, 13 Jan 2024 11:29:57 +0530 Subject: [PATCH 2/3] dnsproxyrecords integration tests added --- .../targets/dnsproxyrecords/aliases | 3 + .../targets/dnsproxyrecords/tasks/main.yaml | 57 +++++++++++++++++++ .../utils/generate_integration_tests.py | 9 ++- 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 tests/integration/targets/dnsproxyrecords/aliases create mode 100644 tests/integration/targets/dnsproxyrecords/tasks/main.yaml diff --git a/tests/integration/targets/dnsproxyrecords/aliases b/tests/integration/targets/dnsproxyrecords/aliases new file mode 100644 index 000000000..28a231e46 --- /dev/null +++ b/tests/integration/targets/dnsproxyrecords/aliases @@ -0,0 +1,3 @@ +gather_facts/no +netscaler/cpx/ +netscaler/vpx/ diff --git a/tests/integration/targets/dnsproxyrecords/tasks/main.yaml b/tests/integration/targets/dnsproxyrecords/tasks/main.yaml new file mode 100644 index 000000000..ac0d2b0d7 --- /dev/null +++ b/tests/integration/targets/dnsproxyrecords/tasks/main.yaml @@ -0,0 +1,57 @@ +--- +- name: DNSPROXYRECORDS | FLUSH | --check + delegate_to: localhost + register: result + check_mode: true + tags: test + netscaler.adc.dnsproxyrecords: + nsip: "{{ nsip }}" + nitro_user: "{{ nitro_user }}" + nitro_pass: "{{ nitro_pass }}" + nitro_protocol: "{{ nitro_protocol }}" + validate_certs: "{{ validate_certs }}" + save_config: "{{ save_config }}" + state: flushed +- name: Assert | DNSPROXYRECORDS | FLUSH | --check + tags: test + ansible.builtin.assert: + that: + - "result.failed==false" + - "result.changed==true" +- name: DNSPROXYRECORDS | FLUSH + delegate_to: localhost + register: result + check_mode: false + tags: test + netscaler.adc.dnsproxyrecords: + nsip: "{{ nsip }}" + nitro_user: "{{ nitro_user }}" + nitro_pass: "{{ nitro_pass }}" + nitro_protocol: "{{ nitro_protocol }}" + validate_certs: "{{ validate_certs }}" + save_config: "{{ save_config }}" + state: flushed +- name: Assert | DNSPROXYRECORDS | FLUSH + ansible.builtin.assert: + that: + - "result.failed==false" + - "result.changed==true" +- name: DNSPROXYRECORDS | FLUSH | idempotent + delegate_to: localhost + register: result + check_mode: false + tags: test + netscaler.adc.dnsproxyrecords: + nsip: "{{ nsip }}" + nitro_user: "{{ nitro_user }}" + nitro_pass: "{{ nitro_pass }}" + nitro_protocol: "{{ nitro_protocol }}" + validate_certs: "{{ validate_certs }}" + save_config: "{{ save_config }}" + state: flushed +- name: Assert | DNSPROXYRECORDS | ADD | idempotent + tags: test + ansible.builtin.assert: + that: + - "result.failed==false" + - "result.changed==true" # flushed always returns changed true diff --git a/tests/integration/utils/generate_integration_tests.py b/tests/integration/utils/generate_integration_tests.py index 796863fd3..b605d0c5b 100644 --- a/tests/integration/utils/generate_integration_tests.py +++ b/tests/integration/utils/generate_integration_tests.py @@ -54,13 +54,12 @@ def main(module_name, module_specific_params): # abcdefghijklmnopqrstuvwxyz with open(target_dir + os.sep + "aliases", "w") as aliases_file: - aliases_file.write("gather_facts: no\n") - + aliases_file.write("gather_facts/no\n") + aliases_file.write("netscaler/cpx/\n") + aliases_file.write("netscaler/vpx/\n") if __name__ == "__main__": - module_name = "ntpserver" + module_name = "dnsproxyrecords" module_specific_params = { - "servername": "pool.ntp.org", - "preferredntpserver": '"YES"', } main(module_name, module_specific_params) From 4fd1fe734d45fd76e7c725b63799dcb5f72a16e9 Mon Sep 17 00:00:00 2001 From: Sumanth Lingappa Date: Sat, 13 Jan 2024 12:42:01 +0530 Subject: [PATCH 3/3] reformatted to fix sanity errors Signed-off-by: Sumanth Lingappa --- Makefile | 1 + tests/integration/utils/generate_integration_tests.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b409d4c5b..2ee4fdcd8 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,7 @@ lint: yamllint . echo "\n\n\n\n\n\n\n\n\n\n" ansible-lint + python3 -m pycodestyle --max-line-length 160 --config /dev/null --ignore E203,E402,E741,W503,W504 plugins tests test_sanity: galaxy_importer install cd ~/.ansible/collections/ansible_collections/netscaler/adc && \ diff --git a/tests/integration/utils/generate_integration_tests.py b/tests/integration/utils/generate_integration_tests.py index b605d0c5b..3ac39c761 100644 --- a/tests/integration/utils/generate_integration_tests.py +++ b/tests/integration/utils/generate_integration_tests.py @@ -58,8 +58,8 @@ def main(module_name, module_specific_params): aliases_file.write("netscaler/cpx/\n") aliases_file.write("netscaler/vpx/\n") + if __name__ == "__main__": module_name = "dnsproxyrecords" - module_specific_params = { - } + module_specific_params = {} main(module_name, module_specific_params)