diff --git a/plugins/module_utils/client.py b/plugins/module_utils/client.py index f1d35fa72..344af92e0 100644 --- a/plugins/module_utils/client.py +++ b/plugins/module_utils/client.py @@ -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 @@ -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): diff --git a/tests/integration/targets/service/aliases b/tests/integration/targets/service/aliases new file mode 100644 index 000000000..28a231e46 --- /dev/null +++ b/tests/integration/targets/service/aliases @@ -0,0 +1,3 @@ +gather_facts/no +netscaler/cpx/ +netscaler/vpx/ diff --git a/tests/integration/targets/service/tasks/main.yaml b/tests/integration/targets/service/tasks/main.yaml new file mode 100644 index 000000000..19afb5bcb --- /dev/null +++ b/tests/integration/targets/service/tasks/main.yaml @@ -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" diff --git a/tests/integration/utils/generate_integration_tests.py b/tests/integration/utils/generate_integration_tests.py index 3ac39c761..59c8dea5e 100644 --- a/tests/integration/utils/generate_integration_tests.py +++ b/tests/integration/utils/generate_integration_tests.py @@ -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)