From 0b7a8645de235f9fd1d06a059bf767f8cd618ee3 Mon Sep 17 00:00:00 2001 From: siavash sardari Date: Wed, 13 Apr 2022 19:28:11 +0430 Subject: [PATCH] Add ovs support for lxc containers. The main problem this commit is resolving is that with openvswitch, the ports were not get cleaned up, and after restart (hard restart or even with soft restart lxc.service gets time-out) containers couldn't start properly, due to existing port on the bridges. Change-Id: I707dbfc6878095f7593abe3fca3a5e5b310063e5 Depends-On: https://review.opendev.org/c/openstack/openstack-ansible/+/837742 --- files/lxc-veth-wiring.sh | 9 ++++++--- tasks/lxc_container_config.yml | 1 + templates/veth-cleanup.sh.j2 | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/files/lxc-veth-wiring.sh b/files/lxc-veth-wiring.sh index 23b8033..defd13e 100644 --- a/files/lxc-veth-wiring.sh +++ b/files/lxc-veth-wiring.sh @@ -23,6 +23,7 @@ VETH="${2}" INTERFACE="${3}" BRIDGE="${4}" VETH_PEER="$(openssl rand -hex 4)" +BRIDGE_TYPE="${5}" # PID of running container PID="$(lxc-info -pHn ${CONTAINER_NAME})" @@ -51,9 +52,11 @@ if ip a l "${VETH_PEER}";then EXIT=3 fi -if ! brctl show "${BRIDGE}" | grep -q "${VETH}"; then - brctl addif "${BRIDGE}" "${VETH}" - EXIT_CODE=3 +if [ "${BRIDGE}" != "openvswitch" ]; then + if ! brctl show "${BRIDGE}" | grep -q "${VETH}"; then + brctl addif "${BRIDGE}" "${VETH}" + EXIT_CODE=3 + fi fi ns_cmd ip link set dev "${INTERFACE}" down || true diff --git a/tasks/lxc_container_config.yml b/tasks/lxc_container_config.yml index b8eb004..61a332b 100644 --- a/tasks/lxc_container_config.yml +++ b/tasks/lxc_container_config.yml @@ -199,6 +199,7 @@ "{{ lxc_container_network_veth_pair[-15:] }}" "{{ item.value.interface }}" "{{ item.value.bridge }}" + "{{ item.value.bridge_type | default('linux_bridge') }}" register: wiring_script with_dict: "{{ lxc_container_networks_combined }}" when: diff --git a/templates/veth-cleanup.sh.j2 b/templates/veth-cleanup.sh.j2 index f374abc..1c6265c 100644 --- a/templates/veth-cleanup.sh.j2 +++ b/templates/veth-cleanup.sh.j2 @@ -5,5 +5,9 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" {% for key, value in lxc_container_networks_combined.items() %} {% if value.type is not defined or value.type == 'veth' %} ip link del {{ lxc_container_network_veth_pair_prefix }}_{{ value.interface }} || true +{% if 'bridge_type' in value and value.bridge_type == "openvswitch" %} +{% set lxc_container_network_ovs_port_indexed = lxc_container_network_veth_pair_prefix ~ "_" ~ value.interface %} +ovs-vsctl --if-exists del-port {{ lxc_container_network_ovs_port_indexed[-15:] }} || true +{% endif %} {% endif %} {% endfor %}