def test_get_transport_sad(self):
        self.config(rpc_backend=self.rpc_backend, transport_url=self.transport_url)

        if self.rpc_backend:
            self.mox.StubOutWithMock(driver, "DriverManager")

            invoke_args = [self.conf, messaging.TransportURL.parse(self.conf, self.url)]
            invoke_kwds = dict(default_exchange="openstack", allowed_remote_exmods=[])

            driver.DriverManager(
                "oslo.messaging.drivers",
                self.rpc_backend,
                invoke_on_load=True,
                invoke_args=invoke_args,
                invoke_kwds=invoke_kwds,
            ).AndRaise(RuntimeError())

            self.mox.ReplayAll()

        try:
            messaging.get_transport(self.conf, url=self.url)
            self.assertFalse(True)
        except Exception as ex:
            ex_cls = self.ex.pop("cls")
            ex_msg_contains = self.ex.pop("msg_contains")

            self.assertIsInstance(ex, messaging.MessagingException)
            self.assertIsInstance(ex, ex_cls)
            self.assertIn(ex_msg_contains, six.text_type(ex))

            for k, v in self.ex.items():
                self.assertTrue(hasattr(ex, k))
                self.assertEqual(v, str(getattr(ex, k)))
    def test_get_transport_sad(self):
        self.config(rpc_backend=self.rpc_backend,
                    transport_url=self.transport_url)

        if self.rpc_backend:
            self.mox.StubOutWithMock(driver, 'DriverManager')

            invoke_args = [self.conf]
            invoke_kwds = dict(default_exchange='openstack')

            driver.DriverManager('oslo.messaging.drivers',
                                 self.rpc_backend,
                                 invoke_on_load=True,
                                 invoke_args=invoke_args,
                                 invoke_kwds=invoke_kwds).\
                AndRaise(RuntimeError())

            self.mox.ReplayAll()

        try:
            messaging.get_transport(self.conf, url=self.url)
            self.assertFalse(True)
        except Exception as ex:
            ex_cls = self.ex.pop('cls')
            ex_msg_contains = self.ex.pop('msg_contains')

            self.assertTrue(isinstance(ex, messaging.MessagingException))
            self.assertTrue(isinstance(ex, ex_cls))
            self.assertTrue(hasattr(ex, 'msg'))
            self.assertTrue(ex_msg_contains in ex.msg)

            for k, v in self.ex.items():
                self.assertTrue(hasattr(ex, k))
                self.assertEqual(getattr(ex, k), v)
Beispiel #3
0
    def test_multiple_servers(self):
        url1 = "fake:///" + (self.exchange1 or "")
        url2 = "fake:///" + (self.exchange2 or "")

        transport1 = messaging.get_transport(self.conf, url=url1)
        if url1 != url2:
            transport2 = messaging.get_transport(self.conf, url=url1)
        else:
            transport2 = transport1

        class TestEndpoint(object):
            def __init__(self):
                self.pings = []

            def ping(self, ctxt, arg):
                self.pings.append(arg)

            def alive(self, ctxt):
                return "alive"

        if self.multi_endpoints:
            endpoint1, endpoint2 = TestEndpoint(), TestEndpoint()
        else:
            endpoint1 = endpoint2 = TestEndpoint()

        thread1 = self._setup_server(transport1, endpoint1, topic=self.topic1, server=self.server1)
        thread2 = self._setup_server(transport2, endpoint2, topic=self.topic2, server=self.server2)

        client1 = self._setup_client(transport1, topic=self.topic1)
        client2 = self._setup_client(transport2, topic=self.topic2)

        client1 = client1.prepare(server=self.server1)
        client2 = client2.prepare(server=self.server2)

        if self.fanout1:
            client1.call({}, "alive")
            client1 = client1.prepare(fanout=True)
        if self.fanout2:
            client2.call({}, "alive")
            client2 = client2.prepare(fanout=True)

        (client1.call if self.call1 else client1.cast)({}, "ping", arg="1")
        (client2.call if self.call2 else client2.cast)({}, "ping", arg="2")

        self.assertTrue(thread1.isAlive())
        self._stop_server(client1.prepare(fanout=None), thread1, topic=self.topic1)
        self.assertTrue(thread2.isAlive())
        self._stop_server(client2.prepare(fanout=None), thread2, topic=self.topic2)

        def check(pings, expect):
            self.assertEqual(len(expect), len(pings))
            for a in expect:
                self.assertIn(a, pings)

        if self.expect_either:
            check(endpoint1.pings + endpoint2.pings, self.expect_either)
        else:
            check(endpoint1.pings, self.expect1)
            check(endpoint2.pings, self.expect2)
