From 2aa24eedf2443367272fe2e41bb9dcf508533a18 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Tue, 8 Jan 2019 09:54:07 +0200 Subject: [PATCH] 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. Reviewed-By: Christian Heimes --- ipalib/cli.py | 2 +- ipalib/util.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ipalib/cli.py b/ipalib/cli.py index 5d10aacae..ecd9ef2b3 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 e68414544..bf46950db 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -1123,15 +1123,16 @@ 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)): + not os.listdir(paths.IPA_CLIENT_SYSRESTORE))): raise ScriptError('IPA client is not configured on this system', 2) # CLIENT_NOT_CONFIGURED