예제 #1
0
def main():
    try:
        config.parse_args()
        config.set_config_defaults()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'xmonitor')
        notifier.set_defaults()

        if cfg.CONF.profiler.enabled:
            _notifier = osprofiler.notifier.create("Messaging",
                                                   oslo_messaging, {},
                                                   notifier.get_transport(),
                                                   "xmonitor", "registry",
                                                   cfg.CONF.bind_host)
            osprofiler.notifier.set(_notifier)
            osprofiler.web.enable(cfg.CONF.profiler.hmac_keys)
        else:
            osprofiler.web.disable()

        server = wsgi.Server()
        server.start(config.load_paste_app('xmonitor-registry'),
                     default_port=9191)
        server.wait()
    except RuntimeError as e:
        sys.exit("ERROR: %s" % encodeutils.exception_to_unicode(e))
예제 #2
0
def main():
    """The main function."""

    try:
        config.parse_args()
    except RuntimeError as e:
        sys.exit("ERROR: %s" % encodeutils.exception_to_unicode(e))
    except SystemExit as e:
        sys.exit("Please specify one command")

    # Setup logging
    logging.setup(CONF, 'xmonitor')

    if CONF.token:
        CONF.slavetoken = CONF.token
        CONF.mastertoken = CONF.token

    command = lookup_command(CONF.command)

    try:
        command(CONF, CONF.args)
    except TypeError as e:
        LOG.error(_LE(command.__doc__) % {'prog': command.__name__})  # noqa
        sys.exit("ERROR: %s" % encodeutils.exception_to_unicode(e))
    except ValueError as e:
        LOG.error(_LE(command.__doc__) % {'prog': command.__name__})  # noqa
        sys.exit("ERROR: %s" % encodeutils.exception_to_unicode(e))
예제 #3
0
 def setUp(self):
     """Run before each test method to initialize test environment."""
     super(TestMetadefDriver, self).setUp()
     config.parse_args(args=[])
     context_cls = context.RequestContext
     self.adm_context = context_cls(is_admin=True,
                                    auth_token='user:user:admin')
     self.context = context_cls(is_admin=False, auth_token='user:user:user')
     self.db_api = db_tests.get_db(self.config)
     db_tests.reset_db(self.db_api)
예제 #4
0
 def setUp(self):
     """Run before each test method to initialize test environment."""
     super(TestMetadefDriver, self).setUp()
     config.parse_args(args=[])
     context_cls = context.RequestContext
     self.adm_context = context_cls(is_admin=True,
                                    auth_token='user:user:admin')
     self.context = context_cls(is_admin=False,
                                auth_token='user:user:user')
     self.db_api = db_tests.get_db(self.config)
     db_tests.reset_db(self.db_api)
