added unit testing for db
This commit is contained in:
parent
d43e56ed84
commit
9753c300e7
@ -113,7 +113,9 @@ def pgsql_db_joined():
|
|||||||
'associated a mysql one')
|
'associated a mysql one')
|
||||||
log(e, level=ERROR)
|
log(e, level=ERROR)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
relation_set(database=config('database'))
|
|
||||||
|
conf = config()
|
||||||
|
relation_set(database=conf['database'])
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('shared-db-relation-changed')
|
@hooks.hook('shared-db-relation-changed')
|
||||||
|
@ -113,7 +113,9 @@ def pgsql_db_joined():
|
|||||||
'associated a mysql one')
|
'associated a mysql one')
|
||||||
log(e, level=ERROR)
|
log(e, level=ERROR)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
relation_set(database=config('database'))
|
|
||||||
|
conf = config()
|
||||||
|
relation_set(database=conf['database'])
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('shared-db-relation-changed')
|
@hooks.hook('shared-db-relation-changed')
|
||||||
|
@ -113,7 +113,9 @@ def pgsql_db_joined():
|
|||||||
'associated a mysql one')
|
'associated a mysql one')
|
||||||
log(e, level=ERROR)
|
log(e, level=ERROR)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
relation_set(database=config('database'))
|
|
||||||
|
conf = config()
|
||||||
|
relation_set(database=conf['database'])
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('shared-db-relation-changed')
|
@hooks.hook('shared-db-relation-changed')
|
||||||
|
@ -113,7 +113,9 @@ def pgsql_db_joined():
|
|||||||
'associated a mysql one')
|
'associated a mysql one')
|
||||||
log(e, level=ERROR)
|
log(e, level=ERROR)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
relation_set(database=config('database'))
|
|
||||||
|
conf = config()
|
||||||
|
relation_set(database=conf['database'])
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('shared-db-relation-changed')
|
@hooks.hook('shared-db-relation-changed')
|
||||||
|
@ -31,6 +31,7 @@ TO_PATCH = [
|
|||||||
'ensure_ceph_keyring',
|
'ensure_ceph_keyring',
|
||||||
'ensure_ceph_pool',
|
'ensure_ceph_pool',
|
||||||
'juju_log',
|
'juju_log',
|
||||||
|
'log',
|
||||||
'lsb_release',
|
'lsb_release',
|
||||||
'migrate_database',
|
'migrate_database',
|
||||||
'prepare_lvm_storage',
|
'prepare_lvm_storage',
|
||||||
@ -43,6 +44,7 @@ TO_PATCH = [
|
|||||||
'ceph_config_file',
|
'ceph_config_file',
|
||||||
# charmhelpers.core.hookenv
|
# charmhelpers.core.hookenv
|
||||||
'config',
|
'config',
|
||||||
|
'is_relation_made',
|
||||||
'relation_get',
|
'relation_get',
|
||||||
'relation_ids',
|
'relation_ids',
|
||||||
'relation_set',
|
'relation_set',
|
||||||
@ -159,12 +161,25 @@ class TestChangedHooks(CharmTestCase):
|
|||||||
self.CONFIGS.write.assert_called_with('/etc/cinder/cinder.conf')
|
self.CONFIGS.write.assert_called_with('/etc/cinder/cinder.conf')
|
||||||
self.assertTrue(self.migrate_database.called)
|
self.assertTrue(self.migrate_database.called)
|
||||||
|
|
||||||
|
def test_pgsql_db_changed(self):
|
||||||
|
'It writes out cinder.conf on db changed'
|
||||||
|
self.CONFIGS.complete_contexts.return_value = ['pgsql-db']
|
||||||
|
hooks.hooks.execute(['hooks/pgsql-db-relation-changed'])
|
||||||
|
self.CONFIGS.write.assert_called_with('/etc/cinder/cinder.conf')
|
||||||
|
self.assertTrue(self.migrate_database.called)
|
||||||
|
|
||||||
def test_db_changed_relation_incomplete(self):
|
def test_db_changed_relation_incomplete(self):
|
||||||
'It does not write out cinder.conf with incomplete shared-db rel'
|
'It does not write out cinder.conf with incomplete shared-db rel'
|
||||||
hooks.hooks.execute(['hooks/shared-db-relation-changed'])
|
hooks.hooks.execute(['hooks/shared-db-relation-changed'])
|
||||||
self.assertFalse(self.CONFIGS.write.called)
|
self.assertFalse(self.CONFIGS.write.called)
|
||||||
self.assertFalse(self.migrate_database.called)
|
self.assertFalse(self.migrate_database.called)
|
||||||
|
|
||||||
|
def test_pgsql_db_changed_relation_incomplete(self):
|
||||||
|
'It does not write out cinder.conf with incomplete pgsql-db rel'
|
||||||
|
hooks.hooks.execute(['hooks/pgsql-db-relation-changed'])
|
||||||
|
self.assertFalse(self.CONFIGS.write.called)
|
||||||
|
self.assertFalse(self.migrate_database.called)
|
||||||
|
|
||||||
def test_db_changed_not_leader(self):
|
def test_db_changed_not_leader(self):
|
||||||
'It does not migrate database when not leader'
|
'It does not migrate database when not leader'
|
||||||
self.eligible_leader.return_value = False
|
self.eligible_leader.return_value = False
|
||||||
@ -173,6 +188,14 @@ class TestChangedHooks(CharmTestCase):
|
|||||||
self.CONFIGS.write.assert_called_with('/etc/cinder/cinder.conf')
|
self.CONFIGS.write.assert_called_with('/etc/cinder/cinder.conf')
|
||||||
self.assertFalse(self.migrate_database.called)
|
self.assertFalse(self.migrate_database.called)
|
||||||
|
|
||||||
|
def test_pgsql_db_changed_not_leader(self):
|
||||||
|
'It does not migrate database when not leader'
|
||||||
|
self.eligible_leader.return_value = False
|
||||||
|
self.CONFIGS.complete_contexts.return_value = ['pgsql-db']
|
||||||
|
hooks.hooks.execute(['hooks/pgsql-db-relation-changed'])
|
||||||
|
self.CONFIGS.write.assert_called_with('/etc/cinder/cinder.conf')
|
||||||
|
self.assertFalse(self.migrate_database.called)
|
||||||
|
|
||||||
def test_amqp_changed(self):
|
def test_amqp_changed(self):
|
||||||
'It writes out cinder.conf on amqp changed with complete relation'
|
'It writes out cinder.conf on amqp changed with complete relation'
|
||||||
self.CONFIGS.complete_contexts.return_value = ['amqp']
|
self.CONFIGS.complete_contexts.return_value = ['amqp']
|
||||||
@ -237,11 +260,38 @@ class TestJoinedHooks(CharmTestCase):
|
|||||||
def test_db_joined(self):
|
def test_db_joined(self):
|
||||||
'It properly requests access to a shared-db service'
|
'It properly requests access to a shared-db service'
|
||||||
self.unit_get.return_value = 'cindernode1'
|
self.unit_get.return_value = 'cindernode1'
|
||||||
|
self.is_relation_made.return_value = False
|
||||||
hooks.hooks.execute(['hooks/shared-db-relation-joined'])
|
hooks.hooks.execute(['hooks/shared-db-relation-joined'])
|
||||||
expected = {'username': 'cinder',
|
expected = {'username': 'cinder',
|
||||||
'hostname': 'cindernode1', 'database': 'cinder'}
|
'hostname': 'cindernode1', 'database': 'cinder'}
|
||||||
self.relation_set.assert_called_with(**expected)
|
self.relation_set.assert_called_with(**expected)
|
||||||
|
|
||||||
|
def test_db_joined_with_postgresql(self):
|
||||||
|
self.is_relation_made.return_value = True
|
||||||
|
|
||||||
|
with self.assertRaises(Exception) as context:
|
||||||
|
hooks.hooks.execute(['hooks/shared-db-relation-joined'])
|
||||||
|
self.assertEqual(context.exception.message,
|
||||||
|
'Attempting to associate a mysql database when there '
|
||||||
|
'is already associated a postgresql one')
|
||||||
|
|
||||||
|
def test_postgresql_db_joined(self):
|
||||||
|
'It properly requests access to a postgresql-db service'
|
||||||
|
self.unit_get.return_value = 'cindernode1'
|
||||||
|
self.is_relation_made.return_value = False
|
||||||
|
hooks.hooks.execute(['hooks/pgsql-db-relation-joined'])
|
||||||
|
expected = {'database': 'cinder'}
|
||||||
|
self.relation_set.assert_called_with(**expected)
|
||||||
|
|
||||||
|
def test_postgresql_joined_with_db(self):
|
||||||
|
self.is_relation_made.return_value = True
|
||||||
|
|
||||||
|
with self.assertRaises(Exception) as context:
|
||||||
|
hooks.hooks.execute(['hooks/pgsql-db-relation-joined'])
|
||||||
|
self.assertEqual(context.exception.message,
|
||||||
|
'Attempting to associate a postgresql database when there '
|
||||||
|
'is already associated a mysql one')
|
||||||
|
|
||||||
def test_amqp_joined(self):
|
def test_amqp_joined(self):
|
||||||
'It properly requests access to an amqp service'
|
'It properly requests access to an amqp service'
|
||||||
hooks.hooks.execute(['hooks/amqp-relation-joined'])
|
hooks.hooks.execute(['hooks/amqp-relation-joined'])
|
||||||
|
Loading…
Reference in New Issue
Block a user