Move setup_amqp and setup_database to reactive handler file
They don't have any interaction with barbican charm class code so they make better sense in the handlers file.
This commit is contained in:
parent
71f1af340f
commit
8f87b75f3e
|
@ -5,7 +5,6 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import charmhelpers.fetch
|
||||
import charmhelpers.core.hookenv as hookenv
|
||||
import charmhelpers.contrib.openstack.utils as ch_utils
|
||||
|
||||
import charms_openstack.charm
|
||||
|
@ -30,23 +29,6 @@ def install():
|
|||
BarbicanCharm.singleton.install()
|
||||
|
||||
|
||||
def setup_amqp_req(amqp):
|
||||
"""Use the amqp interface to request access to the amqp broker using our
|
||||
local configuration.
|
||||
"""
|
||||
amqp.request_access(username=hookenv.config('rabbit-user'),
|
||||
vhost=hookenv.config('rabbit-vhost'))
|
||||
|
||||
|
||||
def setup_database(database):
|
||||
"""On receiving database credentials, configure the database on the
|
||||
interface.
|
||||
"""
|
||||
database.configure(hookenv.config('database'),
|
||||
hookenv.config('database-user'),
|
||||
hookenv.unit_private_ip())
|
||||
|
||||
|
||||
def setup_endpoint(keystone):
|
||||
"""When the keystone interface connects, register this unit in the keystone
|
||||
catalogue.
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import charms.reactive as reactive
|
||||
import charmhelpers.core.hookenv as hookenv
|
||||
|
||||
# This charm's library contains all of the handler code
|
||||
# This charm's library contains all of the handler code associated with
|
||||
# barbican
|
||||
import charm.openstack.barbican as barbican
|
||||
|
||||
|
||||
|
@ -17,12 +19,21 @@ def install_packages():
|
|||
|
||||
@reactive.when('amqp.connected')
|
||||
def setup_amqp_req(amqp):
|
||||
barbican.setup_amqp_req(amqp)
|
||||
"""Use the amqp interface to request access to the amqp broker using our
|
||||
local configuration.
|
||||
"""
|
||||
amqp.request_access(username=hookenv.config('rabbit-user'),
|
||||
vhost=hookenv.config('rabbit-vhost'))
|
||||
|
||||
|
||||
@reactive.when('shared-db.connected')
|
||||
def setup_database(database):
|
||||
barbican.setup_database(database)
|
||||
"""On receiving database credentials, configure the database on the
|
||||
interface.
|
||||
"""
|
||||
database.configure(hookenv.config('database'),
|
||||
hookenv.config('database-user'),
|
||||
hookenv.unit_private_ip())
|
||||
|
||||
|
||||
@reactive.when('identity-service.connected')
|
||||
|
|
|
@ -115,14 +115,29 @@ class TestBarbicanHandlers(unittest.TestCase):
|
|||
self.set_state.assert_called_once_with('charm.installed')
|
||||
|
||||
def test_setup_amqp_req(self):
|
||||
self.patch(handlers.barbican, 'setup_amqp_req')
|
||||
handlers.setup_amqp_req('amqp_object')
|
||||
self.setup_amqp_req.assert_called_once_with('amqp_object')
|
||||
amqp = mock.MagicMock()
|
||||
self.patch(handlers.hookenv, 'config')
|
||||
reply = {
|
||||
'rabbit-user': 'user1',
|
||||
'rabbit-vhost': 'vhost1',
|
||||
}
|
||||
self.config.side_effect = lambda x: reply[x]
|
||||
handlers.setup_amqp_req(amqp)
|
||||
amqp.request_access.assert_called_once_with(
|
||||
username='user1', vhost='vhost1')
|
||||
|
||||
def test_setup_database(self):
|
||||
self.patch(handlers.barbican, 'setup_database')
|
||||
handlers.setup_database('keystone_object')
|
||||
self.setup_database.assert_called_once_with('keystone_object')
|
||||
def test_database(self):
|
||||
database = mock.MagicMock()
|
||||
self.patch(handlers.hookenv, 'config')
|
||||
reply = {
|
||||
'database': 'db1',
|
||||
'database-user': 'dbuser1',
|
||||
}
|
||||
self.config.side_effect = lambda x: reply[x]
|
||||
self.patch(handlers.hookenv, 'unit_private_ip', 'private_ip')
|
||||
handlers.setup_database(database)
|
||||
database.configure.assert_called_once_with(
|
||||
'db1', 'dbuser1', 'private_ip')
|
||||
|
||||
def test_setup_endpoint(self):
|
||||
self.patch(handlers.barbican, 'setup_endpoint')
|
||||
|
|
|
@ -37,31 +37,6 @@ class TestOpenStackBarbican(Helper):
|
|||
barbican.install()
|
||||
self.install.assert_called_once_with()
|
||||
|
||||
def test_setup_amqp_req(self):
|
||||
amqp = mock.MagicMock()
|
||||
self.patch(barbican.hookenv, 'config')
|
||||
reply = {
|
||||
'rabbit-user': 'user1',
|
||||
'rabbit-vhost': 'vhost1',
|
||||
}
|
||||
self.config.side_effect = lambda x: reply[x]
|
||||
barbican.setup_amqp_req(amqp)
|
||||
amqp.request_access.assert_called_once_with(
|
||||
username='user1', vhost='vhost1')
|
||||
|
||||
def test_database(self):
|
||||
database = mock.MagicMock()
|
||||
self.patch(barbican.hookenv, 'config')
|
||||
reply = {
|
||||
'database': 'db1',
|
||||
'database-user': 'dbuser1',
|
||||
}
|
||||
self.config.side_effect = lambda x: reply[x]
|
||||
self.patch(barbican.hookenv, 'unit_private_ip', 'private_ip')
|
||||
barbican.setup_database(database)
|
||||
database.configure.assert_called_once_with(
|
||||
'db1', 'dbuser1', 'private_ip')
|
||||
|
||||
def test_setup_endpoint(self):
|
||||
self.patch(barbican.BarbicanCharm, 'service_type',
|
||||
new_callable=mock.PropertyMock)
|
||||
|
@ -92,12 +67,12 @@ class TestOpenStackBarbican(Helper):
|
|||
|
||||
class TestBarbicanConfigurationAdapter(Helper):
|
||||
|
||||
def test_barbican_configuration_adapter(self):
|
||||
self.patch(barbican.hookenv, 'config')
|
||||
@mock.patch('charmhelpers.core.hookenv.config')
|
||||
def test_barbican_configuration_adapter(self, config):
|
||||
reply = {
|
||||
'keystone-api-version': '2',
|
||||
}
|
||||
self.config.side_effect = lambda: reply
|
||||
config.side_effect = lambda: reply
|
||||
# Make one with no errors, api version 2
|
||||
a = barbican.BarbicanConfigurationAdapter()
|
||||
self.assertEqual(a.barbican_api_keystone_pipeline,
|
||||
|
@ -126,12 +101,12 @@ class TestBarbicanConfigurationAdapter(Helper):
|
|||
|
||||
class TestBarbicanAdapters(Helper):
|
||||
|
||||
def test_barbican_adapters(self):
|
||||
self.patch(barbican.hookenv, 'config')
|
||||
@mock.patch('charmhelpers.core.hookenv.config')
|
||||
def test_barbican_adapters(self, config):
|
||||
reply = {
|
||||
'keystone-api-version': '2',
|
||||
}
|
||||
self.config.side_effect = lambda: reply
|
||||
config.side_effect = lambda: reply
|
||||
amqp_relation = mock.MagicMock()
|
||||
amqp_relation.relation_name = 'amqp'
|
||||
shared_db_relation = mock.MagicMock()
|
||||
|
|
Loading…
Reference in New Issue