mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Don't leave dangling map if adding an indirect map fails
When using the add_indirect helper we create a new map and then add a key for it all in one step. If adding the key fails for any reason be sure to remove the map we added. https://fedorahosted.org/freeipa/ticket/1520
This commit is contained in:
@@ -791,11 +791,16 @@ class automountmap_add_indirect(LDAPCreate):
|
|||||||
|
|
||||||
def execute(self, *keys, **options):
|
def execute(self, *keys, **options):
|
||||||
result = self.api.Command['automountmap_add'](*keys, **options)
|
result = self.api.Command['automountmap_add'](*keys, **options)
|
||||||
options['automountinformation'] = keys[1]
|
try:
|
||||||
self.api.Command['automountkey_add'](
|
options['automountinformation'] = keys[1]
|
||||||
keys[0], options['parentmap'],
|
self.api.Command['automountkey_add'](
|
||||||
automountkey=options['key'], **options
|
keys[0], options['parentmap'],
|
||||||
)
|
automountkey=options['key'], **options
|
||||||
|
)
|
||||||
|
except Exception, e:
|
||||||
|
# The key exists, drop the map
|
||||||
|
self.api.Command['automountmap_del'](*keys, **options)
|
||||||
|
raise e
|
||||||
return result
|
return result
|
||||||
|
|
||||||
api.register(automountmap_add_indirect)
|
api.register(automountmap_add_indirect)
|
||||||
|
|||||||
@@ -266,6 +266,17 @@ class test_automount_indirect(XMLRPC_test):
|
|||||||
assert res
|
assert res
|
||||||
assert_attr_equal(res, 'automountmapname', self.mapname)
|
assert_attr_equal(res, 'automountmapname', self.mapname)
|
||||||
|
|
||||||
|
def test_1a_automountmap_add_indirect(self):
|
||||||
|
"""
|
||||||
|
Test adding a duplicate indirect map.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
api.Command['automountmap_add_indirect'](self.locname, self.mapname, **self.map_kw)['result']
|
||||||
|
except errors.DuplicateEntry:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
assert False
|
||||||
|
|
||||||
def test_2_automountmap_show(self):
|
def test_2_automountmap_show(self):
|
||||||
"""
|
"""
|
||||||
Test the `xmlrpc.automountmap_show` method.
|
Test the `xmlrpc.automountmap_show` method.
|
||||||
|
|||||||
Reference in New Issue
Block a user