summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Dodsley <simon@purestorage.com>2018-06-13 12:52:51 -0400
committerMatt Davis <nitzmahone@users.noreply.github.com>2018-06-13 09:52:51 -0700
commit8df02ac37e269078b637caf6e060c9e1de06db3e (patch)
treefa12278f719ff4341235f85e728edd4e22316dca
parent3832d0461111cf2fe7db56aa2bedc8de8f06d4a9 (diff)
downloadansible-8df02ac37e269078b637caf6e060c9e1de06db3e.tar.gz
Fix race condifiton where multiple hosts can try and create or delete (#39698)
the same volume, snapshot or hostgroup,
-rw-r--r--lib/ansible/modules/storage/purestorage/purefa_hg.py26
-rw-r--r--lib/ansible/modules/storage/purestorage/purefa_snap.py23
-rw-r--r--lib/ansible/modules/storage/purestorage/purefa_volume.py24
3 files changed, 52 insertions, 21 deletions
diff --git a/lib/ansible/modules/storage/purestorage/purefa_hg.py b/lib/ansible/modules/storage/purestorage/purefa_hg.py
index a765d7e5f8..e5784b19d0 100644
--- a/lib/ansible/modules/storage/purestorage/purefa_hg.py
+++ b/lib/ansible/modules/storage/purestorage/purefa_hg.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-# (c) 2017, Simon Dodsley (simon@purestorage.com)
+# (c) 2018, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
@@ -126,7 +126,7 @@ def make_hostgroup(module, array):
try:
array.create_hgroup(module.params['hostgroup'])
except:
- module.fail_json(msg='Failed to create hostgroup {0}'.format(module.params['hostgroup']))
+ changed = False
if module.params['host']:
array.set_hgroup(module.params['hostgroup'], hostlist=module.params['host'])
if module.params['volume']:
@@ -188,14 +188,24 @@ def update_hostgroup(module, array):
def delete_hostgroup(module, array):
changed = True
- for vol in array.list_hgroup_connections(module.params['hostgroup']):
- array.disconnect_hgroup(module.params['hostgroup'], vol["vol"])
- host = array.get_hgroup(module.params['hostgroup'])
- array.set_hgroup(module.params['hostgroup'], remhostlist=host['hosts'])
try:
- array.delete_hgroup(module.params['hostgroup'])
+ vols = array.list_hgroup_connections(module.params['hostgroup'])
+ for vol in vols:
+ try:
+ array.disconnect_hgroup(module.params['hostgroup'], vol["vol"])
+ except:
+ changed = False
+ host = array.get_hgroup(module.params['hostgroup'])
+ try:
+ array.set_hgroup(module.params['hostgroup'], remhostlist=host['hosts'])
+ try:
+ array.delete_hgroup(module.params['hostgroup'])
+ except:
+ changed = False
+ except:
+ changed = False
except:
- module.fail_json(msg='Failed to delete hostgroup {0}'.format(module.params['hostgroup']))
+ changed = False
module.exit_json(changed=changed)
diff --git a/lib/ansible/modules/storage/purestorage/purefa_snap.py b/lib/ansible/modules/storage/purestorage/purefa_snap.py
index e70b6a17c1..8accb45903 100644
--- a/lib/ansible/modules/storage/purestorage/purefa_snap.py
+++ b/lib/ansible/modules/storage/purestorage/purefa_snap.py
@@ -132,9 +132,13 @@ def get_snapshot(module, array):
def create_snapshot(module, array):
"""Create Snapshot"""
+ changed = True
if not module.check_mode:
- array.create_snapshot(module.params['name'], suffix=module.params['suffix'])
- module.exit_json(changed=True)
+ try:
+ array.create_snapshot(module.params['name'], suffix=module.params['suffix'])
+ except:
+ changed = False
+ module.exit_json(changed=changed)
def create_from_snapshot(module, array):
@@ -165,12 +169,19 @@ def update_snapshot(module, array):
def delete_snapshot(module, array):
""" Delete Snapshot"""
+ changed = True
if not module.check_mode:
snapname = module.params['name'] + "." + module.params['suffix']
- array.destroy_volume(snapname)
- if module.params['eradicate']:
- array.eradicate_volume(snapname)
- module.exit_json(changed=True)
+ try:
+ array.destroy_volume(snapname)
+ if module.params['eradicate']:
+ try:
+ array.eradicate_volume(snapname)
+ except:
+ changed = False
+ except:
+ changed = False
+ module.exit_json(changed=changed)
def main():
diff --git a/lib/ansible/modules/storage/purestorage/purefa_volume.py b/lib/ansible/modules/storage/purestorage/purefa_volume.py
index d547b4dbc0..052d2e1a0c 100644
--- a/lib/ansible/modules/storage/purestorage/purefa_volume.py
+++ b/lib/ansible/modules/storage/purestorage/purefa_volume.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-# (c) 2017, Simon Dodsley (simon@purestorage.com)
+# (c) 2018, Simon Dodsley (simon@purestorage.com)
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
@@ -149,10 +149,13 @@ def get_target(module, array):
def create_volume(module, array):
"""Create Volume"""
size = module.params['size']
-
+ changed = True
if not module.check_mode:
- array.create_volume(module.params['name'], size)
- module.exit_json(changed=True)
+ try:
+ array.create_volume(module.params['name'], size)
+ except:
+ changed = False
+ module.exit_json(changed=changed)
def copy_from_volume(module, array):
@@ -190,10 +193,17 @@ def update_volume(module, array):
def delete_volume(module, array):
""" Delete Volume"""
+ changed = True
if not module.check_mode:
- array.destroy_volume(module.params['name'])
- if module.params['eradicate']:
- array.eradicate_volume(module.params['name'])
+ try:
+ array.destroy_volume(module.params['name'])
+ if module.params['eradicate']:
+ try:
+ array.eradicate_volume(module.params['name'])
+ except:
+ changed = False
+ except:
+ changed = False
module.exit_json(changed=True)