Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust test cases to fix resource interuse issues #1354

Merged
merged 14 commits into from Dec 11, 2023
11 changes: 11 additions & 0 deletions plugins/modules/azure_rm_virtualmachine.py
Expand Up @@ -2250,7 +2250,18 @@ def get_vm(self):
:return: VirtualMachine object
'''
try:
retry_count = 0
vm = self.compute_client.virtual_machines.get(self.resource_group, self.name, expand='instanceview')
while True:
if retry_count == 20:
self.fail("Error {0} has a provisioning state of Updating. Expecting state to be Successed.".format(self.name))

if vm.provisioning_state != 'Succeeded':
retry_count = retry_count + 1
time.sleep(150)
vm = self.compute_client.virtual_machines.get(self.resource_group, self.name, expand='instanceview')
else:
break
return vm
except Exception as exc:
self.fail("Error getting virtual machine {0} - {1}".format(self.name, str(exc)))
Expand Down
12 changes: 12 additions & 0 deletions plugins/modules/azure_rm_virtualmachinescaleset.py
Expand Up @@ -647,6 +647,7 @@
''' # NOQA

import base64
import time

try:
from azure.core.exceptions import ResourceNotFoundError
Expand Down Expand Up @@ -1378,7 +1379,18 @@ def get_vmss(self):
:return: VirtualMachineScaleSet object
'''
try:
retry_count = 0
vmss = self.compute_client.virtual_machine_scale_sets.get(self.resource_group, self.name)
while True:
if retry_count == 20:
self.fail("Error {0} has a provisioning state of Updating. Expecting state to be Successed.".format(self.name))

if vmss.provisioning_state != 'Succeeded':
retry_count = retry_count + 1
time.sleep(150)
vmss = self.compute_client.virtual_machine_scale_sets.get(self.resource_group, self.name)
else:
break
return vmss
except ResourceNotFoundError as exc:
self.fail("Error getting virtual machine scale set {0} - {1}".format(self.name, str(exc)))
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/targets/azure_rm_cdnprofile/tasks/main.yml
Expand Up @@ -24,7 +24,8 @@

- name: Check there is no CDN profile created
ansible.builtin.assert:
{ that: "{{ fact.cdnprofiles | length }} == 0" }
that:
- fact.cdnprofiles | length == 0

- name: Create a CDN profile
azure_rm_cdnprofile:
Expand Down
Expand Up @@ -71,7 +71,7 @@
- output.changed
- output.state.virtual_network_rules | length == 1
- output.state.virtual_network_rules[0].name == "vnet_rule_1"
- output.state.virtual_network_rules[0].subnet_id == "{{ subnet_output.state.id }}"
- output.state.virtual_network_rules[0].subnet_id == subnet_output.state.id

- name: Update data lake store to change encryption state that must fail
azure_rm_datalakestore:
Expand Down Expand Up @@ -154,7 +154,7 @@
- output.state.trusted_id_provider_state == "Disabled"
- output.state.virtual_network_rules | length == 1
- output.state.virtual_network_rules[0].name == "vnet_rule_1"
- output.state.virtual_network_rules[0].subnet_id == "{{ subnet_output.state.id }}"
- output.state.virtual_network_rules[0].subnet_id == subnet_output.state.id

- name: Create new data lake store (Idempotence)
azure_rm_datalakestore:
Expand Down
Expand Up @@ -64,7 +64,7 @@
- name: Assert the registration assignment facts
ansible.builtin.assert:
that:
- output.registration_assignments[0].properties.registration_definition_id == "{{ output1.state.id }}"
- output.registration_assignments[0].properties.registration_definition_id == output1.state.id

- name: Get all RegistrationAssignment
azure_rm_registrationassignment_info:
Expand Down
Expand Up @@ -100,7 +100,7 @@
- name: Assert the registration definition info
ansible.builtin.assert:
that:
- output.registration_definitions[0].name == "{{ output1.state.name }}"
- output.registration_definitions[0].name == output1.state.name
- output.registration_definitions[0].properties.authorizations[0].principal_id == "{{ principal_id }}"
- output.registration_definitions[0].properties.authorizations[0].role_definition_id == "{{ role_definition_id }}"
- output.registration_definitions[0].properties.provisioning_state == "Succeeded"
Expand Down
11 changes: 6 additions & 5 deletions tests/integration/targets/azure_rm_securitygroup/tasks/main.yml
Expand Up @@ -33,7 +33,8 @@
register: output
- name: Assert resource created
ansible.builtin.assert:
that: "{{ output.state.rules | length }} == 2"
that:
- output.state.rules | length == 2

- name: Gather facts by tags
azure_rm_securitygroup_info:
Expand Down Expand Up @@ -80,7 +81,7 @@
- name: Assert resource updated
ansible.builtin.assert:
that:
- "{{ output.state.rules | length }} == 4"
- output.state.rules | length== 4
- output.state.rules[0].source_address_prefix == '174.108.158.0/24'

- name: Gather facts after update
Expand Down Expand Up @@ -197,8 +198,8 @@
- name: Assert resource created
ansible.builtin.assert:
that:
- "{{ output.state.rules | length }} == 1"
- "{{ output.state.rules[0].source_address_prefixes | length }} == 3"
- output.state.rules | length == 1
- output.state.rules[0].source_address_prefixes | length == 3
- not output.state.rules[0].source_address_prefix

- name: Create security group with source_address_prefixes(idempotent)
Expand Down Expand Up @@ -248,7 +249,7 @@
ansible.builtin.assert:
that:
- output.changed
- "{{ output.state.rules | length }} == 2"
- output.state.rules | length == 2

# Use azure_rm_resource module to create with uppercase protocol name
- name: Create security group with uppercase protocol name
Expand Down
Expand Up @@ -33,7 +33,9 @@
register: fact

- name: Check there is no Traffic Manager profile created
ansible.builtin.assert: { that: "{{ fact.tms | length }} == 0" }
ansible.builtin.assert:
that:
- fact.tms | length == 0

- name: Create a Traffic Manager profile
azure_rm_trafficmanagerprofile:
Expand Down Expand Up @@ -69,7 +71,7 @@
- name: Assert fact returns the created one
ansible.builtin.assert:
that:
- "fact.tms | length == 1"
- fact.tms | length == 1
- fact.tms[0].id == tm.id
- fact.tms[0].endpoints | length == 0

Expand Down Expand Up @@ -261,7 +263,7 @@
- name: Assert the traffic manager profile is still there
ansible.builtin.assert:
that:
- "fact.tms | length == 1"
- fact.tms | length == 1
- fact.tms[0].id == tm.id
- fact.tms[0].endpoints | length == 1

Expand All @@ -286,4 +288,4 @@
- name: Assert fact returns empty
ansible.builtin.assert:
that:
- "fact.tms | length == 0"
- fact.tms | length == 0
Expand Up @@ -21,24 +21,28 @@
resource_group: "{{ resource_group }}"
allocation_method: Static
name: testPublicIP
sku: Standard

- name: Create load balancer
azure_rm_loadbalancer:
resource_group: "{{ resource_group }}"
name: testLB
public_ip_address_name: testPublicIP
sku: Standard

- name: Create public IP address 1
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
allocation_method: Static
name: testPublicIP1
sku: Standard

- name: Create load balancer 1
azure_rm_loadbalancer:
resource_group: "{{ resource_group }}"
name: testLB1
public_ip_address_name: testPublicIP1
sku: Standard

- name: Create network security group within same resource group of VMSS.
azure_rm_securitygroup:
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/targets/inventory_azure/playbooks/setup.yml
Expand Up @@ -47,3 +47,7 @@
sku: 20_04-lts
version: latest
register: vm_output

- name: Pause for 5 mimutes for updating
ansible.builtin.command: sleep 300
changed_when: false
Expand Up @@ -7,10 +7,6 @@
- name: Set facts
ansible.builtin.include_vars: vars.yml

- name: Pause for 10 mimutes for updating
ansible.builtin.command: sleep 600
changed_when: false

- name: Refresh inventory
ansible.builtin.meta: refresh_inventory

Expand Down