예제 #5
0
파일: utils.py 프로젝트: froyobin/xmonitor
    def setUp(self):
        super(BaseTestCase, self).setUp()

        self._config_fixture = self.useFixture(cfg_fixture.Config())

        # NOTE(bcwaldon): parse_args has to be called to register certain
        # command-line options - specifically we need config_dir for
        # the following policy tests
        config.parse_args(args=[])
        self.addCleanup(CONF.reset)
        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.stubs = mox_fixture.stubs
        self.stubs.Set(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', True)
        self.test_dir = self.useFixture(fixtures.TempDir()).path
        self.conf_dir = os.path.join(self.test_dir, 'etc')
        utils.safe_mkdirs(self.conf_dir)
        self.set_policy()
예제 #6
0
파일: utils.py 프로젝트: froyobin/xmonitor
    def setUp(self):
        super(BaseTestCase, self).setUp()

        self._config_fixture = self.useFixture(cfg_fixture.Config())

        # NOTE(bcwaldon): parse_args has to be called to register certain
        # command-line options - specifically we need config_dir for
        # the following policy tests
        config.parse_args(args=[])
        self.addCleanup(CONF.reset)
        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.stubs = mox_fixture.stubs
        self.stubs.Set(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', True)
        self.test_dir = self.useFixture(fixtures.TempDir()).path
        self.conf_dir = os.path.join(self.test_dir, 'etc')
        utils.safe_mkdirs(self.conf_dir)
        self.set_policy()
예제 #7
0
파일: api.py 프로젝트: froyobin/xmonitor
def main():
    config.parse_args()
    config.set_config_defaults()
    wsgi.set_eventlet_hub()
    logging.setup(CONF, 'xmonitor')
    notifier.set_defaults()
    if cfg.CONF.profiler.enabled:
        _notifier = osprofiler.notifier.create("Messaging", oslo_messaging, {},
                                               notifier.get_transport(),
                                               "xmonitor", "api",
                                               cfg.CONF.bind_host)
        osprofiler.notifier.set(_notifier)
        osprofiler.web.enable(cfg.CONF.profiler.hmac_keys)
    else:
        osprofiler.web.disable()

    server = wsgi.Server(initialize_glance_store=True)
    server.start(config.load_paste_app('xmonitor-api'), default_port=9696)
    server.wait()
예제 #8
0
def main():
    CONF.register_cli_opt(command_opt)
    if len(sys.argv) < 2:
        script_name = sys.argv[0]
        print("%s category action [<args>]" % script_name)
        print(_("Available categories:"))
        for category in CATEGORIES:
            print(_("\t%s") % category)
        sys.exit(2)

    try:
        logging.register_options(CONF)
        cfg_files = cfg.find_config_files(project='xmonitor',
                                          prog='xmonitor-registry')
        cfg_files.extend(
            cfg.find_config_files(project='xmonitor', prog='xmonitor-api'))
        cfg_files.extend(
            cfg.find_config_files(project='xmonitor', prog='xmonitor-manage'))
        config.parse_args(default_config_files=cfg_files)
        config.set_config_defaults()
        logging.setup(CONF, 'xmonitor')
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    try:
        if CONF.command.action.startswith('db'):
            return CONF.command.action_fn()
        else:
            func_kwargs = {}
            for k in CONF.command.action_kwargs:
                v = getattr(CONF.command, 'action_kwarg_' + k)
                if v is None:
                    continue
                if isinstance(v, six.string_types):
                    v = encodeutils.safe_decode(v)
                func_kwargs[k] = v
            func_args = [
                encodeutils.safe_decode(arg)
                for arg in CONF.command.action_args
            ]
            return CONF.command.action_fn(*func_args, **func_kwargs)
    except exception.GlanceException as e:
        sys.exit("ERROR: %s" % encodeutils.exception_to_unicode(e))
예제 #9
0
파일: api.py 프로젝트: froyobin/xmonitor
def main():
    config.parse_args()
    config.set_config_defaults()
    wsgi.set_eventlet_hub()
    logging.setup(CONF, 'xmonitor')
    notifier.set_defaults()
    if cfg.CONF.profiler.enabled:
        _notifier = osprofiler.notifier.create("Messaging",
                                               oslo_messaging, {},
                                               notifier.get_transport(),
                                               "xmonitor", "api",
                                               cfg.CONF.bind_host)
        osprofiler.notifier.set(_notifier)
        osprofiler.web.enable(cfg.CONF.profiler.hmac_keys)
    else:
        osprofiler.web.disable()

    server = wsgi.Server(initialize_glance_store=True)
    server.start(config.load_paste_app('xmonitor-api'), default_port=9696)
    server.wait()
예제 #10
0
파일: manage.py 프로젝트: froyobin/xmonitor
def main():
    CONF.register_cli_opt(command_opt)
    if len(sys.argv) < 2:
        script_name = sys.argv[0]
        print("%s category action [<args>]" % script_name)
        print(_("Available categories:"))
        for category in CATEGORIES:
            print(_("\t%s") % category)
        sys.exit(2)

    try:
        logging.register_options(CONF)
        cfg_files = cfg.find_config_files(project='xmonitor',
                                          prog='xmonitor-registry')
        cfg_files.extend(cfg.find_config_files(project='xmonitor',
                                               prog='xmonitor-api'))
        cfg_files.extend(cfg.find_config_files(project='xmonitor',
                                               prog='xmonitor-manage'))
        config.parse_args(default_config_files=cfg_files)
        config.set_config_defaults()
        logging.setup(CONF, 'xmonitor')
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    try:
        if CONF.command.action.startswith('db'):
            return CONF.command.action_fn()
        else:
            func_kwargs = {}
            for k in CONF.command.action_kwargs:
                v = getattr(CONF.command, 'action_kwarg_' + k)
                if v is None:
                    continue
                if isinstance(v, six.string_types):
                    v = encodeutils.safe_decode(v)
                func_kwargs[k] = v
            func_args = [encodeutils.safe_decode(arg)
                         for arg in CONF.command.action_args]
            return CONF.command.action_fn(*func_args, **func_kwargs)
    except exception.GlanceException as e:
        sys.exit("ERROR: %s" % encodeutils.exception_to_unicode(e))
예제 #11
0
파일: glare.py 프로젝트: froyobin/xmonitor
def main():
    try:
        config.parse_args()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'glare')

        if cfg.CONF.profiler.enabled:
            _notifier = osprofiler.notifier.create("Messaging",
                                                   oslo_messaging, {},
                                                   notifier.get_transport(),
                                                   "xmonitor", "artifacts",
                                                   cfg.CONF.bind_host)
            osprofiler.notifier.set(_notifier)
        else:
            osprofiler.web.disable()

        server = wsgi.Server(initialize_glance_store=True)
        server.start(config.load_paste_app('glare-api'), default_port=9494)
        server.wait()
    except KNOWN_EXCEPTIONS as e:
        fail(e)
예제 #12
0
def main():
    try:
        config.parse_args()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'glare')

        if cfg.CONF.profiler.enabled:
            _notifier = osprofiler.notifier.create("Messaging",
                                                   oslo_messaging, {},
                                                   notifier.get_transport(),
                                                   "xmonitor", "artifacts",
                                                   cfg.CONF.bind_host)
            osprofiler.notifier.set(_notifier)
        else:
            osprofiler.web.disable()

        server = wsgi.Server(initialize_glance_store=True)
        server.start(config.load_paste_app('glare-api'), default_port=9494)
        server.wait()
    except KNOWN_EXCEPTIONS as e:
        fail(e)
