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:
Rob Crittenden
2011-07-27 10:25:48 -04:00
parent a2641254fe
commit 62445b8673
2 changed files with 21 additions and 5 deletions

View File

@@ -791,11 +791,16 @@ class automountmap_add_indirect(LDAPCreate):
def execute(self, *keys, **options):
result = self.api.Command['automountmap_add'](*keys, **options)
options['automountinformation'] = keys[1]
self.api.Command['automountkey_add'](
keys[0], options['parentmap'],
automountkey=options['key'], **options
)
try:
options['automountinformation'] = keys[1]
self.api.Command['automountkey_add'](
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
api.register(automountmap_add_indirect)