Beispiel #4
0
    def __init__(self, strategy=None):

        _driver = None
        _strategy = strategy

        if CONF.notifier_strategy != 'default':
            msg = _("notifier_strategy was deprecated in "
                    "favor of `notification_driver`")
            LOG.warn(msg)

            # NOTE(flaper87): Use this to keep backwards
            # compatibility. We'll try to get an oslo.messaging
            # driver from the specified strategy.
            _strategy = strategy or CONF.notifier_strategy
            _driver = _STRATEGY_ALIASES.get(_strategy)

        publisher_id = CONF.default_publisher_id

        try:
            # NOTE(flaper87): Assume the user has configured
            # the transport url.
            self._transport = messaging.get_transport(CONF,
                                                      aliases=_ALIASES)
        except messaging.DriverLoadFailure:
            # NOTE(flaper87): Catch driver load failures and re-raise
            # them *just* if the `transport_url` option was set. This
            # step is intended to keep backwards compatibility and avoid
            # weird behaviors (like exceptions on missing dependencies)
            # when the old notifier options are used.
            if CONF.transport_url is not None:
                with excutils.save_and_reraise_exception():
                    LOG.exception(_('Error loading the notifier'))

        # NOTE(flaper87): This needs to be checked
        # here because the `get_transport` call
        # registers `transport_url` into ConfigOpts.
        if not CONF.transport_url:
            # NOTE(flaper87): The next 3 lines help
            # with the migration to oslo.messaging.
            # Without them, gate tests won't know
            # what driver should be loaded.
            # Once this patch lands, devstack will be
            # updated and then these lines will be removed.
            url = None
            if _strategy in ['rabbit', 'qpid']:
                url = _strategy + '://'
            self._transport = messaging.get_transport(CONF, url,
                                                      aliases=_ALIASES)

        self._notifier = messaging.Notifier(self._transport,
                                            driver=_driver,
                                            publisher_id=publisher_id)
    def test_set_default_control_exchange(self):
        messaging.set_transport_defaults(control_exchange='foo')

        self.mox.StubOutWithMock(driver, 'DriverManager')
        invoke_kwds = mox.ContainsKeyValue('default_exchange', 'foo')
        driver.DriverManager(mox.IgnoreArg(),
                             mox.IgnoreArg(),
                             invoke_on_load=mox.IgnoreArg(),
                             invoke_args=mox.IgnoreArg(),
                             invoke_kwds=invoke_kwds).\
            AndReturn(_FakeManager(_FakeDriver(self.conf)))
        self.mox.ReplayAll()

        messaging.get_transport(self.conf)
Beispiel #6
0
def get_fake_transport():
    # Get transport here to let oslo.messaging setup default config
    # before changing the rpc_backend to the fake driver; otherwise,
    # oslo.messaging will throw exception.
    messaging.get_transport(cfg.CONF)
    cfg.CONF.set_default('rpc_backend', 'fake')
    url = transport.TransportURL.parse(cfg.CONF, None, None)
    kwargs = dict(default_exchange=cfg.CONF.control_exchange,
                  allowed_remote_exmods=[])
    mgr = driver.DriverManager('oslo.messaging.drivers',
                               url.transport,
                               invoke_on_load=True,
                               invoke_args=[cfg.CONF, url],
                               invoke_kwds=kwargs)
    return transport.Transport(mgr.driver)
Beispiel #7
0
 def __init__(self, target):
     super(RPCServer, self).__init__()
     self._server = messaging.get_rpc_server(
         target=target,
         transport=messaging.get_transport(cfg.CONF),
         endpoints=[ContextEndpointHandler(self, target)],
     )