예제 #13
0
def main():
    CONF.register_cli_opts(scrubber.scrubber_cmd_cli_opts)
    CONF.register_opts(scrubber.scrubber_cmd_opts)

    try:
        config.parse_args()
        logging.setup(CONF, 'xmonitor')

        glance_store.register_opts(config.CONF)
        glance_store.create_stores(config.CONF)
        glance_store.verify_default_store()

        app = scrubber.Scrubber(glance_store)

        if CONF.daemon:
            server = scrubber.Daemon(CONF.wakeup_time)
            server.start(app)
            server.wait()
        else:
            app.run()
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)
예제 #14
0
    def _do_test_load_paste_app(self,
                                expected_app_type,
                                make_paste_file=True,
                                paste_flavor=None,
                                paste_config_file=None,
                                paste_append=None):

        def _writeto(path, str):
            with open(path, 'w') as f:
                f.write(str or '')
                f.flush()

        def _appendto(orig, copy, str):
            shutil.copy(orig, copy)
            with open(copy, 'a') as f:
                f.write(str or '')
                f.flush()

        self.config(flavor=paste_flavor,
                    config_file=paste_config_file,
                    group='paste_deploy')

        temp_dir = self.useFixture(fixtures.TempDir()).path
        temp_file = os.path.join(temp_dir, 'testcfg.conf')

        _writeto(temp_file, '[DEFAULT]\n')

        config.parse_args(['--config-file', temp_file])

        paste_to = temp_file.replace('.conf', '-paste.ini')
        if not paste_config_file and make_paste_file:
            paste_from = os.path.join(os.getcwd(),
                                      'etc/xmonitor-registry-paste.ini')
            _appendto(paste_from, paste_to, paste_append)

        app = config.load_paste_app('xmonitor-registry')

        self.assertIsInstance(app, expected_app_type)
예제 #15
0
    def _do_test_load_paste_app(self,
                                expected_app_type,
                                make_paste_file=True,
                                paste_flavor=None,
                                paste_config_file=None,
                                paste_append=None):
        def _writeto(path, str):
            with open(path, 'w') as f:
                f.write(str or '')
                f.flush()

        def _appendto(orig, copy, str):
            shutil.copy(orig, copy)
            with open(copy, 'a') as f:
                f.write(str or '')
                f.flush()

        self.config(flavor=paste_flavor,
                    config_file=paste_config_file,
                    group='paste_deploy')

        temp_dir = self.useFixture(fixtures.TempDir()).path
        temp_file = os.path.join(temp_dir, 'testcfg.conf')

        _writeto(temp_file, '[DEFAULT]\n')

        config.parse_args(['--config-file', temp_file])

        paste_to = temp_file.replace('.conf', '-paste.ini')
        if not paste_config_file and make_paste_file:
            paste_from = os.path.join(os.getcwd(),
                                      'etc/xmonitor-registry-paste.ini')
            _appendto(paste_from, paste_to, paste_append)

        app = config.load_paste_app('xmonitor-registry')

        self.assertIsInstance(app, expected_app_type)
예제 #16
0
from xmonitor import context
from xmonitor.db.sqlalchemy import api as db_api
from xmonitor.i18n import _
from xmonitor.registry.api import v2 as rserver
import xmonitor.registry.client.v2.api as rapi
from xmonitor.registry.client.v2.api import client as rclient
from xmonitor.tests.unit import base
from xmonitor.tests import utils as test_utils

