From 9f044d54bfd809c03da2e15ff50ca556a8bb09a0 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Jan 14 2019 08:33:04 +0000 Subject: make sure IPA_CONFDIR is used to check that client is configured Fixes a test ipatests/test_cmdline/test_cli.py:test_cli_fs_encoding() which sets IPA_CONFDIR and attempts to interpret the resulting error message. However, if the test is run on an enrolled machine (a developer's laptop, for example), check_client_configuration() will succeed because it ignores IPA_CONFDIR and, as result, api.finalize() will fail later with a stacktrace. Pass an environment object and test an overridden config file existence in this case to fail with a proper and expected message. The change for ipa-4-6 branch also incorporates partial fix from the commit e59ee6099f065c2155e3be13025459108daf7900 which touch the check_client_configuration(). Reviewed-By: Christian Heimes (cherry picked from commit 2aa24eedf2443367272fe2e41bb9dcf508533a18) Reviewed-By: Christian Heimes --- diff --git a/ipalib/cli.py b/ipalib/cli.py index 40dbc63..7b2af48 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -1454,7 +1454,7 @@ def run(api): (_options, argv) = api.bootstrap_with_global_options(context='cli') try: - check_client_configuration() + check_client_configuration(env=api.env) except ScriptError as e: sys.exit(e) diff --git a/ipalib/util.py b/ipalib/util.py index c5b5597..c28be2e 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -1121,14 +1121,18 @@ def ensure_krbcanonicalname_set(ldap, entry_attrs): entry_attrs.update(old_entry) -def check_client_configuration(): +def check_client_configuration(env=None): """ Check if IPA client is configured on the system. + + Hardcode return code to avoid recursive imports """ - if (not os.path.isfile(paths.IPA_DEFAULT_CONF) or + if ((env is not None and not os.path.isfile(env.conf_default)) or + (not os.path.isfile(paths.IPA_DEFAULT_CONF) or not os.path.isdir(paths.IPA_CLIENT_SYSRESTORE) or - not os.listdir(paths.IPA_CLIENT_SYSRESTORE)): - raise ScriptError('IPA client is not configured on this system') + not os.listdir(paths.IPA_CLIENT_SYSRESTORE))): + raise ScriptError('IPA client is not configured on this system', + 2) # CLIENT_NOT_CONFIGURED def check_principal_realm_in_trust_namespace(api_instance, *keys):