Skip to content

Commit

Permalink
Don't skip interfaces without names: they don't have names on k8s (#443)
Browse files Browse the repository at this point in the history
* Do not skip interfaces without names as there is never a name on kubernetes
* added unit test
  • Loading branch information
dstathis authored Nov 5, 2020
1 parent 78bcfb7 commit 2ed341e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 0 additions & 2 deletions ops/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,6 @@ def __init__(self, network_info: dict):
# interfaces with the same name.
for interface_info in network_info.get('bind-addresses', []):
interface_name = interface_info.get('interface-name')
if not interface_name:
continue
for address_info in interface_info.get('addresses', []):
self.interfaces.append(NetworkInterface(interface_name, address_info))
self.ingress_addresses = []
Expand Down
34 changes: 34 additions & 0 deletions test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,40 @@ def test_binding_by_relation(self):
self._check_binding_data(binding_name, binding)
self.assertEqual(fake_script_calls(self, clear=True), expected_calls)

def test_binding_no_iface_name(self):
network_get_out_obj = {
'bind-addresses': [
{
'mac-address': '',
'interface-name': '',
'addresses': [
{
'hostname': '',
'value': '10.1.89.35',
'cidr': ''
}
]
}
],
'egress-subnets': [
'10.152.183.158/32'
],
'ingress-addresses': [
'10.152.183.158'
]
}
network_get_out = json.dumps(network_get_out_obj)
fake_script(self, 'network-get',
'''[ "$1" = db0 ] && echo '{}' || exit 1'''.format(network_get_out))
binding_name = 'db0'
expected_calls = [['network-get', 'db0', '--format=json']]

binding = self.model.get_binding(binding_name)
self.assertEqual(binding.name, 'db0')
self.assertEqual(binding.network.bind_address, ipaddress.ip_address('10.1.89.35'))
self.assertEqual(binding.network.ingress_address, ipaddress.ip_address('10.152.183.158'))
self.assertEqual(fake_script_calls(self, clear=True), expected_calls)

def test_missing_bind_addresses(self):
network_data = json.dumps({})
fake_script(self, 'network-get',
Expand Down

0 comments on commit 2ed341e

Please sign in to comment.