def init(conf):
    global TRANSPORT
    exmods = get_allowed_exmods()
    TRANSPORT = messaging.get_transport(conf,
                                        url = CONF.hades_rabbit_url,
                                        allowed_remote_exmods = exmods,
                                        aliases = {})
    def main(self):

        # TODO: clean up and make more configurable!
        logger = logging.getLogger('katello_notification')
        logger.setLevel(self._get_loglevel())
        handler = logging.FileHandler(LOG_LOCATION)
        formatter = logging.Formatter('%(asctime)s - %(name)s - @%(filename)s %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        logger.addHandler(handler)

        # quick config check
        mgmt_server = self._katello_or_spacewalk()

        if mgmt_server == 'katello':
            payload_actions = KatelloPayloadActions()
        elif mgmt_server == 'spacewalk':
            payload_actions = SpacewalkPayloadActions()
        else:
            logger.error("mgmt server not set to 'katello' or 'spacewalk', aborting")

        # set up transport and listener
        transport = messaging.get_transport(cfg.CONF, url=self._get_amqp_url())

        targets = [
            messaging.Target(topic='subscription_notifications', exchange='nova'),
        ]
        endpoints = [
            NotificationEndpoint(payload_actions),
        ]
        server = messaging.get_notification_listener(transport, targets, endpoints)
        logger.info("listener initialized")
        server.start()
        server.wait()
Beispiel #10
0
    def create_namespace_agent(self, context, port):
        conf = self.conf
        port_id = port["id"]
        path = "rpc-proxy-%s" % port_id
        unix_url = "punix:///%s" % path
        unix_transport = messaging.get_transport(conf, unix_url)
        unix_transport._driver.punix_listening.wait()

        self._plug(port)
        pm = external_process.ProcessManager(
            conf, port_id, root_helper=self.root_helper, namespace=self._get_ns_name(port_id)
        )

        def cmd_callback(pid_file_name):
            cmd = [
                "tacker-servicevm-ns-rpc-proxy",
                "--pid-file=%s" % pid_file_name,
                "--svcvm-proxy-dir=%s" % conf.svcvm_proxy_dir,
                "--src-transport-url",
                "unix:///%s" % path,
            ]
            cmd.extend(agent_config.get_log_args(conf, "tacker-servicevm-ns-rpc-proxy-%s.log" % port_id))
            if _DEBUG:
                cmd += ["--log-file=/tmp/tacker-servicevm-ns-rpc-proxy-" "%s.log" % port_id]
            return cmd

        pm.enable(cmd_callback)

        ns_agent = NamespaceAgent(port_id, unix_transport, pm)
        self._proxy_agents[port_id] = ns_agent
Beispiel #11
0
    def test_get_transport(self):
        self.config(rpc_backend=self.rpc_backend,
                    control_exchange=self.control_exchange,
                    transport_url=self.transport_url)

        self.mox.StubOutWithMock(driver, 'DriverManager')

        invoke_args = [self.conf]
        invoke_kwds = dict(default_exchange=self.expect['exchange'])
        if self.expect['url']:
            invoke_kwds['url'] = self.expect['url']

        drvr = _FakeDriver(self.conf)
        driver.DriverManager('oslo.messaging.drivers',
                             self.expect['backend'],
                             invoke_on_load=True,
                             invoke_args=invoke_args,
                             invoke_kwds=invoke_kwds).\
            AndReturn(_FakeManager(drvr))

        self.mox.ReplayAll()

        transport = messaging.get_transport(self.conf, url=self.url)

        self.assertTrue(transport is not None)
        self.assertTrue(transport.conf is self.conf)
        self.assertTrue(transport._driver is drvr)
    def test_reply_wire_format(self):
        if hasattr(self, "skip_msg"):
            self.skipTest(self.skip_msg)

        transport = messaging.get_transport(self.conf, "kombu+memory:////")
        self.addCleanup(transport.cleanup)

        driver = transport._driver

        target = messaging.Target(topic=self.topic, server=self.server, fanout=self.fanout)

        listener = driver.listen(target)

        connection, producer = _create_producer(target)
        self.addCleanup(connection.release)

        msg = {"oslo.version": "2.0", "oslo.message": {}}

        msg["oslo.message"].update(self.msg)
        msg["oslo.message"].update(self.ctxt)

        msg["oslo.message"].update(
            {"_msg_id": uuid.uuid4().hex, "_unique_id": uuid.uuid4().hex, "_reply_q": "reply_" + uuid.uuid4().hex}
        )

        msg["oslo.message"] = jsonutils.dumps(msg["oslo.message"])

        producer.publish(msg)

        received = listener.poll()
        self.assertIsNotNone(received)
        self.assertEqual(self.expected_ctxt, received.ctxt)
        self.assertEqual(self.expected, received.message)
    def test_two_endpoints(self):
        transport = messaging.get_transport(self.conf, url='fake:')

        endpoint1 = mock.Mock()
        endpoint1.info.return_value = None
        endpoint2 = mock.Mock()
        endpoint2.info.return_value = messaging.NotificationResult.HANDLED
        listener_thread = self._setup_listener(transport,
                                               [endpoint1, endpoint2])
        notifier = self._setup_notifier(transport)
        notifier.info({}, 'an_event.start', 'test')

        self.wait_for_messages(1)
        self.assertFalse(listener_thread.stop())

        endpoint1.info.assert_called_once_with({}, 'testpublisher',
                                               'an_event.start', 'test', {
                                                   'timestamp': mock.ANY,
                                                   'message_id': mock.ANY
                                               })

        endpoint2.info.assert_called_once_with({}, 'testpublisher',
                                               'an_event.start', 'test', {
                                                   'timestamp': mock.ANY,
                                                   'message_id': mock.ANY
                                               })
    def test_client_call_timeout(self):
        transport = messaging.get_transport(self.conf, url='fake:')

        finished = False
        wait = threading.Condition()

        class TestEndpoint(object):
            def ping(self, ctxt, arg):
                with wait:
                    if not finished:
                        wait.wait()

        server_thread = self._setup_server(transport, TestEndpoint())
        client = self._setup_client(transport)

        try:
            client.prepare(timeout=0).call({}, 'ping', arg='foo')
        except Exception as ex:
            self.assertIsInstance(ex, messaging.MessagingTimeout, ex)
        else:
            self.assertTrue(False)

        with wait:
            finished = True
            wait.notify()

        self._stop_server(client, server_thread)
    def test_two_topics(self):
        transport = messaging.get_transport(self.conf, url='fake:')

        endpoint = mock.Mock()
        endpoint.info.return_value = None
        targets = [
            messaging.Target(topic="topic1"),
            messaging.Target(topic="topic2")
        ]
        listener_thread = self._setup_listener(transport, [endpoint],
                                               targets=targets)
        notifier = self._setup_notifier(transport, topic='topic1')
        notifier.info({'ctxt': '1'}, 'an_event.start1', 'test')
        notifier = self._setup_notifier(transport, topic='topic2')
        notifier.info({'ctxt': '2'}, 'an_event.start2', 'test')

        self.wait_for_messages(2)
        self.assertFalse(listener_thread.stop())

        endpoint.info.assert_has_calls([
            mock.call({'ctxt': '1'}, 'testpublisher', 'an_event.start1',
                      'test', {
                          'timestamp': mock.ANY,
                          'message_id': mock.ANY
                      }),
            mock.call({'ctxt': '2'}, 'testpublisher', 'an_event.start2',
                      'test', {
                          'timestamp': mock.ANY,
                          'message_id': mock.ANY
                      })
        ],
                                       any_order=True)
Beispiel #16
0
    def __init__(self, strategy=None):

        if CONF.notifier_strategy != 'default':
            msg = _("notifier_strategy was deprecated in "
                    "favor of `notification_driver`")
            warnings.warn(msg, DeprecationWarning)

        # NOTE(flaper87): Use this to keep backwards
        # compatibility. We'll try to get an oslo.messaging
        # driver from the specified strategy.
        _strategy = strategy or CONF.notifier_strategy
        _driver = _STRATEGY_ALIASES.get(_strategy)

        # NOTE(flaper87): The next 3 lines help
        # with the migration to oslo.messaging.
        # Without them, gate tests won't know
        # what driver should be loaded.
        # Once this patch lands, devstack will be
        # updated and then these lines will be removed.
        url = None
        if _strategy in ['rabbit', 'qpid']:
            url = _strategy + '://'

        publisher_id = CONF.default_publisher_id
        self._transport = messaging.get_transport(CONF, url)
        self._notifier = messaging.Notifier(self._transport,
                                            driver=_driver,
                                            publisher_id=publisher_id)
Beispiel #17
0
 def __init__(self, topic, endpoints):
     self.hostname = socket.gethostname()
     self.topic = topic 
     self.transport = messaging.get_transport(cfg.CONF)
     self.target = messaging.Target(topic=self.topic, server=self.hostname, version=self.version)
     self.endpoints = endpoints 
     self.server = messaging.get_rpc_server(self.transport, self.target, self.endpoints)
Beispiel #18
0
    def test_get_transport(self):
        self.config(rpc_backend=self.rpc_backend,
                    control_exchange=self.control_exchange,
                    transport_url=self.transport_url)

        self.mox.StubOutWithMock(driver, 'DriverManager')

        invoke_args = [self.conf,
                       messaging.TransportURL.parse(self.conf,
                                                    self.expect['url'])]
        invoke_kwds = dict(default_exchange=self.expect['exchange'],
                           allowed_remote_exmods=self.expect['allowed'])

        drvr = _FakeDriver(self.conf)
        driver.DriverManager('oslo.messaging.drivers',
                             self.expect['backend'],
                             invoke_on_load=True,
                             invoke_args=invoke_args,
                             invoke_kwds=invoke_kwds).\
            AndReturn(_FakeManager(drvr))

        self.mox.ReplayAll()

        kwargs = dict(url=self.url)
        if self.allowed is not None:
            kwargs['allowed_remote_exmods'] = self.allowed
        if self.aliases is not None:
            kwargs['aliases'] = self.aliases
        transport_ = messaging.get_transport(self.conf, **kwargs)

        self.assertIsNotNone(transport_)
        self.assertIs(transport_.conf, self.conf)
        self.assertIs(transport_._driver, drvr)
Beispiel #19
0
def get_transport():
    global _TRANSPORT

    if not _TRANSPORT:
        _TRANSPORT = messaging.get_transport(cfg.CONF)

    return _TRANSPORT
Beispiel #20
0
    def __init__(self, parsed_url):
        options = urlparse.parse_qs(parsed_url.query)
        # the values of the option is a list of url params values
        # only take care of the latest one if the option
        # is provided more than once
        self.per_meter_topic = bool(int(
            options.get('per_meter_topic', [0])[-1]))

        self.target = options.get('target', ['record_metering_data'])[0]

        self.policy = options.get('policy', ['default'])[-1]
        self.max_queue_length = int(options.get(
            'max_queue_length', [1024])[-1])

        self.local_queue = []

        if self.policy in ['queue', 'drop']:
            LOG.info(_('Publishing policy set to %s, '
                       'override backend retry config to 1') % self.policy)
            override_backend_retry_config(1)
        elif self.policy == 'default':
            LOG.info(_('Publishing policy set to %s') % self.policy)
        else:
            LOG.warn(_('Publishing policy is unknown (%s) force to default')
                     % self.policy)
            self.policy = 'default'

        transport = messaging.get_transport()
        self.rpc_client = messaging.get_rpc_client(transport, version='1.0')
    def test_transport_url(self, fake_ensure_connection, fake_reset):
        transport = messaging.get_transport(self.conf, self.url)
        self.addCleanup(transport.cleanup)
        driver = transport._driver

        urls = driver._get_connection()._url.split(";")
        self.assertEqual(sorted(self.expected), sorted(urls))
Beispiel #22
0
def main():
    try:
        config.parse_args()
        logging.setup('Mistral')

        # Map cli options to appropriate functions. The cli options are
        # registered in mistral's config.py.
        launch_options = {
            'all': launch_all,
            'api': launch_api,
            'engine': launch_engine,
            'executor': launch_executor
        }

        # Please refer to the oslo.messaging documentation for transport
        # configuration. The default transport for oslo.messaging is rabbitMQ.
        # The available transport drivers are listed under oslo.messaging at
        # ./oslo/messaging/rpc/_drivers.  The drivers are prefixed with "impl".
        # The transport driver is specified using the rpc_backend option in the
        # default section of the oslo configuration file. The expected value
        # for rpc_backend is the last part of the driver name. For example,
        # the driver for rabbit is impl_rabbit and for the fake driver is
        # impl_fake. The rpc_backend value for these are "rabbit" and "fake"
        # respectively. There are additional options such as ssl and credential
        # that can be specified depending on the driver.  Please refer to the
        # driver implementation for those additional options.
        transport = messaging.get_transport(cfg.CONF)

        # Launch server(s).
        launch_options[cfg.CONF.server](transport)

    except RuntimeError, e:
        sys.stderr.write("ERROR: %s\n" % e)
        sys.exit(1)
    def test_two_pools(self):
        transport = messaging.get_transport(self.conf, url='fake:')

        endpoint1 = mock.Mock()
        endpoint1.info.return_value = None
        endpoint2 = mock.Mock()
        endpoint2.info.return_value = None

        targets = [messaging.Target(topic="topic")]
        listener1_thread = self._setup_listener(transport, [endpoint1], 2,
                                                targets=targets, pool="pool1")
        listener2_thread = self._setup_listener(transport, [endpoint2], 2,
                                                targets=targets, pool="pool2")

        notifier = self._setup_notifier(transport, topic="topic")
        notifier.info({'ctxt': '0'}, 'an_event.start', 'test message0')
        notifier.info({'ctxt': '1'}, 'an_event.start', 'test message1')

        self.assertFalse(listener2_thread.wait_end())
        self.assertFalse(listener1_thread.wait_end())

        def mocked_endpoint_call(i):
            return mock.call({'ctxt': '%d' % i}, 'testpublisher',
                             'an_event.start', 'test message%d' % i,
                             {'timestamp': mock.ANY, 'message_id': mock.ANY})

        endpoint1.info.assert_has_calls([mocked_endpoint_call(0),
                                         mocked_endpoint_call(1)])
        endpoint2.info.assert_has_calls([mocked_endpoint_call(0),
                                         mocked_endpoint_call(1)])
Beispiel #24
0
def init(conf):
    global TRANSPORT, NOTIFIER
    exmods = get_allowed_exmods()
    TRANSPORT = messaging.get_transport(conf, allowed_remote_exmods=exmods, aliases=TRANSPORT_ALIASES)

    serializer = RequestContextSerializer(JsonPayloadSerializer())
    NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer)
