URL: https://github.com/freeipa/freeipa/pull/266 Author: HonzaCholasta Title: #266: ipapython: simplify Env object initialization Action: synchronized
To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/266/head:pr266 git checkout pr266
From bd4d58716c77b0ed9b13fe7fc78bc43b0bd5f178 Mon Sep 17 00:00:00 2001 From: Jan Cholasta <[email protected]> Date: Tue, 22 Nov 2016 12:42:40 +0100 Subject: [PATCH 1/2] wsgi, oddjob: remove needless uses of Env Do not use custom Env instance to determine the debug level to use for the IPA API object - the IPA API object can properly determining the configured debug level on its own. https://fedorahosted.org/freeipa/ticket/6408 --- doc/guide/wsgi.py.txt | 13 ++----------- install/oddjob/com.redhat.idm.trust-fetch-domains | 8 +------- install/share/wsgi.py | 13 +------------ 3 files changed, 4 insertions(+), 30 deletions(-) diff --git a/doc/guide/wsgi.py.txt b/doc/guide/wsgi.py.txt index 8566a25..8c2f7e5 100644 --- a/doc/guide/wsgi.py.txt +++ b/doc/guide/wsgi.py.txt @@ -1,16 +1,7 @@ +from ipaplatform.paths import paths from ipalib import api -from ipalib.config import Env -from ipalib.constants import DEFAULT_CONFIG -# Determine what debug level is configured. We can only do this -# by reading in the configuration file(s). The server always reads -# default.conf and will also read in `context'.conf. -env = Env() -env._bootstrap(context='server', log=None) -env._finalize_core(**dict(DEFAULT_CONFIG)) - -# Initialize the API with the proper debug level -api.bootstrap(context='server', debug=env.debug, log=None) (ref:wsgi-app-bootstrap) +api.bootstrap(context='server', confdir=paths.ETC_IPA, log=None) (ref:wsgi-app-bootstrap) try: api.finalize() (ref:wsgi-app-finalize) except Exception as e: diff --git a/install/oddjob/com.redhat.idm.trust-fetch-domains b/install/oddjob/com.redhat.idm.trust-fetch-domains index e5c2e8c..a472dd6 100755 --- a/install/oddjob/com.redhat.idm.trust-fetch-domains +++ b/install/oddjob/com.redhat.idm.trust-fetch-domains @@ -5,8 +5,6 @@ from ipaserver.install.installutils import is_ipa_configured, ScriptError from ipapython import config, ipautil from ipalib import api from ipapython.dn import DN -from ipalib.config import Env -from ipalib.constants import DEFAULT_CONFIG from ipaplatform.constants import constants from ipaplatform.paths import paths import sys @@ -91,12 +89,8 @@ if len(args) != 1: trusted_domain = ipautil.fsdecode(args[0]).lower() -env = Env() -env._bootstrap(debug=options.debug, log=None) -env._finalize_core(**dict(DEFAULT_CONFIG)) - # Initialize the API with the proper debug level -api.bootstrap(in_server=True, debug=env.debug, log=None, +api.bootstrap(in_server=True, debug=options.debug, log=None, context='server', confdir=paths.ETC_IPA) api.finalize() diff --git a/install/share/wsgi.py b/install/share/wsgi.py index ca97d1e..a0aa3fc 100644 --- a/install/share/wsgi.py +++ b/install/share/wsgi.py @@ -25,19 +25,8 @@ """ from ipaplatform.paths import paths from ipalib import api -from ipalib.config import Env -from ipalib.constants import DEFAULT_CONFIG -# Determine what debug level is configured. We can only do this -# by reading in the configuration file(s). The server always reads -# default.conf and will also read in `context'.conf. -env = Env() -env._bootstrap(context='server', log=None, confdir=paths.ETC_IPA) -env._finalize_core(**dict(DEFAULT_CONFIG)) - -# Initialize the API with the proper debug level -api.bootstrap(context='server', confdir=paths.ETC_IPA, - debug=env.debug, log=None) +api.bootstrap(context='server', confdir=paths.ETC_IPA, log=None) try: api.finalize() except Exception as e: From 4008218a2704e2f511c0ea05894a627d62011663 Mon Sep 17 00:00:00 2001 From: Jan Cholasta <[email protected]> Date: Mon, 16 Jan 2017 12:20:47 +0100 Subject: [PATCH 2/2] config: add public API to initialize Env Add new API to initialize Env instances: env = Env() env.bootstrap(**overrides) env.finalize() This replaces the old private API: env = Env() env._bootstrap(**overrides) env._finalize_core(**dict(DEFAULT_CONFIG)) env._finalize() https://fedorahosted.org/freeipa/ticket/6408 --- install/tools/ipa-pki-retrieve-key | 2 +- ipalib/__init__.py | 6 +- ipalib/config.py | 120 +++++++++++++--------------- ipalib/constants.py | 18 ++--- ipalib/plugable.py | 11 +-- ipaserver/install/server/replicainstall.py | 4 +- ipatests/test_ipalib/test_config.py | 123 ++++++++++------------------- ipatests/test_ipalib/test_frontend.py | 9 ++- ipatests/test_ipalib/test_plugable.py | 6 +- 9 files changed, 120 insertions(+), 179 deletions(-) diff --git a/install/tools/ipa-pki-retrieve-key b/install/tools/ipa-pki-retrieve-key index 505ed23..69c720c 100755 --- a/install/tools/ipa-pki-retrieve-key +++ b/install/tools/ipa-pki-retrieve-key @@ -11,7 +11,7 @@ from ipaplatform.paths import paths from ipaserver.secrets.client import CustodiaClient env = Env() -env._finalize() +env.finalize() keyname = "ca_wrapped/" + sys.argv[1] servername = sys.argv[2] diff --git a/ipalib/__init__.py b/ipalib/__init__.py index 4f09090..08afef6 100644 --- a/ipalib/__init__.py +++ b/ipalib/__init__.py @@ -712,7 +712,7 @@ class my_command(Command): assume these variables will all exist by the time the module containing their plugin (or plugins) is imported. -`Env._bootstrap()`, which is called by `API.bootstrap()`, will create several +`Env.bootstrap()`, which is called by `API.bootstrap()`, will create several run-time variables that cannot be overridden in configuration files or through command-line options. Here is an overview of this run-time information: @@ -732,8 +732,8 @@ class my_command(Command): the freeIPA built-in plugins, you should add the defaults for your variables in `ipalib.constants.DEFAULT_CONFIG`. Also, you should consider whether your new environment variables should have any auto-magic logic to determine their -values if they haven't already been set by the time `config.Env._bootstrap()`, -`config.Env._finalize_core()`, or `config.Env._finalize()` is called. +values if they haven't already been set by the time `config.Env.bootstrap()`, +or `config.Env.finalize()` is called. On the other hand, if your plugin requires new environment variables and will be installed in a 3rd-party package, your plugin should set these variables diff --git a/ipalib/config.py b/ipalib/config.py index 20591db..fa6418b 100644 --- a/ipalib/config.py +++ b/ipalib/config.py @@ -40,14 +40,18 @@ # pylint: enable=import-error from ipapython.dn import DN +from ipapython.ipa_log_manager import log_mgr from ipalib.base import check_name -from ipalib.constants import CONFIG_SECTION +from ipalib.constants import CONFIG_SECTION, DEFAULT_CONFIG from ipalib.constants import OVERRIDE_ERROR, SET_ERROR, DEL_ERROR from ipalib import errors if six.PY3: unicode = str +logger = log_mgr.get_logger(__name__) + + class Env(object): """ Store and retrieve environment variables. @@ -179,20 +183,17 @@ class provides high-level methods for bootstraping a fresh `Env` instance These are the `Env` bootstraping methods, in the order they must be called: - 1. `Env._bootstrap()` - initialize the run-time variables and then - merge-in variables specified on the command-line. - - 2. `Env._finalize_core()` - merge-in variables from the configuration - files and then merge-in variables from the internal defaults, after + 1. `Env.bootstrap()` - initialize the run-time variables and then + merge-in variables specified on the command-line, variables from the + configuration files and variables from the internal defaults, after which at least all the standard variables will be set. After this method is called, the plugins will be loaded, during which third-party plugins can merge-in defaults for additional variables - they use (likely using the `Env._merge()` method). + they use. - 3. `Env._finalize()` - one last chance to merge-in variables and then - the instance is locked. After this method is called, no more - environment variables can be set during the remaining life of the - process. + 3. `Env.finalize()` - the instance is locked. After this method is + called, no more environment variables can be set during the + remaining life of the process. However, normally none of these three bootstraping methods are called directly and instead only `plugable.API.bootstrap()` is called, which itself @@ -201,11 +202,9 @@ class provides high-level methods for bootstraping a fresh `Env` instance __locked = False - def __init__(self, **initialize): + def __init__(self): object.__setattr__(self, '_Env__d', {}) object.__setattr__(self, '_Env__done', set()) - if initialize: - self._merge(**initialize) def __lock__(self): """ @@ -408,9 +407,9 @@ def __do_if_not_done(self, name): def _isdone(self, name): return name in self.__done - def _bootstrap(self, **overrides): + def bootstrap(self, **overrides): """ - Initialize basic environment. + Complete initialization of standard IPA environment. This method will perform the following steps: @@ -420,19 +419,43 @@ def _bootstrap(self, **overrides): in the configuration files. 2. Merge-in the variables in ``overrides`` by calling - `Env._merge()`. The intended use of ``overrides`` is to merge-in - variables specified on the command-line. + `Env._merge()`. The intended use of ``overrides`` is to + merge-in variables specified on the command-line. 3. Intelligently fill-in the *in_tree*, *context*, *conf*, and *conf_default* variables if they haven't been set already. - Also see `Env._finalize_core()`, the next method in the bootstrap - sequence. + 4. Merge-in variables from the configuration file ``self.conf`` + (if it exists) by calling `Env._merge_from_file()`. + + 5. Merge-in variables from the defaults configuration file + ``self.conf_default`` (if it exists) by calling + `Env._merge_from_file()`. + + 6. Intelligently fill-in the *in_server* , *logdir*, *log*, and + *jsonrpc_uri* variables if they haven't already been set. + + 7. Merge-in the variables in `constants.DEFAULT_CONFIG` by calling + `Env._merge()`. + + After this method is called, all the environment variables used by all + the built-in plugins will be available. As such, this method should be + called *before* any plugins are loaded. + + After this method has finished, the `Env` instance is still writable + so that 3rd-party plugins can set variables they may require as the + plugins are registered. + + Also see `Env.finalize()`, the final method in the bootstrap sequence. :param overrides: Variables specified via command-line options. """ - self.__doing('_bootstrap') + self.__doing('bootstrap') + + self._bootstrap(**overrides) + self._finalize_core(**dict(DEFAULT_CONFIG)) + def _bootstrap(self, **overrides): # Set run-time variables (cannot be overridden): self.ipalib = path.dirname(path.abspath(__file__)) self.site_packages = path.dirname(self.ipalib) @@ -482,6 +505,11 @@ def _bootstrap(self, **overrides): else: self.confdir = path.join('/', 'etc', 'ipa') + if self.env_confdir is not None: + if self.env_confdir == self.confdir: + logger.info( + "IPA_CONFDIR env sets confdir to '%s'.", self.confdir) + # Set conf (config file for this context): if 'conf' not in self: self.conf = self._join('confdir', '%s.conf' % self.context) @@ -498,42 +526,6 @@ def _bootstrap(self, **overrides): self.plugins_on_demand = (self.context == 'cli') def _finalize_core(self, **defaults): - """ - Complete initialization of standard IPA environment. - - This method will perform the following steps: - - 1. Call `Env._bootstrap()` if it hasn't already been called. - - 2. Merge-in variables from the configuration file ``self.conf`` - (if it exists) by calling `Env._merge_from_file()`. - - 3. Merge-in variables from the defaults configuration file - ``self.conf_default`` (if it exists) by calling - `Env._merge_from_file()`. - - 4. Intelligently fill-in the *in_server* , *logdir*, *log*, and - *jsonrpc_uri* variables if they haven't already been set. - - 5. Merge-in the variables in ``defaults`` by calling `Env._merge()`. - In normal circumstances ``defaults`` will simply be those - specified in `constants.DEFAULT_CONFIG`. - - After this method is called, all the environment variables used by all - the built-in plugins will be available. As such, this method should be - called *before* any plugins are loaded. - - After this method has finished, the `Env` instance is still writable - so that 3rd-party plugins can set variables they may require as the - plugins are registered. - - Also see `Env._finalize()`, the final method in the bootstrap sequence. - - :param defaults: Internal defaults for all built-in variables. - """ - self.__doing('_finalize_core') - self.__do_if_not_done('_bootstrap') - # Merge in context config file and then default config file: if self.__d.get('mode', None) != 'dummy': self._merge_from_file(self.conf) @@ -578,18 +570,15 @@ def _finalize_core(self, **defaults): self._merge(**defaults) - def _finalize(self, **lastchance): + def finalize(self): """ Finalize and lock environment. This method will perform the following steps: - 1. Call `Env._finalize_core()` if it hasn't already been called. - - 2. Merge-in the variables in ``lastchance`` by calling - `Env._merge()`. + 1. Call `Env.bootstrap()` if it hasn't already been called. - 3. Lock this `Env` instance, after which no more environment + 2. Lock this `Env` instance, after which no more environment variables can be set on this instance. Aside from unit-tests and example code, normally only one `Env` instance is created, which means that after this step, no more variables can be set @@ -600,7 +589,6 @@ def _finalize(self, **lastchance): :param lastchance: Any final variables to merge-in before locking. """ - self.__doing('_finalize') - self.__do_if_not_done('_finalize_core') - self._merge(**lastchance) + self.__doing('finalize') + self.__do_if_not_done('bootstrap') self.__lock__() diff --git a/ipalib/constants.py b/ipalib/constants.py index 81643da..3278910 100644 --- a/ipalib/constants.py +++ b/ipalib/constants.py @@ -125,7 +125,7 @@ # Ports, hosts, and URIs: ('xmlrpc_uri', 'http://localhost:8888/ipa/xml'), - # jsonrpc_uri is set in Env._finalize_core() + # jsonrpc_uri is set in Env.bootstrap() ('ldap_uri', 'ldap://localhost:389'), ('rpc_protocol', 'jsonrpc'), @@ -158,7 +158,7 @@ ('wait_for_dns', 0), # CA plugin: - ('ca_host', FQDN), # Set in Env._finalize_core() + ('ca_host', FQDN), # Set in Env.bootstrap() ('ca_port', 80), ('ca_agent_port', 443), ('ca_ee_port', 443), @@ -197,18 +197,18 @@ # The remaining keys are never set from the values here! # ******************************************************** # - # Env._bootstrap() or Env._finalize_core() will have filled in all the keys + # Env.bootstrap() will have filled in all the keys # below by the time DEFAULT_CONFIG is merged in, so the values below are # never actually used. They are listed both to provide a big picture and # also so DEFAULT_CONFIG contains at least all the keys that should be - # present after Env._finalize_core() is called. + # present after Env.bootstrap() is called. # # Each environment variable below is sent to ``object``, which just happens # to be an invalid value for an environment variable, so if for some reason # any of these keys were set from the values here, an exception will be # raised. - # Non-overridable vars set in Env._bootstrap(): + # Non-overridable vars set in Env.bootstrap(): ('host', FQDN), ('ipalib', object), # The directory containing ipalib/__init__.py ('site_packages', object), # The directory contaning ipalib @@ -216,7 +216,7 @@ ('bin', object), # The directory containing the script ('home', object), # $HOME - # Vars set in Env._bootstrap(): + # Vars set in Env.bootstrap(): ('in_tree', object), # Whether or not running in-tree (bool) ('dot_ipa', object), # ~/.ipa directory ('context', object), # Name of context, default is 'default' @@ -227,12 +227,12 @@ ('plugins_on_demand', object), # Whether to finalize plugins on-demand (bool) ('nss_dir', object), # Path to nssdb, default {confdir}/nssdb - # Set in Env._finalize_core(): + # Set in Env.bootstrap(): ('in_server', object), # Whether or not running in-server (bool) ('logdir', object), # Directory containing log files ('log', object), # Path to context specific log file - ('jsonrpc_uri', object), # derived from xmlrpc_uri in Env._finalize_core() - ('server', object), # derived from jsonrpc_uri in Env._finalize_core() + ('jsonrpc_uri', object), # derived from xmlrpc_uri in Env.bootstrap() + ('server', object), # derived from jsonrpc_uri in Env.bootstrap() ) diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 1a9164f..fccf3c9 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -41,7 +41,6 @@ from ipalib.text import _ from ipalib.util import classproperty from ipalib.base import ReadOnly, lock, islocked -from ipalib.constants import DEFAULT_CONFIG from ipapython import ipautil from ipapython.ipa_log_manager import ( log_mgr, @@ -431,8 +430,7 @@ def bootstrap(self, parser=None, **overrides): self.log_mgr = log_mgr log = log_mgr.root_logger self.log = log - self.env._bootstrap(**overrides) - self.env._finalize_core(**dict(DEFAULT_CONFIG)) + self.env.bootstrap(**overrides) # Add the argument parser if not parser: @@ -713,11 +711,6 @@ def finalize(self): self.__doing('finalize') self.__do_if_not_done('load_plugins') - if self.env.env_confdir is not None: - if self.env.env_confdir == self.env.confdir: - self.log.info( - "IPA_CONFDIR env sets confdir to '%s'.", self.env.confdir) - for plugin in self.__plugins: if not self.env.validate_api: if plugin.full_name not in DEFAULT_PLUGINS: @@ -761,6 +754,8 @@ def finalize(self): self.__finalized = True + self.env.finalize() + if not production_mode: lock(self) diff --git a/ipaserver/install/server/replicainstall.py b/ipaserver/install/server/replicainstall.py index 18222c8..1be67ea 100644 --- a/ipaserver/install/server/replicainstall.py +++ b/ipaserver/install/server/replicainstall.py @@ -965,8 +965,8 @@ def promote_check(installer): fstore = sysrestore.FileStore(paths.SYSRESTORE) env = Env() - env._bootstrap(context='installer', confdir=paths.ETC_IPA, log=None) - env._finalize_core(**dict(constants.DEFAULT_CONFIG)) + env.bootstrap(context='installer', confdir=paths.ETC_IPA, log=None) + env.finalize() # pylint: disable=no-member xmlrpc_uri = 'https://{}/ipa/xml'.format(ipautil.format_netloc(env.host)) diff --git a/ipatests/test_ipalib/test_config.py b/ipatests/test_ipalib/test_config.py index 1df9a39..5ef6cec 100644 --- a/ipatests/test_ipalib/test_config.py +++ b/ipatests/test_ipalib/test_config.py @@ -363,7 +363,7 @@ def test_merge_from_file(self): no_exist = tmp.join('no_exist.conf') assert not path.exists(no_exist) o = self.cls() - o._bootstrap() + o.bootstrap() keys = tuple(o) orig = dict((k, o[k]) for k in o) assert o._merge_from_file(no_exist) is None @@ -389,7 +389,7 @@ def test_merge_from_file(self): assert o._merge_from_file(override) == (4, 6) for (k, v) in orig.items(): assert o[k] is v - assert list(o) == sorted(keys + ('key0', 'key1', 'key2', 'key3', 'config_loaded')) + assert list(o) == sorted(keys + ('key0', 'key1', 'key2', 'key3')) for i in range(4): assert o['key%d' % i] == ('var%d' % i) keys = tuple(o) @@ -426,20 +426,32 @@ def bootstrap(self, **overrides): Helper method used in testing bootstrap related methods below. """ (o, home) = self.new() - assert o._isdone('_bootstrap') is False - o._bootstrap(**overrides) - assert o._isdone('_bootstrap') is True - e = raises(Exception, o._bootstrap) - assert str(e) == 'Env._bootstrap() already called' + + # Check that calls cascade down the chain: + set_here = ('in_server', 'logdir', 'log') + assert o._isdone('bootstrap') is False + assert o._isdone('finalize') is False + for key in set_here: + assert key not in o + o.bootstrap(**overrides) + assert o._isdone('bootstrap') is True + assert o._isdone('finalize') is False # Should not cascade + for key in set_here: + assert key in o + + # Check that it can't be called twice: + e = raises(Exception, o.bootstrap) + assert str(e) == 'Env.bootstrap() already called' + return (o, home) def test_bootstrap(self): """ - Test the `ipalib.config.Env._bootstrap` method. + Test the `ipalib.config.Env.bootstrap` method. """ - # Test defaults created by _bootstrap(): + # Test defaults created by bootstrap(): (o, home) = self.new() - o._bootstrap() + o.bootstrap() ipalib = path.dirname(path.abspath(config.__file__)) assert o.ipalib == ipalib assert o.site_packages == path.dirname(ipalib) @@ -453,7 +465,7 @@ def test_bootstrap(self): assert o.conf == '/etc/ipa/default.conf' assert o.conf_default == o.conf - # Test overriding values created by _bootstrap() + # Test overriding values created by bootstrap() (o, home) = self.bootstrap(in_tree='True', context='server') assert o.in_tree is True assert o.context == 'server' @@ -482,74 +494,32 @@ def test_bootstrap(self): (o, home) = self.new() for key in kw: assert key not in o - o._bootstrap(**override) + o.bootstrap(**override) for (key, value) in kw.items(): assert getattr(o, key) == value assert o[key] == value - def finalize_core(self, ctx, **defaults): - """ - Helper method used in testing `Env._finalize_core`. - """ + # Test that correct defaults are generated: # We must force in_tree=True so we don't load possible config files in # /etc/ipa/, whose contents could break this test: - (o, home) = self.new(in_tree=True) - if ctx: - o.context = ctx - - # Check that calls cascade down the chain: - set_here = ('in_server', 'logdir', 'log') - assert o._isdone('_bootstrap') is False - assert o._isdone('_finalize_core') is False - assert o._isdone('_finalize') is False - for key in set_here: - assert key not in o - o._finalize_core(**defaults) - assert o._isdone('_bootstrap') is True - assert o._isdone('_finalize_core') is True - assert o._isdone('_finalize') is False # Should not cascade - for key in set_here: - assert key in o - - # Check that it can't be called twice: - e = raises(Exception, o._finalize_core) - assert str(e) == 'Env._finalize_core() already called' - - return (o, home) - - def test_finalize_core(self): - """ - Test the `ipalib.config.Env._finalize_core` method. - """ - # Test that correct defaults are generated: - (o, home) = self.finalize_core(None) + (o, home) = self.bootstrap(in_tree=True) assert o.in_server is False assert o.logdir == home.join('.ipa', 'log') assert o.log == home.join('.ipa', 'log', 'default.log') # Test with context='server' - (o, home) = self.finalize_core('server') + (o, home) = self.bootstrap(in_tree=True, context='server') assert o.in_server is True assert o.logdir == home.join('.ipa', 'log') assert o.log == home.join('.ipa', 'log', 'server.log') - # Test that **defaults can't set in_server, logdir, nor log: - (o, home) = self.finalize_core(None, - in_server='IN_SERVER', - logdir='LOGDIR', - log='LOG', - ) - assert o.in_server is False - assert o.logdir == home.join('.ipa', 'log') - assert o.log == home.join('.ipa', 'log', 'default.log') - # Test loading config file, plus test some in-tree stuff - (o, home) = self.bootstrap(in_tree=True, context='server') + (o, home) = self.new(in_tree=True) for key in ('yes', 'no', 'number'): assert key not in o home.write(config_good, '.ipa', 'server.conf') home.write(config_default, '.ipa', 'default.conf') - o._finalize_core() + o.bootstrap(context='server') assert o.in_tree is True assert o.context == 'server' assert o.in_server is True @@ -562,7 +532,7 @@ def test_finalize_core(self): # Test using DEFAULT_CONFIG: defaults = dict(constants.DEFAULT_CONFIG) - (o, home) = self.finalize_core(None, **defaults) + (o, home) = self.bootstrap(in_tree=True) assert list(o) == sorted(defaults) for (key, value) in defaults.items(): if value is object: @@ -573,37 +543,24 @@ def test_finalize_core(self): def test_finalize(self): """ - Test the `ipalib.config.Env._finalize` method. + Test the `ipalib.config.Env.finalize` method. """ # Check that calls cascade up the chain: o, _home = self.new(in_tree=True) - assert o._isdone('_bootstrap') is False - assert o._isdone('_finalize_core') is False - assert o._isdone('_finalize') is False - o._finalize() - assert o._isdone('_bootstrap') is True - assert o._isdone('_finalize_core') is True - assert o._isdone('_finalize') is True + assert o._isdone('bootstrap') is False + assert o._isdone('finalize') is False + o.finalize() + assert o._isdone('bootstrap') is True + assert o._isdone('finalize') is True # Check that it can't be called twice: - e = raises(Exception, o._finalize) - assert str(e) == 'Env._finalize() already called' + e = raises(Exception, o.finalize) + assert str(e) == 'Env.finalize() already called' - # Check that _finalize() calls __lock__() + # Check that finalize() calls __lock__() o, _home = self.new(in_tree=True) assert o.__islocked__() is False - o._finalize() + o.finalize() assert o.__islocked__() is True e = raises(Exception, o.__lock__) assert str(e) == 'Env.__lock__() already called' - - # Check that **lastchance works - o, _home = self.finalize_core(None) - key = 'just_one_more_key' - value = u'with one more value' - lastchance = {key: value} - assert key not in o - assert o._isdone('_finalize') is False - o._finalize(**lastchance) - assert key in o - assert o[key] is value diff --git a/ipatests/test_ipalib/test_frontend.py b/ipatests/test_ipalib/test_frontend.py index 7413408..f8df2b3 100644 --- a/ipatests/test_ipalib/test_frontend.py +++ b/ipatests/test_ipalib/test_frontend.py @@ -154,7 +154,8 @@ def get_stuff(self): assert type(p) is parameters.Str # Test when env.context == 'cli': - cli = config.Env(context='cli') + cli = config.Env() + cli.context = 'cli' assert cli.context == 'cli' params = list(o._filter_param_by_context('stuff', cli)) assert list(p.name for p in params) == ['one', 'two', 'three', 'four'] @@ -162,7 +163,8 @@ def get_stuff(self): assert type(p) is parameters.Str # Test when env.context == 'server' - server = config.Env(context='server') + server = config.Env() + server.context = 'server' assert server.context == 'server' params = list(o._filter_param_by_context('stuff', server)) assert list(p.name for p in params) == ['one', 'two', 'five'] @@ -471,7 +473,8 @@ def test_validate(self): Test the `ipalib.frontend.Command.validate` method. """ class api(object): - env = config.Env(context='cli') + env = config.Env() + env.context = 'cli' @staticmethod def is_production_mode(): return False diff --git a/ipatests/test_ipalib/test_plugable.py b/ipatests/test_ipalib/test_plugable.py index 6954610..7b4f23f 100644 --- a/ipatests/test_ipalib/test_plugable.py +++ b/ipatests/test_ipalib/test_plugable.py @@ -252,13 +252,11 @@ def test_bootstrap(self): Test the `ipalib.plugable.API.bootstrap` method. """ o, _home = create_test_api() - assert o.env._isdone('_bootstrap') is False - assert o.env._isdone('_finalize_core') is False + assert o.env._isdone('bootstrap') is False assert o.isdone('bootstrap') is False o.bootstrap(my_test_override='Hello, world!') assert o.isdone('bootstrap') is True - assert o.env._isdone('_bootstrap') is True - assert o.env._isdone('_finalize_core') is True + assert o.env._isdone('bootstrap') is True assert o.env.my_test_override == 'Hello, world!' e = raises(Exception, o.bootstrap) assert str(e) == 'API.bootstrap() already called'
-- 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
