tests: fix cleanup for CATracker

With ca-del now requiring disablement first, CATracker cleanup fails
because the CA is not yet disabled.  Implement auto disable before
delete in CATracker, with an option to suppress.  This suppress
option is used when testing the "disable first" option.

The patch also includes a tweak to EnableTracker cleanup.  In case
the CA already got deleted (and in the case of CATracker, also
disabled), this avoids an attempt to re-enable the already-deleted
object.

Part of: https://fedorahosted.org/freeipa/ticket/5011

Reviewed-By: Rob Crittenden <rcritten@redhat.com>
This commit is contained in:
Fraser Tweedale authored and Rob Crittenden committed 2020-07-07 10:07:48 -04:00
1 parent 6da63e3be4
commit 6a0901f6fd
3 files changed
+25 -3

No files matched your search

+9 -1
View File
@@ -48,7 +48,7 @@ def default_ca(request):
def crud_subca(request, xmlrpc_setup):
name = u'crud-subca'
subject = u'CN=crud subca test,O=crud testing inc'
tracker = CATracker(name, subject)
tracker = CATracker(name, subject, auto_disable_for_delete=False)
return tracker.make_fixture(request)
@@ -208,3 +208,11 @@ class TestCAbasicCRUD(XMLRPC_test):
self, unrecognised_subject_dn_attrs_subca):
with pytest.raises(errors.ValidationError):
unrecognised_subject_dn_attrs_subca.create()
def test_pre_cleanup_disable(self, crud_subca):
# crud_subca was initialised with auto_disable_for_delete=False. But
# we already tested disablement and deletion. Then we recreated it for
# subsequent tests. Now we have finished the tests; crud_subca is
# about to be deleted. But we have to explicitly disable it first,
# otherwise deletion will will and raise a test teardown failure.
crud_subca.disable()
+5
View File
@@ -302,6 +302,11 @@ class EnableTracker(BaseTracker):
(enabled/disabled) after the test as it was before it.
"""
def cleanup():
if isinstance(self, CreationTracker):
# special case: if it already got deleted there is
# nothing to enable or disable
return
if self.original_enabled != self.enabled:
if self.original_enabled:
command = self.make_enable_command()
+11 -2
View File
@@ -42,7 +42,7 @@ class CATracker(Tracker, EnableTracker):
update_keys = ldap_keys - {'dn'}
def __init__(self, name, subject, desc=u"Test generated CA",
default_version=None):
default_version=None, auto_disable_for_delete=True):
super(CATracker, self).__init__(default_version=default_version)
self.attrs = {}
self.ipasubjectdn = subject
@@ -52,6 +52,9 @@ class CATracker(Tracker, EnableTracker):
self.api.env.container_ca,
self.api.env.basedn)
# Whether to run ca-disable automatically before deleting the CA.
self.auto_disable_for_delete = auto_disable_for_delete
def make_create_command(self):
"""Make function that creates the plugin entry object."""
return self.make_command(
@@ -92,7 +95,13 @@ class CATracker(Tracker, EnableTracker):
def make_delete_command(self):
"""Make function that deletes the plugin entry object."""
return self.make_command('ca_del', self.name)
if self.auto_disable_for_delete:
def disable_then_delete():
self.make_command('ca_disable', self.name)()
return self.make_command('ca_del', self.name)()
return disable_then_delete
else:
return self.make_command('ca_del', self.name)
def check_delete(self, result):
assert_deepequal(dict(