summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipalib/frontend.py4
-rw-r--r--ipalib/plugable.py23
-rw-r--r--tests/test_ipalib/test_config.py2
3 files changed, 21 insertions, 8 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index cf78d441f..b9b75372c 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -24,7 +24,7 @@ Base classes for all front-end plugins.
import re
import inspect
from base import lock, check_name, NameSpace
-from plugable import Plugin
+from plugable import Plugin, is_production_mode
from parameters import create_param, parse_param_spec, Param, Str, Flag, Password
from util import make_repr
from output import Output, Entry, ListOfEntries
@@ -351,7 +351,7 @@ class HasParam(Plugin):
self._filter_param_by_context(name, env),
sort=False
)
- if self.env.mode != 'production':
+ if not is_production_mode(self):
check = getattr(self, 'check_' + name, None)
if callable(check):
check(namespace)
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 82bd52283..a7e61ddbd 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -44,6 +44,17 @@ from constants import DEFAULT_CONFIG, FORMAT_STDERR, FORMAT_FILE
# FIXME: Updated constants.TYPE_ERROR to use this clearer format from wehjit:
TYPE_ERROR = '%s: need a %r; got a %r: %r'
+def is_production_mode(obj):
+ """
+ If the object has self.env.mode defined and that mode is
+ production return True, otherwise return False.
+ """
+ if getattr(obj, 'env', None) is None:
+ return False
+ if getattr(obj.env, 'mode', None) is None:
+ return False
+ return obj.env.mode == 'production'
+
class SetProxy(ReadOnly):
"""
@@ -207,9 +218,8 @@ class Plugin(ReadOnly):
def finalize(self):
"""
"""
- if self.env.mode == 'production':
- return
- lock(self)
+ if not is_production_mode(self):
+ lock(self)
def set_api(self, api):
"""
@@ -597,13 +607,14 @@ class API(DictProxy):
p.bases.append(base)
yield p.instance
+ production_mode = is_production_mode(self)
for name in self.register:
base = self.register[name]
magic = getattr(self.register, name)
namespace = NameSpace(
plugin_iter(base, (magic[k] for k in magic))
)
- if self.env.mode != 'production':
+ if not production_mode:
assert not (
name in self.__d or hasattr(self, name)
)
@@ -612,12 +623,12 @@ class API(DictProxy):
for p in plugins.itervalues():
p.instance.set_api(self)
- if self.env.mode != 'production':
+ if not production_mode:
assert p.instance.api is self
for p in plugins.itervalues():
p.instance.finalize()
- if self.env.mode != 'production':
+ if not production_mode:
assert islocked(p.instance) is True
object.__setattr__(self, '_API__finalized', True)
tuple(PluginInfo(p) for p in plugins.itervalues())
diff --git a/tests/test_ipalib/test_config.py b/tests/test_ipalib/test_config.py
index af4aeb6fb..97d7548fe 100644
--- a/tests/test_ipalib/test_config.py
+++ b/tests/test_ipalib/test_config.py
@@ -568,6 +568,8 @@ class test_Env(ClassChecker):
for (key, value) in defaults.items():
if value is object:
continue
+ if key == 'mode':
+ continue
assert o[key] == value, '%r is %r; should be %r' % (key, o[key], value)
def test_finalize(self):