summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xci/clean.sh11
-rwxr-xr-xci/deploy.sh9
-rw-r--r--lib/common-functions.sh148
3 files changed, 164 insertions, 4 deletions
diff --git a/ci/clean.sh b/ci/clean.sh
index 89e89aa4..45486de0 100755
--- a/ci/clean.sh
+++ b/ci/clean.sh
@@ -2,7 +2,12 @@
#Clean script to uninstall provisioning server for Apex
#author: Dan Radez (dradez@redhat.com)
-#
+#author: Tim Rozet (trozet@redhat.com)
+CONFIG=/var/opt/opnfv
+
+##LIBRARIES
+source $CONFIG/lib/common-functions.sh
+
vm_index=4
ovs_bridges="brbm brbm1 brbm2 brbm3"
# Clean off instack VM
@@ -29,7 +34,9 @@ done
for bridge in ${ovs_bridges}; do
virsh net-destroy ${bridge} 2> /dev/null
virsh net-undefine ${bridge} 2> /dev/null
- ovs-vsctl del-br ${bridge} 2> /dev/null
+ if detach_interface_from_ovs ${bridge}; then
+ ovs-vsctl del-br ${bridge} 2> /dev/null
+ fi
done
# clean pub keys from root's auth keys
diff --git a/ci/deploy.sh b/ci/deploy.sh
index 01bf003d..de3ef513 100755
--- a/ci/deploy.sh
+++ b/ci/deploy.sh
@@ -389,8 +389,13 @@ function configure_deps {
for network in ${enabled_network_list}; do
this_interface=$(eval echo \${${network}_bridged_interface})
# check if this a bridged interface for this network
- if [[ -n "$this_interface" || "$this_interface" != "none" ]]; then
- ovs-vsctl list-ports ${NET_MAP[$network]} | grep ${this_interface} || ovs-vsctl add-port ${NET_MAP[$network]} ${this_interface}
+ if [[ ! -z "$this_interface" || "$this_interface" != "none" ]]; then
+ if ! attach_interface_to_ovs ${NET_MAP[$network]} ${this_interface} ${network}; then
+ echo -e "${red}ERROR: Unable to bridge interface ${this_interface} to bridge ${NET_MAP[$network]} for enabled network: ${network}${reset}"
+ exit 1
+ else
+ echo -e "${blue}INFO: Interface ${this_interface} bridged to bridge ${NET_MAP[$network]} for enabled network: ${network}${reset}"
+ fi
else
echo "${red}ERROR: Unable to determine interface to bridge to for enabled network: ${network}${reset}"
exit 1
diff --git a/lib/common-functions.sh b/lib/common-functions.sh
index 9aa97e87..055d7fa2 100644
--- a/lib/common-functions.sh
+++ b/lib/common-functions.sh
@@ -312,3 +312,151 @@ function generate_floating_ip_range {
float_range_end=${last_ip}
echo "${float_range_start},${float_range_end}"
}
+
+##attach interface to OVS and set the network config correctly
+##params: bride to attach to, interface to attach, network type (optional)
+##public indicates attaching to a public interface
+function attach_interface_to_ovs {
+ local bridge interface
+ local if_ip if_mask if_gw if_file ovs_file
+
+ if [[ -z "$1" || -z "$2" ]]; then
+ return 1
+ else
+ bridge=$1
+ interface=$2
+ fi
+
+ if ovs-vsctl list-ports ${bridge} | grep ${interface}; then
+ return 0
+ fi
+
+ if_file=/etc/sysconfig/network-scripts/ifcfg-${interface}
+ ovs_file=/etc/sysconfig/network-scripts/ifcfg-${bridge}
+
+ if [ -e "$if_file" ]; then
+ if_ip=$(sed -n 's/^IPADDR=\(.*\)$/\1/p' ${if_file})
+ if_mask=$(sed -n 's/^NETMASK=\(.*\)$/\1/p' ${if_file})
+ if_gw=$(sed -n 's/^GATEWAY=\(.*\)$/\1/p' ${if_file})
+ else
+ echo "ERROR: ifcfg file missing for ${interface}"
+ return 1
+ fi
+
+ if [[ -z "$if_ip" || -z "$if_mask" ]]; then
+ echo "ERROR: IPADDR or NETMASK missing for ${interface}"
+ return 1
+ elif [[ -z "$if_gw" && "$3" == "public_network" ]]; then
+ echo "ERROR: GATEWAY missing for ${interface}, which is public"
+ return 1
+ fi
+
+ # move old config file to .orig
+ mv -f ${if_file} ${if_file}.orig
+ echo "DEVICE=${interface},
+TYPE=OVSPort,
+PEERDNS=no,
+BOOTPROTO=static,
+NM_CONTROLLED=no,
+ONBOOT=yes,
+OVS_BRIDGE=${bridge},
+PROMISC=yes" > ${if_file}
+
+ if [ -z ${if_gw} ]; then
+ # create bridge cfg
+ echo "DEVICE=${bridge},
+IPADDR=${if_ip},
+NETMASK=${if_mask},
+BOOTPROTO=static,
+ONBOOT=yes,
+TYPE=OVSBridge,
+PROMISC=yes,
+PEERDNS=no" > ${ovs_file}
+
+ else
+ echo "DEVICE=${bridge},
+IPADDR=${if_ip},
+NETMASK=${if_mask},
+BOOTPROTO=static,
+ONBOOT=yes,
+TYPE=OVSBridge,
+PROMISC=yes,
+GATEWAY=${if_gw},
+PEERDNS=no" > ${ovs_file}
+ fi
+
+ sudo systemctl restart network
+}
+
+##detach interface from OVS and set the network config correctly
+##params: bridge to detach from
+##assumes only 1 real interface attached to OVS
+function detach_interface_from_ovs {
+ local bridge
+ local port_output ports_no_orig
+ local net_path
+ local if_ip if_mask if_gw
+
+ net_path=/etc/sysconfig/network-scripts/
+ if [[ -z "$1" ]]; then
+ return 1
+ else
+ bridge=$1
+ fi
+
+ # if no interfaces attached then return
+ if ! ovs-vsctl list-ports ${bridge} | grep -Ev "vnet[0-9]*"; then
+ return 0
+ fi
+
+ # look for .orig ifcfg files to use
+ port_output=$(ovs-vsctl list-ports ${bridge} | grep -Ev "vnet[0-9]*")
+ while read -r line; do
+ if [ -z "$line" ]; then
+ continue
+ elif [ -e ${net_path}/ifcfg-${line}.orig ]; then
+ mv -f ${net_path}/ifcfg-${line}.orig ${net_path}/ifcfg-${line}
+ elif [ -e ${net_path}/ifcfg-${bridge} ]; then
+ if_ip=$(sed -n 's/^IPADDR=\(.*\)$/\1/p' ${if_file})
+ if_mask=$(sed -n 's/^NETMASK=\(.*\)$/\1/p' ${if_file})
+ if_gw=$(sed -n 's/^GATEWAY=\(.*\)$/\1/p' ${if_file})
+
+ if [[ -z "$if_ip" || -z "$if_mask" ]]; then
+ echo "ERROR: IPADDR or NETMASK missing for ${bridge} and no .orig file for interface ${line}"
+ return 1
+ fi
+
+ if [ -z ${if_gw} ]; then
+ # create if cfg
+ echo "DEVICE=${line},
+IPADDR=${if_ip},
+NETMASK=${if_mask},
+BOOTPROTO=static,
+ONBOOT=yes,
+TYPE=Ethernet,
+NM_CONTROLLED=no,
+PEERDNS=no" > ${net_path}/ifcfg-${line}
+ else
+ echo "DEVICE=${line},
+IPADDR=${if_ip},
+NETMASK=${if_mask},
+BOOTPROTO=static,
+ONBOOT=yes,
+TYPE=Ethernet,
+NM_CONTROLLED=no,
+GATEWAY=${if_gw},
+PEERDNS=no" > ${net_path}/ifcfg-${line}
+ fi
+ break
+ else
+ echo "ERROR: Real interface ${line} attached to bridge, but no interface or ${bridge} ifcfg file exists"
+ return 1
+ fi
+
+ done <<< "$port_output"
+
+ # now remove the bridge ifcfg file
+ rm -f ${net_path}/ifcfg-${bridge}
+
+ sudo systemctl restart network
+}