mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-24 16:10:02 -06:00
plugable: Change is_production_mode to method of API
https://fedorahosted.org/freeipa/ticket/3090 Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
This commit is contained in:
parent
1a21fd971c
commit
4b277d0477
@ -27,7 +27,7 @@ from distutils import version
|
||||
from ipapython.version import API_VERSION
|
||||
from ipapython.ipa_log_manager import root_logger
|
||||
from base import NameSpace
|
||||
from plugable import Plugin, is_production_mode
|
||||
from plugable import Plugin
|
||||
from parameters import create_param, Param, Str, Flag, Password
|
||||
from output import Output, Entry, ListOfEntries
|
||||
from text import _
|
||||
@ -359,7 +359,7 @@ class HasParam(Plugin):
|
||||
self._filter_param_by_context(name, env),
|
||||
sort=False
|
||||
)
|
||||
if not is_production_mode(self):
|
||||
if not self.api.is_production_mode():
|
||||
check = getattr(self, 'check_' + name, None)
|
||||
if callable(check):
|
||||
check(namespace)
|
||||
|
@ -49,17 +49,6 @@ from ipapython.version import VERSION, API_VERSION
|
||||
# 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'
|
||||
|
||||
|
||||
# FIXME: This function has no unit test
|
||||
def find_modules_in_dir(src_dir):
|
||||
@ -184,7 +173,7 @@ class Plugin(ReadOnly):
|
||||
self.__finalize_called = True
|
||||
self._on_finalize()
|
||||
self.__finalized = True
|
||||
if not is_production_mode(self):
|
||||
if not self.__api.is_production_mode():
|
||||
lock(self)
|
||||
|
||||
def _on_finalize(self):
|
||||
@ -368,6 +357,13 @@ class API(ReadOnly):
|
||||
except AttributeError:
|
||||
raise KeyError(name)
|
||||
|
||||
def is_production_mode(self):
|
||||
"""
|
||||
If the object has self.env.mode defined and that mode is
|
||||
production return True, otherwise return False.
|
||||
"""
|
||||
return getattr(self.env, 'mode', None) == 'production'
|
||||
|
||||
def __doing(self, name):
|
||||
if name in self.__done:
|
||||
raise StandardError(
|
||||
@ -664,7 +660,7 @@ class API(ReadOnly):
|
||||
self.__doing('finalize')
|
||||
self.__do_if_not_done('load_plugins')
|
||||
|
||||
production_mode = is_production_mode(self)
|
||||
production_mode = self.is_production_mode()
|
||||
plugins = {}
|
||||
plugin_info = {}
|
||||
|
||||
|
@ -221,7 +221,10 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Helper method used to test args and options.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
class example(self.cls):
|
||||
takes_args = args
|
||||
takes_options = options
|
||||
@ -264,7 +267,10 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the ``ipalib.frontend.Command.args`` instance attribute.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
o = self.cls(api)
|
||||
o.finalize()
|
||||
assert type(o.args) is plugable.NameSpace
|
||||
@ -313,7 +319,10 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the ``ipalib.frontend.Command.options`` instance attribute.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
o = self.cls(api)
|
||||
o.finalize()
|
||||
assert type(o.options) is plugable.NameSpace
|
||||
@ -334,7 +343,10 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the ``ipalib.frontend.Command.output`` instance attribute.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
inst = self.cls(api)
|
||||
inst.finalize()
|
||||
assert type(inst.output) is plugable.NameSpace
|
||||
@ -381,6 +393,9 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
class api(object):
|
||||
env = config.Env(context='cli')
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
class user_add(frontend.Command):
|
||||
takes_args = parameters.Str('uid',
|
||||
normalizer=lambda value: value.lower(),
|
||||
@ -405,7 +420,10 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.convert` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
kw = dict(
|
||||
option0=u'1.5',
|
||||
option1=u'7',
|
||||
@ -419,7 +437,10 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.normalize` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
kw = dict(
|
||||
option0=u'OPTION0',
|
||||
option1=u'OPTION1',
|
||||
@ -467,6 +488,9 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
class api(object):
|
||||
env = config.Env(context='cli')
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
|
||||
sub = self.subcls(api)
|
||||
sub.finalize()
|
||||
@ -672,7 +696,10 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.validate_output` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
class Example(self.cls):
|
||||
has_output = ('foo', 'bar', 'baz')
|
||||
|
||||
@ -711,7 +738,10 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test `ipalib.frontend.Command.validate_output` per-type validation.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
|
||||
class Complex(self.cls):
|
||||
has_output = (
|
||||
@ -737,7 +767,10 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test `ipalib.frontend.Command.validate_output` nested validation.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
|
||||
class Subclass(output.ListOfEntries):
|
||||
pass
|
||||
@ -769,7 +802,10 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.get_output_params` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
class example(self.cls):
|
||||
has_output_params = (
|
||||
'one',
|
||||
@ -802,7 +838,10 @@ class test_LocalOrRemote(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.LocalOrRemote.__init__` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
o = self.cls(api)
|
||||
o.finalize()
|
||||
assert list(o.args) == []
|
||||
@ -915,6 +954,8 @@ class test_Object(ClassChecker):
|
||||
return hasattr(self, key)
|
||||
def __getitem__(self, key):
|
||||
return getattr(self, key)
|
||||
def is_production_mode(self):
|
||||
return False
|
||||
api = FakeAPI()
|
||||
assert len(api.Method) == cnt * 3
|
||||
|
||||
@ -1073,6 +1114,9 @@ class test_Attribute(ClassChecker):
|
||||
user_obj = 'The user frontend.Object instance'
|
||||
class api(object):
|
||||
Object = dict(user=user_obj)
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
class user_add(self.cls):
|
||||
pass
|
||||
o = user_add(api)
|
||||
|
@ -88,7 +88,10 @@ class test_Plugin(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.plugable.Plugin.finalize` method.
|
||||
"""
|
||||
api = 'the api instance'
|
||||
class api(object):
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
o = self.cls(api)
|
||||
assert not o.__islocked__()
|
||||
o.finalize()
|
||||
|
Loading…
Reference in New Issue
Block a user