From f867bd6dbc5eafead576a64375ae532131e80ad6 Mon Sep 17 00:00:00 2001 From: lx <1120722567@qq.com> Date: Wed, 13 Nov 2019 17:47:03 +0800 Subject: [PATCH] improve(slb): Fix the error of passing parameters and add test --- .../modules/cloud/alicloud/ali_slb_server.py | 2 +- tests/ali_slb_server_test.yml | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 tests/ali_slb_server_test.yml diff --git a/lib/ansible/modules/cloud/alicloud/ali_slb_server.py b/lib/ansible/modules/cloud/alicloud/ali_slb_server.py index 05e9df75..8ce80079 100644 --- a/lib/ansible/modules/cloud/alicloud/ali_slb_server.py +++ b/lib/ansible/modules/cloud/alicloud/ali_slb_server.py @@ -190,7 +190,7 @@ def add_set_backend_servers(module, slb, load_balancer_id, backend_servers): try: - load_balancer_info = slb.describe_load_balancer_attribute(load_balancer_id) + load_balancer_info = slb.describe_load_balancer_attribute(load_balancer_id=load_balancer_id) # Verifying if server load balancer Object is present if load_balancer_info: diff --git a/tests/ali_slb_server_test.yml b/tests/ali_slb_server_test.yml new file mode 100644 index 00000000..965ee82b --- /dev/null +++ b/tests/ali_slb_server_test.yml @@ -0,0 +1,75 @@ +--- +- name: Validate module ali_slb_server + hosts: localhost + remote_user: root + + vars: + name: ansible-testacc-ali_slb_lb + + roles: + - vpc + - vswitch + - slb + - security_group + - instance + + tasks: + - name: Add backend servers + ali_slb_server: + lb_id: '{{ slbpri.load_balancer.id }}' + backend_servers: + - server_id: '{{instances.ids.0}}' + weight: 100 + - server_id: '{{instances.ids.1}}' + weight: 90 + + - name: Filter slb using name_regex + ali_slb_lb_info: + name_prefix: '{{name}}' + register: slbs + + - name: Remove backend servers + ali_slb_server: + lb_id: '{{ slbpri.load_balancer.id }}' + state: absent + backend_servers: + - server_id: '{{instances.ids.0}}' + weight: 100 + + - name: Filter slb using name_regex + ali_slb_lb_info: + name_prefix: '{{name}}' + register: slbs + + - name: Changed. Delete ecs instances + ali_instance: + instance_ids: '{{ instances.ids }}' + force: True + state: absent + + - name: Changed. Delete slb instance when C(absent) + ali_slb_lb: + name: '{{ item.name }}' + state: absent + with_items: '{{slbs.load_balancers}}' + + - name: Changed. Deleting security groups + ali_security_group: + name: '{{ item.group_name }}' + vpc_id: '{{item.vpc_id}}' + state: absent + with_items: '{{sgs.groups}}' + + - name: Changed. Deleting vswitches + ali_vswitch: + vpc_id: '{{ item.vpc_id}}' + cidr_block: '{{ item.cidr_block}}' + state: absent + with_items: '{{vswitches.vswitches}}' + + - name: Changed. Deleting vpcs + ali_vpc: + name: '{{item.vpc_name}}' + cidr_block: '{{item.cidr_block}}' + state: absent + with_items: '{{vpcs.vpcs}}'