diff --git a/requires.py b/requires.py index e756a43..7bb7be0 100644 --- a/requires.py +++ b/requires.py @@ -17,6 +17,8 @@ import json import socket import uuid +from netaddr.core import AddrFormatError + # the reactive framework unfortunately does not grok `import as` in conjunction # with decorators on class instance methods, so we have to revert to `from ...` # imports @@ -215,7 +217,13 @@ class CephRBDMirrorRequires(Endpoint): """ public_addr = self.all_joined_units.received['ceph-public-address'] if public_addr: - return ch_ip.resolve_network_cidr(public_addr) + try: + return ch_ip.resolve_network_cidr(public_addr) + except AddrFormatError: + # LP#1898299 in some cases the netmask will be None, which + # leads to an AddrFormatError. In this case, we should return + # None + return None @property def cluster_network(self): @@ -230,7 +238,13 @@ class CephRBDMirrorRequires(Endpoint): """ cluster_addr = self.all_joined_units.received['ceph-cluster-address'] if cluster_addr: - return ch_ip.resolve_network_cidr(cluster_addr) + try: + return ch_ip.resolve_network_cidr(cluster_addr) + except AddrFormatError: + # LP#1898299 in some cases the netmask will be None, which + # leads to an AddrFormatError. In this case, we should return + # None + return None @property def pools(self): diff --git a/unit_tests/test_requires.py b/unit_tests/test_requires.py index 64eafb2..f38c1b6 100644 --- a/unit_tests/test_requires.py +++ b/unit_tests/test_requires.py @@ -16,6 +16,8 @@ import json import mock import requires +from netaddr.core import AddrFormatError + import charms_openstack.test_utils as test_utils @@ -201,6 +203,10 @@ class TestCephRBDMirrorRequires(test_utils.PatchHelper): 'ceph-public-address') self.resolve_network_cidr.assert_called_once_with('192.0.2.1') + # Test no netmask condition + self.resolve_network_cidr.side_effect = AddrFormatError() + self.assertEqual(self.requires_class.public_network, None) + def test_cluster_network(self): self.patch_requires_class('_all_joined_units') self._all_joined_units.received.__getitem__.return_value = '192.0.2.1' @@ -211,6 +217,10 @@ class TestCephRBDMirrorRequires(test_utils.PatchHelper): 'ceph-cluster-address') self.resolve_network_cidr.assert_called_once_with('192.0.2.1') + # Test no netmask condition + self.resolve_network_cidr.side_effect = AddrFormatError() + self.assertEqual(self.requires_class.cluster_network, None) + def test_maybe_send_rq(self): self.patch_requires_class('_relations') relation = mock.MagicMock()