azure_rm_webapp: fix updating app settings (#49181)

This commit is contained in:
Yunge Zhu 2019-01-04 16:32:36 +08:00 committed by GitHub
parent 06f0cde97d
commit 83da2de9a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 27 deletions

View file

@ -388,7 +388,7 @@ def webapp_to_dict(webapp):
class Actions:
NoAction, CreateOrUpdate, UpdateAppSettings, Delete = range(4)
CreateOrUpdate, UpdateAppSettings, Delete = range(3)
class AzureRMWebApps(AzureRMModuleBase):
@ -504,7 +504,7 @@ class AzureRMWebApps(AzureRMModuleBase):
id=None,
)
self.state = None
self.to_do = Actions.NoAction
self.to_do = []
self.frameworks = None
@ -642,7 +642,7 @@ class AzureRMWebApps(AzureRMModuleBase):
self.log("Web App instance doesn't exist")
to_be_updated = True
self.to_do = Actions.CreateOrUpdate
self.to_do.append(Actions.CreateOrUpdate)
self.site.tags = self.tags
# service plan is required for creation
@ -688,19 +688,19 @@ class AzureRMWebApps(AzureRMModuleBase):
# check if root level property changed
if self.is_updatable_property_changed(old_response):
to_be_updated = True
self.to_do = Actions.CreateOrUpdate
self.to_do.append(Actions.CreateOrUpdate)
# check if site_config changed
old_config = self.get_webapp_configuration()
if self.is_site_config_changed(old_config):
to_be_updated = True
self.to_do = Actions.CreateOrUpdate
self.to_do.append(Actions.CreateOrUpdate)
# check if linux_fx_version changed
if old_config.linux_fx_version != self.site_config.get('linux_fx_version', ''):
to_be_updated = True
self.to_do = Actions.CreateOrUpdate
self.to_do.append(Actions.CreateOrUpdate)
self.app_settings_strDic = self.list_app_settings()
@ -708,11 +708,12 @@ class AzureRMWebApps(AzureRMModuleBase):
if self.purge_app_settings:
to_be_updated = True
self.app_settings_strDic.properties = dict()
self.to_do.append(Actions.UpdateAppSettings)
# check if app settings changed
if self.purge_app_settings or self.is_app_settings_changed():
to_be_updated = True
self.to_do = Actions.CreateOrUpdate
self.to_do.append(Actions.UpdateAppSettings)
if self.app_settings:
for key in self.app_settings.keys():
@ -740,11 +741,15 @@ class AzureRMWebApps(AzureRMModuleBase):
if self.check_mode:
return self.results
if self.to_do == Actions.CreateOrUpdate:
if Actions.CreateOrUpdate in self.to_do:
response = self.create_update_webapp()
self.results['id'] = response['id']
if Actions.UpdateAppSettings in self.to_do:
update_response = self.update_app_settings()
self.results['id'] = update_response.id
webapp = None
if old_response:
webapp = old_response
@ -785,13 +790,11 @@ class AzureRMWebApps(AzureRMModuleBase):
# comparing existing app setting with input, determine whether it's changed
def is_app_settings_changed(self):
if self.app_settings:
if len(self.app_settings_strDic.properties) != len(self.app_settings):
return True
elif self.app_settings_strDic.properties and len(self.app_settings_strDic.properties) > 0:
if self.app_settings_strDic.properties:
for key in self.app_settings.keys():
if not self.app_settings_strDic.properties.get(key) \
or self.app_settings[key] != self.app_settings_strDic.properties[key]:
if self.app_settings[key] != self.app_settings_strDic.properties.get(key, None):
return True
else:
return True
return False
@ -943,10 +946,8 @@ class AzureRMWebApps(AzureRMModuleBase):
return response
except CloudError as ex:
self.log("Failed to list application settings for web app {0} in resource group {1}".format(
self.name, self.resource_group))
return False
self.fail("Failed to list application settings for web app {0} in resource group {1}: {2}".format(
self.name, self.resource_group, str(ex)))
def update_app_settings(self):
'''
@ -960,12 +961,10 @@ class AzureRMWebApps(AzureRMModuleBase):
resource_group_name=self.resource_group, name=self.name, app_settings=self.app_settings_strDic)
self.log("Response : {0}".format(response))
return response.as_dict()
return response
except CloudError as ex:
self.log("Failed to update application settings for web app {0} in resource group {1}".format(
self.name, self.resource_group))
return False
self.fail("Failed to update application settings for web app {0} in resource group {1}: {2}".format(
self.name, self.resource_group, str(ex)))
def create_or_update_source_control(self):
'''

View file

@ -101,24 +101,38 @@
- output.webapps[0].app_settings | length == 1
- output.webapps[0].frameworks | length > 1 # there's default frameworks eg net_framework
- name: Update app settings
- name: Update app settings and framework
azure_rm_webapp:
resource_group: "{{ resource_group }}"
name: "{{ win_app_name }}4"
plan: "{{ win_plan_name }}"
frameworks:
- name: "java"
version: "1.8"
version: "1.7"
settings:
java_container: "Tomcat"
java_container_version: "8.0"
java_container_version: "8.5"
app_settings:
testkey2: "testvalue2"
register: output
- name: Assert the web app was updated
assert:
that: output.changed
that:
- output.changed
- name: get web app with name
azure_rm_webapp_facts:
resource_group: "{{ resource_group }}"
name: "{{ win_app_name }}4"
register: output
- name: Assert updating
assert:
that:
- output.webapps[0].app_settings | length == 2
- output.webapps[0].app_settings['testkey'] == 'testvalue'
- output.webapps[0].app_settings['testkey2'] == 'testvalue2'
- name: get web app with return publishing profile
azure_rm_webapp_facts: