diff options
author | Dan Radez <dradez@redhat.com> | 2016-07-06 09:35:07 -0400 |
---|---|---|
committer | Dan Radez <dradez@redhat.com> | 2016-07-06 14:12:41 -0400 |
commit | 2ae3711e9513a6de12169e7ea7d0485411ea7b21 (patch) | |
tree | fb41b5f6f926f13dd5f3e3bcb2a699b73d9da8f9 | |
parent | 6e26a8b75cb70ba0af3aae82733ea70127dd616b (diff) |
Splitting out deps configuration to a functions file
trying to reduce the monolith deploy.sh to smaller parts
Change-Id: Ic788748969819637171a51d10b87b018fe286ae1
Signed-off-by: Dan Radez <dradez@redhat.com>
-rw-r--r-- | build/opnfv-apex-common.spec | 4 | ||||
-rwxr-xr-x | ci/deploy.sh | 136 | ||||
-rwxr-xr-x | lib/configure-deps-functions.sh | 144 |
3 files changed, 148 insertions, 136 deletions
diff --git a/build/opnfv-apex-common.spec b/build/opnfv-apex-common.spec index ce77d6df..d6599c89 100644 --- a/build/opnfv-apex-common.spec +++ b/build/opnfv-apex-common.spec @@ -52,6 +52,7 @@ install config/network/network_settings_v6.yaml %{buildroot}%{_sysconfdir}/opnfv mkdir -p %{buildroot}%{_var}/opt/opnfv/lib/python/apex install lib/common-functions.sh %{buildroot}%{_var}/opt/opnfv/lib/ +install lib/configure-deps-functions.sh %{buildroot}%{_var}/opt/opnfv/lib/ install lib/parse-functions.sh %{buildroot}%{_var}/opt/opnfv/lib/ install lib/utility-functions.sh %{buildroot}%{_var}/opt/opnfv/lib/ install lib/python/apex_python_utils.py %{buildroot}%{_var}/opt/opnfv/lib/python/ @@ -85,6 +86,7 @@ install config/inventory/pod_example_settings.yaml %{buildroot}%{_docdir}/opnfv/ %attr(755,root,root) %{_bindir}/opnfv-clean %attr(755,root,root) %{_bindir}/opnfv-util %{_var}/opt/opnfv/lib/common-functions.sh +%{_var}/opt/opnfv/lib/configure-deps-functions.sh %{_var}/opt/opnfv/lib/parse-functions.sh %{_var}/opt/opnfv/lib/utility-functions.sh %{_var}/opt/opnfv/lib/python/ @@ -116,7 +118,7 @@ install config/inventory/pod_example_settings.yaml %{buildroot}%{_docdir}/opnfv/ %changelog * Tue Jul 5 2016 Dan Radez <dradez@redhat.com> - 3.0-10 -- Adding parse-functions.sh +- Adding functions.sh files * Thu Jun 15 2016 Tim Rozet <trozet@redhat.com> - 3.0-9 - Add fdio scenarios. * Tue Jun 14 2016 Feng Pan <fpan@redhat.com> - 3.0-8 diff --git a/ci/deploy.sh b/ci/deploy.sh index bb4e12ed..d996b92a 100755 --- a/ci/deploy.sh +++ b/ci/deploy.sh @@ -58,6 +58,7 @@ ip_address_family=4 # Libraries lib_files=( $LIB/common-functions.sh +$LIB/configure-deps-functions.sh $LIB/parse-functions.sh $LIB/utility-functions.sh $LIB/installer/onos/onos_gw_mac_update.sh @@ -100,141 +101,6 @@ function verify_internet { fi } -##download dependencies if missing and configure host -#params: none -function configure_deps { - if ! verify_internet; then - echo "${red}Will not download dependencies${reset}" - internet=false - fi - - # verify ip forwarding - if sysctl net.ipv4.ip_forward | grep 0; then - sudo sysctl -w net.ipv4.ip_forward=1 - sudo sh -c "echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf" - fi - - # ensure no dhcp server is running on jumphost - if ! sudo systemctl status dhcpd | grep dead; then - echo "${red}WARN: DHCP Server detected on jumphost, disabling...${reset}" - sudo systemctl stop dhcpd - sudo systemctl disable dhcpd - fi - - # ensure networks are configured - systemctl status libvirtd || systemctl start libvirtd - systemctl status openvswitch || systemctl start openvswitch - - # If flat we only use admin network - if [[ "$net_isolation_enabled" == "FALSE" ]]; then - virsh_enabled_networks="admin_network" - enabled_network_list="admin_network" - # For baremetal we only need to create/attach Undercloud to admin and public - elif [ "$virtual" == "FALSE" ]; then - virsh_enabled_networks="admin_network public_network" - else - virsh_enabled_networks=$enabled_network_list - fi - - # ensure default network is configured correctly - libvirt_dir="/usr/share/libvirt/networks" - virsh net-list --all | grep default || virsh net-define ${libvirt_dir}/default.xml - virsh net-list --all | grep -E "default\s+active" > /dev/null || virsh net-start default - virsh net-list --all | grep -E "default\s+active\s+yes" > /dev/null || virsh net-autostart --network default - - if [[ -z "$virtual" || "$virtual" == "FALSE" ]]; then - for network in ${enabled_network_list}; do - echo "${blue}INFO: Creating Virsh Network: $network & OVS Bridge: ${NET_MAP[$network]}${reset}" - ovs-vsctl list-br | grep "^${NET_MAP[$network]}$" > /dev/null || ovs-vsctl add-br ${NET_MAP[$network]} - virsh net-list --all | grep $network > /dev/null || (cat > ${libvirt_dir}/apex-virsh-net.xml && virsh net-define ${libvirt_dir}/apex-virsh-net.xml) << EOF -<network> - <name>$network</name> - <forward mode='bridge'/> - <bridge name='${NET_MAP[$network]}'/> - <virtualport type='openvswitch'/> -</network> -EOF - if ! (virsh net-list --all | grep $network > /dev/null); then - echo "${red}ERROR: unable to create network: ${network}${reset}" - exit 1; - fi - rm -f ${libvirt_dir}/apex-virsh-net.xml &> /dev/null; - virsh net-list | grep -E "$network\s+active" > /dev/null || virsh net-start $network - virsh net-list | grep -E "$network\s+active\s+yes" > /dev/null || virsh net-autostart --network $network - done - - echo -e "${blue}INFO: Bridges set: ${reset}" - ovs-vsctl list-br - - # bridge interfaces to correct OVS instances for baremetal deployment - for network in ${enabled_network_list}; do - if [[ "$network" != "admin_network" && "$network" != "public_network" ]]; then - continue - fi - this_interface=$(eval echo \${${network}_bridged_interface}) - # check if this a bridged interface for this network - 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 - fi - done - else - for network in ${OPNFV_NETWORK_TYPES}; do - echo "${blue}INFO: Creating Virsh Network: $network${reset}" - virsh net-list --all | grep $network > /dev/null || (cat > ${libvirt_dir}/apex-virsh-net.xml && virsh net-define ${libvirt_dir}/apex-virsh-net.xml) << EOF -<network ipv6='yes'> -<name>$network</name> -<bridge name='${NET_MAP[$network]}'/> -</network> -EOF - if ! (virsh net-list --all | grep $network > /dev/null); then - echo "${red}ERROR: unable to create network: ${network}${reset}" - exit 1; - fi - rm -f ${libvirt_dir}/apex-virsh-net.xml &> /dev/null; - virsh net-list | grep -E "$network\s+active" > /dev/null || virsh net-start $network - virsh net-list | grep -E "$network\s+active\s+yes" > /dev/null || virsh net-autostart --network $network - done - - echo -e "${blue}INFO: Bridges set: ${reset}" - brctl show - fi - - echo -e "${blue}INFO: virsh networks set: ${reset}" - virsh net-list - - # ensure storage pool exists and is started - virsh pool-list --all | grep default > /dev/null || virsh pool-define-as --name default dir --target /var/lib/libvirt/images - virsh pool-list | grep -Eo "default\s+active" > /dev/null || (virsh pool-autostart default; virsh pool-start default) - - if ! egrep '^flags.*(vmx|svm)' /proc/cpuinfo > /dev/null; then - echo "${red}virtualization extensions not found, kvm kernel module insertion may fail.\n \ -Are you sure you have enabled vmx in your bios or hypervisor?${reset}" - fi - - if ! lsmod | grep kvm > /dev/null; then modprobe kvm; fi - if ! lsmod | grep kvm_intel > /dev/null; then modprobe kvm_intel; fi - - if ! lsmod | grep kvm > /dev/null; then - echo "${red}kvm kernel modules not loaded!${reset}" - return 1 - fi - - ##sshkeygen for root - if [ ! -e ~/.ssh/id_rsa.pub ]; then - ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa - fi - - echo "${blue}All dependencies installed and running${reset}" -} - ##verify vm exists, an has a dhcp lease assigned to it ##params: none function setup_undercloud_vm { diff --git a/lib/configure-deps-functions.sh b/lib/configure-deps-functions.sh new file mode 100755 index 00000000..06a4c72c --- /dev/null +++ b/lib/configure-deps-functions.sh @@ -0,0 +1,144 @@ +#!/usr/bin/env bash +############################################################################## +# Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +##download dependencies if missing and configure host +#params: none +function configure_deps { + if ! verify_internet; then + echo "${red}Will not download dependencies${reset}" + internet=false + fi + + # verify ip forwarding + if sysctl net.ipv4.ip_forward | grep 0; then + sudo sysctl -w net.ipv4.ip_forward=1 + sudo sh -c "echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf" + fi + + # ensure no dhcp server is running on jumphost + if ! sudo systemctl status dhcpd | grep dead; then + echo "${red}WARN: DHCP Server detected on jumphost, disabling...${reset}" + sudo systemctl stop dhcpd + sudo systemctl disable dhcpd + fi + + # ensure networks are configured + systemctl status libvirtd || systemctl start libvirtd + systemctl status openvswitch || systemctl start openvswitch + + # If flat we only use admin network + if [[ "$net_isolation_enabled" == "FALSE" ]]; then + virsh_enabled_networks="admin_network" + enabled_network_list="admin_network" + # For baremetal we only need to create/attach Undercloud to admin and public + elif [ "$virtual" == "FALSE" ]; then + virsh_enabled_networks="admin_network public_network" + else + virsh_enabled_networks=$enabled_network_list + fi + + # ensure default network is configured correctly + libvirt_dir="/usr/share/libvirt/networks" + virsh net-list --all | grep default || virsh net-define ${libvirt_dir}/default.xml + virsh net-list --all | grep -E "default\s+active" > /dev/null || virsh net-start default + virsh net-list --all | grep -E "default\s+active\s+yes" > /dev/null || virsh net-autostart --network default + + if [[ -z "$virtual" || "$virtual" == "FALSE" ]]; then + for network in ${enabled_network_list}; do + echo "${blue}INFO: Creating Virsh Network: $network & OVS Bridge: ${NET_MAP[$network]}${reset}" + ovs-vsctl list-br | grep "^${NET_MAP[$network]}$" > /dev/null || ovs-vsctl add-br ${NET_MAP[$network]} + virsh net-list --all | grep $network > /dev/null || (cat > ${libvirt_dir}/apex-virsh-net.xml && virsh net-define ${libvirt_dir}/apex-virsh-net.xml) << EOF +<network> + <name>$network</name> + <forward mode='bridge'/> + <bridge name='${NET_MAP[$network]}'/> + <virtualport type='openvswitch'/> +</network> +EOF + if ! (virsh net-list --all | grep $network > /dev/null); then + echo "${red}ERROR: unable to create network: ${network}${reset}" + exit 1; + fi + rm -f ${libvirt_dir}/apex-virsh-net.xml &> /dev/null; + virsh net-list | grep -E "$network\s+active" > /dev/null || virsh net-start $network + virsh net-list | grep -E "$network\s+active\s+yes" > /dev/null || virsh net-autostart --network $network + done + + echo -e "${blue}INFO: Bridges set: ${reset}" + ovs-vsctl list-br + + # bridge interfaces to correct OVS instances for baremetal deployment + for network in ${enabled_network_list}; do + if [[ "$network" != "admin_network" && "$network" != "public_network" ]]; then + continue + fi + this_interface=$(eval echo \${${network}_bridged_interface}) + # check if this a bridged interface for this network + 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 + fi + done + else + for network in ${OPNFV_NETWORK_TYPES}; do + echo "${blue}INFO: Creating Virsh Network: $network${reset}" + virsh net-list --all | grep $network > /dev/null || (cat > ${libvirt_dir}/apex-virsh-net.xml && virsh net-define ${libvirt_dir}/apex-virsh-net.xml) << EOF +<network ipv6='yes'> +<name>$network</name> +<bridge name='${NET_MAP[$network]}'/> +</network> +EOF + if ! (virsh net-list --all | grep $network > /dev/null); then + echo "${red}ERROR: unable to create network: ${network}${reset}" + exit 1; + fi + rm -f ${libvirt_dir}/apex-virsh-net.xml &> /dev/null; + virsh net-list | grep -E "$network\s+active" > /dev/null || virsh net-start $network + virsh net-list | grep -E "$network\s+active\s+yes" > /dev/null || virsh net-autostart --network $network + done + + echo -e "${blue}INFO: Bridges set: ${reset}" + brctl show + fi + + echo -e "${blue}INFO: virsh networks set: ${reset}" + virsh net-list + + # ensure storage pool exists and is started + virsh pool-list --all | grep default > /dev/null || virsh pool-define-as --name default dir --target /var/lib/libvirt/images + virsh pool-list | grep -Eo "default\s+active" > /dev/null || (virsh pool-autostart default; virsh pool-start default) + + if ! egrep '^flags.*(vmx|svm)' /proc/cpuinfo > /dev/null; then + echo "${red}virtualization extensions not found, kvm kernel module insertion may fail.\n \ +Are you sure you have enabled vmx in your bios or hypervisor?${reset}" + fi + + if ! lsmod | grep kvm > /dev/null; then modprobe kvm; fi + if ! lsmod | grep kvm_intel > /dev/null; then modprobe kvm_intel; fi + + if ! lsmod | grep kvm > /dev/null; then + echo "${red}kvm kernel modules not loaded!${reset}" + return 1 + fi + + ##sshkeygen for root + if [ ! -e ~/.ssh/id_rsa.pub ]; then + ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa + fi + + echo "${blue}All dependencies installed and running${reset}" +} |