Beispiel #25
0
def main():
    try:
        config.parse_args()
        logging.setup('Mistral')

        # TODO(rakhmerov): This is a temporary hack.
        # We have to initialize engine in executor process because
        # executor now calls engine.convey_task_result() directly.
        engine.load_engine()

        # Please refer to the oslo.messaging documentation for transport
        # configuration. The default transport for oslo.messaging is rabbitMQ.
        # The available transport drivers are listed under oslo.messaging at
        # ./oslo/messaging/rpc/_drivers.  The drivers are prefixed with "impl".
        # The transport driver is specified using the rpc_backend option in the
        # default section of the oslo configuration file. The expected value
        # for rpc_backend is the last part of the driver name. For example,
        # the driver for rabbit is impl_rabbit and for the fake driver is
        # impl_fake. The rpc_backend value for these are "rabbit" and "fake"
        # respectively. There are additional options such as ssl and credential
        # that can be specified depending on the driver.  Please refer to the
        # driver implementation for those additional options.
        transport = messaging.get_transport(cfg.CONF)
        target = messaging.Target(topic=cfg.CONF.executor.topic,
                                  server=cfg.CONF.executor.host)
        endpoints = [server.Executor()]

        ex_server = messaging.get_rpc_server(transport, target, endpoints)
        ex_server.start()
        ex_server.wait()
    except RuntimeError, e:
        sys.stderr.write("ERROR: %s\n" % e)
        sys.exit(1)
    def create_rpc_namespace_proxy(self, context, src_target,
                                   dst_transport_url, dst_target, direction):
        LOG.debug('create_rpc_namespace_proxy %s %s %s %s %s',
                  context, src_target, dst_transport_url, dst_target,
                  direction)
        dst_transport = self._proxies.get_transport(dst_transport_url)
        if dst_transport is None:
            dst_transport = messaging.get_transport(self.conf,
                                                    dst_transport_url)
            self._proxies.add_transport(dst_transport_url, dst_transport)
        if direction == 'send':
            proxy_server = self._create_rpc_namespace_proxy(
                self.src_transport, src_target, dst_transport, dst_target)
        elif direction == 'receive':
            proxy_server = self._create_rpc_namespace_proxy(
                dst_transport, dst_target, self.src_transport, src_target)
        else:
            msg = _('unknown direction %s') % direction
            LOG.error(msg)
            raise RuntimeError(msg)

        # proxy_server.start()
        eventlet.spawn(proxy_server.start)
        namespace_proxy_id = str(uuid.uuid4())
        self._proxies.add_proxy(namespace_proxy_id,
                                dst_transport, proxy_server)
        LOG.debug('namespace_proxy_id %s', namespace_proxy_id)
        return namespace_proxy_id
