[build.sh] Fix quotes, missing deb arch for repo
[fuel.git] / mcp / scripts / lib.sh
index ce5db25..5f1275d 100644 (file)
@@ -243,7 +243,8 @@ function cleanup_vms {
   for node in $(virsh list --name --all | grep -P '\w{3}\d{2}'); do
     virsh domblklist "${node}" | awk '/^.da/ {print $2}' | \
       xargs --no-run-if-empty -I{} sudo rm -f {}
-    virsh undefine "${node}" --remove-all-storage --nvram
+    virsh undefine "${node}" --remove-all-storage --nvram || \
+      virsh undefine "${node}" --remove-all-storage
   done
 }
 
@@ -320,6 +321,7 @@ function prepare_vms {
 }
 
 function jumpserver_pkg_install {
+  local req_type=$1
   if [ -n "$(command -v apt-get)" ]; then
     pkg_type='deb'; pkg_cmd='sudo apt-get install -y'
   else
@@ -327,7 +329,7 @@ function jumpserver_pkg_install {
   fi
   eval "$(parse_yaml "./requirements_${pkg_type}.yaml")"
   for section in 'common' "$(uname -i)"; do
-    section_var="requirements_pkg_${section}[*]"
+    section_var="${req_type}_${section}[*]"
     pkg_list+=" ${!section_var}"
   done
   # shellcheck disable=SC2086
@@ -406,6 +408,7 @@ function create_vms {
 
   # create vms with specified options
   for serialized_vnode_data in "${vnodes[@]}"; do
+    if [ -z "${serialized_vnode_data}" ]; then continue; fi
     IFS=',' read -r -a vnode_data <<< "${serialized_vnode_data}"
 
     # prepare network args
@@ -451,6 +454,23 @@ function update_mcpcontrol_network {
     "<host mac='${amac}' name='mas01' ip='${MAAS_IP}'/>" --live --config
 }
 
+function reset_vms {
+  local vnodes=("$@")
+  local cmd_str="ssh ${SSH_OPTS} ${SSH_SALT}"
+
+  # reset non-infrastructure vms, wait for them to come back online
+  for node in "${vnodes[@]}"; do
+    if [[ ! "${node}" =~ (cfg01|mas01) ]]; then
+      virsh reset "${node}"
+    fi
+  done
+  for node in "${vnodes[@]}"; do
+    if [[ ! "${node}" =~ (cfg01|mas01) ]]; then
+      wait_for 20.0 "${cmd_str} sudo salt -C '${node}*' saltutil.sync_all"
+    fi
+  done
+}
+
 function start_vms {
   local vnodes=("$@")
 
@@ -527,6 +547,13 @@ function wait_for {
   )
 }
 
+function do_udev_cfg {
+  local _conf='/etc/udev/rules.d/99-opnfv-fuel-vnet-mtu.rules'
+  # http://linuxaleph.blogspot.com/2013/01/how-to-network-jumbo-frames-to-kvm-guest.html
+  echo 'SUBSYSTEM=="net", ACTION=="add", KERNEL=="vnet*", RUN+="/sbin/ip link set mtu 9000 dev '"'"%k"'"'"' |& sudo tee "${_conf}"
+  sudo udevadm control --reload || true
+}
+
 function do_sysctl_cfg {
   local _conf='/etc/sysctl.d/99-opnfv-fuel-bridge.conf'
   # https://wiki.libvirt.org/page/Net.bridge.bridge-nf-call_and_sysctl.conf
@@ -545,3 +572,14 @@ function get_nova_compute_pillar_data {
     echo "${value}"
   fi
 }
+
+function docker_install {
+  # Mininum effort attempt at installing Docker if missing
+  if ! which docker; then
+    curl -fsSL https://get.docker.com -o get-docker.sh
+    sudo sh get-docker.sh
+    rm get-docker.sh
+    # On RHEL distros, the Docker service should be explicitly started
+    sudo systemctl start docker
+  fi
+}