add wait_for_running option in azure_rm_rediscache module (#54976)
This commit is contained in:
parent
e12846f540
commit
ed1334fbe3
2 changed files with 55 additions and 13 deletions
|
@ -131,6 +131,14 @@ options:
|
|||
choices:
|
||||
- primary
|
||||
- secondary
|
||||
wait_for_provisioning:
|
||||
description:
|
||||
- Wait till the Azure Cache for Redis instance provisioning_state is Succeeded.
|
||||
- It takes several minutes for Azure Cache for Redis to be provisioned ready for use after creating/updating/rebooting.
|
||||
- Set this option to true to wait for provisioning_state. Set to false if you don't care about provisioning_state.
|
||||
- Poll wait timeout is 60 minutes.
|
||||
type: bool
|
||||
default: True
|
||||
state:
|
||||
description:
|
||||
- Assert the state of the Azure Cache for Redis.
|
||||
|
@ -209,8 +217,8 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase
|
|||
|
||||
try:
|
||||
from msrestazure.azure_exceptions import CloudError
|
||||
from msrest.polling import LROPoller
|
||||
from msrestazure.azure_operation import AzureOperationPoller
|
||||
from msrest.polling import LROPoller
|
||||
from msrest.serialization import Model
|
||||
from azure.mgmt.redis import RedisManagementClient
|
||||
from azure.mgmt.redis.models import (RedisCreateParameters, RedisUpdateParameters, Sku)
|
||||
|
@ -366,6 +374,10 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
regenerate_key=dict(
|
||||
type='dict',
|
||||
options=regenerate_key_spec
|
||||
),
|
||||
wait_for_provisioning=dict(
|
||||
type='bool',
|
||||
default='True'
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -386,6 +398,10 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
self.reboot = None
|
||||
self.regenerate_key = None
|
||||
|
||||
self.wait_for_provisioning = None
|
||||
self.wait_for_provisioning_polling_interval_in_seconds = 30
|
||||
self.wait_for_provisioning_polling_times = 120
|
||||
|
||||
self.tags = None
|
||||
|
||||
self.results = dict(
|
||||
|
@ -562,9 +578,12 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
response = self._client.redis.create(resource_group_name=self.resource_group,
|
||||
name=self.name,
|
||||
parameters=params)
|
||||
if isinstance(response, LROPoller) or isinstance(response, AzureOperationPoller):
|
||||
if isinstance(response, AzureOperationPoller) or isinstance(response, LROPoller):
|
||||
response = self.get_poller_result(response)
|
||||
|
||||
if self.wait_for_provisioning:
|
||||
self.wait_for_redis_running()
|
||||
|
||||
except CloudError as exc:
|
||||
self.log('Error attempting to create the Azure Cache for Redis instance.')
|
||||
self.fail(
|
||||
|
@ -598,9 +617,12 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
response = self._client.redis.update(resource_group_name=self.resource_group,
|
||||
name=self.name,
|
||||
parameters=params)
|
||||
if isinstance(response, LROPoller) or isinstance(response, AzureOperationPoller):
|
||||
if isinstance(response, AzureOperationPoller) or isinstance(response, LROPoller):
|
||||
response = self.get_poller_result(response)
|
||||
|
||||
if self.wait_for_provisioning:
|
||||
self.wait_for_redis_running()
|
||||
|
||||
except CloudError as exc:
|
||||
self.log('Error attempting to update the Azure Cache for Redis instance.')
|
||||
self.fail(
|
||||
|
@ -659,6 +681,11 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
name=self.name,
|
||||
reboot_type=self.reboot['reboot_type'],
|
||||
shard_id=self.reboot.get('shard_id'))
|
||||
if isinstance(response, AzureOperationPoller) or isinstance(response, LROPoller):
|
||||
response = self.get_poller_result(response)
|
||||
|
||||
if self.wait_for_provisioning:
|
||||
self.wait_for_redis_running()
|
||||
except CloudError as e:
|
||||
self.log('Error attempting to force reboot the redis cache instance.')
|
||||
self.fail(
|
||||
|
@ -718,6 +745,24 @@ class AzureRMRedisCaches(AzureRMModuleBase):
|
|||
subnet_id = self.subnet
|
||||
return subnet_id
|
||||
|
||||
def wait_for_redis_running(self):
|
||||
try:
|
||||
response = self._client.redis.get(resource_group_name=self.resource_group, name=self.name)
|
||||
status = response.provisioning_state
|
||||
polling_times = 0
|
||||
|
||||
while polling_times < self.wait_for_provisioning_polling_times:
|
||||
if status.lower() != "succeeded":
|
||||
polling_times += 1
|
||||
time.sleep(self.wait_for_provisioning_polling_interval_in_seconds)
|
||||
response = self._client.redis.get(resource_group_name=self.resource_group, name=self.name)
|
||||
status = response.provisioning_state
|
||||
else:
|
||||
return True
|
||||
self.fail("Azure Cache for Redis is not running after 60 mins.")
|
||||
except CloudError as e:
|
||||
self.fail("Failed to get Azure Cache for Redis: {0}".format(str(e)))
|
||||
|
||||
|
||||
def main():
|
||||
"""Main execution"""
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
sku:
|
||||
name: basic
|
||||
size: C1
|
||||
wait_for_provisioning: False
|
||||
check_mode: yes
|
||||
register: output
|
||||
|
||||
|
@ -28,6 +29,7 @@
|
|||
sku:
|
||||
name: basic
|
||||
size: C1
|
||||
wait_for_provisioning: False
|
||||
register: output
|
||||
|
||||
- name: Assert creating redis cache
|
||||
|
@ -59,6 +61,7 @@
|
|||
sku:
|
||||
name: basic
|
||||
size: C1
|
||||
wait_for_provisioning: False
|
||||
register: output
|
||||
|
||||
- name: assert output not changed
|
||||
|
@ -92,6 +95,7 @@
|
|||
enable_non_ssl_port: true
|
||||
tags:
|
||||
testing: foo
|
||||
wait_for_provisioning: True
|
||||
register: output
|
||||
|
||||
- name: assert output changed
|
||||
|
@ -106,7 +110,7 @@
|
|||
sku:
|
||||
name: basic
|
||||
size: C1
|
||||
enable_non_ssl_port: true
|
||||
enable_non_ssl_port: True
|
||||
maxmemory_policy: allkeys_lru
|
||||
tags:
|
||||
testing: foo
|
||||
|
@ -126,21 +130,13 @@
|
|||
size: C1
|
||||
tags:
|
||||
testing: foo
|
||||
wait_for_provisioning: True
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
|
||||
- name: Wait for Redis provisioning to complete
|
||||
azure_rm_rediscache_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "{{ redis_name }}"
|
||||
register: facts
|
||||
until: facts.rediscaches[0]['provisioning_state'] == 'Succeeded'
|
||||
retries: 30
|
||||
delay: 60
|
||||
|
||||
- name: Force reboot redis cache
|
||||
azure_rm_rediscache:
|
||||
resource_group: "{{ resource_group }}"
|
||||
|
@ -201,6 +197,7 @@
|
|||
subnet:
|
||||
name: "{{ subnet_name }}"
|
||||
virtual_network_name: "{{ vnet_name }}"
|
||||
wait_for_provisioning: False
|
||||
register: output
|
||||
|
||||
- name: Assert creating redis cache
|
||||
|
|
Loading…
Reference in a new issue