From b06db4ab7f4bdb7843f8b75205570041a0a045d7 Mon Sep 17 00:00:00 2001 From: Michael Basnight Date: Sat, 1 Feb 2014 00:24:57 +0000 Subject: [PATCH] Migrating trove to entry points PBR/Distribute generates binscripts for us. By moving the binscript code into the source tree, we can unit test it as well. Run setup.py develop to generate the binscripts for development use. implements blueprint entrypoints-for-binscripts Change-Id: I9ad4bb4ddc55f64bcd806c588a795cd6e0847aa9 --- bin/trove-api-os-database | 72 ----- bin/trove-cli | 303 ------------------ bin/trove-mgmt-taskmanager | 66 ---- bin/trove-api => contrib/trove-guestagent | 45 +-- setup.cfg | 18 +- {bin => tools}/start-fake-mode.sh | 0 {bin => tools}/stop-fake-mode.sh | 0 trove/cmd/__init__.py | 0 trove/cmd/api.py | 42 +++ bin/trove-conductor => trove/cmd/conductor.py | 10 +- bin/trove-fake-mode => trove/cmd/fakemode.py | 30 +- bin/trove-guestagent => trove/cmd/guest.py | 35 +- bin/trove-manage => trove/cmd/manage.py | 13 - .../cmd/taskmanager.py | 36 +-- 14 files changed, 90 insertions(+), 580 deletions(-) delete mode 100755 bin/trove-api-os-database delete mode 100755 bin/trove-cli delete mode 100755 bin/trove-mgmt-taskmanager rename bin/trove-api => contrib/trove-guestagent (50%) rename {bin => tools}/start-fake-mode.sh (100%) rename {bin => tools}/stop-fake-mode.sh (100%) create mode 100644 trove/cmd/__init__.py create mode 100755 trove/cmd/api.py rename bin/trove-conductor => trove/cmd/conductor.py (89%) rename bin/trove-fake-mode => trove/cmd/fakemode.py (70%) rename bin/trove-guestagent => trove/cmd/guest.py (53%) rename bin/trove-manage => trove/cmd/manage.py (89%) rename bin/trove-taskmanager => trove/cmd/taskmanager.py (63%) diff --git a/bin/trove-api-os-database b/bin/trove-api-os-database deleted file mode 100755 index 654f3052d9..0000000000 --- a/bin/trove-api-os-database +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Starter script for Nova OS API.""" - -import eventlet -eventlet.monkey_patch() - -import os -import sys - - -possible_topdir = os.path.normpath(os.path.join(os.path.abspath( - sys.argv[0]), os.pardir, os.pardir)) -if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")): - sys.path.insert(0, possible_topdir) - -from nova import flags -from nova import log as logging -from nova import service -from nova import utils -from nova import wsgi -from nova.openstack.common import cfg - -SERVICE_NAME = "troveapi_database" - -trove_opts = [ - cfg.StrOpt('trove_api_paste_config', - default='trove-api-paste.ini', - help='Trove API paste config'), - # port magic in service.WSGIService the name of the app has to be the same - # as the name of the service - cfg.IntOpt('%s_listen_port' % SERVICE_NAME, - default=8779, - help='Trove API default port'), - cfg.MultiStrOpt('trove_api_extension', - default=['trove.api.database.contrib.standard_extensions'], - help='osapi compute extension to load'), ] - -FLAGS = flags.FLAGS -FLAGS.register_opts(trove_opts) - - -def main(): - utils.default_flagfile() - flags.FLAGS(sys.argv) - logging.setup() - utils.monkey_patch() - loader = wsgi.Loader(config_path=FLAGS.trove_api_paste_config) - server = service.WSGIService(SERVICE_NAME, loader=loader) - service.serve(server) - service.wait() - - -if __name__ == '__main__': - main() diff --git a/bin/trove-cli b/bin/trove-cli deleted file mode 100755 index 0857262c88..0000000000 --- a/bin/trove-cli +++ /dev/null @@ -1,303 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2011 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -Trove Command line tool -""" - -import json -import optparse -import os -import sys - - -# If ../trove/__init__.py exists, add ../ to Python search path, so that -# it will override what happens to be installed in /usr/(local/)lib/python... -possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), - os.pardir, - os.pardir)) -if os.path.exists(os.path.join(possible_topdir, 'troveclient', - '__init__.py')): - sys.path.insert(0, possible_topdir) -if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): - sys.path.insert(0, possible_topdir) - - -from troveclient import common - - -oparser = None - - -def _pretty_print(info): - print(json.dumps(info, sort_keys=True, indent=4)) - - -class InstanceCommands(object): - """Commands to perform various instances operations and actions""" - - def __init__(self): - pass - - def create(self, name, volume_size, - flavorRef="http://localhost:8775/v1.0/flavors/1"): - """Create a new instance""" - dbaas = common.get_client() - volume = {"size": volume_size} - try: - result = dbaas.instances.create(name, flavorRef, volume) - _pretty_print(result._info) - except Exception: - print(sys.exc_info()[1]) - - def delete(self, id): - """Delete the specified instance""" - dbaas = common.get_client() - try: - result = dbaas.instances.delete(id) - if result: - print(result) - except Exception: - print(sys.exc_info()[1]) - - def get(self, id): - """Get details for the specified instance""" - dbaas = common.get_client() - try: - _pretty_print(dbaas.instances.get(id)._info) - except Exception: - print(sys.exc_info()[1]) - - def list(self): - """List all instances for account""" - dbaas = common.get_client() - try: - for instance in dbaas.instances.list(): - _pretty_print(instance._info) - except Exception: - print(sys.exc_info()[1]) - - def resize(self, id, size): - """Resize an instance volume""" - dbaas = common.get_client() - try: - result = dbaas.instances.resize(id, size) - if result: - print(result) - except Exception: - print(sys.exc_info()[1]) - - def restart(self, id): - """Restart the database""" - dbaas = common.get_client() - try: - result = dbaas.instances.restart(id) - if result: - print(result) - except Exception: - print(sys.exc_info()[1]) - - -class FlavorsCommands(object): - """Commands for listing Flavors""" - - def __init__(self): - pass - - def list(self): - """List the available flavors""" - dbaas = common.get_client() - try: - for flavor in dbaas.flavors.list(): - _pretty_print(flavor._info) - except Exception: - print(sys.exc_info()[1]) - - -class DatabaseCommands(object): - """Database CRUD operations on an instance""" - - def __init__(self): - pass - - def create(self, id, dbname): - """Create a database""" - dbaas = common.get_client() - try: - databases = [{'name': dbname}] - dbaas.databases.create(id, databases) - except Exception: - print(sys.exc_info()[1]) - - def delete(self, id, dbname): - """Delete a database""" - dbaas = common.get_client() - try: - dbaas.databases.delete(id, dbname) - except Exception: - print(sys.exc_info()[1]) - - def list(self, id): - """List the databases""" - dbaas = common.get_client() - try: - for database in dbaas.databases.list(id): - _pretty_print(database._info) - except Exception: - print(sys.exc_info()[1]) - - -class UserCommands(object): - """User CRUD operations on an instance""" - - def __init__(self): - pass - - def create(self, id, username, password, dbname, *args): - """Create a user in instance, with access to one or more databases""" - dbaas = common.get_client() - try: - databases = [{'name': dbname}] - [databases.append({"name": db}) for db in args] - users = [{'name': username, 'password': password, - 'databases': databases}] - dbaas.users.create(id, users) - except Exception: - print(sys.exc_info()[1]) - - def delete(self, id, user): - """Delete the specified user""" - dbaas = common.get_client() - try: - dbaas.users.delete(id, user) - except Exception: - print(sys.exc_info()[1]) - - def list(self, id): - """List all the users for an instance""" - dbaas = common.get_client() - try: - for user in dbaas.users.list(id): - _pretty_print(user._info) - except Exception: - print(sys.exc_info()[1]) - - -class RootCommands(object): - """Root user related operations on an instance""" - - def __init__(self): - pass - - def create(self, id): - """Enable the instance's root user.""" - dbaas = common.get_client() - try: - user, password = dbaas.root.create(id) - print("User:\t\t%s\nPassword:\t%s" % (user, password)) - except Exception: - print(sys.exc_info()[1]) - - def enabled(self, id): - """Check the instance for root access""" - dbaas = common.get_client() - try: - _pretty_print(dbaas.root.is_root_enabled(id)) - except Exception: - print(sys.exc_info()[1]) - - -class VersionCommands(object): - """List available versions""" - - def __init__(self): - pass - - def list(self, url): - """List all the supported versions""" - dbaas = common.get_client() - try: - versions = dbaas.versions.index(url) - for version in versions: - _pretty_print(version._info) - except Exception: - print(sys.exc_info()[1]) - - -def config_options(): - global oparser - oparser.add_option("-u", "--url", default="http://localhost:5000/v1.1", - help="Auth API endpoint URL with port and version. \ - Default: http://localhost:5000/v1.1") - - -COMMANDS = {'auth': common.Auth, - 'instance': InstanceCommands, - 'flavor': FlavorsCommands, - 'database': DatabaseCommands, - 'user': UserCommands, - 'root': RootCommands, - 'version': VersionCommands} - - -def main(): - # Parse arguments - global oparser - oparser = optparse.OptionParser("%prog [options] ", - version='1.0') - config_options() - (options, args) = oparser.parse_args() - - if not args: - common.print_commands(COMMANDS) - - # Pop the command and check if it's in the known commands - cmd = args.pop(0) - if cmd in COMMANDS: - fn = COMMANDS.get(cmd) - command_object = fn() - - # Get a list of supported actions for the command - actions = common.methods_of(command_object) - - if len(args) < 1: - common.print_actions(cmd, actions) - - # Check for a valid action and perform that action - action = args.pop(0) - if action in actions: - fn = actions.get(action) - - try: - fn(*args) - sys.exit(0) - except TypeError as err: - print("Possible wrong number of arguments supplied.") - print("%s %s: %s" % (cmd, action, fn.__doc__)) - print("\t\t", [fn.func_code.co_varnames[i] for i in - range(fn.func_code.co_argcount)]) - print("ERROR: %s" % err) - except Exception: - print("Command failed, please check the log for more info.") - raise - else: - common.print_actions(cmd, actions) - else: - common.print_commands(COMMANDS) - - -if __name__ == '__main__': - main() diff --git a/bin/trove-mgmt-taskmanager b/bin/trove-mgmt-taskmanager deleted file mode 100755 index ae564c227c..0000000000 --- a/bin/trove-mgmt-taskmanager +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2011 OpenStack Foundation -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import eventlet -eventlet.monkey_patch() - -import gettext -import os -import sys - - -gettext.install('trove', unicode=1) - - -# If ../trove/__init__.py exists, add ../ to Python search path, so that -# it will override what happens to be installed in /usr/(local/)lib/python... -possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), - os.pardir, - os.pardir)) -if os.path.exists(os.path.join(possible_topdir, 'trove', '__init__.py')): - sys.path.insert(0, possible_topdir) - -from trove.common import cfg -from trove.common.rpc import service as rpc_service -from oslo.config import cfg as openstack_cfg -from trove.openstack.common import log as logging -from trove.openstack.common import service as openstack_service -from trove.db import get_db_api - -CONF = cfg.CONF -CONF.register_opts([openstack_cfg.StrOpt('taskmanager_manager')]) - - -def main(): - cfg.parse_args(sys.argv) - logging.setup(None) - - try: - get_db_api().configure_db(CONF) - server = rpc_service.RpcService(manager=CONF.taskmanager_manager, - topic="mgmt-taskmanager") - launcher = openstack_service.launch(server) - launcher.wait() - except RuntimeError as error: - import traceback - print(traceback.format_exc()) - sys.exit("ERROR: %s" % error) - - -if __name__ == '__main__': - main() diff --git a/bin/trove-api b/contrib/trove-guestagent similarity index 50% rename from bin/trove-api rename to contrib/trove-guestagent index a1fa0815c9..c9c8ebb12b 100755 --- a/bin/trove-api +++ b/contrib/trove-guestagent @@ -1,5 +1,4 @@ -#!/usr/bin/env python -# vim: tabstop=4 shiftwidth=4 softtabstop=4 +#!/usr/bin/python # Copyright 2011 OpenStack Foundation # All Rights Reserved. @@ -16,46 +15,20 @@ # License for the specific language governing permissions and limitations # under the License. -import gettext -import os +"""This is necessary currently because the guest needs a init script. +When the guest is moved out of the application, this will no longer +be needed in the project.""" + import sys +import os - -gettext.install('trove', unicode=1) - - -# If ../trove/__init__.py exists, add ../ to Python search path, so that -# it will override what happens to be installed in /usr/(local/)lib/python... possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, os.pardir)) if os.path.exists(os.path.join(possible_topdir, 'trove', '__init__.py')): sys.path.insert(0, possible_topdir) -from trove.common import cfg -from trove.openstack.common import log as logging -from trove.common import wsgi -from trove.db import get_db_api +from trove.cmd.guest import main - -CONF = cfg.CONF - - -def main(): - cfg.parse_args(sys.argv) - logging.setup(None) - - try: - get_db_api().configure_db(CONF) - conf_file = CONF.find_file(CONF.api_paste_config) - launcher = wsgi.launch('trove', CONF.bind_port or 8779, conf_file, - workers=CONF.trove_api_workers) - launcher.wait() - except RuntimeError as error: - import traceback - print(traceback.format_exc()) - sys.exit("ERROR: %s" % error) - - -if __name__ == '__main__': - main() +if __name__ == "__main__": + sys.exit(main()) diff --git a/setup.cfg b/setup.cfg index 98dad17541..cd4a630f79 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,14 +21,16 @@ classifier = [files] packages = trove -scripts = - bin/trove-api - bin/trove-fake-mode - bin/trove-conductor - bin/trove-manage - bin/trove-mgmt-taskmanager - bin/trove-taskmanager - bin/trove-guestagent + +[entry_points] +console_scripts = + trove-api = trove.cmd.api:main + trove-taskmanager = trove.cmd.taskmanager:main + trove-mgmt-taskmanager = trove.cmd.taskmanager:mgmt_main + trove-conductor = trove.cmd.conductor:main + trove-manage = trove.cmd.manage:main + trove-guestagent = trove.cmd.guest:main + trove-fake-mode = trove.cmd.fakemode:main [global] setup-hooks = diff --git a/bin/start-fake-mode.sh b/tools/start-fake-mode.sh similarity index 100% rename from bin/start-fake-mode.sh rename to tools/start-fake-mode.sh diff --git a/bin/stop-fake-mode.sh b/tools/stop-fake-mode.sh similarity index 100% rename from bin/stop-fake-mode.sh rename to tools/stop-fake-mode.sh diff --git a/trove/cmd/__init__.py b/trove/cmd/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/trove/cmd/api.py b/trove/cmd/api.py new file mode 100755 index 0000000000..757180f00a --- /dev/null +++ b/trove/cmd/api.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +# Copyright 2011 OpenStack Foundation +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import gettext +import sys + + +gettext.install('trove', unicode=1) + + +from trove.common import cfg +from trove.openstack.common import log as logging +from trove.common import wsgi +from trove.db import get_db_api + + +CONF = cfg.CONF + + +def main(): + cfg.parse_args(sys.argv) + logging.setup(None) + + get_db_api().configure_db(CONF) + conf_file = CONF.find_file(CONF.api_paste_config) + launcher = wsgi.launch('trove', CONF.bind_port or 8779, conf_file, + workers=CONF.trove_api_workers) + launcher.wait() diff --git a/bin/trove-conductor b/trove/cmd/conductor.py similarity index 89% rename from bin/trove-conductor rename to trove/cmd/conductor.py index 166c8618db..ea5204e79f 100755 --- a/bin/trove-conductor +++ b/trove/cmd/conductor.py @@ -20,7 +20,6 @@ import eventlet eventlet.monkey_patch(all=True, thread=False) import gettext -import traceback import sys @@ -55,12 +54,5 @@ def main(): if not debug_utils.enabled(): eventlet.monkey_patch(thread=True) - try: - launch_services() - except RuntimeError as error: - print(traceback.format_exc()) - sys.exit("ERROR: %s" % error) - -if __name__ == '__main__': - main() + launch_services() diff --git a/bin/trove-fake-mode b/trove/cmd/fakemode.py similarity index 70% rename from bin/trove-fake-mode rename to trove/cmd/fakemode.py index 2b09dde1dc..8a5aa61bf2 100755 --- a/bin/trove-fake-mode +++ b/trove/cmd/fakemode.py @@ -17,21 +17,12 @@ # under the License. import gettext -import os import sys gettext.install('trove', unicode=1) -# If ../trove/__init__.py exists, add ../ to Python search path, so that -# it will override what happens to be installed in /usr/(local/)lib/python... -possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), - os.pardir, - os.pardir)) -if os.path.exists(os.path.join(possible_topdir, 'trove', '__init__.py')): - sys.path.insert(0, possible_topdir) - from trove.common import cfg from oslo.config import cfg as openstack_cfg from trove.openstack.common import log as logging @@ -64,17 +55,12 @@ def start_fake_taskmanager(): def run_server(): - try: - get_db_api().configure_db(CONF) - conf_file = CONF.find_file(CONF.api_paste_config) - launcher = wsgi.launch('trove', CONF.bind_port or 8779, conf_file, - workers=CONF.trove_api_workers) - start_fake_taskmanager() - launcher.wait() - except Exception: - import traceback - print(traceback.format_exc()) - sys.exit("ERROR Starting up") + get_db_api().configure_db(CONF) + conf_file = CONF.find_file(CONF.api_paste_config) + launcher = wsgi.launch('trove', CONF.bind_port or 8779, conf_file, + workers=CONF.trove_api_workers) + start_fake_taskmanager() + launcher.wait() def main(): @@ -96,7 +82,3 @@ def main(): f.write(str(pid)) else: run_server() - - -if __name__ == '__main__': - main() diff --git a/bin/trove-guestagent b/trove/cmd/guest.py similarity index 53% rename from bin/trove-guestagent rename to trove/cmd/guest.py index 819f547a47..456342a8b4 100755 --- a/bin/trove-guestagent +++ b/trove/cmd/guest.py @@ -20,18 +20,11 @@ import eventlet eventlet.monkey_patch() import gettext -import os import sys + gettext.install('trove', unicode=1) -# If ../trove/__init__.py exists, add ../ to Python search path, so that -# it will override what happens to be installed in /usr/(local/)lib/python... -possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), - os.pardir, - os.pardir)) -if os.path.exists(os.path.join(possible_topdir, 'trove', '__init__.py')): - sys.path.insert(0, possible_topdir) from trove.common import cfg from trove.common.rpc import service as rpc_service @@ -39,6 +32,7 @@ from oslo.config import cfg as openstack_cfg from trove.openstack.common import log as logging from trove.openstack.common import service as openstack_service + CONF = cfg.CONF CONF.register_opts([openstack_cfg.StrOpt('guest_id')]) @@ -48,20 +42,11 @@ def main(): from trove.guestagent import dbaas logging.setup(None) - try: - manager = dbaas.datastore_registry().get(CONF.datastore_manager) - if not manager: - msg = ("Manager class not registered for datastore manager %s" % - CONF.datastore_manager) - raise RuntimeError(msg) - server = rpc_service.RpcService(manager=manager, host=CONF.guest_id) - launcher = openstack_service.launch(server) - launcher.wait() - except RuntimeError as error: - import traceback - print(traceback.format_exc()) - sys.exit("ERROR: %s" % error) - - -if __name__ == '__main__': - main() + manager = dbaas.datastore_registry().get(CONF.datastore_manager) + if not manager: + msg = ("Manager class not registered for datastore manager %s" % + CONF.datastore_manager) + raise RuntimeError(msg) + server = rpc_service.RpcService(manager=manager, host=CONF.guest_id) + launcher = openstack_service.launch(server) + launcher.wait() diff --git a/bin/trove-manage b/trove/cmd/manage.py similarity index 89% rename from bin/trove-manage rename to trove/cmd/manage.py index 2764a1009b..ad1bcc5a12 100755 --- a/bin/trove-manage +++ b/trove/cmd/manage.py @@ -18,21 +18,12 @@ import gettext import inspect -import os import sys gettext.install('trove', unicode=1) -# If ../trove/__init__.py exists, add ../ to Python search path, so that -# it will override what happens to be installed in /usr/(local/)lib/python... -possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), - os.pardir, - os.pardir)) -if os.path.exists(os.path.join(possible_topdir, 'trove', '__init__.py')): - sys.path.insert(0, possible_topdir) - from trove.common import cfg from trove.common import exception from trove.common import utils @@ -140,7 +131,3 @@ def main(): except Exception: print(_("Command failed, please check log for more info")) raise - - -if __name__ == '__main__': - main() diff --git a/bin/trove-taskmanager b/trove/cmd/taskmanager.py similarity index 63% rename from bin/trove-taskmanager rename to trove/cmd/taskmanager.py index 4fb41de5a7..2f3d43f049 100755 --- a/bin/trove-taskmanager +++ b/trove/cmd/taskmanager.py @@ -16,8 +16,6 @@ # License for the specific language governing permissions and limitations # under the License. -import gettext -import os import sys import eventlet @@ -32,21 +30,11 @@ from trove.common import debug_utils # after debug_utils setting up eventlet.monkey_patch(all=True, thread=False) -gettext.install('trove', unicode=1) - -# If ../trove/__init__.py exists, add ../ to Python search path, so that -# it will override what happens to be installed in /usr/(local/)lib/python... -possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), - os.pardir, - os.pardir)) -if os.path.exists(os.path.join(possible_topdir, 'trove', '__init__.py')): - sys.path.insert(0, possible_topdir) - CONF = cfg.CONF CONF.register_opts([openstack_cfg.StrOpt('taskmanager_manager')]) -def main(): +def startup(topic): cfg.parse_args(sys.argv) logging.setup(None) @@ -60,16 +48,16 @@ def main(): from trove.openstack.common import service as openstack_service from trove.db import get_db_api - try: - get_db_api().configure_db(CONF) - server = rpc_service.RpcService(manager=CONF.taskmanager_manager) - launcher = openstack_service.launch(server) - launcher.wait() - except RuntimeError as error: - import traceback - print(traceback.format_exc()) - sys.exit("ERROR: %s" % error) + get_db_api().configure_db(CONF) + server = rpc_service.RpcService(manager=CONF.taskmanager_manager, + topic=topic) + launcher = openstack_service.launch(server) + launcher.wait() -if __name__ == '__main__': - main() +def main(): + startup(None) + + +def mgmt_main(): + startup("mgmt-taskmanager")