Skip to content

Commit

Permalink
Added the VM status detection mechanism (#772)
Browse files Browse the repository at this point in the history
* Set the parameter to a random number

* Update storage account name

Update azure_rm_virtualmachine vars

add new change

add new change 02

add new change 03

add new change 05

add new change 06

add new change 08

add new change09

update new

Update new 02

Improve code logic
  • Loading branch information
Fred-sun authored Mar 4, 2022
1 parent 199c7ee commit af6b034
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
14 changes: 13 additions & 1 deletion plugins/modules/azure_rm_virtualmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@
import base64
import random
import re
import time

try:
from msrestazure.azure_exceptions import CloudError
Expand Down Expand Up @@ -1108,7 +1109,18 @@ def exec_module(self, **kwargs):
try:
self.log("Fetching virtual machine {0}".format(self.name))
vm = self.compute_client.virtual_machines.get(self.resource_group, self.name, expand='instanceview')
self.check_provisioning_state(vm, self.state)
retry_count = 0
while True:
if retry_count == 10:
self.fail("Error {0} has a provisioning state of Updating. Expecting state to be Successed.".format(self.name))

if vm.provisioning_state == 'Updating':
retry_count = retry_count + 1
time.sleep(300)
vm = self.compute_client.virtual_machines.get(self.resource_group, self.name, expand='instanceview')
else:
break

vm_dict = self.serialize_vm(vm)

if self.state == 'present':
Expand Down
26 changes: 15 additions & 11 deletions tests/integration/targets/azure_rm_containerinstance/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
- name: Set Container Instance Names
set_fact:
rpfx: "{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"

- name: Create sample container instance
azure_rm_containerinstance:
resource_group: "{{ resource_group }}"
name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}"
name: "aci{{ rpfx }}"
os_type: linux
ip_address: public
location: eastus
Expand All @@ -28,7 +32,7 @@
- name: Create sample container instance -- same parameters
azure_rm_containerinstance:
resource_group: "{{ resource_group }}"
name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}"
name: "aci{{ rpfx }}"
os_type: linux
ip_address: public
location: eastus
Expand All @@ -51,7 +55,7 @@
- name: Create sample container instance -- force update
azure_rm_containerinstance:
resource_group: "{{ resource_group }}"
name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}"
name: "aci{{ rpfx }}"
os_type: linux
ip_address: public
location: eastus
Expand All @@ -76,7 +80,7 @@
- name: Create second container instance for testing purposes
azure_rm_containerinstance:
resource_group: "{{ resource_group }}"
name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}sec"
name: "aci{{ rpfx }}sec"
os_type: linux
ip_address: public
dns_name_label: mydnslabel{{ resource_group | hash('md5') | truncate(7, True, '') }}
Expand All @@ -99,7 +103,7 @@
- name: Gather facts for single Container Instance
azure_rm_containerinstance_info:
resource_group: "{{ resource_group }}"
name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}sec"
name: "aci{{ rpfx }}sec"
register: output

- debug:
Expand Down Expand Up @@ -146,7 +150,7 @@
- name: Create sample container instance with volume
azure_rm_containerinstance:
resource_group: "{{ resource_group }}"
name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}thi"
name: "aci{{ rpfx }}thi"
os_type: linux
ip_address: public
location: eastus
Expand Down Expand Up @@ -185,7 +189,7 @@
- name: Gather facts for Container Instance
azure_rm_containerinstance_info:
resource_group: "{{ resource_group }}"
name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}thi"
name: "aci{{ rpfx }}thi"
register: output
ignore_errors: True

Expand Down Expand Up @@ -213,7 +217,7 @@
- name: Remove container instance
azure_rm_containerinstance:
resource_group: "{{ resource_group }}"
name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}thi"
name: "aci{{ rpfx }}thi"
os_type: linux
ip_address: public
location: eastus
Expand Down Expand Up @@ -242,7 +246,7 @@
- name: Remove container instance
azure_rm_containerinstance:
resource_group: "{{ resource_group }}"
name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}"
name: "aci{{ rpfx }}"
os_type: linux
ip_address: public
location: eastus
Expand All @@ -266,7 +270,7 @@
- name: Remove container instance
azure_rm_containerinstance:
resource_group: "{{ resource_group }}"
name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}sec"
name: "aci{{ rpfx }}sec"
os_type: linux
ip_address: public
location: eastus
Expand All @@ -284,7 +288,7 @@
- name: Remove container instance again
azure_rm_containerinstance:
resource_group: "{{ resource_group }}"
name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}"
name: "aci{{ rpfx }}"
os_type: linux
ip_address: public
location: eastus
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/targets/azure_rm_gallery/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"
name: testVnet
name: "testVnet{{ rpfx }}"
address_prefixes: "10.0.0.0/16"

- name: Add subnet
azure_rm_subnet:
resource_group: "{{ resource_group }}"
name: testSubnet
name: "testSubnet{{ rpfx }}"
address_prefix: "10.0.1.0/24"
virtual_network: testVnet
virtual_network: "testVnet{{ rpfx }}"

- name: Create public IP address
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
allocation_method: Static
name: testPublicIP
name: "testPublicIP{{ rpfx }}"

- name: Create virtual network inteface cards for VM A and B
azure_rm_networkinterface:
resource_group: "{{ resource_group }}"
name: "vmforimage{{ rpfx }}nic"
virtual_network: testVnet
subnet: testSubnet
virtual_network: "testVnet{{ rpfx }}"
subnet: "testSubnet{{ rpfx }}"

- name: Create VM
azure_rm_virtualmachine:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ security_group: "{{ 'sg' ~ uid_short }}"
public_ip_name: "{{ 'ip' ~ uid_short }}"
interface_name: "{{ 'int' ~ uid_short }}"
network: 10.42.0.0/24
subnet: 10.42.0.0/28
subnet: 10.42.0.0/28

0 comments on commit af6b034

Please sign in to comment.