Beispiel #27
0
 def get_transport(self):
     # get transport manually, oslo.messaging get_transport is broken
     from stevedore import driver
     from oslo.messaging import transport
     messaging.get_transport(cfg.CONF)
     cfg.CONF.set_default('verbose', True)
     cfg.CONF.set_default('rpc_backend', 'fake')
     url = transport.TransportURL.parse(cfg.CONF, None, None)
     kwargs = dict(default_exchange=cfg.CONF.control_exchange,
                   allowed_remote_exmods=[])
     mgr = driver.DriverManager('oslo.messaging.drivers',
                                url.transport,
                                invoke_on_load=True,
                                invoke_args=[cfg.CONF, url],
                                invoke_kwds=kwargs)
     return transport.Transport(mgr.driver)
 def __init__(self, target, url):
     self._transport = messaging.get_transport(cfg.CONF, url)
     self._target = messaging.Target(topic=target,
                                     server='server1',
                                     version='1.0')
     self.timeout = 2
     self.retry = True
    def test_two_topics(self):
        transport = messaging.get_transport(self.conf, url='fake:')

        endpoint = mock.Mock()
        endpoint.info.return_value = None
        targets = [messaging.Target(topic="topic1"),
                   messaging.Target(topic="topic2")]
        listener_thread = self._setup_listener(transport, [endpoint],
                                               targets=targets)
        notifier = self._setup_notifier(transport, topic='topic1')
        notifier.info({'ctxt': '1'}, 'an_event.start1', 'test')
        notifier = self._setup_notifier(transport, topic='topic2')
        notifier.info({'ctxt': '2'}, 'an_event.start2', 'test')

        self.wait_for_messages(2)
        self.assertFalse(listener_thread.stop())

        endpoint.info.assert_has_calls([
            mock.call({'ctxt': '1'}, 'testpublisher',
                      'an_event.start1', 'test',
                      {'timestamp': mock.ANY, 'message_id': mock.ANY}),
            mock.call({'ctxt': '2'}, 'testpublisher',
                      'an_event.start2', 'test',
                      {'timestamp': mock.ANY, 'message_id': mock.ANY})],
            any_order=True)
