forked from ansible-collections/azure
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ansible-collections#1 from ansible-collections/loa…
…d_balancer_role load_balancer, virtual_machine, and network_interface roles and Molecule Tests
- Loading branch information
Showing
19 changed files
with
1,241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
--- | ||
- name: define resource group name | ||
set_fact: | ||
resource_group: "test-{{ lookup('password', '/dev/null chars=ascii_lowercase,digits length=6') }}" | ||
azure_tags: | ||
cloud.azure_roles: load_balancer | ||
|
||
- name: define load balancer variables | ||
set_fact: | ||
azure_resource_group: "{{ resource_group }}" | ||
azure_region: 'canadacentral' | ||
azure_lb_name: "{{ resource_group }}-lb" | ||
|
||
- name: Test load balancer role | ||
block: | ||
- name: Test valid creation of load balancer with no public ip specified | ||
block: | ||
- name: Create load balancer | ||
include_role: | ||
name: load_balancer | ||
vars: | ||
operation: "create" | ||
|
||
- name: Get resource group info | ||
azure_rm_resourcegroup_info: | ||
name: '{{ azure_resource_group }}' | ||
register: rg | ||
|
||
- name: Assert that resource group was created | ||
assert: | ||
that: | ||
- rg.resourcegroups | length == 1 | ||
|
||
- name: Get lb info | ||
azure_rm_loadbalancer_info: | ||
resource_group: '{{ azure_resource_group }}' | ||
register: lb_info | ||
|
||
- name: Assert that load balancer was successfully created & a public IP was assigned | ||
assert: | ||
that: | ||
- lb_info.ansible_info.azure_loadbalancers | length == 1 | ||
- lb_info.ansible_info.azure_loadbalancers[0].properties.frontendIPConfigurations[0].properties.publicIPAddress is not none | ||
|
||
- name: Delete load balancer | ||
include_role: | ||
name: load_balancer | ||
vars: | ||
operation: 'delete' | ||
|
||
- name: Assert resource group still exists | ||
azure_rm_resourcegroup_info: | ||
name: '{{ azure_resource_group }}' | ||
register: rg | ||
|
||
- assert: | ||
that: | ||
- rg.resourcegroups | length == 1 | ||
|
||
- name: Assert that load balancer was deleted | ||
azure_rm_loadbalancer_info: | ||
resource_group: '{{ azure_resource_group }}' | ||
register: lb_info | ||
|
||
- assert: | ||
that: | ||
- lb_info.ansible_info.azure_loadbalancers | length == 0 | ||
|
||
- name: Test valid creation of load balancer with public ip specified | ||
block: | ||
- name: Set public IP name | ||
set_fact: | ||
azure_lb_pip_name: 'testinput' | ||
|
||
- name: Create load balancer | ||
include_role: | ||
name: load_balancer | ||
vars: | ||
operation: "create" | ||
|
||
- name: Get resource group info | ||
azure_rm_resourcegroup_info: | ||
name: '{{ azure_resource_group }}' | ||
register: rg | ||
|
||
- name: Assert that resource group was created | ||
assert: | ||
that: | ||
- rg.resourcegroups | length == 1 | ||
|
||
- name: Get lb info | ||
azure_rm_loadbalancer_info: | ||
resource_group: '{{ azure_resource_group }}' | ||
register: lb_info | ||
|
||
- name: Assert that load balancer was successfully created & a public IP was assigned | ||
assert: | ||
that: | ||
- lb_info.ansible_info.azure_loadbalancers | length == 1 | ||
- azure_lb_pip_name in lb_info.ansible_info.azure_loadbalancers[0].properties.frontendIPConfigurations[0].properties.publicIPAddress.id | ||
|
||
- name: Delete load balancer | ||
include_role: | ||
name: load_balancer | ||
vars: | ||
operation: 'delete' | ||
|
||
- name: Assert resource group still exists | ||
azure_rm_resourcegroup_info: | ||
name: '{{ azure_resource_group }}' | ||
register: rg | ||
|
||
- assert: | ||
that: | ||
- rg.resourcegroups | length == 1 | ||
|
||
- name: Assert that load balancer was deleted | ||
azure_rm_loadbalancer_info: | ||
resource_group: '{{ azure_resource_group }}' | ||
register: lb_info | ||
|
||
- assert: | ||
that: | ||
- lb_info.ansible_info.azure_loadbalancers | length == 0 | ||
|
||
- name: Test adding NICs to load balancer | ||
block: | ||
- name: Set networking variables to create NICs | ||
set_fact: | ||
azure_lb_network_interface_instances: | ||
- "{{ resource_group }}-nic1" | ||
- "{{ resource_group }}-nic2" | ||
- "{{ resource_group }}-nic3" | ||
azure_virtual_network: "{{ resource_group }}-vnet-00" | ||
azure_subnet: "{{ resource_group }}-subnet-00" | ||
azure_vnet_address_prefixes_cidr: | ||
- 10.16.0.0/16 | ||
azure_subnet_address_prefixes_cidr: 10.16.0.0/24 | ||
|
||
- name: Create load balancer with supplied nics attached | ||
include_role: | ||
name: load_balancer | ||
vars: | ||
operation: "create" | ||
|
||
- name: Get lb info | ||
azure_rm_loadbalancer_info: | ||
resource_group: '{{ azure_resource_group }}' | ||
register: lb_info | ||
|
||
- name: Assert that load balancer was successfully created & nics were attached | ||
assert: | ||
that: | ||
- lb_info.ansible_info.azure_loadbalancers | length == 1 | ||
- "{{ lb_info.ansible_info.azure_loadbalancers[0].properties.backendAddressPools[0].properties.backendIPConfigurations | length == ( azure_lb_network_interface_instances | length ) }}" | ||
|
||
- name: Test deleting NIC when attached to LB | ||
include_role: | ||
name: network_interface | ||
vars: | ||
operation: 'delete' | ||
azure_network_interface_name: "{{ resource_group }}-nic1" | ||
|
||
- name: Assert that NIC was deleted | ||
azure_rm_networkinterface_info: | ||
resource_group: '{{ azure_resource_group }}' | ||
name: "{{ resource_group }}-nic1" | ||
register: nic_info | ||
|
||
- assert: | ||
that: | ||
- nic_info.networkinterfaces | length == 0 | ||
|
||
always: | ||
- name: Delete resource group | ||
azure_rm_resourcegroup: | ||
name: "{{ azure_resource_group }}" | ||
state: absent | ||
force_delete_nonempty: yes | ||
ignore_errors: yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
--- | ||
- name: Define resource group name | ||
set_fact: | ||
resource_group: "test-{{ lookup('password', '/dev/null chars=ascii_lowercase,digits length=6') }}" | ||
azure_tags: | ||
cloud.azure_roles: network_interface | ||
|
||
- name: Define network interface variables | ||
set_fact: | ||
azure_resource_group: "{{ resource_group }}" | ||
azure_region: 'canadacentral' | ||
nic_instances: 2 | ||
azure_virtual_network: "{{ resource_group }}-vnet-00" | ||
azure_subnet: "{{ resource_group }}-subnet-00" | ||
azure_vnet_address_prefixes_cidr: | ||
- 10.16.0.0/16 | ||
azure_subnet_address_prefixes_cidr: 10.16.0.0/24 | ||
|
||
- name: Test network interface role | ||
block: | ||
- name: Test valid creation of network interface w/ no load balancer | ||
block: | ||
- name: Create NICs | ||
include_role: | ||
name: network_interface | ||
vars: | ||
operation: "create" | ||
azure_network_interface_name: "{{ resource_group }}-nic{{ idx }}" | ||
loop: "{{ range(0, (nic_instances | int)) | list }}" | ||
loop_control: | ||
index_var: idx | ||
|
||
- name: Get resource group info | ||
azure_rm_resourcegroup_info: | ||
name: '{{ azure_resource_group }}' | ||
register: rg | ||
|
||
- name: Assert that resource group was created | ||
assert: | ||
that: | ||
- rg.resourcegroups | length == 1 | ||
|
||
- azure_rm_networkinterface_info: | ||
resource_group: '{{ azure_resource_group }}' | ||
register: nics_info | ||
|
||
- name: Assert that network interfaces were successfully created | ||
assert: | ||
that: | ||
- "nics_info.networkinterfaces | length == {{ nic_instances | int }}" | ||
|
||
- name: Assert that network interface is not attached to load balancer | ||
assert: | ||
that: | ||
- nics_info.networkinterfaces[0].ip_configurations[0].load_balancer_backend_address_pools is none | ||
|
||
- name: Test updating network interface w/ load balancer | ||
block: | ||
- name: Update NICs | ||
include_role: | ||
name: network_interface | ||
vars: | ||
operation: "create" | ||
azure_lb_name: "{{ resource_group }}-lb" | ||
azure_network_interface_name: "{{ resource_group }}-nic{{ idx }}" | ||
loop: "{{ range(0, (nic_instances | int)) | list }}" | ||
loop_control: | ||
index_var: idx | ||
|
||
- azure_rm_networkinterface_info: | ||
resource_group: '{{ azure_resource_group }}' | ||
register: nics_info | ||
|
||
- name: Assert that network interfaces still exist | ||
assert: | ||
that: | ||
- "nics_info.networkinterfaces | length == {{ nic_instances | int }}" | ||
|
||
- name: Assert that network interface is attached to load balancer | ||
assert: | ||
that: | ||
- nics_info.networkinterfaces[0].ip_configurations[0].load_balancer_backend_address_pools is not none | ||
|
||
- name: Test deletion of network interfaces | ||
block: | ||
- name: Delete NICs | ||
include_role: | ||
name: network_interface | ||
vars: | ||
operation: "delete" | ||
azure_network_interface_name: "{{ resource_group }}-nic{{ idx }}" | ||
loop: "{{ range(0, (nic_instances | int)) | list }}" | ||
loop_control: | ||
index_var: idx | ||
|
||
- azure_rm_networkinterface_info: | ||
resource_group: '{{ azure_resource_group }}' | ||
register: nics_info | ||
|
||
- name: Assert that network interfaces were successfully deleted | ||
assert: | ||
that: | ||
- nics_info.networkinterfaces | length == 0 | ||
|
||
- name: Test creating network interface w/ load balancer | ||
block: | ||
- name: Create NICs w/ load balancer | ||
include_role: | ||
name: network_interface | ||
vars: | ||
operation: "create" | ||
azure_lb_name: "{{ resource_group }}-lb" | ||
azure_network_interface_name: "{{ resource_group }}-nic{{ idx }}" | ||
loop: "{{ range(0, (nic_instances | int)) | list }}" | ||
loop_control: | ||
index_var: idx | ||
|
||
- azure_rm_networkinterface_info: | ||
resource_group: '{{ azure_resource_group }}' | ||
register: nics_info | ||
|
||
- name: Assert that network interfaces were created | ||
assert: | ||
that: | ||
- "nics_info.networkinterfaces | length == {{ nic_instances | int }}" | ||
|
||
- name: Assert that network interface is attached to load balancer | ||
assert: | ||
that: | ||
- nics_info.networkinterfaces[0].ip_configurations[0].load_balancer_backend_address_pools is not none | ||
|
||
- name: Test updating network interface to remove load balancer | ||
block: | ||
- name: Update NICs | ||
include_role: | ||
name: network_interface | ||
vars: | ||
operation: "create" | ||
azure_network_interface_name: "{{ resource_group }}-nic{{ idx }}" | ||
loop: "{{ range(0, (nic_instances | int)) | list }}" | ||
loop_control: | ||
index_var: idx | ||
|
||
- azure_rm_networkinterface_info: | ||
resource_group: '{{ azure_resource_group }}' | ||
register: nics_info | ||
|
||
- name: Assert that network interfaces still exist | ||
assert: | ||
that: | ||
- "nics_info.networkinterfaces | length == {{ nic_instances | int }}" | ||
|
||
- name: Assert that network interface is not attached to load balancer | ||
assert: | ||
that: | ||
- nics_info.networkinterfaces[0].ip_configurations[0].load_balancer_backend_address_pools is none | ||
|
||
always: | ||
- name: Delete resource group | ||
azure_rm_resourcegroup: | ||
name: "{{ azure_resource_group }}" | ||
state: absent | ||
force_delete_nonempty: yes | ||
ignore_errors: yes |
Oops, something went wrong.