From 474d76c0dde91fa446d0aeb4fa267e28ff471077 Mon Sep 17 00:00:00 2001 From: Zim Kalinowski Date: Mon, 18 Feb 2019 14:04:01 +0800 Subject: [PATCH] Fixing azure_rm_postgresqldatabase force_update parameter (#52388) (cherry picked from commit 8422e23533f44cf9c5b22f5102fba7cbaa09bdd5) --- ...88-postgresqldatabase-fix-force-update.yml | 2 ++ .../azure/azure_rm_postgresqldatabase.py | 2 ++ .../azure_rm_postgresqlserver/tasks/main.yml | 35 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 changelogs/fragments/52388-postgresqldatabase-fix-force-update.yml diff --git a/changelogs/fragments/52388-postgresqldatabase-fix-force-update.yml b/changelogs/fragments/52388-postgresqldatabase-fix-force-update.yml new file mode 100644 index 00000000000..50e82408dfe --- /dev/null +++ b/changelogs/fragments/52388-postgresqldatabase-fix-force-update.yml @@ -0,0 +1,2 @@ +bugfixes: + - azure_rm_postgresqldatabase - fix force_update bug (https://github.com/ansible/ansible/issues/50978). diff --git a/lib/ansible/modules/cloud/azure/azure_rm_postgresqldatabase.py b/lib/ansible/modules/cloud/azure/azure_rm_postgresqldatabase.py index dfee3392513..8f84e180c7a 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_postgresqldatabase.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_postgresqldatabase.py @@ -145,6 +145,7 @@ class AzureRMDatabases(AzureRMModuleBase): self.resource_group = None self.server_name = None self.name = None + self.force_update = None self.parameters = dict() self.results = dict(changed=False) @@ -199,6 +200,7 @@ class AzureRMDatabases(AzureRMModuleBase): if not self.check_mode: self.delete_postgresqldatabase() else: + self.fail("Database properties cannot be updated without setting 'force_update' option") self.to_do = Actions.NoAction if (self.to_do == Actions.Create) or (self.to_do == Actions.Update): diff --git a/test/integration/targets/azure_rm_postgresqlserver/tasks/main.yml b/test/integration/targets/azure_rm_postgresqlserver/tasks/main.yml index 2d62dd9fa90..f0cbf8d872a 100644 --- a/test/integration/targets/azure_rm_postgresqlserver/tasks/main.yml +++ b/test/integration/targets/azure_rm_postgresqlserver/tasks/main.yml @@ -160,6 +160,8 @@ resource_group: "{{ resource_group }}" server_name: postgresqlsrv{{ rpfx }} name: testdatabase + charset: UTF8 + collation: English_United States.1252 check_mode: yes register: output - name: Assert the resource instance is well created @@ -172,6 +174,8 @@ resource_group: "{{ resource_group }}" server_name: postgresqlsrv{{ rpfx }} name: testdatabase + charset: UTF8 + collation: English_United States.1252 register: output - name: Assert the resource instance is well created assert: @@ -184,6 +188,8 @@ resource_group: "{{ resource_group }}" server_name: postgresqlsrv{{ rpfx }} name: testdatabase + charset: UTF8 + collation: English_United States.1252 register: output - name: Assert the state has not changed assert: @@ -191,6 +197,35 @@ - output.changed == false - output.name == 'testdatabase' +- name: Try to update PostgreSQL Database without force_update + azure_rm_postgresqldatabase: + resource_group: "{{ resource_group }}" + server_name: postgresqlsrv{{ rpfx }} + name: testdatabase + charset: WIN1252 + collation: SQL_Latin1_General_CP1_CS_AS + ignore_errors: yes + register: output +- name: Assert that nothing has changed + assert: + that: + - output.changed == False + +- name: Try to update PostgreSQL Database with force_update + azure_rm_postgresqldatabase: + resource_group: "{{ resource_group }}" + server_name: postgresqlsrv{{ rpfx }} + name: testdatabase + charset: WIN1252 + collation: SQL_Latin1_General_CP1_CS_AS + force_update: yes + register: output +- name: Assert the state has changed + assert: + that: + - output.changed + - output.name == 'testdatabase' + - name: Create second instance of PostgreSQL Database azure_rm_postgresqldatabase: resource_group: "{{ resource_group }}"