diff --git a/zaza/openstack/configure/network.py b/zaza/openstack/configure/network.py index 68965d9..542c595 100755 --- a/zaza/openstack/configure/network.py +++ b/zaza/openstack/configure/network.py @@ -219,6 +219,17 @@ def setup_gateway_ext_port(network_config, keystone_session=None): dvr_mode=network_config.get("dvr_enabled", False), net_id=net_id) + current_release = openstack_utils.get_os_release() + bionic_queens = openstack_utils.get_os_release('bionic_queens') + if current_release >= bionic_queens: + logging.warn("Adding second interface for dataport to guest netplan, \ + for bionic-queens and later") + openstack_utils.plumb_guest_nic( + nova_client, + neutron_client, + dvr_mode=network_config.get("dvr_enabled", False), + net_id=net_id) + def run_from_cli(**kwargs): """Run network configurations from CLI. diff --git a/zaza/openstack/utilities/openstack.py b/zaza/openstack/utilities/openstack.py index 9b2e617..87c54ef 100644 --- a/zaza/openstack/utilities/openstack.py +++ b/zaza/openstack/utilities/openstack.py @@ -55,6 +55,7 @@ import sys import tempfile import tenacity import urllib +import textwrap from zaza import model from zaza.openstack.utilities import ( @@ -483,6 +484,60 @@ def get_admin_net(neutron_client): return net +def plumb_guest_nic(novaclient, neutronclient, + dvr_mode=None, net_id=None): + + """Add port associated with net_id to netplan + + :type net_id: string + """ + + if dvr_mode: + uuids = get_ovs_uuids() + else: + uuids = get_gateway_uuids() + + for uuid in uuids: + server = novaclient.servers.get(uuid) + ext_port_name = "{}_ext-port".format(server.name) + for port in neutronclient.list_ports(device_id=server.id)['ports']: + if port['name'] == ext_port_name: + logging.info('Adding second port to netplan in guest:\ + {}'.format(port['name'])) + mac_address = port['mac_address'] + if dvr_mode: + application_name = 'neutron-openvswitch' + else: + application_name = 'neutron-gateway' + unit_name = juju_utils.get_unit_name_from_ip_address( + server.ip, application_name) + interface = model.async_run_on_unit( + unit_name, "ip addr|grep\ + {}".format( + mac_address)).split("\n")[0].split(" ")[2] + body_value = textwrap.dedent("""\ + network: + ethernets: + {}: + dhcp4: false + dhcp6: true + optional: true + match: + macaddress: {} + set-name: {} + \n + version: 2 + """.format(interface, mac_address, interface)) + netplan_file = open("60-dataport.yaml", "w") + netplan_file.write(body_value) + netplan_file.close() + model.async_scp_to_unit(unit_name, './60-dataport.yaml', + '/etc/netplan/', user="root") + subprocess.call("rm 60-dataport.yaml") + model.async_run_on_unit(unit_name, "netplan apply", + user="root") + + def configure_gateway_ext_port(novaclient, neutronclient, dvr_mode=None, net_id=None): """Configure the neturong-gateway external port.