URL: https://github.com/freeipa/freeipa/pull/625 Author: HonzaCholasta Title: #625: [RFC] remote plugins: add option to force compat plugins Action: opened
PR body: """ Add a new `force_client_compat` env flag to force client API not to do any RPC calls to initialize remote plugins in `.finalize()` and use the newest compat plugins instead. Setting the flag serves as a workaround for `api.finalize()` requiring valid Kerberos credentials. https://pagure.io/freeipa/issue/6408 """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/625/head:pr625 git checkout pr625
From 533040ded447bfdbc606fe0c9f40c304becdb46e Mon Sep 17 00:00:00 2001 From: Jan Cholasta <jchol...@redhat.com> Date: Mon, 20 Mar 2017 09:51:55 +0000 Subject: [PATCH] remote plugins: add option to force compat plugins Add a new `force_client_compat` env flag to force client API not to do any RPC calls to initialize remote plugins in `.finalize()` and use the newest compat plugins instead. Setting the flag serves as a workaround for `api.finalize()` requiring valid Kerberos credentials. https://pagure.io/freeipa/issue/6408 --- ipaclient/remote_plugins/compat.py | 47 +++++++++++++++++++++----------------- ipaclient/remote_plugins/schema.py | 3 +++ ipalib/constants.py | 2 ++ 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/ipaclient/remote_plugins/compat.py b/ipaclient/remote_plugins/compat.py index c1ae635..b60552d 100644 --- a/ipaclient/remote_plugins/compat.py +++ b/ipaclient/remote_plugins/compat.py @@ -12,6 +12,7 @@ from ipaclient.frontend import ClientCommand, ClientMethod from ipalib.frontend import Object from ipapython.ipautil import APIVersion +from ipapython.version import API_VERSION if six.PY3: unicode = str @@ -32,31 +33,35 @@ class CompatObject(Object): def get_package(server_info, client): - try: - server_version = server_info['version'] - except KeyError: - is_valid = False - else: - is_valid = server_info.is_valid() - - if not is_valid: - if not client.isconnected(): - client.connect(verbose=False) - env = client.forward(u'env', u'api_version', version=u'2.0') + if not client.api.env.force_client_compat: try: - server_version = env['result']['api_version'] + server_version = server_info['version'] except KeyError: - ping = client.forward(u'ping', version=u'2.0') + is_valid = False + else: + is_valid = server_info.is_valid() + + if not is_valid: + if not client.isconnected(): + client.connect(verbose=False) + env = client.forward(u'env', u'api_version', version=u'2.0') try: - match = re.search(u'API version (2\.[0-9]+)', ping['summary']) + server_version = env['result']['api_version'] except KeyError: - match = None - if match is not None: - server_version = match.group(1) - else: - server_version = u'2.0' - server_info['version'] = server_version - server_info.update_validity() + ping = client.forward(u'ping', version=u'2.0') + try: + match = re.search(u'API version (2\.[0-9]+)', + ping['summary']) + except KeyError: + match = None + if match is not None: + server_version = match.group(1) + else: + server_version = u'2.0' + server_info['version'] = server_version + server_info.update_validity() + else: + server_version = API_VERSION server_version = APIVersion(server_version) diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py index 3ecd608..be29722 100644 --- a/ipaclient/remote_plugins/schema.py +++ b/ipaclient/remote_plugins/schema.py @@ -521,6 +521,9 @@ def get_help(self, namespace, member): def get_package(server_info, client): + if client.api.env.force_client_compat: + raise NotAvailable() + NO_FINGERPRINT = object() fingerprint = NO_FINGERPRINT diff --git a/ipalib/constants.py b/ipalib/constants.py index f8a194c..eb8b953 100644 --- a/ipalib/constants.py +++ b/ipalib/constants.py @@ -196,6 +196,8 @@ # Ignore TTL. Perform schema call and download schema if not in cache. ('force_schema_check', False), + # Force client API to use compat remote plugins + ('force_client_compat', False), # ******************************************************** # The remaining keys are never set from the values here!
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code