Skip to content

Commit

Permalink
Merge pull request openstack-charmers#301 from openstack-charmers/iss…
Browse files Browse the repository at this point in the history
…ue/298

Fail early when no units found for external port creation
  • Loading branch information
coreycb authored May 28, 2020
2 parents 6494047 + 8c74739 commit b54dede
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions unit_tests/utilities/test_zaza_utilities_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,3 +1216,33 @@ def test_ovn_present(self):
self.assertTrue(openstack_utils.ovn_present())
self.get_application.side_effect = [KeyError, KeyError]
self.assertFalse(openstack_utils.ovn_present())

def test_configure_gateway_ext_port(self):
# FIXME: this is not a complete unit test for the function as one did
# not exist at all I'm adding this to test one bit and we'll add more
# as we go.
self.patch_object(openstack_utils, 'deprecated_external_networking')
self.patch_object(openstack_utils, 'dvr_enabled')
self.patch_object(openstack_utils, 'ovn_present')
self.patch_object(openstack_utils, 'get_gateway_uuids')
self.patch_object(openstack_utils, 'get_admin_net')
self.dvr_enabled = False
self.ovn_present = False
self.get_admin_net.return_value = {'id': 'fakeid'}

novaclient = mock.MagicMock()
neutronclient = mock.MagicMock()

def _fake_empty_generator(empty=True):
if empty:
return
yield

self.get_gateway_uuids.side_effect = _fake_empty_generator
with self.assertRaises(RuntimeError):
openstack_utils.configure_gateway_ext_port(
novaclient, neutronclient)
# provide a uuid and check that we don't raise RuntimeError
self.get_gateway_uuids.side_effect = ['fake-uuid']
openstack_utils.configure_gateway_ext_port(
novaclient, neutronclient)
8 changes: 8 additions & 0 deletions zaza/openstack/utilities/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ def configure_gateway_ext_port(novaclient, neutronclient, net_id=None,
if not net_id:
net_id = get_admin_net(neutronclient)['id']

ports_created = 0
for uuid in uuids:
server = novaclient.servers.get(uuid)
ext_port_name = "{}_ext-port".format(server.name)
Expand All @@ -752,12 +753,19 @@ def configure_gateway_ext_port(novaclient, neutronclient, net_id=None,
}
}
port = neutronclient.create_port(body=body_value)
ports_created += 1
server.interface_attach(port_id=port['port']['id'],
net_id=None, fixed_ip=None)
if add_dataport_to_netplan:
mac_address = get_mac_from_port(port, neutronclient)
add_interface_to_netplan(server.name,
mac_address=mac_address)
if not ports_created:
# NOTE: uuids is an iterator so testing it for contents or length prior
# to iterating over it is futile.
raise RuntimeError('Unable to determine UUIDs for machines to attach '
'external networking to.')

ext_br_macs = []
for port in neutronclient.list_ports(network_id=net_id)['ports']:
if 'ext-port' in port['name']:
Expand Down

0 comments on commit b54dede

Please sign in to comment.