New module: manage Citrix Netscaler load balancer virtual servers configuration (network/netscaler/netscaler_lb_vserver) (#26144)

* Add netscaler_lb_vserver

* Correct version_added
pull/19786/merge
George Nikolopoulos 7 years ago committed by John R Barker
parent 727a7e8a1c
commit 7df14bd2b0

@ -0,0 +1,6 @@
---
testcase: "*"
test_cases: []
nitro_user: nsroot
nitro_pass: nsroot

@ -0,0 +1,5 @@
[netscaler]
netscaler01 nsip=172.18.0.2 nitro_user=nsroot nitro_pass=nsroot

@ -0,0 +1,7 @@
---
- include: testbed_setup.yaml state=present
- { include: nitro.yaml, tags: ['nitro'] }
- include: testbed_setup.yaml state=absent

@ -0,0 +1,14 @@
- name: collect all nitro test cases
find:
paths: "{{ role_path }}/tests/nitro"
patterns: "{{ testcase }}.yaml"
register: test_cases
- name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case
include: "{{ test_case_to_run }}"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

@ -0,0 +1,78 @@
---
- name: Setup server
delegate_to: localhost
netscaler_server:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
state: "{{ state }}"
name: "server-{{ item }}"
ipaddress: "192.168.1.{{ item }}"
with_sequence: count=6
- name: Setup http service
delegate_to: localhost
netscaler_service:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
state: "{{ state }}"
name: "service-http-{{ item }}"
servername: "server-{{ item }}"
servicetype: HTTP
port: 80
with_sequence: count=2
- name: Setup service group
delegate_to: localhost
netscaler_servicegroup:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
state: "{{ state }}"
servicegroupname: service-group-1
servicetype: HTTP
servicemembers:
- servername: server-3
port: 80
weight: 50
- servername: server-4
port: 80
weight: 50
- name: Setup service group
delegate_to: localhost
netscaler_servicegroup:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
state: "{{ state }}"
servicegroupname: service-group-2
servicetype: HTTP
servicemembers:
- servername: server-5
port: 80
weight: 50
- servername: server-6
port: 80
weight: 50
- name: Setup push vserver
delegate_to: localhost
netscaler_lb_vserver:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
state: "{{ state }}"
name: lb-vserver-push
port: 80
servicetype: PUSH
ipv46: 193.1.1.1

@ -0,0 +1,57 @@
---
- include: "{{ role_path }}/tests/nitro/lb_vserver_any/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_any/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_any/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_any/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_any/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_any/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_any/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_any/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

@ -0,0 +1,12 @@
---
- name: remove http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: lb-vserver-4

@ -0,0 +1,17 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-4
ipv46: 10.79.1.4
port: 80
servicetype: ANY
connfailover: STATELESS
skippersistency: None

@ -0,0 +1,57 @@
---
- include: "{{ role_path }}/tests/nitro/lb_vserver_dns/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_dns/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_dns/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_dns/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_dns/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_dns/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_dns/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_dns/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

@ -0,0 +1,12 @@
---
- name: remove http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: lb-vserver-8

@ -0,0 +1,17 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-8
ipv46: 10.79.1.8
port: 80
servicetype: DNS
recursionavailable: no

@ -0,0 +1,9 @@
---
- include: "{{ role_path }}/tests/nitro/lb_vserver_flap_disabled/setup.yaml"
vars:
check_mode: no
- include: "{{ role_path }}/tests/nitro/lb_vserver_flap_disabled/remove.yaml"
vars:
check_mode: no

@ -0,0 +1,12 @@
---
- name: remove http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: lb-vserver-flap

@ -0,0 +1,47 @@
---
- name: flap http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-flap
ipv46: 10.79.1.2
port: 80
servicetype: HTTP
servicebindings:
- servicename: service-http-1
weight: 50
- servicename: service-http-2
weight: 50
disabled: "{{ item|int % 2 }}"
with_sequence: count=20
delay: 1
- name: flap http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-flap
ipv46: 10.79.1.2
port: 80
servicetype: HTTP
servicebindings:
- servicename: service-http-1
weight: 50
- servicename: service-http-2
weight: 50
disabled: "{{ item|int % 2 }}"
with_sequence: count=20
delay: 5

@ -0,0 +1,85 @@
---
- include: "{{ role_path }}/tests/nitro/lb_vserver_http/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_http/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_http/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_http/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_http/update.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_http/update.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_http/update.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_http/update.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_http/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_http/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_http/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_http/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

@ -0,0 +1,12 @@
---
- name: remove http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: lb-vserver-1

@ -0,0 +1,71 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-1
ipv46: 10.79.1.1
port: 80
range: 2
servicetype: HTTP
persistencetype: COOKIEINSERT
timeout: 100
persistencebackup: SOURCEIP
backuppersistencetimeout: 110
lbmethod: URLHASH
cookiename: COOKIE
listenpolicy: "CLIENT.IP.DST.IN_SUBNET(192.0.2.0/24)"
listenpriority: 66
persistmask: 255.255.0.0
v6persistmasklen: 64
m: IP
tosid: 6
sessionless: DISABLED
redirurl: http://somewhere.com
cacheable: no
clttimeout: 111
somethod: CONNECTION
sopersistence: DISABLED
sopersistencetimeout: 222
sothreshold: 4096
healththreshold: 55
sobackupaction: DROP
redirectportrewrite: DISABLED
downstateflush: DISABLED
disableprimaryondown: DISABLED
insertvserveripport: VIPADDR
vipheader: vip
authenticationhost: authenticate.me
authentication: off
authn401: off
authnvsname: somename
push: DISABLED
pushmulticlients: no
comment: Vserver comment
l2conn: "OFF"
appflowlog: DISABLED
icmpvsrresponse: PASSIVE
rhistate: PASSIVE
newservicerequest: 11
newservicerequestunit: PER_SECOND
newservicerequestincrementinterval: 5
minautoscalemembers: 8
maxautoscalemembers: 10
macmoderetainvlan: DISABLED
dns64: DISABLED
bypassaaaa: no
processlocal: DISABLED
backuplbmethod: LEASTCONNECTION
hashlength: 100
servicebindings:
- servicename: service-http-1
weight: 50
- servicename: service-http-2
weight: 50

@ -0,0 +1,71 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-1
ipv46: 10.79.1.1
port: 80
range: 2
servicetype: HTTP
persistencetype: COOKIEINSERT
timeout: 100
persistencebackup: SOURCEIP
backuppersistencetimeout: 110
lbmethod: URLHASH
cookiename: COOKIE
listenpolicy: "CLIENT.IP.DST.IN_SUBNET(192.0.2.0/24)"
listenpriority: 66
persistmask: 255.255.0.0
v6persistmasklen: 64
m: IP
tosid: 6
sessionless: DISABLED
redirurl: http://somewhere.com
cacheable: no
clttimeout: 222
somethod: CONNECTION
sopersistence: DISABLED
sopersistencetimeout: 222
sothreshold: 4096
healththreshold: 55
sobackupaction: DROP
redirectportrewrite: DISABLED
downstateflush: DISABLED
disableprimaryondown: DISABLED
insertvserveripport: VIPADDR
vipheader: vip
authenticationhost: authenticate.me
authentication: off
authn401: off
authnvsname: somename
push: DISABLED
pushmulticlients: no
comment: Vserver comment
l2conn: "OFF"
appflowlog: DISABLED
icmpvsrresponse: PASSIVE
rhistate: PASSIVE
newservicerequest: 11
newservicerequestunit: PER_SECOND
newservicerequestincrementinterval: 5
minautoscalemembers: 8
maxautoscalemembers: 10
macmoderetainvlan: DISABLED
dns64: DISABLED
bypassaaaa: no
processlocal: DISABLED
backuplbmethod: LEASTCONNECTION
hashlength: 100
servicebindings:
- servicename: service-http-1
weight: 60
- servicename: service-http-2
weight: 40

@ -0,0 +1,57 @@
---
- include: "{{ role_path }}/tests/nitro/lb_vserver_iphash/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_iphash/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_iphash/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_iphash/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_iphash/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_iphash/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_iphash/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_iphash/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

@ -0,0 +1,12 @@
---
- name: remove http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: lb-vserver-10

@ -0,0 +1,19 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-10
port: 80
servicetype: HTTP
lbmethod: DESTINATIONIPHASH
netmask: 255.255.255.0
ippattern: 10.68.0.0
ipmask: 255.255.0.0
v6netmasklen: 24

@ -0,0 +1,57 @@
---
- include: "{{ role_path }}/tests/nitro/lb_vserver_ippattern/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_ippattern/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_ippattern/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_ippattern/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_ippattern/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_ippattern/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_ippattern/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_ippattern/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

@ -0,0 +1,12 @@
---
- name: remove http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: lb-vserver-9

@ -0,0 +1,16 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-9
port: 80
servicetype: HTTP
ippattern: 10.67.0.0
ipmask: 255.255.0.0

@ -0,0 +1,57 @@
---
- include: "{{ role_path }}/tests/nitro/lb_vserver_mssql/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mssql/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mssql/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mssql/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mssql/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mssql/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mssql/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mssql/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

@ -0,0 +1,12 @@
---
- name: remove http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: lb-vserver-6

@ -0,0 +1,16 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-6
ipv46: 10.79.1.6
port: 80
servicetype: MSSQL
mssqlserverversion: 2000

@ -0,0 +1,57 @@
---
- include: "{{ role_path }}/tests/nitro/lb_vserver_mysql/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mysql/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mysql/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mysql/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mysql/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mysql/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mysql/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_mysql/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

@ -0,0 +1,12 @@
---
- name: remove http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: lb-vserver-7

@ -0,0 +1,22 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-7
ipv46: 10.79.1.7
port: 80
servicetype: MYSQL
mysqlprotocolversion: 2
mysqlserverversion: 10
mysqlcharacterset: 8
mysqlservercapabilities: 244
dbslb: DISABLED

@ -0,0 +1,57 @@
---
- include: "{{ role_path }}/tests/nitro/lb_vserver_oracle/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_oracle/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_oracle/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_oracle/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_oracle/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_oracle/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_oracle/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_oracle/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

@ -0,0 +1,12 @@
---
- name: remove http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: lb-vserver-5

@ -0,0 +1,16 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-5
ipv46: 10.79.1.5
port: 80
servicetype: ORACLE
oracleserverversion: 10G

@ -0,0 +1,57 @@
---
- include: "{{ role_path }}/tests/nitro/lb_vserver_push/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_push/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_push/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_push/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_push/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_push/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_push/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_push/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

@ -0,0 +1,12 @@
---
- name: remove http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: lb-vserver-11

@ -0,0 +1,21 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-11
port: 80
servicetype: HTTP
lbmethod: DESTINATIONIPHASH
netmask: 255.255.255.0
ippattern: 10.69.0.0
ipmask: 255.255.0.0
v6netmasklen: 24
pushvserver: lb-vserver-push
pushlabel: none

@ -0,0 +1,57 @@
---
- include: "{{ role_path }}/tests/nitro/lb_vserver_rtspnat/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_rtspnat/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_rtspnat/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_rtspnat/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_rtspnat/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_rtspnat/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_rtspnat/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_rtspnat/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

@ -0,0 +1,12 @@
---
- name: remove http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: lb-vserver-3

@ -0,0 +1,20 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-3
ipv46: 10.79.1.3
port: 80
servicetype: TCP
lbmethod: TOKEN
datalength: 20
dataoffset: 5

@ -0,0 +1,132 @@
---
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/setup.yaml"
vars:
check_mode: no
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/update.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/update.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/update.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/update.yaml"
vars:
check_mode: no
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/update_service.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/update_service.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/update_service.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/update_service.yaml"
vars:
check_mode: no
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/update.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/update.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/update.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/update.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_servicegroup/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

@ -0,0 +1,12 @@
---
- name: remove http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: lb-vserver-20

@ -0,0 +1,17 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-20
ipv46: 10.79.1.8
port: 80
servicetype: HTTP
servicegroupbindings:
- servicegroupname: service-group-1

@ -0,0 +1,17 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-20
ipv46: 10.79.1.8
port: 80
servicetype: HTTP
servicegroupbindings:
- servicegroupname: service-group-2

@ -0,0 +1,20 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-20
ipv46: 10.79.1.8
port: 80
servicetype: HTTP
servicebindings:
- servicename: service-http-1
weight: 50
- servicename: service-http-2
weight: 50

@ -0,0 +1,57 @@
---
- include: "{{ role_path }}/tests/nitro/lb_vserver_tcp/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_tcp/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_tcp/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_tcp/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_tcp/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_tcp/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_tcp/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/lb_vserver_tcp/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

@ -0,0 +1,12 @@
---
- name: remove http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: lb-vserver-2

@ -0,0 +1,16 @@
---
- name: setup http lb vserver
register: result
check_mode: "{{ check_mode }}"
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: lb-vserver-2
ipv46: 10.79.1.2
port: 80
servicetype: RTSP
rtspnat: on

@ -0,0 +1,835 @@
# Copyright (c) 2017 Citrix Systems
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
from ansible.compat.tests.mock import patch, Mock, MagicMock, call
from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
import sys
if sys.version_info[:2] != (2, 6):
import requests
class TestNetscalerLBVServerModule(TestModule):
@classmethod
def setUpClass(cls):
class MockException(Exception):
pass
cls.MockException = MockException
m = MagicMock()
cls.server_mock = MagicMock()
cls.server_mock.__class__ = MagicMock(add=Mock())
nssrc_modules_mock = {
'nssrc.com.citrix.netscaler.nitro.resource.config.lb': m,
'nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbvserver': m,
'nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbvserver.lbvserver': m,
'nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding': m,
'nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.lbvserver_service_binding': m,
'nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbvserver_servicegroup_binding': m,
'nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbvserver_servicegroup_binding.lbvserver_servicegroup_binding': m,
'nssrc.com.citrix.netscaler.nitro.resource.config.ssl': m,
'nssrc.com.citrix.netscaler.nitro.resource.config.ssl.sslvserver_sslcertkey_binding': m,
'nssrc.com.citrix.netscaler.nitro.resource.config.ssl.sslvserver_sslcertkey_binding.sslvserver_sslcertkey_binding': m,
}
cls.nitro_specific_patcher = patch.dict(sys.modules, nssrc_modules_mock)
cls.nitro_base_patcher = nitro_base_patcher
@classmethod
def tearDownClass(cls):
cls.nitro_base_patcher.stop()
cls.nitro_specific_patcher.stop()
def setUp(self):
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
# Setup minimal required arguments to pass AnsibleModule argument parsing
def tearDown(self):
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
def test_graceful_nitro_api_import_error(self):
# Stop nitro api patching to cause ImportError
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
from ansible.modules.network.netscaler import netscaler_lb_vserver
self.module = netscaler_lb_vserver
result = self.failed()
self.assertEqual(result['msg'], 'Could not load nitro python sdk')
def test_graceful_nitro_error_on_login(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
class MockException(Exception):
def __init__(self, *args, **kwargs):
self.errorcode = 0
self.message = ''
client_mock = Mock()
client_mock.login = Mock(side_effect=MockException)
m = Mock(return_value=client_mock)
with patch('ansible.modules.network.netscaler.netscaler_lb_vserver.get_nitro_client', m):
with patch('ansible.modules.network.netscaler.netscaler_lb_vserver.nitro_exception', MockException):
self.module = netscaler_lb_vserver
result = self.failed()
self.assertTrue(result['msg'].startswith('nitro exception'), msg='nitro exception during login not handled properly')
def test_graceful_no_connection_error(self):
if sys.version_info[:2] == (2, 6):
self.skipTest('requests library not available under python2.6')
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
client_mock = Mock()
attrs = {'login.side_effect': requests.exceptions.ConnectionError}
client_mock.configure_mock(**attrs)
m = Mock(return_value=client_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=m,
nitro_exception=self.MockException,
):
self.module = netscaler_lb_vserver
result = self.failed()
self.assertTrue(result['msg'].startswith('Connection error'), msg='Connection error was not handled gracefully')
def test_graceful_login_error(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
if sys.version_info[:2] == (2, 6):
self.skipTest('requests library not available under python2.6')
client_mock = Mock()
attrs = {'login.side_effect': requests.exceptions.SSLError}
client_mock.configure_mock(**attrs)
m = Mock(return_value=client_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=m,
nitro_exception=self.MockException,
do_state_change=Mock(return_value=Mock(errorcode=0)),
):
self.module = netscaler_lb_vserver
result = self.failed()
self.assertTrue(result['msg'].startswith('SSL Error'), msg='SSL Error was not handled gracefully')
def test_save_config_called_on_state_present(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
client_mock = Mock()
m = Mock(return_value=client_mock)
lb_vserver_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=m,
lb_vserver_exists=Mock(side_effect=[False, True]),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
):
self.module = netscaler_lb_vserver
self.exited()
self.assertIn(call.save_config(), client_mock.mock_calls)
def test_save_config_called_on_state_absent(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
client_mock = Mock()
m = Mock(return_value=client_mock)
lb_vserver_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=m,
lb_vserver_exists=Mock(side_effect=[True, False]),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
):
self.module = netscaler_lb_vserver
self.exited()
self.assertIn(call.save_config(), client_mock.mock_calls)
def test_save_config_not_called_on_state_present(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
save_config=False,
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
client_mock = Mock()
m = Mock(return_value=client_mock)
lb_vserver_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=m,
lb_vserver_exists=Mock(side_effect=[False, True]),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
):
self.module = netscaler_lb_vserver
self.exited()
self.assertNotIn(call.save_config(), client_mock.mock_calls)
def test_save_config_not_called_on_state_absent(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
save_config=False,
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
client_mock = Mock()
m = Mock(return_value=client_mock)
lb_vserver_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=m,
lb_vserver_exists=Mock(side_effect=[True, False]),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
):
self.module = netscaler_lb_vserver
self.exited()
self.assertNotIn(call.save_config(), client_mock.mock_calls)
def test_ensure_feature_is_enabled_called(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
save_config=False,
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
client_mock = Mock()
lb_vserver_proxy_mock = Mock()
feature_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
lb_vserver_exists=Mock(side_effect=[True, True]),
lb_vserver_identical=Mock(side_effect=[True, True]),
servicegroup_bindings_identical=Mock(side_effect=[True, True]),
service_bindings_identical=Mock(side_effect=[True, True]),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=feature_mock,
do_state_change=Mock(return_value=Mock(errorcode=0)),
):
self.module = netscaler_lb_vserver
self.exited()
feature_mock.assert_called_with(client_mock, 'LB')
def test_ensure_feature_is_enabled_nitro_exception_caught(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
save_config=False,
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
client_mock = Mock()
lb_vserver_proxy_mock = Mock()
errorcode = 10
message = 'mock error'
class MockException(Exception):
def __init__(self):
self.errorcode = errorcode
self.message = message
feature_mock = Mock(side_effect=MockException)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
lb_vserver_exists=Mock(side_effect=[True, True]),
lb_vserver_identical=Mock(side_effect=[True, True]),
servicegroup_bindings_identical=Mock(side_effect=[True, True]),
service_bindings_identical=Mock(side_effect=[True, True]),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=feature_mock,
nitro_exception=MockException,
):
self.module = netscaler_lb_vserver
result = self.failed()
expected_msg = 'nitro exception errorcode=%s, message=%s' % (errorcode, message)
self.assertEqual(result['msg'], expected_msg, 'Failed to handle nitro exception')
def test_create_new_lb_vserver_workflow(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
save_config=False,
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=Mock()),
lb_vserver_exists=Mock(side_effect=[False, True]),
lb_vserver_identical=Mock(side_effect=[True]),
servicegroup_bindings_identical=Mock(side_effect=[True, True]),
service_bindings_identical=Mock(side_effect=[True, True]),
do_state_change=Mock(return_value=Mock(errorcode=0)),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
):
self.module = netscaler_lb_vserver
result = self.exited()
lb_vserver_proxy_mock.assert_has_calls([call.add()])
self.assertTrue(result['changed'])
def test_update_lb_vserver_workflow(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
save_config=False,
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=Mock()),
lb_vserver_exists=Mock(side_effect=[True, True]),
lb_vserver_identical=Mock(side_effect=[False, True]),
servicegroup_bindings_identical=Mock(side_effect=[True, True]),
service_bindings_identical=Mock(side_effect=[True, True]),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
get_immutables_intersection=Mock(return_value=[]),
):
self.module = netscaler_lb_vserver
result = self.exited()
lb_vserver_proxy_mock.assert_has_calls([call.update()])
self.assertTrue(result['changed'])
def test_service_bindings_handling(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
save_config=False,
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
configured_dict = {
'first': Mock(),
'second': Mock(has_equal_attributes=Mock(return_value=False)),
}
actual_dict = {
'second': Mock(),
'third': Mock(),
}
client_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
lb_vserver_exists=Mock(side_effect=[True, True]),
lb_vserver_identical=Mock(side_effect=[False, True]),
servicegroup_bindings_identical=Mock(side_effect=[True, True]),
service_bindings_identical=Mock(side_effect=[False, True]),
get_configured_service_bindings=Mock(return_value=configured_dict),
get_actual_service_bindings=Mock(return_value=actual_dict),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
get_immutables_intersection=(Mock(return_value=[])),
):
self.module = netscaler_lb_vserver
result = self.exited()
configured_dict['first'].assert_has_calls([call.add()])
configured_dict['second'].assert_has_calls([call.has_equal_attributes(actual_dict['second']), call.add()])
actual_dict['second'].assert_has_calls([call.delete(client_mock, actual_dict['second'])])
actual_dict['third'].assert_has_calls([call.delete(client_mock, actual_dict['third'])])
self.assertTrue(result['changed'])
def test_servicegroup_bindings_handling(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
save_config=False,
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
configured_dict = {
'first': Mock(),
'second': Mock(has_equal_attributes=Mock(return_value=False)),
}
actual_dict = {
'second': Mock(),
'third': Mock(),
}
client_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
lb_vserver_exists=Mock(side_effect=[True, True]),
lb_vserver_identical=Mock(side_effect=[False, True]),
servicegroup_bindings_identical=Mock(side_effect=[False, True]),
service_bindings_identical=Mock(side_effect=[True, True]),
get_configured_servicegroup_bindings=Mock(return_value=configured_dict),
get_actual_servicegroup_bindings=Mock(return_value=actual_dict),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
get_immutables_intersection=(Mock(return_value=[])),
):
self.module = netscaler_lb_vserver
result = self.exited()
configured_dict['first'].assert_has_calls([call.add()])
configured_dict['second'].assert_has_calls([call.has_equal_attributes(actual_dict['second']), call.add()])
actual_dict['second'].assert_has_calls([call.delete(client_mock, actual_dict['second'])])
actual_dict['third'].assert_has_calls([call.delete(client_mock, actual_dict['third'])])
self.assertTrue(result['changed'])
def test_ssl_bindings_handling(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
save_config=False,
servicetype='SSL',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
ssl_sync_mock = Mock()
client_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
lb_vserver_exists=Mock(side_effect=[True, True]),
lb_vserver_identical=Mock(side_effect=[False, True]),
servicegroup_bindings_identical=Mock(side_effect=[True, True]),
service_bindings_identical=Mock(side_effect=[True, True]),
ssl_certkey_bindings_identical=Mock(side_effect=[False, True]),
ssl_certkey_bindings_sync=ssl_sync_mock,
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
get_immutables_intersection=(Mock(return_value=[])),
nitro_exception=self.MockException,
):
self.module = netscaler_lb_vserver
result = self.exited()
self.assertTrue(len(ssl_sync_mock.mock_calls) > 0, msg='ssl cert_key bindings not called')
self.assertTrue(result['changed'])
def test_ssl_bindings_not_called_for_non_ssl_service(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
save_config=False,
servicetype='HTTP',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
ssl_sync_mock = Mock()
client_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
lb_vserver_exists=Mock(side_effect=[True, True]),
lb_vserver_identical=Mock(side_effect=[False, True]),
servicegroup_bindings_identical=Mock(side_effect=[True, True]),
service_bindings_identical=Mock(side_effect=[True, True]),
ssl_certkey_bindings_identical=Mock(side_effect=[False, True]),
ssl_certkey_bindings_sync=ssl_sync_mock,
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
get_immutables_intersection=(Mock(return_value=[])),
):
self.module = netscaler_lb_vserver
result = self.exited()
ssl_sync_mock.assert_not_called()
self.assertTrue(result['changed'])
def test_server_exists_sanity_check(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
ssl_sync_mock = Mock()
client_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
lb_vserver_exists=Mock(side_effect=[False, False]),
lb_vserver_identical=Mock(side_effect=[False, True]),
servicegroup_bindings_identical=Mock(side_effect=[True, True]),
service_bindings_identical=Mock(side_effect=[True, True]),
ssl_certkey_bindings_identical=Mock(side_effect=[False, True]),
ssl_certkey_bindings_sync=ssl_sync_mock,
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
nitro_exception=self.MockException,
):
self.module = netscaler_lb_vserver
result = self.failed()
self.assertEqual(result['msg'], 'Did not create lb vserver')
def test_server_identical_sanity_check(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
ssl_sync_mock = Mock()
client_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
lb_vserver_exists=Mock(side_effect=[True, True]),
lb_vserver_identical=Mock(side_effect=[False, False]),
servicegroup_bindings_identical=Mock(side_effect=[True, True]),
service_bindings_identical=Mock(side_effect=[True, True]),
ssl_certkey_bindings_identical=Mock(side_effect=[False, True]),
ssl_certkey_bindings_sync=ssl_sync_mock,
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
get_immutables_intersection=(Mock(return_value=[])),
nitro_exception=self.MockException,
):
self.module = netscaler_lb_vserver
result = self.failed()
self.assertEqual(result['msg'], 'lb vserver is not configured correctly')
def test_service_bindings_sanity_check(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
client_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
lb_vserver_exists=Mock(side_effect=[True, True]),
lb_vserver_identical=Mock(side_effect=[False, True]),
servicegroup_bindings_identical=Mock(side_effect=[True, True]),
service_bindings_identical=Mock(side_effect=[False, False]),
ssl_certkey_bindings_identical=Mock(side_effect=[False, False]),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
get_immutables_intersection=(Mock(return_value=[])),
nitro_exception=self.MockException,
):
self.module = netscaler_lb_vserver
result = self.failed()
self.assertEqual(result['msg'], 'service bindings are not identical')
def test_servicegroup_bindings_sanity_check(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
client_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
lb_vserver_exists=Mock(side_effect=[True, True]),
lb_vserver_identical=Mock(side_effect=[False, True]),
servicegroup_bindings_identical=Mock(side_effect=[False, False]),
service_bindings_identical=Mock(side_effect=[True, True]),
ssl_certkey_bindings_identical=Mock(side_effect=[False, False]),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
get_immutables_intersection=(Mock(return_value=[])),
nitro_exception=self.MockException,
):
self.module = netscaler_lb_vserver
result = self.failed()
self.assertEqual(result['msg'], 'servicegroup bindings are not identical')
def test_server_servicegroup_bindings_sanity_check(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
client_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
lb_vserver_exists=Mock(side_effect=[True, True]),
lb_vserver_identical=Mock(side_effect=[False, True]),
servicegroup_bindings_identical=Mock(side_effect=[False, False]),
service_bindings_identical=Mock(side_effect=[True, True]),
ssl_certkey_bindings_identical=Mock(side_effect=[False, False]),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
do_state_change=Mock(return_value=Mock(errorcode=0)),
get_immutables_intersection=(Mock(return_value=[])),
nitro_exception=self.MockException,
):
self.module = netscaler_lb_vserver
result = self.failed()
self.assertEqual(result['msg'], 'servicegroup bindings are not identical')
def test_absent_state_workflow(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
client_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
lb_vserver_exists=Mock(side_effect=[True, False]),
):
self.module = netscaler_lb_vserver
result = self.exited()
lb_vserver_proxy_mock.assert_has_calls([call.delete()])
self.assertTrue(result['changed'])
def test_absent_state_sanity_check(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
client_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
lb_vserver_exists=Mock(side_effect=[True, True]),
nitro_exception=self.MockException,
):
self.module = netscaler_lb_vserver
result = self.failed()
lb_vserver_proxy_mock.assert_has_calls([call.delete()])
self.assertEqual(result['msg'], 'lb vserver still exists')
def test_disabled_state_change_called(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
do_state_change_mock = Mock(return_value=Mock(errorcode=0))
client_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(return_value=True),
lb_vserver_exists=Mock(side_effect=[True, True]),
do_state_change=do_state_change_mock,
):
self.module = netscaler_lb_vserver
self.exited()
self.assertTrue(len(do_state_change_mock.mock_calls) > 0, msg='Did not call state change')
def test_get_immutables_failure(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_lb_vserver
lb_vserver_proxy_mock = Mock()
client_mock = Mock()
m = Mock(return_value=['some'])
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_lb_vserver',
get_nitro_client=Mock(return_value=client_mock),
ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
ensure_feature_is_enabled=Mock(),
lb_vserver_exists=Mock(side_effect=[True, True]),
lb_vserver_identical=Mock(side_effect=[False]),
do_state_change=Mock(return_value=Mock(errorcode=0)),
get_immutables_intersection=m,
nitro_exception=self.MockException,
):
self.module = netscaler_lb_vserver
result = self.failed()
self.assertTrue(
result['msg'].startswith('Cannot update immutable attributes'),
msg='Did not handle immutables error correctly',
)
Loading…
Cancel
Save