Beispiel #30
0
def init(conf):
    global TRANSPORT, NOTIFIER
    exmods = get_allowed_exmods()
    TRANSPORT = messaging.get_transport(conf,
                                        allowed_remote_exmods=exmods,
                                        aliases=TRANSPORT_ALIASES)
    NOTIFIER = messaging.Notifier(TRANSPORT)
    def start(self):
        """Bind the UDP socket and handle incoming data."""
        # ensure dispatcher is configured before starting other services
        self.dispatcher_manager = dispatcher.load_dispatcher_manager()
        self.rpc_server = None
        self.notification_server = None
        super(CollectorService, self).start()

        if cfg.CONF.collector.udp_address:
            self.tg.add_thread(self.start_udp)

        allow_requeue = cfg.CONF.collector.requeue_sample_on_dispatcher_error
        transport = messaging.get_transport(optional=True)
        if transport:
            self.rpc_server = messaging.get_rpc_server(
                transport, cfg.CONF.publisher_rpc.metering_topic, self)

            target = oslo.messaging.Target(
                topic=cfg.CONF.publisher_notifier.metering_topic)
            self.notification_server = messaging.get_notification_listener(
                transport, [target], [self],
                allow_requeue=allow_requeue)

            self.rpc_server.start()
            self.notification_server.start()

            if not cfg.CONF.collector.udp_address:
                # Add a dummy thread to have wait() working
                self.tg.add_timer(604800, lambda: None)
Beispiel #32
0
    def test_client_call_timeout(self):
        transport = messaging.get_transport(self.conf, url='fake:')

        finished = False
        wait = threading.Condition()

        class TestEndpoint(object):
            def ping(self, ctxt, arg):
                with wait:
                    if not finished:
                        wait.wait()

        server_thread = self._setup_server(transport, TestEndpoint())
        client = self._setup_client(transport)

        try:
            client.prepare(timeout=0).call({}, 'ping', arg='foo')
        except Exception as ex:
            self.assertIsInstance(ex, messaging.MessagingTimeout, ex)
        else:
            self.assertTrue(False)

        with wait:
            finished = True
            wait.notify()

        self._stop_server(client, server_thread)
Beispiel #33
0
    def __init__(self):

        driver = None
        transport_url = None
        publisher_id = CONF.default_publisher_id

        if CONF.notifier_strategy:
            msg = _("notifier_strategy was deprecated in "
                    "favor of `notification_driver`")
            LOG.warn(msg)

            strategy = CONF.notifier_strategy

            # NOTE(flaper87): Use this to keep backwards
            # compatibility. We'll try to get an oslo.messaging
            # driver from the specified strategy.
            driver = _STRATEGY_ALIASES.get(strategy)
            if driver == 'messaging':
                transport_url = strategy + ':///'

        self._transport = messaging.get_transport(CONF,
                                                  url=transport_url,
                                                  aliases=_ALIASES)

        self._notifier = messaging.Notifier(self._transport,
                                            driver=driver,
                                            publisher_id=publisher_id)
Beispiel #34
0
    def __init__(self, parsed_url):
        super(RPCPublisher, self).__init__(parsed_url)

        options = urlparse.parse_qs(parsed_url.query)
        self.target = options.get('target', ['record_metering_data'])[0]

        self.rpc_client = messaging.get_rpc_client(messaging.get_transport(),
                                                   version='1.0')
Beispiel #35
0
def _prepare_notification_service(server_id):
    endpoints = [report_notification, track_instance, untrack_instance]

    transport = messaging.get_transport(config.CONF)
    s_target = target.Target(topic='murano', server=server_id)
    dispatcher = oslo_dispatcher.NotificationDispatcher([s_target], endpoints,
                                                        None, True)
    return messaging.MessageHandlingServer(transport, dispatcher, 'eventlet')
Beispiel #36
0
 def __init__(self, parsed_url):
     super(NotifierPublisher, self).__init__(parsed_url)
     self.notifier = oslo.messaging.Notifier(
         messaging.get_transport(),
         driver=cfg.CONF.publisher_notifier.metering_driver,
         publisher_id='metering.publisher.%s' % cfg.CONF.host,
         topic=cfg.CONF.publisher_notifier.metering_topic
     )
Beispiel #37
0
    def start(self):
        super(NotificationService, self).start()
        self.pipeline_manager = pipeline.setup_pipeline()
        if cfg.CONF.notification.store_events:
            self.event_pipeline_manager = pipeline.setup_event_pipeline()

        transport = messaging.get_transport()
        self.partition_coordinator = coordination.PartitionCoordinator()
        self.partition_coordinator.start()

        event_transporter = None
        if cfg.CONF.notification.workload_partitioning:
            transporter = []
            for pipe in self.pipeline_manager.pipelines:
                transporter.append(self._get_notifier(transport, pipe))
            if cfg.CONF.notification.store_events:
                event_transporter = []
                for pipe in self.event_pipeline_manager.pipelines:
                    event_transporter.append(
                        self._get_notifier(transport, pipe))

            self.ctxt = context.get_admin_context()
            self.group_id = self.NOTIFICATION_NAMESPACE
        else:
            # FIXME(sileht): endpoint use notification_topics option
            # and it should not because this is oslo.messaging option
            # not a ceilometer, until we have a something to get
            # the notification_topics in an other way
            # we must create a transport to ensure the option have
            # beeen registered by oslo.messaging
            messaging.get_notifier(transport, '')
            transporter = self.pipeline_manager
            if cfg.CONF.notification.store_events:
                event_transporter = self.event_pipeline_manager
            self.group_id = None

        self.listeners, self.pipeline_listeners = [], []
        self._configure_main_queue_listeners(transporter, event_transporter)

        if cfg.CONF.notification.workload_partitioning:
            self.partition_coordinator.join_group(self.group_id)
            self._configure_pipeline_listeners()
            self.partition_coordinator.watch_group(self.group_id,
                                                   self._refresh_agent)

            self.tg.add_timer(cfg.CONF.coordination.heartbeat,
                              self.partition_coordinator.heartbeat)
            self.tg.add_timer(cfg.CONF.coordination.check_watchers,
                              self.partition_coordinator.run_watchers)

        if not cfg.CONF.notification.disable_non_metric_meters:
            LOG.warning(
                _LW('Non-metric meters may be collected. It is highly '
                    'advisable to disable these meters using '
                    'ceilometer.conf or the pipeline.yaml'))
        # Add a dummy thread to have wait() working
        self.tg.add_timer(604800, lambda: None)
