add step to execute gw_mac_update.sh after apex deployed 57/6657/6
authorbob <bob.zh@huawei.com>
Thu, 14 Jan 2016 09:42:49 +0000 (17:42 +0800)
committerTim Rozet <trozet@redhat.com>
Sat, 16 Jan 2016 13:54:33 +0000 (13:54 +0000)
Change-Id: I47c316e26ff8e597c781562645397335e8c5bd70
Signed-off-by: bob zhou <bob.zh@huawei.com>
Signed-off-by: Tim Rozet <trozet@redhat.com>
build/opnfv-apex-common.spec
ci/deploy.sh
lib/common-functions.sh
lib/installer/onos/onos_gw_mac_update.sh [new file with mode: 0644]

index 9aaf088..4d3c450 100644 (file)
@@ -38,6 +38,8 @@ install config/deploy/network/network_settings.yaml %{buildroot}%{_sysconfdir}/o
 
 mkdir -p %{buildroot}%{_var}/opt/opnfv/lib/
 install lib/common-functions.sh %{buildroot}%{_var}/opt/opnfv/lib/
+mkdir -p %{buildroot}%{_var}/opt/opnfv/lib/installer/onos/
+install lib/installer/onos/onos_gw_mac_update.sh %{buildroot}%{_var}/opt/opnfv/lib/installer/onos/
 
 mkdir -p %{buildroot}%{_docdir}/opnfv/
 install LICENSE.rst %{buildroot}%{_docdir}/opnfv/
@@ -53,6 +55,7 @@ install config/deploy/network/network_settings.yaml %{buildroot}%{_docdir}/opnfv
 %attr(755,root,root) %{_bindir}/opnfv-deploy
 %attr(755,root,root) %{_bindir}/opnfv-clean
 %{_var}/opt/opnfv/lib/common-functions.sh
+%{_var}/opt/opnfv/lib/installer/onos/onos_gw_mac_update.sh
 %{_sysconfdir}/opnfv-apex/os-odl_l2-nofeature-ha.yaml
 %{_sysconfdir}/opnfv-apex/os-odl_l2-sfc-ha.yaml
 %{_sysconfdir}/opnfv-apex/os-odl_l3-nofeature-ha.yaml
index 232d825..6ac6aff 100755 (executable)
@@ -47,6 +47,7 @@ NET_MAP['storage_network']="brbm3"
 
 ##LIBRARIES
 source $CONFIG/lib/common-functions.sh
+source $CONFIG/lib/installer/onos/onos_gw_mac_update.sh
 
 ##FUNCTIONS
 ##translates yaml into variables
@@ -873,6 +874,16 @@ EOI
       fi
     fi
   done
+
+  # for virtual, we NAT public network through instack
+  if [ "$virtual" == "TRUE" ]; then
+    if ! configure_undercloud_nat ${public_network_cidr}; then
+      echo -e "${red}ERROR: Unable to NAT undercloud with external net: ${public_network_cidr}${reset}"
+      exit 1
+    else
+      echo -e "${blue}INFO: Undercloud (instack VM) has been setup to NAT Overcloud public network${reset}"
+    fi
+  fi
 }
 
 display_usage() {
@@ -1029,6 +1040,14 @@ main() {
       echo -e "${blue}INFO: Post Install Configuration Complete${reset}"
     fi
   fi
+  if [[ ${deploy_options_array['sdn_controller']} == 'onos' ]]; then
+    if ! onos_update_gw_mac ${public_network_cidr} ${public_network_gateway}; then
+      echo -e "${red}ERROR:ONOS Post Install Configuration Failed, Exiting.${reset}"
+      exit 1
+    else
+      echo -e "${blue}INFO: ONOS Post Install Configuration Complete${reset}"
+    fi
+  fi
 }
 
 main "$@"
index edf06cf..1e55aa1 100644 (file)
@@ -504,3 +504,23 @@ PEERDNS=no" > ${net_path}/ifcfg-${line}
 
   sudo systemctl restart network
 }
+
+# Update iptables rule for external network reach internet
+# for virtual deployments
+# params: external_cidr
+function configure_undercloud_nat {
+  local external_cidr
+  if [[ -z "$1" ]]; then
+    return 1
+  else
+    external_cidr=$1
+  fi
+
+  ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" <<EOI
+iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
+iptables -t nat -A POSTROUTING -s ${external_cidr} -o eth0 -j MASQUERADE
+iptables -A FORWARD -i eth2 -j ACCEPT
+iptables -A FORWARD -s ${external_cidr} -m state --state ESTABLISHED,RELATED -j ACCEPT
+service iptables save
+EOI
+}
diff --git a/lib/installer/onos/onos_gw_mac_update.sh b/lib/installer/onos/onos_gw_mac_update.sh
new file mode 100644 (file)
index 0000000..d003cc0
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+# Update gateway mac to onos for l3 function
+
+# author: Bob zhou
+# author: Tim Rozet
+
+
+# Update gateway mac to onos for l3 function
+# params: external CIDR, external gateway
+function onos_update_gw_mac {
+  local CIDR
+  local GW_IP
+
+  if [[ -z "$1" || -z "$2" ]]; then
+    return 1
+  else
+    CIDR=$1
+    GW_IP=$2
+  fi
+
+  if [ -z "$UNDERCLOUD" ]; then
+    #if not found then dnsmasq may be using leasefile-ro
+    instack_mac=$(virsh domiflist instack | grep default | \
+                  grep -Eo "[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+")
+    UNDERCLOUD=$(/usr/sbin/arp -e | grep ${instack_mac} | awk {'print $1'})
+  fi
+  # get controller ip address
+  controller_ip=$(ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
+source stackrc
+openstack server list | grep overcloud-controller-0 | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"
+EOI
+)
+
+  if [ -z "$controller_ip" ]; then
+    echo "ERROR: Failed to find controller_ip for overcloud-controller-0"
+    return 1
+  fi
+
+  # get gateway mac
+  GW_MAC=$(arping ${GW_IP} -c 1 -I brbm2 | grep -Eo '([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})')
+
+  if [ -z "$GW_MAC" ]; then
+    echo "ERROR: Failed to find gateway mac for ${GW_IP}"
+    return 1
+  fi
+
+  # update gateway mac to onos
+  ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
+ssh -T ${SSH_OPTIONS[@]} "heat-admin@${controller_ip}" <<EOF
+echo "external gateway mac is ${GW_MAC}"
+/opt/onos/bin/onos "externalgateway-update -m ${GW_MAC}"
+EOF
+EOI
+
+}