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
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import charmhelpers.fetch
|
import charmhelpers.fetch
|
||||||
import charmhelpers.core.hookenv as hookenv
|
|
||||||
import charmhelpers.contrib.openstack.utils as ch_utils
|
import charmhelpers.contrib.openstack.utils as ch_utils
|
||||||
|
|
||||||
import charms_openstack.charm
|
import charms_openstack.charm
|
||||||
|
@ -30,23 +29,6 @@ def install():
|
||||||
BarbicanCharm.singleton.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):
|
def setup_endpoint(keystone):
|
||||||
"""When the keystone interface connects, register this unit in the keystone
|
"""When the keystone interface connects, register this unit in the keystone
|
||||||
catalogue.
|
catalogue.
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import charms.reactive as reactive
|
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
|
import charm.openstack.barbican as barbican
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,12 +19,21 @@ def install_packages():
|
||||||
|
|
||||||
@reactive.when('amqp.connected')
|
@reactive.when('amqp.connected')
|
||||||
def setup_amqp_req(amqp):
|
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')
|
@reactive.when('shared-db.connected')
|
||||||
def setup_database(database):
|
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')
|
@reactive.when('identity-service.connected')
|
||||||
|
|
|
@ -115,14 +115,29 @@ class TestBarbicanHandlers(unittest.TestCase):
|
||||||
self.set_state.assert_called_once_with('charm.installed')
|
self.set_state.assert_called_once_with('charm.installed')
|
||||||
|
|
||||||
def test_setup_amqp_req(self):
|
def test_setup_amqp_req(self):
|
||||||
self.patch(handlers.barbican, 'setup_amqp_req')
|
amqp = mock.MagicMock()
|
||||||
handlers.setup_amqp_req('amqp_object')
|
self.patch(handlers.hookenv, 'config')
|
||||||
self.setup_amqp_req.assert_called_once_with('amqp_object')
|
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):
|
def test_database(self):
|
||||||
self.patch(handlers.barbican, 'setup_database')
|
database = mock.MagicMock()
|
||||||
handlers.setup_database('keystone_object')
|
self.patch(handlers.hookenv, 'config')
|
||||||
self.setup_database.assert_called_once_with('keystone_object')
|
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):
|
def test_setup_endpoint(self):
|
||||||
self.patch(handlers.barbican, 'setup_endpoint')
|
self.patch(handlers.barbican, 'setup_endpoint')
|
||||||
|
|
|
@ -37,31 +37,6 @@ class TestOpenStackBarbican(Helper):
|
||||||
barbican.install()
|
barbican.install()
|
||||||
self.install.assert_called_once_with()
|
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):
|
def test_setup_endpoint(self):
|
||||||
self.patch(barbican.BarbicanCharm, 'service_type',
|
self.patch(barbican.BarbicanCharm, 'service_type',
|
||||||
new_callable=mock.PropertyMock)
|
new_callable=mock.PropertyMock)
|
||||||
|
@ -92,12 +67,12 @@ class TestOpenStackBarbican(Helper):
|
||||||
|
|
||||||
class TestBarbicanConfigurationAdapter(Helper):
|
class TestBarbicanConfigurationAdapter(Helper):
|
||||||
|
|
||||||
def test_barbican_configuration_adapter(self):
|
@mock.patch('charmhelpers.core.hookenv.config')
|
||||||
self.patch(barbican.hookenv, 'config')
|
def test_barbican_configuration_adapter(self, config):
|
||||||
reply = {
|
reply = {
|
||||||
'keystone-api-version': '2',
|
'keystone-api-version': '2',
|
||||||
}
|
}
|
||||||
self.config.side_effect = lambda: reply
|
config.side_effect = lambda: reply
|
||||||
# Make one with no errors, api version 2
|
# Make one with no errors, api version 2
|
||||||
a = barbican.BarbicanConfigurationAdapter()
|
a = barbican.BarbicanConfigurationAdapter()
|
||||||
self.assertEqual(a.barbican_api_keystone_pipeline,
|
self.assertEqual(a.barbican_api_keystone_pipeline,
|
||||||
|
@ -126,12 +101,12 @@ class TestBarbicanConfigurationAdapter(Helper):
|
||||||
|
|
||||||
class TestBarbicanAdapters(Helper):
|
class TestBarbicanAdapters(Helper):
|
||||||
|
|
||||||
def test_barbican_adapters(self):
|
@mock.patch('charmhelpers.core.hookenv.config')
|
||||||
self.patch(barbican.hookenv, 'config')
|
def test_barbican_adapters(self, config):
|
||||||
reply = {
|
reply = {
|
||||||
'keystone-api-version': '2',
|
'keystone-api-version': '2',
|
||||||
}
|
}
|
||||||
self.config.side_effect = lambda: reply
|
config.side_effect = lambda: reply
|
||||||
amqp_relation = mock.MagicMock()
|
amqp_relation = mock.MagicMock()
|
||||||
amqp_relation.relation_name = 'amqp'
|
amqp_relation.relation_name = 'amqp'
|
||||||
shared_db_relation = mock.MagicMock()
|
shared_db_relation = mock.MagicMock()
|
||||||
|
|
Loading…
Reference in New Issue