summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-10-27 15:19:49 -0600
committerJason Gerard DeRose <jderose@redhat.com>2008-10-27 15:19:49 -0600
commite6254026fe73c423d357a2fa1489de35475da46c (patch)
treec24f21fc60eff3ee62d36a99325197581f63fb37
parent17fd9cc4315f171a8d9e9d189936eea8ba2af0c0 (diff)
downloadfreeipa-e6254026fe73c423d357a2fa1489de35475da46c.tar.gz
freeipa-e6254026fe73c423d357a2fa1489de35475da46c.tar.xz
freeipa-e6254026fe73c423d357a2fa1489de35475da46c.zip
Implemented basic CLI.bootstrap(); added corresponding unit tests
-rw-r--r--ipalib/cli.py35
-rw-r--r--ipalib/plugable.py3
-rw-r--r--tests/test_ipalib/test_cli.py26
3 files changed, 35 insertions, 29 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index eb8df591b..e15e2ff09 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -396,28 +396,19 @@ class CLI(object):
def bootstrap(self):
self.__doing('bootstrap')
self.parse_globals()
-
-# if options.interactive == True:
-# self.__all_interactive = True
-# elif options.interactive == False:
-# self.__not_interactive = True
-# if options.verbose != None:
-# self.api.env.verbose = True
-# if options.environment:
-# env_dict = {}
-# for a in options.environment.split(','):
-# a = a.split('=', 1)
-# if len(a) < 2:
-# parser.error('badly specified environment string,'\
-# 'use var1=val1[,var2=val2]..')
-# env_dict[a[0].strip()] = a[1].strip()
-# self.api.env.update(env_dict, True)
-# if options.config_file:
-# self.api.env.update(read_config(options.config_file), True)
-# else:
-# self.api.env.update(read_config(), True)
-
-# return args
+ self.api.env.verbose = self.options.verbose
+ if self.options.config_file:
+ self.api.env.conf = self.options.config_file
+ overrides = {}
+ if self.options.environment:
+ for a in self.options.environment.split(','):
+ a = a.split('=', 1)
+ if len(a) < 2:
+ parser.error('badly specified environment string,'\
+ 'use var1=val1[,var2=val2]..')
+ overrides[a[0].strip()] = a[1].strip()
+ overrides['context'] = 'cli'
+ self.api.bootstrap(**overrides)
def get_usage(self, cmd):
return ' '.join(self.get_usage_iter(cmd))
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 594849896..f704077a2 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -714,7 +714,7 @@ class API(DictProxy):
self.__d = dict()
self.__done = set()
self.register = Registrar(*allowed)
- self.env = Env
+ self.env = Env()
super(API, self).__init__(self.__d)
def __doing(self, name):
@@ -736,6 +736,7 @@ class API(DictProxy):
Initialize environment variables needed by built-in plugins.
"""
self.__doing('bootstrap')
+ self.env._bootstrap(**overrides)
def load_plugins(self, dry_run=False):
"""
diff --git a/tests/test_ipalib/test_cli.py b/tests/test_ipalib/test_cli.py
index 28e441e7d..293371b79 100644
--- a/tests/test_ipalib/test_cli.py
+++ b/tests/test_ipalib/test_cli.py
@@ -22,6 +22,7 @@ Test the `ipalib.cli` module.
"""
from tests.util import raises, getitem, no_set, no_del, read_only, ClassChecker
+from tests.util import TempHome
from ipalib import cli, plugable, frontend, backend
@@ -81,7 +82,8 @@ class test_CLI(ClassChecker):
"""
_cls = cli.CLI
- def new(self, argv):
+ def new(self, argv=tuple()):
+ home = TempHome()
api = plugable.API(
frontend.Command,
frontend.Object,
@@ -90,17 +92,18 @@ class test_CLI(ClassChecker):
frontend.Application,
backend.Backend,
)
+ api.env.in_tree = True
o = self.cls(api, argv)
assert o.api is api
- return o
+ return (o, api, home)
def test_init(self):
"""
Test the `ipalib.cli.CLI.__init__` method.
"""
argv = ['-v', 'user-add', '--first=Jonh', '--last=Doe']
- o = self.new(argv)
- assert type(o.api) is plugable.API
+ (o, api, home) = self.new(argv)
+ assert o.api is api
assert o.argv == tuple(argv)
def test_parse_globals(self):
@@ -108,7 +111,7 @@ class test_CLI(ClassChecker):
Test the `ipalib.cli.CLI.parse_globals` method.
"""
# Test with empty argv
- o = self.new([])
+ (o, api, home) = self.new()
assert not hasattr(o, 'options')
assert not hasattr(o, 'cmd_argv')
assert o.isdone('parse_globals') is False
@@ -125,7 +128,7 @@ class test_CLI(ClassChecker):
# Test with a populated argv
argv = ('-a', '-n', '-v', '-c', '/my/config.conf', '-e', 'my_key=my_val')
cmd_argv = ('user-add', '--first', 'John', '--last', 'Doe')
- o = self.new(argv + cmd_argv)
+ (o, api, home) = self.new(argv + cmd_argv)
assert not hasattr(o, 'options')
assert not hasattr(o, 'cmd_argv')
assert o.isdone('parse_globals') is False
@@ -144,3 +147,14 @@ class test_CLI(ClassChecker):
"""
Test the `ipalib.cli.CLI.bootstrap` method.
"""
+ (o, api, home) = self.new()
+ keys = tuple(api.env)
+ assert o.isdone('parse_globals') is False
+ assert o.isdone('bootstrap') is False
+ o.bootstrap()
+ assert o.isdone('parse_globals') is True
+ assert o.isdone('bootstrap') is True
+ e = raises(StandardError, o.bootstrap)
+ assert str(e) == 'CLI.bootstrap() already called'
+ assert api.env.verbose is False
+ assert api.env.context == 'cli'