Add ``public_network`` and ``cluster_network`` properties

Change-Id: Ia49f4921e772376763be178e11d7777676ccc8da
This commit is contained in:
Frode Nordahl 2019-03-06 11:09:40 +01:00
parent e7fb14440e
commit 2677eb3a2f
2 changed files with 45 additions and 2 deletions

View File

@ -29,6 +29,7 @@ from charms.reactive import (
)
import charmhelpers.contrib.storage.linux.ceph as ch_ceph
import charmhelpers.contrib.network.ip as ch_ip
class CephRBDMirrorRequires(Endpoint):
@ -182,11 +183,33 @@ class CephRBDMirrorRequires(Endpoint):
@property
def public_network(self):
pass
"""Get CIDR for the Ceph public network.
The public network address advertiesed on the relation is mapped to the
corrensponding local interface from which we get the netmask/cidr of
the network.
:returns: CIDR or None
:rtype: Option[str, None]
"""
public_addr = self.all_joined_units.received['ceph-public-address']
if public_addr:
return ch_ip.resolve_network_cidr(public_addr)
@property
def cluster_network(self):
pass
"""Get CIDR for the Ceph cluster network.
The cluster network address advertiesed on the relation is mapped to
the corrensponding local interface from which we get the netmask/cidr
of the network.
:returns: CIDR or None
:rtype: Option[str, None]
"""
cluster_addr = self.all_joined_units.received['ceph-cluster-address']
if cluster_addr:
return ch_ip.resolve_network_cidr(cluster_addr)
@property
def pools(self):

View File

@ -189,3 +189,23 @@ class TestCephRBDMirrorRequires(test_utils.PatchHelper):
self._relations.__iter__.return_value = [relation]
self.assertEqual(list(self.requires_class.mon_hosts()),
['[2001:db8:42::1]:6789', '192.0.2.1:6789'])
def test_public_network(self):
self.patch_requires_class('_all_joined_units')
self._all_joined_units.received.__getitem__.return_value = '192.0.2.1'
self.patch_object(requires.ch_ip, 'resolve_network_cidr')
self.resolve_network_cidr.return_value = '192.0.2.0/24'
self.assertEqual(self.requires_class.public_network, '192.0.2.0/24')
self._all_joined_units.received.__getitem__.assert_called_once_with(
'ceph-public-address')
self.resolve_network_cidr.assert_called_once_with('192.0.2.1')
def test_cluster_network(self):
self.patch_requires_class('_all_joined_units')
self._all_joined_units.received.__getitem__.return_value = '192.0.2.1'
self.patch_object(requires.ch_ip, 'resolve_network_cidr')
self.resolve_network_cidr.return_value = '192.0.2.0/24'
self.assertEqual(self.requires_class.cluster_network, '192.0.2.0/24')
self._all_joined_units.received.__getitem__.assert_called_once_with(
'ceph-cluster-address')
self.resolve_network_cidr.assert_called_once_with('192.0.2.1')