mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Return a value if exceptions are raised in server uninstall
The AdminTool class purports to "call sys.exit() with the return value" but most of the run implementations returned no value, or the methods they called returned nothing so there was nothing to return, so this was a no-op. The fix is to capture and bubble up the return values which will return 1 if any exceptions are caught. This potentially affects other users in that when executing the steps of an installer or uninstaller the highest return code will be the exit value of that installer. Don't use the Continuous class because it doesn't add any value and makes catching the exceptions more difficult. https://pagure.io/freeipa/issue/7330 Signed-off-by: Rob Crittenden rcritten@redhat.com Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
This commit is contained in:
committed by
Christian Heimes
parent
2b47f8994f
commit
68c7b03689
79
ipatests/test_integration/test_uninstallation.py
Normal file
79
ipatests/test_integration/test_uninstallation.py
Normal file
@@ -0,0 +1,79 @@
|
||||
#
|
||||
# Copyright (C) 2018 FreeIPA Contributors see COPYING for license
|
||||
#
|
||||
|
||||
"""
|
||||
Module provides tests that uninstallation is successful.
|
||||
|
||||
It is important not to leave the remote system in an inconsistent
|
||||
state. Every failed uninstall should successfully remove remaining
|
||||
pieces if possible.
|
||||
"""
|
||||
|
||||
from ipatests.test_integration.base import IntegrationTest
|
||||
from ipatests.pytest_plugins.integration import tasks
|
||||
from ipaplatform.paths import paths
|
||||
from ipaserver.install.installutils import realm_to_serverid
|
||||
from ipaserver.install import dsinstance
|
||||
|
||||
|
||||
class TestUninstallBase(IntegrationTest):
|
||||
|
||||
@classmethod
|
||||
def install(cls, mh):
|
||||
tasks.install_master(cls.master, setup_dns=False)
|
||||
|
||||
def test_failed_uninstall(self):
|
||||
self.master.run_command(['ipactl', 'stop'])
|
||||
|
||||
serverid = realm_to_serverid(self.master.domain.realm)
|
||||
instance_name = ''.join([dsinstance.DS_INSTANCE_PREFIX, serverid])
|
||||
|
||||
try:
|
||||
# Moving the DS instance out of the way will cause the
|
||||
# uninstaller to raise an exception and return with a
|
||||
# non-zero return code.
|
||||
self.master.run_command([
|
||||
'/usr/bin/mv',
|
||||
'%s/%s' % (paths.ETC_DIRSRV, instance_name),
|
||||
'%s/%s.test' % (paths.ETC_DIRSRV, instance_name)
|
||||
])
|
||||
|
||||
cmd = self.master.run_command([
|
||||
'ipa-server-install',
|
||||
'--uninstall', '-U'],
|
||||
raiseonerr=False
|
||||
)
|
||||
assert cmd.returncode == 1
|
||||
finally:
|
||||
# Be paranoid. If something really went wrong then DS may
|
||||
# be marked as uninstalled so server cert will still be
|
||||
# tracked and the instances may remain. This can cause
|
||||
# subsequent installations to fail so be thorough.
|
||||
ds = dsinstance.DsInstance()
|
||||
ds_running = ds.is_running()
|
||||
if ds_running:
|
||||
ds.stop(serverid)
|
||||
|
||||
# Moving it back should allow the uninstall to finish
|
||||
# successfully.
|
||||
self.master.run_command([
|
||||
'/usr/bin/mv',
|
||||
'%s/%s.test' % (paths.ETC_DIRSRV, instance_name),
|
||||
'%s/%s' % (paths.ETC_DIRSRV, instance_name)
|
||||
])
|
||||
|
||||
# DS has been marked as uninstalled so force the issue
|
||||
ds.stop_tracking_certificates(serverid)
|
||||
|
||||
self.master.run_command([
|
||||
paths.REMOVE_DS_PL,
|
||||
'-i', instance_name
|
||||
])
|
||||
|
||||
cmd = self.master.run_command([
|
||||
'ipa-server-install',
|
||||
'--uninstall', '-U'],
|
||||
raiseonerr=False
|
||||
)
|
||||
assert cmd.returncode == 0
|
||||
Reference in New Issue
Block a user