From 8e2fc00ef3708808f9976acced886dde57741200 Mon Sep 17 00:00:00 2001 From: He Guimin Date: Fri, 4 Jan 2019 13:16:37 +0800 Subject: [PATCH] Improve test cases --- CHANGELOG.md | 1 + tests/ali_eip_facts_test.yml | 3 + tests/ali_eip_test.yml | 1 + tests/ali_eni_facts_test.yml | 2 +- tests/ali_eni_test.yml | 2 +- tests/ali_instance_facts_test.yml | 12 ++- tests/ali_instance_test.yml | 15 +-- tests/ali_security_group_facts_test.yml | 2 +- tests/ali_security_group_test.yml | 2 +- tests/ali_slb_lb_facts_test.yml | 23 ++++- tests/ali_slb_lb_test.yml | 40 ++++++-- tests/ali_slb_vsg_facts_test.yml | 12 ++- tests/ali_slb_vsg_test.yml | 10 +- tests/ali_vpc_facts_test.yml | 2 +- tests/ali_vpc_test.yml | 2 +- tests/ali_vswitch_facts_test.yml | 2 +- tests/ali_vswitch_test.yml | 2 +- tests/destroy.yml | 128 ++++++++++++------------ tests/roles/instance/tasks/main.yml | 2 +- 19 files changed, 170 insertions(+), 93 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 116ac505..8a59a0e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ FEATURES: IMPROVEMENTS: +- Improve test cases ([#152](https://github.com/alibaba/ansible-provider/pull/152)) - Improve inventory alicloud.py meta and use public_ip_address instead eip_address ([#152](https://github.com/alibaba/ansible-provider/pull/152)) - Improve module ali_vpc and ali_security_group multi_ok ([#149](https://github.com/alibaba/ansible-provider/pull/149)) - Improve module ali_slb_vsg and ali_slb_vsg_facts ([#148](https://github.com/alibaba/ansible-provider/pull/148)) diff --git a/tests/ali_eip_facts_test.yml b/tests/ali_eip_facts_test.yml index 19868548..b547177e 100644 --- a/tests/ali_eip_facts_test.yml +++ b/tests/ali_eip_facts_test.yml @@ -3,6 +3,9 @@ hosts: localhost remote_user: root + vars: + name: ansible-testacc-ali_eip_facts-module + roles: - eip diff --git a/tests/ali_eip_test.yml b/tests/ali_eip_test.yml index eee5566a..f55f9098 100644 --- a/tests/ali_eip_test.yml +++ b/tests/ali_eip_test.yml @@ -5,6 +5,7 @@ vars: allocate_public_ip: False + name: ansible-testacc-ali_eip-module roles: - vpc diff --git a/tests/ali_eni_facts_test.yml b/tests/ali_eni_facts_test.yml index ff5457e4..cc3b2112 100644 --- a/tests/ali_eni_facts_test.yml +++ b/tests/ali_eni_facts_test.yml @@ -4,7 +4,7 @@ remote_user: root vars: - name: ansible-testacc-ali_eni_facts + name: ansible-testacc-ali_eni_facts-module roles: - vpc diff --git a/tests/ali_eni_test.yml b/tests/ali_eni_test.yml index 21a19905..b9fb0d5f 100644 --- a/tests/ali_eni_test.yml +++ b/tests/ali_eni_test.yml @@ -4,7 +4,7 @@ remote_user: root vars: - name: ansible-testacc-ali_eni + name: ansible-testacc-ali_eni-module roles: - vpc diff --git a/tests/ali_instance_facts_test.yml b/tests/ali_instance_facts_test.yml index a34d9c38..34a882ba 100644 --- a/tests/ali_instance_facts_test.yml +++ b/tests/ali_instance_facts_test.yml @@ -3,6 +3,9 @@ hosts: localhost remote_user: root + vars: + name: ansible-testacc-ali_instance_facts-module + roles: - vpc - vswitch @@ -61,19 +64,22 @@ - name: Changed. Deleting security groups ali_security_group: - group_id: '{{item.id}}' + name: '{{ item.group_name }}' + vpc_id: '{{item.vpc_id}}' state: absent with_items: '{{sgs.groups}}' - name: Changed. Deleting vswitches ali_vswitch: - id: '{{item.id}}' + vpc_id: '{{ item.vpc_id}}' + cidr_block: '{{ item.cidr_block}}' state: absent with_items: '{{vswitches.vswitches}}' - name: Changed. Deleting vpcs ali_vpc: - vpc_id: '{{item.id}}' + name: '{{item.vpc_name}}' + cidr_block: '{{item.cidr_block}}' state: absent with_items: '{{vpcs.vpcs}}' diff --git a/tests/ali_instance_test.yml b/tests/ali_instance_test.yml index d76af21e..e62005c7 100644 --- a/tests/ali_instance_test.yml +++ b/tests/ali_instance_test.yml @@ -13,7 +13,7 @@ - name: Changed. Modifying name, host name and description when C(present) ali_instance: instance_ids: '{{ instances.ids}}' - name: '{{ name }}-instance-modified' + name: '{{ name }}-modified' description: 'Test modify name, host name and description' host_name: 'modify-host-name' @@ -40,14 +40,14 @@ ali_instance: state: running instance_ids: '{{ instances.ids}}' - name: '{{ name }}-instance' + name: '{{ name }}' description: '{{instance_description}}' host_name: 'modify-host-name' - name: No Changed. There is no any attribute changed ali_instance: instance_ids: '{{ instances.ids}}' - name: '{{ name }}-instance' + name: '{{ name }}' description: '{{instance_description}}' host_name: 'modify-host-name' password: 'Test12345' @@ -100,19 +100,22 @@ - name: Changed. Deleting security groups ali_security_group: - group_id: '{{item.id}}' + name: '{{ item.group_name }}' + vpc_id: '{{item.vpc_id}}' state: absent with_items: '{{sgs.groups}}' - name: Changed. Deleting vswitches ali_vswitch: - id: '{{item.id}}' + vpc_id: '{{ item.vpc_id}}' + cidr_block: '{{ item.cidr_block}}' state: absent with_items: '{{vswitches.vswitches}}' - name: Changed. Deleting vpcs ali_vpc: - vpc_id: '{{item.id}}' + name: '{{item.vpc_name}}' + cidr_block: '{{item.cidr_block}}' state: absent with_items: '{{vpcs.vpcs}}' diff --git a/tests/ali_security_group_facts_test.yml b/tests/ali_security_group_facts_test.yml index ec68d579..157790f3 100644 --- a/tests/ali_security_group_facts_test.yml +++ b/tests/ali_security_group_facts_test.yml @@ -3,7 +3,7 @@ hosts: localhost remote_user: root vars: - name: ansible-testacc-ali_security_group_facts + name: ansible-testacc-ali_security_group_facts-module roles: - vpc - security_group diff --git a/tests/ali_security_group_test.yml b/tests/ali_security_group_test.yml index 8b5abe75..01cafeed 100644 --- a/tests/ali_security_group_test.yml +++ b/tests/ali_security_group_test.yml @@ -4,7 +4,7 @@ remote_user: root vars: - name: ansible-testacc-ali_security_group + name: ansible-testacc-ali_security_group-module roles: - vpc diff --git a/tests/ali_slb_lb_facts_test.yml b/tests/ali_slb_lb_facts_test.yml index 0e1826b1..ab6f9a17 100644 --- a/tests/ali_slb_lb_facts_test.yml +++ b/tests/ali_slb_lb_facts_test.yml @@ -3,17 +3,22 @@ hosts: localhost remote_user: root + vars: + name: ansible-testacc-ali_slb_lb_facts + roles: + - vpc + - vswitch - slb tasks: - name: Retrieving slbs using ids ali_slb_lb_facts: - ids: '{{slb.load_balancer.id}}' + ids: '{{slbpub.load_balancer.id}}' - name: Create a slb and used to test name_regex ali_slb_lb: - name: '{{name}}regex-slb' + name: '{{name}}regex' - name: Filter slb using name_regex ali_slb_lb_facts: @@ -33,3 +38,17 @@ state: absent with_items: '{{slbs.load_balancers}}' + - 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}}' + diff --git a/tests/ali_slb_lb_test.yml b/tests/ali_slb_lb_test.yml index 91d7bdb7..d1adfa0d 100644 --- a/tests/ali_slb_lb_test.yml +++ b/tests/ali_slb_lb_test.yml @@ -3,32 +3,60 @@ hosts: localhost remote_user: root + vars: + name: ansible-testacc-ali_slb_lb + roles: + - vpc + - vswitch - slb tasks: - name: Changed. Modifying internet charge type when C(present) ali_slb_lb: - name: '{{ slb.load_balancer.name }}' + name: '{{ slbpub.load_balancer.name }}' internet_charge_type: 'PayByBandwidth' bandwidth: 5 + - name: Filter slb using name_regex + ali_slb_lb_facts: + name_prefix: '{{name}}' + register: slbs + - name: Changed. Stop slb instance when C(stopped) ali_slb_lb: - name: '{{ slb.load_balancer.name }}' + name: '{{ item.name }}' state: stopped + with_items: '{{slbs.load_balancers}}' - name: Changed. Running slb instance when C(running) ali_slb_lb: - name: '{{ slb.load_balancer.name }}' + name: '{{ item.name }}' state: running + with_items: '{{slbs.load_balancers}}' - name: No Changed. There is no changed when C(running) ali_slb_lb: - name: '{{ slb.load_balancer.name }}' + name: '{{ item.name }}' state: running + with_items: '{{slbs.load_balancers}}' - name: Changed. Delete slb instance when C(absent) ali_slb_lb: - name: '{{ slb.load_balancer.name }}' - state: absent \ No newline at end of file + name: '{{ item.name }}' + state: absent + with_items: '{{slbs.load_balancers}}' + + - 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}}' diff --git a/tests/ali_slb_vsg_facts_test.yml b/tests/ali_slb_vsg_facts_test.yml index 8fc1c972..2f48fb8a 100644 --- a/tests/ali_slb_vsg_facts_test.yml +++ b/tests/ali_slb_vsg_facts_test.yml @@ -4,13 +4,13 @@ remote_user: root vars: number_of_instances: 2 - name: ansible-testacc-ali_slb_vsg_facts + name: ansible-testacc-ali_slb_vsg_facts-module roles: - vpc - vswitch - security_group - - slb - instance + - slb tasks: - name: Changed. Create a VServer Group in public SLB @@ -76,6 +76,14 @@ force: True state: absent + - name: Changed. Deleting security groups + ali_security_group: + name: '{{ item.group_name }}' + vpc_id: '{{item.vpc_id}}' + state: absent + with_items: '{{sgs.groups}}' + when: sgs.groups + - name: Changed. Deleting vswitches ali_vswitch: vpc_id: '{{ item.vpc_id}}' diff --git a/tests/ali_slb_vsg_test.yml b/tests/ali_slb_vsg_test.yml index 6991fa9b..b657cf0b 100644 --- a/tests/ali_slb_vsg_test.yml +++ b/tests/ali_slb_vsg_test.yml @@ -4,7 +4,7 @@ remote_user: root vars: number_of_instances: 4 - name: ansible-testacc-ali_slb_vsg + name: ansible-testacc-ali_slb_vsg-module roles: - vpc - vswitch @@ -198,6 +198,14 @@ force: True state: absent + - name: Changed. Deleting security groups + ali_security_group: + name: '{{ item.group_name }}' + vpc_id: '{{item.vpc_id}}' + state: absent + with_items: '{{sgs.groups}}' + when: sgs.groups + - name: Changed. Deleting vswitches ali_vswitch: vpc_id: '{{ item.vpc_id}}' diff --git a/tests/ali_vpc_facts_test.yml b/tests/ali_vpc_facts_test.yml index b23a064c..d352c5c6 100644 --- a/tests/ali_vpc_facts_test.yml +++ b/tests/ali_vpc_facts_test.yml @@ -4,7 +4,7 @@ remote_user: root vars: - name: ansible-testacc-ali_vpc_facts + name: ansible-testacc-ali_vpc_facts-module roles: - vpc diff --git a/tests/ali_vpc_test.yml b/tests/ali_vpc_test.yml index 4922c5f3..4fcecb8a 100644 --- a/tests/ali_vpc_test.yml +++ b/tests/ali_vpc_test.yml @@ -4,7 +4,7 @@ remote_user: root vars: - name: ansible-testacc-ali_vpc + name: ansible-testacc-ali_vpc-module roles: - vpc diff --git a/tests/ali_vswitch_facts_test.yml b/tests/ali_vswitch_facts_test.yml index 522fa678..3a282d79 100644 --- a/tests/ali_vswitch_facts_test.yml +++ b/tests/ali_vswitch_facts_test.yml @@ -4,7 +4,7 @@ remote_user: root vars: - name: ansible-testacc-ali_vswitch_facts + name: ansible-testacc-ali_vswitch_facts-module roles: - vpc diff --git a/tests/ali_vswitch_test.yml b/tests/ali_vswitch_test.yml index 6f582346..5e3b572b 100644 --- a/tests/ali_vswitch_test.yml +++ b/tests/ali_vswitch_test.yml @@ -4,7 +4,7 @@ remote_user: root vars: - name: ansible-testacc-ali_vswitch + name: ansible-testacc-ali_vswitch-module roles: - vpc diff --git a/tests/destroy.yml b/tests/destroy.yml index e3b463f5..a608b7ef 100644 --- a/tests/destroy.yml +++ b/tests/destroy.yml @@ -6,88 +6,88 @@ tasks: - name: Get the existing instances ali_instance_facts: - alicloud_region: '{{ alicloud_region }}' - alicloud_zone: '{{ alicloud_zone }}' - instance_names: - - '{{ instance_name }}' + name_prefix: '{{ name }}' register: instances - name: Delete the existing instances ali_instance: - alicloud_region: '{{ alicloud_region }}' - alicloud_zone: '{{ alicloud_zone }}' - instance_ids: - - '{{ instances.instances.0.id }}' - - '{{ instances.instances.1.id }}' + instance_ids: '{{ instances.ids.0.id }}' force: true state: absent - when: instances.instances + when: instances.ids +# +# - name: Get the existing disks +# ali_disk_facts: +# alicloud_region: '{{ alicloud_region }}' +# alicloud_zone: '{{ alicloud_zone }}' +# disk_names: +# - '{{ disk_name }}-0' +# - '{{ disk_name }}-1' +# register: disks +# +# - name: Delete the existing disk 0 +# ali_disk: +# alicloud_region: '{{ alicloud_region }}' +# alicloud_zone: '{{ alicloud_zone }}' +# disk_id: '{{ disks.disks.0.id }}' +# state: absent +# when: disks.disks +# +# - name: Delete the existing disk 1 +# ali_disk: +# alicloud_region: '{{ alicloud_region }}' +# alicloud_zone: '{{ alicloud_zone }}' +# disk_id: '{{ disks.disks.1.id}}' +# state: absent +# when: disks.disks - - name: Get the existing disks - ali_disk_facts: - alicloud_region: '{{ alicloud_region }}' - alicloud_zone: '{{ alicloud_zone }}' - disk_names: - - '{{ disk_name }}-0' - - '{{ disk_name }}-1' - register: disks - - - name: Delete the existing disk 0 - ali_disk: - alicloud_region: '{{ alicloud_region }}' - alicloud_zone: '{{ alicloud_zone }}' - disk_id: '{{ disks.disks.0.id }}' - state: absent - when: disks.disks - - - name: Delete the existing disk 1 - ali_disk: - alicloud_region: '{{ alicloud_region }}' - alicloud_zone: '{{ alicloud_zone }}' - disk_id: '{{ disks.disks.1.id}}' - state: absent - when: disks.disks - - - name: Get the existing vpc - ali_vpc_facts: - region: '{{alicloud_region}}' - vpc_name: '{{vpc_name}}' - register: vpcs - - - name: Get the existing groups + - name: Retrieving all security groups based on name_regex ali_security_group_facts: - region: '{{alicloud_region}}' - filters: - vpc_id: '{{vpcs.vpcs.0.id}}' - when: vpcs.vpcs + name_prefix: '{{name}}' register: sgs - - name: Delete the existing security groups + - name: Changed. Deleting security groups ali_security_group: - alicloud_region: '{{ alicloud_region }}' - group_id: '{{ sgs.groups.0.id}}' + name: '{{ item.group_name }}' + vpc_id: '{{item.vpc_id}}' + state: absent + with_items: '{{sgs.groups}}' + when: sgs.groups + + - name: Retrieving all slbs based on name_regex + ali_slb_lb_facts: + name_prefix: '{{name}}' + register: slbs + + - name: Changed. Deleting slbs + ali_slb_lb: + name: '{{ item.name }}' state: absent - when: sgs.ids + with_items: '{{slbs.load_balancers}}' + when: slbs.load_balancers - - name: Get the existing vswitches + - name: Retrieving all vswitches based on name_regex ali_vswitch_facts: - region: '{{alicloud_region}}' - filters: - vpc_id: '{{vpcs.vpcs.0.id}}' - when: vpcs.vpcs - register: vsws + name_prefix: '{{name}}' + register: vswitches - - name: Delete the existing vswitch + - name: Changed. Deleting vswitches ali_vswitch: - alicloud_region: '{{ alicloud_region }}' - alicloud_zone: '{{ alicloud_zone }}' - vswitch_id: '{{ vsws.vswitches.0.id }}' + vpc_id: '{{ item.vpc_id}}' + cidr_block: '{{ item.cidr_block}}' state: absent - when: vsws.vswitches + with_items: '{{vswitches.vswitches}}' + when: vswitches.vswitches + + - name: Get the existing vpc + ali_vpc_facts: + name_prefix: '{{name}}' + register: vpcs - - name: Delete the existing vpc + - name: Changed. Deleting vpcs ali_vpc: - alicloud_region: '{{ alicloud_region }}' - vpc_id: '{{ vpcs.vpcs.0.id}}' + cidr_block: '{{ item.cidr_block }}' + name: '{{ item.vpc_name }}' state: absent + with_items: '{{vpcs.vpcs}}' when: vpcs.vpcs \ No newline at end of file diff --git a/tests/roles/instance/tasks/main.yml b/tests/roles/instance/tasks/main.yml index aefe57ab..3c830b06 100644 --- a/tests/roles/instance/tasks/main.yml +++ b/tests/roles/instance/tasks/main.yml @@ -11,7 +11,7 @@ ali_instance: image: '{{ image_id }}' type: '{{ instance_type }}' - instance_name: '{{ name }}-instance' + instance_name: '{{ name }}' description: '{{ instance_description }}' host_name: '{{ host_name }}' password: '{{ password }}'