diff --git a/unit_tests/utilities/test_zaza_utilities_openstack.py b/unit_tests/utilities/test_zaza_utilities_openstack.py index 5c344bfdc..308320483 100644 --- a/unit_tests/utilities/test_zaza_utilities_openstack.py +++ b/unit_tests/utilities/test_zaza_utilities_openstack.py @@ -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) diff --git a/zaza/openstack/utilities/openstack.py b/zaza/openstack/utilities/openstack.py index 47cabf367..ea2a6ba51 100644 --- a/zaza/openstack/utilities/openstack.py +++ b/zaza/openstack/utilities/openstack.py @@ -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) @@ -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']: