Don't use the has_files() to know if client/server is configured

Use the is_ipa_configure() and is_ipa_client_configured() utilities
instead which are much more robust.

https://pagure.io/freeipa/issue/8384

Signed-off-by: Rob Crittenden <rcritten@redhat.com>
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-By: Francois Cami <fcami@redhat.com>
This commit is contained in:
Rob Crittenden 2020-07-28 13:17:40 -04:00 committed by Florence Blanc-Renaud
parent d7a4756dac
commit 5e02713481
6 changed files with 12 additions and 15 deletions

View File

@ -37,9 +37,9 @@ from urllib.parse import urlparse, urlunparse
from ipalib import api, errors, x509
from ipalib import sysrestore
from ipalib.constants import IPAAPI_USER, MAXHOSTNAMELEN
from ipalib.facts import is_ipa_client_configured
from ipalib.install import certmonger, certstore, service
from ipalib.install import hostname as hostname_
from ipalib.facts import is_ipa_client_configured, is_ipa_configured
from ipalib.install.kinit import kinit_keytab, kinit_password
from ipalib.install.service import enroll_only, prepare_only
from ipalib.rpc import delete_persistent_client_session_data
@ -3203,8 +3203,7 @@ def uninstall_check(options):
"IPA client is not configured on this system.",
rval=rval)
server_fstore = sysrestore.FileStore(paths.SYSRESTORE)
if server_fstore.has_files() and not options.on_master:
if is_ipa_configured() and not options.on_master:
logger.error(
"IPA client is configured as a part of IPA server on this system.")
logger.info("Refer to ipa-server-install for uninstallation.")

View File

@ -26,7 +26,8 @@ import shutil
from urllib.parse import urlsplit
from ipalib.install import certmonger, certstore, sysrestore
from ipalib.install import certmonger, certstore
from ipalib.facts import is_ipa_configured
from ipalib.install.kinit import kinit_keytab
from ipapython import admintool, certdb, ipaldap, ipautil
from ipaplatform import services
@ -104,8 +105,7 @@ def run_with_args(api):
os.environ['KRB5CCNAME'] = old_krb5ccname
shutil.rmtree(tmpdir)
server_fstore = sysrestore.FileStore(paths.SYSRESTORE)
if server_fstore.has_files():
if is_ipa_configured():
# look up CA servers before service restarts
resp = api.Command.server_role_find(
role_servrole=u'CA server',

View File

@ -6,6 +6,7 @@
Facts about the installation
"""
import os
from . import sysrestore
from ipaplatform.paths import paths

View File

@ -43,7 +43,7 @@ from dns.exception import DNSException
import ldap
import six
from ipalib import facts, sysrestore
from ipalib import facts
from ipalib.install.kinit import kinit_password
import ipaplatform
from ipapython import ipautil, admintool, version, ipaldap
@ -669,8 +669,7 @@ def check_server_configuration():
Most convenient use case for the function is in install tools that require
configured IPA for its function.
"""
server_fstore = sysrestore.FileStore(paths.SYSRESTORE)
if not server_fstore.has_files():
if not is_ipa_configured():
raise ScriptError("IPA is not configured on this system.",
rval=SERVER_NOT_CONFIGURED)

View File

@ -32,7 +32,7 @@ from ipaplatform.paths import paths
from ipaplatform.tasks import tasks
from ipalib import api, errors, x509
from ipalib.constants import DOMAIN_LEVEL_0
from ipalib.facts import is_ipa_configured
from ipalib.facts import is_ipa_configured, is_ipa_client_configured
from ipalib.util import (
validate_domain_name,
no_matching_interface_for_ip_address_warning,
@ -381,8 +381,7 @@ def install_check(installer):
"If you want to reinstall the IPA server, please uninstall "
"it first using 'ipa-server-install --uninstall'.")
client_fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE)
if client_fstore.has_files():
if is_ipa_client_configured(on_master=True):
installer._installation_cleanup = False
raise ScriptError(
"IPA client is already configured on this system.\n"

View File

@ -35,7 +35,7 @@ from ipaplatform.tasks import tasks
from ipaplatform.paths import paths
from ipalib import api, constants, create_api, errors, rpc, x509
from ipalib.config import Env
from ipalib.facts import is_ipa_configured
from ipalib.facts import is_ipa_configured, is_ipa_client_configured
from ipalib.util import no_matching_interface_for_ip_address_warning
from ipaclient.install.client import configure_krb5_conf, purge_host_keytab
from ipaserver.install import (
@ -786,8 +786,7 @@ def promote_check(installer):
raise ScriptError("--setup-ca and --*-cert-file options are "
"mutually exclusive")
client_fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE)
if not client_fstore.has_files():
if not is_ipa_client_configured(on_master=True):
# One-step replica installation
if options.password and options.admin_password:
raise ScriptError("--password and --admin-password options are "