Beispiel #38
0
def main(argv=None):
    _usage = """Usage: %prog [options] <name>"""
    parser = optparse.OptionParser(usage=_usage)
    parser.add_option("--url", action="store", default=None)
    parser.add_option("--id", action="store", default=None)
    parser.add_option("--controller", action="store_true")
    parser.add_option("--calls", action="store", type=int, default=0)
    parser.add_option("--workers", action="store", type=int, default=None)
    parser.add_option("--timeout", action="store", type=int, default=2)
    parser.add_option("--config",
                      action="callback",
                      callback=handle_config_option,
                      nargs=2,
                      type="string")

    opts, extra = parser.parse_args(args=argv)

    logging.basicConfig(level=logging.INFO)  #make this an option

    if opts.url:
        cfg.CONF.transport_url = opts.url

    transport = messaging.get_transport(cfg.CONF)

    server_name = opts.id or "%s_%s" % (socket.gethostname(), os.getpid())
    server = Server(transport, server_name, opts.controller, opts.workers)

    def signal_handler(s, f):
        server.stop()

    signal.signal(signal.SIGINT, signal_handler)

    server.start()
    if opts.controller:
        time.sleep(0.5)  # give server time to initialise
        target = messaging.Target(exchange="test-exchange",
                                  topic="test-topic",
                                  fanout=True)
        stub = messaging.RPCClient(transport, target, timeout=2)
        stub.cast({},
                  'start',
                  controller=server_name,
                  count=opts.calls,
                  timeout=opts.timeout)
    elif opts.calls:
        target = messaging.Target(exchange="test-exchange", topic="test-topic")
        stub = messaging.RPCClient(transport, target, timeout=2)
        client = Client(stub)
        stats = client.run("abcdefghijklmnopqrstuvwxyz",
                           count=opts.calls,
                           verbose=True)
        print stats
        server.stop()
    server.wait()
    if opts.controller:
        server.collector.report()
    return 0
Beispiel #39
0
def get_rpc_client(hosts=[], password='******'):
    conf = cfg.CONF
    conf.transport_url = 'rabbit://'
    conf.rabbit_max_retries = 1
    conf.rabbit_hosts = hosts
    conf.rabbit_password = password
    conf.control_exchange = 'numeter'
    transport = messaging.get_transport(conf)
    return BaseAPIClient(transport)
Beispiel #40
0
 def __init__(self, parsed_url, topic):
     super(NotifierPublisher, self).__init__(parsed_url)
     self.notifier = oslo.messaging.Notifier(
         messaging.get_transport(),
         driver=cfg.CONF.publisher_notifier.telemetry_driver,
         publisher_id='telemetry.publisher.%s' % cfg.CONF.host,
         topic=topic,
         retry=self.retry
     )
Beispiel #41
0
 def __init__(self, app, **conf):
     self.notifier = notify.Notifier(
         messaging.get_transport(cfg.CONF, conf.get('url')),
         publisher_id=conf.get('publisher_id',
                               os.path.basename(sys.argv[0])))
     self.service_name = conf.get('service_name')
     self.ignore_req_list = [x.upper().strip() for x in
                             conf.get('ignore_req_list', '').split(',')]
     super(RequestNotifier, self).__init__(app)
    def test_transport_url(self, *args):
        transport = messaging.get_transport(self.conf, self.url)
        self.addCleanup(transport.cleanup)
        driver = transport._driver

        brokers_params = driver._get_connection().brokers_params
        self.assertEqual(
            sorted(self.expected, key=operator.itemgetter('host')),
            sorted(brokers_params, key=operator.itemgetter('host')))
Beispiel #43
0
 def _notify_task_executors(cls, tasks):
     # TODO(m4dcoder): Use a pool for transport and client
     if not cls.transport:
         cls.transport = messaging.get_transport(cfg.CONF)
     ex_client = client.ExecutorClient(cls.transport)
     for task in tasks:
         # TODO(m4dcoder): Fill request context argument with auth info
         context = {}
         ex_client.handle_task(context, task=task)
         LOG.info("Submitted task for execution: '%s'" % task)
Beispiel #44
0
 def __init__(self, topic, server, handlers):
     serializer = RequestContextSerializer(JsonPayloadSerializer())
     transport = messaging.get_transport(cfg.CONF,
                                         aliases=TRANSPORT_ALIASES)
     # TODO(asalkeld) add support for version='x.y'
     target = messaging.Target(topic=topic, server=server)
     self._server = messaging.get_rpc_server(transport,
                                             target,
                                             handlers,
                                             serializer=serializer)
    def test_driver_load(self):
        self.config(heartbeat_timeout_threshold=0,
                    group='oslo_messaging_rabbit')
        transport = messaging.get_transport(self.conf)
        self.addCleanup(transport.cleanup)
        driver = transport._driver
        url = driver._get_connection()._url

        self.assertIsInstance(driver, rabbit_driver.RabbitDriver)
        self.assertEqual('memory:////', url)
Beispiel #46
0
    def test_unknown_executor(self):
        transport = messaging.get_transport(self.conf, url='fake:')

        try:
            messaging.get_rpc_server(transport, None, [], executor='foo')
        except Exception as ex:
            self.assertIsInstance(ex, messaging.ExecutorLoadFailure)
            self.assertEqual('foo', ex.executor)
        else:
            self.assertTrue(False)
