Merge pull request #10 from gnuoy/bug/no-cluster-relation

No cluster relation breaks PeerHARelationAdapter
This commit is contained in:
Liam Young
2016-06-09 12:22:29 +01:00
2 changed files with 24 additions and 6 deletions

View File

@@ -158,11 +158,14 @@ class PeerHARelationAdapter(OpenStackRelationAdapter):
'network': 'this_unit_private_addr/private_netmask'}}
"""
relation_info = {}
cluster_relid = hookenv.relation_ids('cluster')[0]
if not hookenv.related_units(relid=cluster_relid):
relation_info = {
'cluster_hosts': self.local_default_addresses(),
}
try:
cluster_relid = hookenv.relation_ids('cluster')[0]
if not hookenv.related_units(relid=cluster_relid):
relation_info = {
'cluster_hosts': self.local_default_addresses(),
}
except IndexError:
pass
return relation_info
def local_network_split_addresses(self):

View File

@@ -117,7 +117,6 @@ class FakePeerRelation():
class TestPeerHARelationAdapter(unittest.TestCase):
def test_class(self):
self.maxDiff = None
test_config = {
'os-public-network': 'public_network',
'os-admin-network': 'admin_network',
@@ -179,6 +178,7 @@ class TestPeerHARelationAdapter(unittest.TestCase):
new=lambda: test_config):
fake = FakePeerRelation()
padapt = adapters.PeerHARelationAdapter
peer_ra = padapt(fake)
self.assertEqual(peer_ra.cluster_hosts, expect_full)
@@ -186,6 +186,21 @@ class TestPeerHARelationAdapter(unittest.TestCase):
self.assertEqual(lnetsplit, expect_local_ns)
ldefault = padapt().local_default_addresses()
self.assertEqual(ldefault, expect_local_default)
# Test single_mode_map when a cluster relation is present
with mock.patch.object(adapters.hookenv, 'relation_ids',
new=lambda x: ['rid1']), \
mock.patch.object(adapters.hookenv, 'related_units',
new=lambda relid: []):
expect = {
'cluster_hosts': expect_local_default
}
peer_ra = adapters.PeerHARelationAdapter(FakePeerRelation())
self.assertEqual(peer_ra.single_mode_map, expect)
# Test single_mode_map when a cluster relation is not present
with mock.patch.object(adapters.hookenv, 'relation_ids',
new=lambda x: []):
peer_ra = adapters.PeerHARelationAdapter(FakePeerRelation())
self.assertEqual(peer_ra.single_mode_map, {})
class FakeDatabaseRelation():