_gen_uuid = lambda: str(uuid.uuid4())

UUID1 = str(uuid.uuid4())
UUID2 = str(uuid.uuid4())

# NOTE(bcwaldon): needed to init config_dir cli opt
config.parse_args(args=[])


class TestRegistryV2Client(base.IsolatedUnitTest,
                           test_utils.RegistryAPIMixIn):
    """Test proper actions made against a registry service.

    Test for both valid and invalid requests.
    """

    # Registry server to user
    # in the stub.
    registry = rserver

    def setUp(self):
        """Establish a clean test environment"""
예제 #17
0
def main():
    global exitcode

    opts = [
        cfg.SubCommandOpt('server',
                          title='Server types',
                          help='Available server types',
                          handler=add_command_parsers),
        cfg.StrOpt('pid-file',
                   metavar='PATH',
                   help='File to use as pid file. Default: '
                   '/var/run/xmonitor/$server.pid.'),
        cfg.IntOpt('await-child',
                   metavar='DELAY',
                   default=0,
                   help='Period to wait for service death '
                        'in order to report exit code '
                        '(default is to not wait at all).'),
        cfg.BoolOpt('capture-output',
                    default=False,
                    help='Capture stdout/err in syslog '
                    'instead of discarding it.'),
        cfg.BoolOpt('respawn',
                    default=False,
                    help='Restart service on unexpected death.'),
    ]
    CONF.register_cli_opts(opts)

    config.parse_args(usage=USAGE)

    @gated_by(CONF.await_child)
    @gated_by(CONF.respawn)
    def mutually_exclusive():
        sys.stderr.write('--await-child and --respawn are mutually exclusive')
        sys.exit(1)

    mutually_exclusive()

    @gated_by(CONF.respawn)
    def anticipate_respawn(children):
        while children:
            pid, status = os.wait()
            if pid in children:
                (pid_file, server, args) = children.pop(pid)
                running = os.path.exists(pid_file)
                one_second_ago = time.time() - 1
                bouncing = (running and
                            os.path.getmtime(pid_file) >= one_second_ago)
                if running and not bouncing:
                    args = (pid_file, server, args)
                    new_pid = do_start('Respawn', *args)
                    children[new_pid] = args
                else:
                    rsn = 'bouncing' if bouncing else 'deliberately stopped'
                    print(_('Suppressed respawn as %(serv)s was %(rsn)s.')
                          % {'serv': server, 'rsn': rsn})

    if CONF.server.command == 'start':
        children = {}
        for server in CONF.server.servers:
            pid_file = get_pid_file(server, CONF.pid_file)
            args = (pid_file, server, CONF.server.args)
            pid = do_start('Start', *args)
            children[pid] = args

        anticipate_respawn(children)

    if CONF.server.command == 'status':
        for server in CONF.server.servers:
            pid_file = get_pid_file(server, CONF.pid_file)
            do_check_status(pid_file, server)

    if CONF.server.command == 'stop':
        for server in CONF.server.servers:
            do_stop(server, CONF.server.args)

    if CONF.server.command == 'shutdown':
        for server in CONF.server.servers:
            do_stop(server, CONF.server.args, graceful=True)

    if CONF.server.command == 'restart':
        for server in CONF.server.servers:
            do_stop(server, CONF.server.args)
        for server in CONF.server.servers:
            pid_file = get_pid_file(server, CONF.pid_file)
            do_start('Restart', pid_file, server, CONF.server.args)

    if CONF.server.command in ('reload', 'force-reload'):
        for server in CONF.server.servers:
            pid_file = get_pid_file(server, CONF.pid_file)
            do_reload(pid_file, server)

    sys.exit(exitcode)
예제 #18
0
from xmonitor import context
from xmonitor.db.sqlalchemy import api as db_api
from xmonitor.i18n import _
from xmonitor.registry.api import v2 as rserver
import xmonitor.registry.client.v2.api as rapi
from xmonitor.registry.client.v2.api import client as rclient
from xmonitor.tests.unit import base
from xmonitor.tests import utils as test_utils

_gen_uuid = lambda: str(uuid.uuid4())

UUID1 = str(uuid.uuid4())
UUID2 = str(uuid.uuid4())

# NOTE(bcwaldon): needed to init config_dir cli opt
config.parse_args(args=[])


class TestRegistryV2Client(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn):
    """Test proper actions made against a registry service.

    Test for both valid and invalid requests.
    """

    # Registry server to user
    # in the stub.
    registry = rserver

    def setUp(self):
        """Establish a clean test environment"""
        super(TestRegistryV2Client, self).setUp()