Beispiel #1
0
def main():
    objects.register_all()
    CONF(sys.argv[1:], project='miper', version=version.version_string())
    logging.setup(CONF, "miper")
    LOG = logging.getLogger('miper.all')

    utils.monkey_patch()

    gmr.TextGuruMeditation.setup_autorun(version)

    rpc.init(CONF)

    launcher = service.process_launcher()
    # miper-api
    try:
        server = service.WSGIService('osapi_miper')
        launcher.launch_service(server, workers=server.workers or 1)
    except (Exception, SystemExit):
        LOG.exception(_LE('Failed to load osapi_miper'))

    # miper-mipermanager
    try:
        launcher.launch_service(
            service.Service.create(binary="miper-mipermanager"))
    except (Exception, SystemExit):
        LOG.exception(_LE('Failed to load miper-mipermanager'))

    launcher.wait()
Beispiel #2
0
    def start(self):
        version_string = version.version_string()
        LOG.info(_LI('Starting %(topic)s node (version %(version_string)s)'), {
            'topic': self.topic,
            'version_string': version_string
        })
        self.model_disconnected = False
        self.manager.init_host()
        LOG.debug("Creating RPC server for service %s", self.topic)

        target = messaging.Target(topic=self.topic, server=self.host)
        endpoints = [self.manager]
        endpoints.extend(self.manager.additional_endpoints)
        serializer = objects_base.MiperObjectSerializer()
        self.rpcserver = rpc.get_server(target, endpoints, serializer)
        self.rpcserver.start()

        self.manager.init_host_with_rpc()

        if self.periodic_interval:
            if self.periodic_fuzzy_delay:
                initial_delay = random.randint(0, self.periodic_fuzzy_delay)
            else:
                initial_delay = None

            periodic = loopingcall.FixedIntervalLoopingCall(
                self.periodic_tasks)
            periodic.start(interval=self.periodic_interval,
                           initial_delay=initial_delay)
            self.timers.append(periodic)
Beispiel #3
0
def _application():
    objects.register_all()
    CONF(sys.argv[1:], project='miper', version=version.version_string())
    logging.setup(CONF, "miper")

    rpc.init(CONF)
    return wsgi_common.Loader().load_app(name='osapi_miper')
Beispiel #4
0
    def test_main_argv_lt_2(self, register_cli_opt):
        script_name = 'miper-manage'
        sys.argv = [script_name]
        CONF(sys.argv[1:], project='miper', version=version.version_string())

        with mock.patch('sys.stdout', new=six.StringIO()):
            exit = self.assertRaises(SystemExit, miper_manage.main)
            self.assertTrue(register_cli_opt.called)
            self.assertEqual(2, exit.code)
Beispiel #5
0
def main():
    objects.register_all()
    CONF(sys.argv[1:], project='miper', version=version.version_string())
    logging.setup(CONF, "miper")
    utils.monkey_patch()
    gmr.TextGuruMeditation.setup_autorun(version)
    server = service.Service.create(binary='miper-mipermanager')
    service.serve(server)
    service.wait()
Beispiel #6
0
    def test_main(self, register_cli_opt, config_opts_call):
        script_name = 'miper-manage'
        sys.argv = [script_name, 'config', 'list']
        action_fn = mock.MagicMock()
        CONF.category = mock.MagicMock(action_fn=action_fn)

        miper_manage.main()

        self.assertTrue(register_cli_opt.called)
        config_opts_call.assert_called_once_with(
            sys.argv[1:], project='miper', version=version.version_string())
        self.assertTrue(action_fn.called)
Beispiel #7
0
def main():
    objects.register_all()
    CONF(sys.argv[1:], project='miper', version=version.version_string())
    logging.setup(CONF, "miper")
    utils.monkey_patch()

    gmr.TextGuruMeditation.setup_autorun(version)

    rpc.init(CONF)
    launcher = service.process_launcher()
    server = service.WSGIService('osapi_miper')
    launcher.launch_service(server, workers=server.workers)
    launcher.wait()
Beispiel #8
0
    def test_main(self, log_setup, monkey_patch, service_create, service_serve,
                  service_wait):
        server = service_create.return_value

        miper_mipermanager.main()

        self.assertEqual('miper', CONF.project)
        self.assertEqual(CONF.version, version.version_string())
        log_setup.assert_called_once_with(CONF, "miper")
        monkey_patch.assert_called_once_with()
        service_create.assert_called_once_with(binary='miper-mipermanager')
        service_serve.assert_called_once_with(server)
        service_wait.assert_called_once_with()
