Ejemplo n.º 1
0
 def test_is_ssl(self):
     # false
     url = URL('amqp://localhost')
     self.assertFalse(url.is_ssl())
     # true
     url = URL('amqps://localhost')
     self.assertTrue(url.is_ssl())
Ejemplo n.º 2
0
 def __init__(self, url=None):
     """
     :param url: The connector url:
         <adapter>+<scheme>://<userid:password@<host>:<port>/<virtual-host>.
     :type url: str
     """
     self.url = URL(url or DEFAULT_URL)
     self.ssl = SSL()
Ejemplo n.º 3
0
 def __call__(self, test):
     url = URL(self.url)
     test.assertEqual(url.adapter, self.adapter)
     test.assertEqual(url.scheme, self.scheme)
     test.assertEqual(url.host, self.host)
     test.assertEqual(url.port, self.port)
     test.assertEqual(url.userid, self.userid)
     test.assertEqual(url.password, self.password)
     test.assertEqual(url.path, self.path)
Ejemplo n.º 4
0
    def test_bind(self, _load):
        name = 'qpid'
        adapter = Mock()
        url = URL('redhat.com')
        _load.return_value = [adapter], {name: adapter}

        Adapter.bind(str(url), name)

        _load.assert_called_with()
        self.assertEqual(Adapter.bindings, {url.canonical: adapter})
Ejemplo n.º 5
0
 def test_canonical(self):
     urls = [
         'qpid+amqp://elmer:fudd@test-host:5000/all',
         'amqp://*****:*****@test-host:5000/all',
         'amqp://test-host:5000/all', 'amqp://test-host:5000'
     ]
     for _url in urls:
         url = URL(_url)
         self.assertEqual(url.canonical,
                          _url.split('+')[-1].rsplit('/all')[0])
Ejemplo n.º 6
0
 def test_str(self):
     urls = [
         'qpid+amqp://elmer:fudd@test-host:5000/all',
         'amqp://*****:*****@test-host:5000/all',
         'amqp://test-host:5000/all',
         'amqp://test-host:5000',
         'amqp://test-host',
     ]
     for _url in urls:
         url = URL(_url)
         self.assertEqual(str(url), url.canonical)
Ejemplo n.º 7
0
 def test_is_ssl(self):
     # false
     url = URL('amqp://localhost')
     self.assertFalse(url.is_ssl())
     # true
     url = URL('amqps://localhost')
     self.assertTrue(url.is_ssl())
Ejemplo n.º 8
0
 def find(url):
     """
     Find a broker by URL.
     :param url: A broker URL.
     :type url: str
     :return: The broker.
     :rtype: Broker
     """
     domain_id = URL(url).canonical
     try:
         return Domain.connector.find(domain_id)
     except NotFound:
         return Connector(url)
Ejemplo n.º 9
0
 def test_init(self):
     url = TEST_URL
     b = Connector(url)
     self.assertEqual(b.url, URL(url))
     self.assertEqual(b.adapter, URL(url).adapter)
     self.assertEqual(b.scheme, URL(url).scheme)
     self.assertEqual(b.host, URL(url).host)
     self.assertEqual(b.port, URL(url).port)
     self.assertEqual(b.userid, URL(url).userid)
     self.assertEqual(b.password, URL(url).password)
     self.assertEqual(b.virtual_host, URL(url).path)
     self.assertEqual(b.ssl.ca_certificate, None)
     self.assertEqual(b.ssl.client_key, None)
     self.assertEqual(b.ssl.client_certificate, None)
     self.assertFalse(b.ssl.host_validation)
Ejemplo n.º 10
0
 def bind(url, name):
     """
     Bind (associate) a URL to an adapter.
     :param url: A broker URL.
     :type url: str
     :param name: An adapter name or capability.
     :type name: str
     :raises: KeyError
     """
     _list, catalog = Adapter.loader.load()
     if not _list:
         raise NoAdaptersLoaded()
     try:
         url = URL(url)
         Adapter.bindings[url.canonical] = catalog[name]
     except KeyError:
         raise AdapterNotFound(name)
Ejemplo n.º 11
0
 def find(url=None):
     """
     Find an adapter by URL.
     :param url: A broker URL.
     :type url: str
     :return: The requested adapter or the adapter with the
         highest *priority*.
     :raise: AdapterNotFound
     """
     _list, catalog = Adapter.loader.load()
     if not _list:
         raise NoAdaptersLoaded()
     if not url:
         return _list[0]
     try:
         url = URL(url)
         if url.adapter:
             return catalog[url.adapter]
         else:
             return Adapter.bindings[url.canonical]
     except KeyError:
         raise AdapterNotFound(url.adapter)
Ejemplo n.º 12
0
class Connector(Model):
    """
    Represents an AMQP connector.
    :ivar url: The URL.
    :type url: URL
    :ivar heartbeat: The connection heartbeat in seconds.
    :type heartbeat: int|None
    :ivar ssl: The SSL configuration.
    :type ssl: SSL
    """

    @staticmethod
    def find(url):
        """
        Find a broker by URL.
        :param url: A broker URL.
        :type url: str
        :return: The broker.
        :rtype: Broker
        """
        domain_id = URL(url).canonical
        try:
            return Domain.connector.find(domain_id)
        except NotFound:
            return Connector(url)

    def __init__(self, url=None):
        """
        :param url: The connector url:
            <adapter>+<scheme>://<userid:password@<host>:<port>/<virtual-host>.
        :type url: str
        """
        self.url = URL(url or DEFAULT_URL)
        self.heartbeat = None
        self.ssl = SSL()

    @property
    def domain_id(self):
        """
        Get the domain ID.
        :return: The domain id.
        :rtype: str
        """
        return self.url.canonical

    @property
    def adapter(self):
        """
        Get the (gofer) adapter component of the url.
        :return: The adapter component.
        :rtype: str
        """
        return self.url.adapter

    @property
    def scheme(self):
        """
        Get the scheme component of the url.
        :return: The scheme component.
        :rtype: str
        """
        return self.url.scheme

    @property
    def host(self):
        """
        Get the host component of the url.
        :return: The host component.
        :rtype: str
        """
        return self.url.host

    @property
    def port(self):
        """
        Get the port component of the url.
        :return: The port component.
        :rtype: str
        """
        return self.url.port

    @property
    def userid(self):
        """
        Get the userid component of the url.
        :return: The userid component.
        :rtype: str
        """
        return self.url.userid

    @property
    def password(self):
        """
        Get the password component of the url.
        :return: The password component.
        :rtype: str
        """
        return self.url.password

    @property
    def virtual_host(self):
        """
        Get the virtual_host component of the url.
        :return: The virtual_host component.
        :rtype: str
        """
        return self.url.path

    def add(self):
        """
        Add this broker to the domain.
        """
        Domain.connector.add(self)

    def use_ssl(self):
        """
        Get whether SSL should be used.
        :return: True if SSL should be used.
        :rtype: bool
        """
        return self.url.is_ssl()

    def __unicode__(self):
        s = list()
        s.append('URL: %s' % self.url)
        s.append('SSL: %s' % self.ssl)
        return '|'.join(s)

    def __str__(self):
        return utf8(self)
Ejemplo n.º 13
0
 def test_find(self, find):
     url = 'amqp://localhost'
     found = Connector.find(url)
     find.assert_called_once_with(URL(url).canonical)
     self.assertEqual(found, find.return_value)
Ejemplo n.º 14
0
 def test_hash(self):
     url = URL('test')
     self.assertEqual(hash(url), hash(url.canonical))