From b9b98097a47f27b56500edc972c438597e6609b1 Mon Sep 17 00:00:00 2001 From: François Cami Date: Jul 26 2019 13:09:42 +0000 Subject: ipatests: test multiple invocations of ipa-client-samba --uninstall Related-to: https://pagure.io/freeipa/issue/8019 Signed-off-by: François Cami Reviewed-By: Alexander Bokovoy Reviewed-By: Sergey Orlov --- diff --git a/ipatests/test_integration/test_smb.py b/ipatests/test_integration/test_smb.py index 4e295c0..26d70b3 100644 --- a/ipatests/test_integration/test_smb.py +++ b/ipatests/test_integration/test_smb.py @@ -150,3 +150,6 @@ class TestSMB(IntegrationTest): smbsrv = self.replicas[0] smbsrv.run_command(['ipa-client-samba', '--uninstall', '-U']) + # test for https://pagure.io/freeipa/issue/8019 + # try another uninstall after the first one: + smbsrv.run_command(['ipa-client-samba', '--uninstall', '-U']) From 256a6a879061d2b97c11e9cd97b2427579610fa1 Mon Sep 17 00:00:00 2001 From: François Cami Date: Jul 26 2019 13:09:42 +0000 Subject: ipa-client-samba: remove and restore smb.conf only on first uninstall Fixes: https://pagure.io/freeipa/issue/8019 Signed-off-by: François Cami Reviewed-By: Alexander Bokovoy Reviewed-By: Sergey Orlov --- diff --git a/ipaclient/install/ipa_client_samba.py b/ipaclient/install/ipa_client_samba.py index e2be67d..6a3c3bd 100755 --- a/ipaclient/install/ipa_client_samba.py +++ b/ipaclient/install/ipa_client_samba.py @@ -433,8 +433,9 @@ def uninstall(fstore, statestore, options): ipautil.remove_ccache(ccache_path=paths.KRB5CC_SAMBA) # Remove samba's configuration file - ipautil.remove_file(paths.SMB_CONF) - fstore.restore_file(paths.SMB_CONF) + if fstore.has_file(paths.SMB_CONF): + ipautil.remove_file(paths.SMB_CONF) + fstore.restore_file(paths.SMB_CONF) # Remove samba's persistent and temporary tdb files tdb_files = [ @@ -624,7 +625,7 @@ def run(): api.Command.service_del(api.env.smb_princ) except AttributeError: logger.error( - "Chosen IPA master %s does not have support to" + "Chosen IPA master %s does not have support to " "set up Samba domain members", server, ) return 1 From 00ba2ae6681dafa92d3f00f2a4e11adaa477ea0e Mon Sep 17 00:00:00 2001 From: François Cami Date: Jul 26 2019 13:09:42 +0000 Subject: ipatests: test ipa-client-samba after --uninstall Related-to: https://pagure.io/freeipa/issue/8021 Signed-off-by: François Cami Reviewed-By: Alexander Bokovoy Reviewed-By: Sergey Orlov --- diff --git a/ipatests/test_integration/test_smb.py b/ipatests/test_integration/test_smb.py index 26d70b3..933d468 100644 --- a/ipatests/test_integration/test_smb.py +++ b/ipatests/test_integration/test_smb.py @@ -153,3 +153,8 @@ class TestSMB(IntegrationTest): # test for https://pagure.io/freeipa/issue/8019 # try another uninstall after the first one: smbsrv.run_command(['ipa-client-samba', '--uninstall', '-U']) + # test for https://pagure.io/freeipa/issue/8021 + # try to install again: + smbsrv.run_command(["ipa-client-samba", "-U"]) + # cleanup: + smbsrv.run_command(['ipa-client-samba', '--uninstall', '-U']) From 551cd68d0959b1ee761ead6338dc06c544c0c5da Mon Sep 17 00:00:00 2001 From: François Cami Date: Jul 26 2019 13:09:42 +0000 Subject: ipa-client-samba: remove state on uninstall The "domain_member" state was not removed at uninstall time. Remove it so that future invocations of ipa-client-samba work. Fixes: https://pagure.io/freeipa/issue/8021 Signed-off-by: François Cami https://pagure.io/freeipa/issue/8021 Reviewed-By: Alexander Bokovoy Reviewed-By: Sergey Orlov --- diff --git a/ipaclient/install/ipa_client_samba.py b/ipaclient/install/ipa_client_samba.py index 6a3c3bd..126ef32 100755 --- a/ipaclient/install/ipa_client_samba.py +++ b/ipaclient/install/ipa_client_samba.py @@ -523,11 +523,25 @@ def run(): if options.uninstall: if statestore.has_state("domain_member"): uninstall(fstore, statestore, options) - print( - "Samba configuration is reverted. " - "However, Samba databases were fully cleaned and " - "old configuration file will not be usable anymore." - ) + try: + keys = ( + "configured", "hardening", "groupmap", "tdb", + "service.principal", "smb.conf" + ) + for key in keys: + statestore.delete_state("domain_member", key) + except Exception as e: + print( + "Error: Failed to remove the domain_member statestores: " + "%s" % e + ) + return 1 + else: + print( + "Samba configuration is reverted. " + "However, Samba databases were fully cleaned and " + "old configuration file will not be usable anymore." + ) else: print("Samba domain member is not configured yet") return 0