Beispiel #9
0
def main():
    objects.register_all()
    """Parse options and call the appropriate class/method."""
    CONF.register_cli_opt(category_opt)
    script_name = sys.argv[0]
    if len(sys.argv) < 2:
        print(_("\nOpenStack Miper version: %(version)s\n") %
              {'version': version.version_string()})
        print(script_name + " category action [<args>]")
        print(_("Available categories:"))
        for category in CATEGORIES:
            print(_("\t%s") % category)
        sys.exit(2)

    try:
        CONF(sys.argv[1:], project='miper',
             version=version.version_string())
        logging.setup(CONF, "miper")
    except cfg.ConfigDirNotFoundError as details:
        print(_("Invalid directory: %s") % details)
        sys.exit(2)
    except cfg.ConfigFilesNotFoundError:
        cfgfile = CONF.config_file[-1] if CONF.config_file else None
        if cfgfile and not os.access(cfgfile, os.R_OK):
            st = os.stat(cfgfile)
            print(_("Could not read %s. Re-running with sudo") % cfgfile)
            try:
                os.execvp('sudo', ['sudo', '-u', '#%s' % st.st_uid] + sys.argv)
            except Exception:
                print(_('sudo failed, continuing as if nothing happened'))

        print(_('Please re-run miper-manage as root.'))
        sys.exit(2)

    fn = CONF.category.action_fn
    fn_args = fetch_func_args(fn)
    fn(*fn_args)
Beispiel #10
0
    def test_main_sudo_failed(self, register_cli_opt, log_setup,
                              config_opts_call):
        script_name = 'miper-manage'
        sys.argv = [script_name, 'fake_category', 'fake_action']
        config_opts_call.side_effect = cfg.ConfigFilesNotFoundError(
            mock.sentinel._namespace)

        with mock.patch('sys.stdout', new=six.StringIO()):
            exit = self.assertRaises(SystemExit, miper_manage.main)

            self.assertTrue(register_cli_opt.called)
            config_opts_call.assert_called_once_with(
                sys.argv[1:],
                project='miper',
                version=version.version_string())
            self.assertFalse(log_setup.called)
            self.assertEqual(2, exit.code)
Beispiel #11
0
    def test_main(self, log_setup, monkey_patch, rpc_init, process_launcher,
                  wsgi_service):
        launcher = process_launcher.return_value
        server = wsgi_service.return_value
        server.workers = mock.sentinel.worker_count

        miper_api.main()

        self.assertEqual('miper', CONF.project)
        self.assertEqual(CONF.version, version.version_string())
        log_setup.assert_called_once_with(CONF, "miper")
        monkey_patch.assert_called_once_with()
        rpc_init.assert_called_once_with(CONF)
        process_launcher.assert_called_once_with()
        wsgi_service.assert_called_once_with('osapi_miper')
        launcher.launch_service.assert_called_once_with(server,
                                                        workers=server.workers)
        launcher.wait.assert_called_once_with()
Beispiel #12
0
    def test_main_invalid_dir(self, register_cli_opt, log_setup,
                              config_opts_call):
        script_name = 'miper-manage'
        fake_dir = 'fake-dir'
        invalid_dir = 'Invalid directory:'
        sys.argv = [script_name, '--config-dir', fake_dir]
        config_opts_call.side_effect = cfg.ConfigDirNotFoundError(fake_dir)

        with mock.patch('sys.stdout', new=six.StringIO()) as fake_out:
            exit = self.assertRaises(SystemExit, miper_manage.main)
            self.assertTrue(register_cli_opt.called)
            config_opts_call.assert_called_once_with(
                sys.argv[1:],
                project='miper',
                version=version.version_string())
            self.assertIn(invalid_dir, fake_out.getvalue())
            self.assertIn(fake_dir, fake_out.getvalue())
            self.assertFalse(log_setup.called)
            self.assertEqual(2, exit.code)
Beispiel #13
0
    def test_main(self, log_setup, get_logger, monkey_patch, process_launcher,
                  wsgi_service, service_create, rpc_init):
        launcher = process_launcher.return_value
        server = wsgi_service.return_value
        server.workers = mock.sentinel.worker_count
        service = service_create.return_value

        miper_all.main()

        self.assertEqual('miper', CONF.project)
        self.assertEqual(CONF.version, version.version_string())
        log_setup.assert_called_once_with(CONF, "miper")
        get_logger.assert_called_once_with('miper.all')
        monkey_patch.assert_called_once_with()
        rpc_init.assert_called_once_with(CONF)
        process_launcher.assert_called_once_with()

        service_create.assert_has_calls(
            [mock.call(binary='miper-mipermanager')])
        self.assertEqual(1, service_create.call_count)
        launcher.launch_service.assert_has_calls([mock.call(service)])
        self.assertEqual(2, launcher.launch_service.call_count)

        launcher.wait.assert_called_once_with()
Beispiel #14
0
 def list(self):
     print(version.version_string())
Beispiel #15
0
 def setUp(self):
     super(TestMiperAllCmd, self).setUp()
     sys.argv = ['miper-all']
     CONF(sys.argv[1:], project='miper', version=version.version_string())
Beispiel #16
0
 def service_version(self):
     return version.version_string()