From 0fa8686918f6b79d09ac8fa959fe988f6db633b2 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Tue, 7 Jul 2020 16:24:35 -0400 Subject: [PATCH] Simplify determining if an IPA server installation is complete When asking the quesiton "is my IPA server configured?" right now we look at whether the installation backed up any files and set any state. This isn't exactly precise. Instead set a new state, installation, to True as soon as IPA is restarted at the end of the installer. On upgrades existing installations will automatically get this state. This relies on the fact that get_state returns None if no state at all is set. This indicates that this "new" option isn't available and when upgrading an existing installation we can assume the install at least partly works. The value is forced to False at the beginning of a fresh install so if it fails, or is in a transient state like with an external CA, we know that the installation is not complete. https://pagure.io/freeipa/issue/8384 Signed-off-by: Rob Crittenden Reviewed-By: Alexander Bokovoy Reviewed-By: Francois Cami --- ipaserver/install/installutils.py | 22 ++-------------------- ipaserver/install/server/install.py | 6 ++++++ ipaserver/install/server/replicainstall.py | 6 ++++++ ipaserver/install/server/upgrade.py | 4 ++++ 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py index ba98e8bed..f19f64fbe 100644 --- a/ipaserver/install/installutils.py +++ b/ipaserver/install/installutils.py @@ -700,28 +700,10 @@ def rmtree(path): def is_ipa_configured(): """ - Using the state and index install files determine if IPA is already - configured. + Use the state to determine if IPA has been configured. """ - installed = False - sstore = sysrestore.StateFile(paths.SYSRESTORE) - fstore = sysrestore.FileStore(paths.SYSRESTORE) - - for module in IPA_MODULES: - if sstore.has_state(module): - logger.debug('%s is configured', module) - installed = True - else: - logger.debug('%s is not configured', module) - - if fstore.has_files(): - logger.debug('filestore has files') - installed = True - else: - logger.debug('filestore is tracking no files') - - return installed + return sstore.get_state('installation', 'complete') def run_script(main_function, operation_name, log_file_name=None, diff --git a/ipaserver/install/server/install.py b/ipaserver/install/server/install.py index 1eee9e7a9..137eee2b0 100644 --- a/ipaserver/install/server/install.py +++ b/ipaserver/install/server/install.py @@ -808,6 +808,9 @@ def install(installer): # failure to enable root cause investigation installer._installation_cleanup = False + # Be clear that the installation process is beginning but not done + sstore.backup_state('installation', 'complete', False) + if installer.interactive: print("") print("The following operations may take some minutes to complete.") @@ -1010,6 +1013,8 @@ def install(installer): bind.create_file_with_system_records() # Everything installed properly, activate ipa service. + sstore.delete_state('installation', 'complete') + sstore.backup_state('installation', 'complete', True) services.knownservices.ipa.enable() print("=======================================" @@ -1215,6 +1220,7 @@ def uninstall(installer): if fstore.has_files(): logger.error('Some files have not been restored, see ' '%s/sysrestore.index', SYSRESTORE_DIR_PATH) + sstore.delete_state('installation', 'complete') has_state = False for module in IPA_MODULES: # from installutils if sstore.has_state(module): diff --git a/ipaserver/install/server/replicainstall.py b/ipaserver/install/server/replicainstall.py index 7d6c4108c..b8e896ac7 100644 --- a/ipaserver/install/server/replicainstall.py +++ b/ipaserver/install/server/replicainstall.py @@ -1205,6 +1205,7 @@ def install(installer): ca_enabled = installer._ca_enabled kra_enabled = installer._kra_enabled fstore = installer._fstore + sstore = installer._sstore config = installer._config cafile = installer._ca_file dirsrv_pkcs12_info = installer._dirsrv_pkcs12_info @@ -1215,6 +1216,9 @@ def install(installer): conn = remote_api.Backend.ldap2 ccache = os.environ['KRB5CCNAME'] + # Be clear that the installation process is beginning but not done + sstore.backup_state('installation', 'complete', False) + if tasks.configure_pkcs11_modules(fstore): print("Disabled p11-kit-proxy") @@ -1371,6 +1375,8 @@ def install(installer): api.Backend.ldap2.disconnect() # Everything installed properly, activate ipa service. + sstore.delete_state('installation', 'complete') + sstore.backup_state('installation', 'complete', True) services.knownservices.ipa.enable() # Print a warning if CA role is only installed on one server diff --git a/ipaserver/install/server/upgrade.py b/ipaserver/install/server/upgrade.py index 61e7af34d..af403c6da 100644 --- a/ipaserver/install/server/upgrade.py +++ b/ipaserver/install/server/upgrade.py @@ -1482,6 +1482,10 @@ def upgrade_configuration(): logger.debug('IPA version %s', version.VENDOR_VERSION) fstore = sysrestore.FileStore(paths.SYSRESTORE) + sstore = sysrestore.StateFile(paths.SYSRESTORE) + + if installutils.is_ipa_configured() is None: + sstore.backup_state('installation', 'complete', True) fqdn = api.env.host