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

either 'ip' or 'ipaddress' will now be supported in 'service' module #356

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion plugins/module_utils/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ansible.module_utils.six.moves.urllib.parse import quote
from ansible.module_utils.urls import fetch_url

from .constants import HTTP_SUCCESS_CODES
from .decorators import trace
from .logger import log

Expand Down Expand Up @@ -174,7 +175,14 @@ def send(self, method, url, data=None):
@trace
def get(self, resource, id=None, args=None, attrs=None, filter=None):
url = self.url_builder(resource, id=id, args=args, attrs=attrs, filter=filter)
return self.send("GET", url)
status_code, response_body = self.send("GET", url)
if status_code not in HTTP_SUCCESS_CODES:
return status_code, response_body
if "service" in response_body.keys():
for service in response_body["service"]:
if "ip" not in service.keys() and "ipaddress" in service.keys():
service["ip"] = service["ipaddress"]
return status_code, response_body

@trace
def post(self, post_data, resource, action=None):
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/targets/service/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gather_facts/no
netscaler/cpx/
netscaler/vpx/
137 changes: 137 additions & 0 deletions tests/integration/targets/service/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
- name: SERVICE | ADD | --check
delegate_to: localhost
register: result
check_mode: true
tags: test
netscaler.adc.service:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
nitro_protocol: "{{ nitro_protocol }}"
validate_certs: "{{ validate_certs }}"
save_config: "{{ save_config }}"
state: present
name: test-service
servicetype: HTTP
ip: 172.18.0.4
port: 5000
- name: Assert | SERVICE | ADD | --check
tags: test
ansible.builtin.assert:
that:
- "result.failed==false"
- "result.changed==true"
- name: SERVICE | ADD
delegate_to: localhost
register: result
check_mode: false
tags: test
netscaler.adc.service:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
nitro_protocol: "{{ nitro_protocol }}"
validate_certs: "{{ validate_certs }}"
save_config: "{{ save_config }}"
state: present
name: test-service
servicetype: HTTP
ipaddress: 172.18.0.4
port: 5000
- name: Assert | SERVICE | ADD
ansible.builtin.assert:
that:
- "result.failed==false"
- "result.changed==true"
- name: SERVICE | ADD | idempotent
delegate_to: localhost
register: result
check_mode: false
tags: test
netscaler.adc.service:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
nitro_protocol: "{{ nitro_protocol }}"
validate_certs: "{{ validate_certs }}"
save_config: "{{ save_config }}"
state: present
name: test-service
servicetype: HTTP
ip: 172.18.0.4
port: 5000
- name: Assert | SERVICE | ADD | idempotent
tags: test
ansible.builtin.assert:
that:
- "result.failed==false"
- "result.changed==false"
- name: SERVICE | DELETE | --check
delegate_to: localhost
register: result
check_mode: true
tags: test
netscaler.adc.service:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
nitro_protocol: "{{ nitro_protocol }}"
validate_certs: "{{ validate_certs }}"
save_config: "{{ save_config }}"
state: absent
name: test-service
servicetype: HTTP
ipaddress: 172.18.0.4
port: 5000
- name: Assert | SERVICE | DELETE | --check
tags: test
ansible.builtin.assert:
that:
- "result.failed==false"
- "result.changed==true"
- name: SERVICE | DELETE
delegate_to: localhost
register: result
check_mode: false
tags: test
netscaler.adc.service:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
nitro_protocol: "{{ nitro_protocol }}"
validate_certs: "{{ validate_certs }}"
save_config: "{{ save_config }}"
state: absent
name: test-service
servicetype: HTTP
ipaddress: 172.18.0.4
port: 5000
- name: Assert | SERVICE | DELETE
ansible.builtin.assert:
that:
- "result.failed==false"
- "result.changed==true"
- name: SERVICE | DELETE | idempotent
delegate_to: localhost
register: result
check_mode: false
tags: test
netscaler.adc.service:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
nitro_protocol: "{{ nitro_protocol }}"
validate_certs: "{{ validate_certs }}"
save_config: "{{ save_config }}"
state: absent
name: test-service
servicetype: HTTP
ip: 172.18.0.4
port: 5000
- name: Assert | SERVICE | DELETE | idempotent
tags: test
ansible.builtin.assert:
that:
- "result.failed==false"
- "result.changed==false"
9 changes: 7 additions & 2 deletions tests/integration/utils/generate_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def main(module_name, module_specific_params):


if __name__ == "__main__":
module_name = "dnsproxyrecords"
module_specific_params = {}
module_name = "service"
module_specific_params = {
"name": "service-http",
"servicetype": "HTTP",
"ip": "172.18.0.4",
"port": "5000",
}
main(module_name, module_specific_params)