Beispiel #47
0
def init(conf):
    global TRANSPORT, NOTIFIER
    exmods = get_allowed_exmods()
    TRANSPORT = messaging.get_transport(conf,
                                        allowed_remote_exmods=exmods,
                                        aliases=TRANSPORT_ALIASES)

    #serializer = RequestContextSerializer(JsonPayloadSerializer())
    # https://review.openstack.org/#/c/71532/1/nova/rpc.py
    NOTIFIER = messaging.Notifier(TRANSPORT, serializer=None)
Beispiel #48
0
    def __init__(self, strategy=None):

        _driver = None
        _strategy = strategy

        if CONF.notifier_strategy != 'default':
            msg = _("notifier_strategy was deprecated in "
                    "favor of `notification_driver`")
            warnings.warn(msg, DeprecationWarning)

            # NOTE(flaper87): Use this to keep backwards
            # compatibility. We'll try to get an oslo.messaging
            # driver from the specified strategy.
            _strategy = strategy or CONF.notifier_strategy
            _driver = _STRATEGY_ALIASES.get(_strategy)

        publisher_id = CONF.default_publisher_id

        # NOTE(flaper87): Assume the user has configured
        # the transport url.
        self._transport = messaging.get_transport(CONF,
                                                  aliases=_ALIASES)

        # NOTE(flaper87): This needs to be checked
        # here because the `get_transport` call
        # registers `transport_url` into ConfigOpts.
        if not CONF.transport_url:
            # NOTE(flaper87): The next 3 lines help
            # with the migration to oslo.messaging.
            # Without them, gate tests won't know
            # what driver should be loaded.
            # Once this patch lands, devstack will be
            # updated and then these lines will be removed.
            url = None
            if _strategy in ['rabbit', 'qpid']:
                url = _strategy + '://'
            self._transport = messaging.get_transport(CONF, url,
                                                      aliases=_ALIASES)

        self._notifier = messaging.Notifier(self._transport,
                                            driver=_driver,
                                            publisher_id=publisher_id)
Beispiel #49
0
 def test_no_server_topic(self):
     transport = messaging.get_transport(self.conf, url='fake:')
     target = messaging.Target(server='testserver')
     server = messaging.get_rpc_server(transport, target, [])
     try:
         server.start()
     except Exception as ex:
         self.assertIsInstance(ex, messaging.InvalidTarget, ex)
         self.assertEqual('testserver', ex.target.server)
     else:
         self.assertTrue(False)
Beispiel #50
0
def init(conf):
    """
    初始化过程,实现三方面内容的初始化:
    1.确定xdrs异常类的基类的处理文件xdrs.exception;
    2.确定了使用rabbit这个AMQP的driver方式:
    3.加载notifier各种驱动实现方式:
      [oslo.messaging.notify.drivers]
      log = oslo.messaging.notify._impl_log:LogDriver
      messagingv2 = oslo.messaging.notify._impl_messaging:MessagingV2Driver
      noop = oslo.messaging.notify._impl_noop:NoOpDriver
      routing = oslo.messaging.notify._impl_routing:RoutingDriver
      test = oslo.messaging.notify._impl_test:TestDriver
      messaging = oslo.messaging.notify._impl_messaging:MessagingDriver
    """
    global TRANSPORT, NOTIFIER
    exmods = get_allowed_exmods()
    """
    exmods = ['xdrs.exception']
    这个方法实现了确定xdrs异常类的基类的处理文件;
    """
    
    TRANSPORT = messaging.get_transport(conf,
                                        allowed_remote_exmods=exmods,
                                        aliases=TRANSPORT_ALIASES)
    """
    ======================================================================================
    conf = <oslo.config.cfg.ConfigOpts object at 0x1ebf490>
    allowed_remote_exmods = ['xdrs.exception']
    aliases = {
              'nova.openstack.common.rpc.impl_kombu': 'rabbit'
              'nova.rpc.impl_kombu': 'rabbit', 
              }
    TRANSPORT = <oslo.messaging.transport.Transport object at 0x30b5150>
    ======================================================================================
    ======================================================================================
    返回值复制给TRANSPORT,实际上这里实现的就是确定了使用rabbit这个driver:
    mgr = <stevedore.driver.DriverManager object at 0x2d5a090>
    mgr.driver = <oslo.messaging._drivers.impl_rabbit.RabbitDriver object at 0x2dd90d0>
    Transport(mgr.driver) = <oslo.messaging.transport.Transport object at 0x311f210>
    TRANSPORT._driver = <oslo.messaging._drivers.impl_rabbit.RabbitDriver object at 0x3a000d0>
    ======================================================================================
    """
    serializer = RequestContextSerializer(JsonPayloadSerializer())
    """
    这里实现的是加载notifier各种驱动实现方式;
    [oslo.messaging.notify.drivers]
    log = oslo.messaging.notify._impl_log:LogDriver
    messagingv2 = oslo.messaging.notify._impl_messaging:MessagingV2Driver
    noop = oslo.messaging.notify._impl_noop:NoOpDriver
    routing = oslo.messaging.notify._impl_routing:RoutingDriver
    test = oslo.messaging.notify._impl_test:TestDriver
    messaging = oslo.messaging.notify._impl_messaging:MessagingDriver
    """
    NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer)
    def test_driver_load(self, fake_ensure, fake_reset):
        self.config(heartbeat_timeout_threshold=0,
                    group='oslo_messaging_rabbit')
        self.messaging_conf.transport_driver = self.transport_driver
        transport = messaging.get_transport(self.conf)
        self.addCleanup(transport.cleanup)
        driver = transport._driver
        url = driver._get_connection()._url

        self.assertIsInstance(driver, rabbit_driver.RabbitDriver)
        self.assertEqual(self.url, url)