Add Memcache relation adapter and registration
Add relation adapter for memcache based coordination backends as used by gnocchi and designate. Register adapter for any 'coordinator_memcached' named relations. Change-Id: Id6fd584de4fd524b86dfa71db95f868408830ac9 Related-Bug: 1729236
This commit is contained in:
parent
11733324d5
commit
8e78f89c17
|
@ -145,6 +145,22 @@ class OpenStackRelationAdapter(object):
|
|||
self.relation, name)()))(meth_name))
|
||||
|
||||
|
||||
class MemcacheRelationAdapter(OpenStackRelationAdapter):
|
||||
|
||||
"""
|
||||
Adapter for the MemcacheRequires relation interface.
|
||||
"""
|
||||
|
||||
interface_type = 'memcache'
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
hosts = sorted(self.relation.memcache_hosts())
|
||||
if hosts:
|
||||
return "memcached://{}:11211?timeout=5".format(hosts[0])
|
||||
return None
|
||||
|
||||
|
||||
class RabbitMQRelationAdapter(OpenStackRelationAdapter):
|
||||
"""
|
||||
Adapter for the RabbitMQRequires relation interface.
|
||||
|
@ -1096,6 +1112,7 @@ class OpenStackAPIRelationAdapters(OpenStackRelationAdapters):
|
|||
'amqp': RabbitMQRelationAdapter,
|
||||
'shared_db': DatabaseRelationAdapter,
|
||||
'cluster': PeerHARelationAdapter,
|
||||
'coordinator_memcached': MemcacheRelationAdapter,
|
||||
}
|
||||
|
||||
def __init__(self, relations, options=None, options_instance=None,
|
||||
|
|
|
@ -102,6 +102,26 @@ class TestOpenStackRelationAdapter(unittest.TestCase):
|
|||
self.assertEqual(i.b, 4)
|
||||
|
||||
|
||||
class FakeMemcacheRelation():
|
||||
|
||||
auto_accessors = ['private_address']
|
||||
relation_name = 'memcache'
|
||||
|
||||
def private_address(self):
|
||||
return 'private-address'
|
||||
|
||||
def memcache_hosts(self):
|
||||
return ['host1', 'host2']
|
||||
|
||||
|
||||
class TestMemcacheRelationAdapter(unittest.TestCase):
|
||||
|
||||
def test_class(self):
|
||||
fake = FakeMemcacheRelation()
|
||||
memcache = adapters.MemcacheRelationAdapter(fake)
|
||||
self.assertEqual(memcache.url, 'memcached://host1:11211?timeout=5')
|
||||
|
||||
|
||||
class FakeRabbitMQRelation():
|
||||
|
||||
auto_accessors = ['vip', 'private_address']
|
||||
|
|
Loading…
Reference in New Issue