function __mount_image {
local image=$1
local image_dir=$2
- OPNFV_MNT_DIR="${image_dir}/ubuntu"
+ OPNFV_MNT_DIR="${image_dir}/mnt"
# Find free nbd, loop devices
for dev in '/sys/class/block/nbd'*; do
OPNFV_MAP_DEV=/dev/mapper/$(basename "${OPNFV_NBD_DEV}")p1
export OPNFV_MNT_DIR OPNFV_LOOP_DEV
[ -n "${OPNFV_NBD_DEV}" ] && [ -n "${OPNFV_LOOP_DEV}" ] || exit 1
- qemu-img resize "${image_dir}/${image}" 3G
+ [[ "${MCP_OS:-}" =~ centos ]] || \
+ qemu-img resize "${image_dir}/${image}" 3G
sudo qemu-nbd --connect="${OPNFV_NBD_DEV}" --aio=native --cache=none \
"${image_dir}/${image}"
sudo kpartx -av "${OPNFV_NBD_DEV}"
- sleep 5 # /dev/nbdNp1 takes some time to come up
# Hardcode partition index to 1, unlikely to change for Ubuntu UCA image
- if sudo growpart "${OPNFV_NBD_DEV}" 1; then
+ sudo partx -uvn 1:1 "${OPNFV_NBD_DEV}"
+ if [[ "${MCP_OS:-}" =~ ubuntu1604 ]] && sudo growpart "${OPNFV_NBD_DEV}" 1
+ then
sudo kpartx -u "${OPNFV_NBD_DEV}"
sudo e2fsck -pf "${OPNFV_MAP_DEV}"
sudo resize2fs "${OPNFV_MAP_DEV}"
+ else
+ sleep 5 # /dev/nbdNp1 takes some time to come up
fi
- # grub-update does not like /dev/nbd*, so use a loop device to work around it
- sudo losetup "${OPNFV_LOOP_DEV}" "${OPNFV_MAP_DEV}"
+ sudo partx -d "${OPNFV_NBD_DEV}"
mkdir -p "${OPNFV_MNT_DIR}"
- sudo mount "${OPNFV_LOOP_DEV}" "${OPNFV_MNT_DIR}"
+ if [ "$(uname -i)" = "aarch64" ] && [[ "${MCP_OS:-}" =~ centos ]]; then
+ # AArch64 CentOS cloud image contains a broken shim binary
+ # https://bugzilla.redhat.com/show_bug.cgi?id=1527283
+ sudo mount "${OPNFV_MAP_DEV}" "${OPNFV_MNT_DIR}"
+ sudo cp -f --remove-destination "${OPNFV_MNT_DIR}/EFI/BOOT/fbaa64.efi" \
+ "${OPNFV_MNT_DIR}/EFI/BOOT/BOOTAA64.EFI"
+ sudo umount -l "${OPNFV_MNT_DIR}"
+ # AArch64 CentOS cloud image has root partition at index 4 instead of 1
+ sudo mount "${OPNFV_MAP_DEV/p1/p4}" "${OPNFV_MNT_DIR}"
+ sudo sed -i -e 's/^\(SELINUX\)=.*$/\1=permissive/g' \
+ "${OPNFV_MNT_DIR}/etc/selinux/config"
+ else
+ # grub-update does not like /dev/nbd*, so use a loop device to work around it
+ sudo losetup "${OPNFV_LOOP_DEV}" "${OPNFV_MAP_DEV}"
+ sudo mount "${OPNFV_LOOP_DEV}" "${OPNFV_MNT_DIR}"
+ fi
sudo mount -t proc proc "${OPNFV_MNT_DIR}/proc"
sudo mount -t sysfs sys "${OPNFV_MNT_DIR}/sys"
sudo mount -o bind /dev "${OPNFV_MNT_DIR}/dev"
- sudo mkdir -p "${OPNFV_MNT_DIR}/run/resolvconf"
- sudo cp /etc/resolv.conf "${OPNFV_MNT_DIR}/run/resolvconf"
+ if [[ "${MCP_OS:-}" =~ ubuntu1804 ]]; then
+ # Ubuntu Bionic (18.04) or newer defaults to using netplan.io, revert it
+ sudo mkdir -p "${OPNFV_MNT_DIR}/run/systemd/resolve"
+ sudo cp -f --remove-destination /etc/resolv.conf \
+ "${OPNFV_MNT_DIR}/run/systemd/resolve/stub-resolv.conf"
+ sudo chroot "${OPNFV_MNT_DIR}" systemctl stop \
+ systemd-networkd.socket systemd-networkd \
+ networkd-dispatcher systemd-networkd-wait-online systemd-resolved
+ sudo chroot "${OPNFV_MNT_DIR}" systemctl disable \
+ systemd-networkd.socket systemd-networkd \
+ networkd-dispatcher systemd-networkd-wait-online systemd-resolved
+ sudo chroot "${OPNFV_MNT_DIR}" systemctl mask \
+ systemd-networkd.socket systemd-networkd \
+ networkd-dispatcher systemd-networkd-wait-online systemd-resolved
+ sudo chroot "${OPNFV_MNT_DIR}" apt --assume-yes purge nplan netplan.io
+ echo "source /etc/network/interfaces.d/*" | \
+ sudo tee "${OPNFV_MNT_DIR}/etc/network/interfaces"
+ fi
+ sudo cp -f --remove-destination \
+ /etc/resolv.conf "${OPNFV_MNT_DIR}/etc/resolv.conf"
echo "GRUB_DISABLE_OS_PROBER=true" | \
sudo tee -a "${OPNFV_MNT_DIR}/etc/default/grub"
sudo sed -i -e 's/^\(GRUB_TIMEOUT\)=.*$/\1=1/g' -e 's/^GRUB_HIDDEN.*$//g' \
local pkgs_r=(${4//,/ })
[ -n "${OPNFV_MNT_DIR}" ] || exit 1
+ # NOTE: We don't support (yet) some features for non-APT repos: keys, prio
+
# APT keys
- if [ "${#apt_key_urls[@]}" -gt 0 ]; then
+ if [[ "${MCP_OS:-}" =~ ubuntu ]] && [ "${#apt_key_urls[@]}" -gt 0 ]; then
for apt_key in "${apt_key_urls[@]}"; do
sudo chroot "${OPNFV_MNT_DIR}" /bin/bash -c \
"wget -qO - '${apt_key}' | apt-key add -"
for repo_line in "${all_repos[@]}"; do
# <repo_name>|<repo prio>|deb|[arch=<arch>]|<repo url>|<dist>|<repo comp>
local repo=(${repo_line//|/ })
+
+ if [[ "${MCP_OS:-}" =~ centos ]]; then
+ cat <<-EOF | sudo tee "${OPNFV_MNT_DIR}/etc/yum.repos.d/${repo[0]}.repo"
+ [${repo[0]}]
+ baseurl=${repo[3]}
+ enabled=1
+ gpgcheck=0
+ EOF
+ continue
+ fi
[ "${#repo[@]}" -gt 5 ] || continue
# NOTE: Names and formatting are compatible with Salt linux.system.repo
cat <<-EOF | sudo tee "${OPNFV_MNT_DIR}/etc/apt/preferences.d/${repo[0]}"
done
# Install packages
if [ "${#pkgs_i[@]}" -gt 0 ]; then
- sudo DEBIAN_FRONTEND="noninteractive" \
- chroot "${OPNFV_MNT_DIR}" apt-get update
- sudo DEBIAN_FRONTEND="noninteractive" FLASH_KERNEL_SKIP="true" \
- chroot "${OPNFV_MNT_DIR}" apt-get install -y "${pkgs_i[@]}"
+ if [[ "${MCP_OS:-}" =~ ubuntu ]]; then
+ sudo DEBIAN_FRONTEND="noninteractive" \
+ chroot "${OPNFV_MNT_DIR}" apt-get update
+ sudo DEBIAN_FRONTEND="noninteractive" FLASH_KERNEL_SKIP="true" \
+ chroot "${OPNFV_MNT_DIR}" apt-get install -y "${pkgs_i[@]}"
+ else
+ sudo chroot "${OPNFV_MNT_DIR}" yum install -y "${pkgs_i[@]}"
+ fi
fi
# Remove packages
if [ "${#pkgs_r[@]}" -gt 0 ]; then
- sudo DEBIAN_FRONTEND="noninteractive" FLASH_KERNEL_SKIP="true" \
- chroot "${OPNFV_MNT_DIR}" apt-get purge -y "${pkgs_r[@]}"
+ if [[ "${MCP_OS:-}" =~ ubuntu ]]; then
+ sudo DEBIAN_FRONTEND="noninteractive" FLASH_KERNEL_SKIP="true" \
+ chroot "${OPNFV_MNT_DIR}" apt-get purge -y "${pkgs_r[@]}"
+ else
+ sudo chroot "${OPNFV_MNT_DIR}" yum remove -y "${pkgs_r[@]}"
+ fi
fi
# Disable cloud-init metadata service datasource
sudo mkdir -p "${OPNFV_MNT_DIR}/etc/cloud/cloud.cfg.d"
##############################################################################
function prepare_vms {
- local base_image=$1; shift
+ local base_image_f=$1; shift
+ local base_image=${base_image_f%.xz}
local image_dir=$1; shift
local repos_pkgs_str=$1; shift # ^-sep list of repos, pkgs to install/rm
- local vnodes=("$@")
local image=base_image_opnfv_fuel.img
local vcp_image=${image%.*}_vcp.img
local _o=${base_image/*\/}
cleanup_uefi
__cleanup_vms
- __get_base_image "${base_image}" "${image_dir}"
+ __get_base_image "${base_image_f}" "${image_dir}"
+ [ "${base_image}" == "${base_image_f}" ] || unxz -fk "${image_dir}/${_o}.xz"
IFS='^' read -r -a repos_pkgs <<< "${repos_pkgs_str}"
local _h=$(echo "${repos_pkgs_str}.$(md5sum "${image_dir}/${_o}")" | \
ln -sf "${image_dir}/${_tmp}" "${image_dir}/${image}"
fi
- # Create config ISO and resize OS disk image for each foundation node VM
- for node in "${vnodes[@]}"; do
- ./create-config-drive.sh -k "$(basename "${SSH_KEY}").pub" \
- -u 'user-data.sh' -h "${node}" "${image_dir}/mcp_${node}.iso"
- cp "${image_dir}/${image}" "${image_dir}/mcp_${node}.qcow2"
- qemu-img resize "${image_dir}/mcp_${node}.qcow2" 100G
- # Prepare dedicated drive for cinder on cmp nodes
- if [[ "${node}" =~ ^(cmp) ]]; then
- qemu-img create "${image_dir}/mcp_${node}_storage.qcow2" 100G
- fi
- done
-
# VCP VMs base image specific changes
if [[ ! "${repos_pkgs_str}" =~ \^{3}$ ]] && [ -n "${repos_pkgs[*]:4}" ]; then
echo "[INFO] Lookup cache / build patched VCP image for md5sum: ${_h}"
${VIRSH} net-start "${net}"
fi
done
- # create veth pairs for relevant networks (pxebr, mgmt)
- for i in $(seq 0 2 2); do
- sudo ip link del "veth_mcp$i" || true
- sudo ip link add "veth_mcp$i" type veth peer name "veth_mcp$((i+1))"
- sudo ip link set "veth_mcp$i" up mtu 9000
- sudo ip link set "veth_mcp$((i+1))" up mtu 9000
- sudo brctl addif "${all_vnode_networks[$((i/2))]}" "veth_mcp$i"
+
+ sudo ip link del veth_mcp0 || true
+ sudo ip link del veth_mcp2 || true
+ # Create systemd service for veth creation after reboot
+ FUEL_VETHC_SERVICE="/etc/systemd/system/opnfv-fuel-vethc.service"
+ FUEL_VETHA_SERVICE="/etc/systemd/system/opnfv-fuel-vetha.service"
+ test -f /usr/sbin/ip && PREFIX=/usr/sbin || PREFIX=/sbin
+ cat <<-EOF | sudo tee "${FUEL_VETHC_SERVICE}"
+ [Unit]
+ After=libvirtd.service
+ Before=docker.service
+ [Service]
+ ExecStart=/bin/sh -ec '\
+ ${PREFIX}/ip link add veth_mcp0 type veth peer name veth_mcp1 && \
+ ${PREFIX}/ip link add veth_mcp2 type veth peer name veth_mcp3 && \
+ ${PREFIX}/ip link set veth_mcp0 up mtu 9000 && \
+ ${PREFIX}/ip link set veth_mcp1 up mtu 9000 && \
+ ${PREFIX}/ip link set veth_mcp2 up mtu 9000 && \
+ ${PREFIX}/ip link set veth_mcp3 up mtu 9000'
+ EOF
+ cat <<-EOF | sudo tee "${FUEL_VETHA_SERVICE}"
+ [Unit]
+ StartLimitInterval=200
+ StartLimitBurst=10
+ After=opnfv-fuel-vethc.service
+ [Service]
+ Restart=on-failure
+ RestartSec=10
+ ExecStartPre=/bin/sh -ec '\
+ ${PREFIX}/brctl showstp ${all_vnode_networks[0]} > /dev/null 2>&1 && \
+ ${PREFIX}/brctl showstp ${all_vnode_networks[1]} > /dev/null 2>&1'
+ ExecStart=/bin/sh -ec '\
+ ${PREFIX}/brctl addif ${all_vnode_networks[0]} veth_mcp0 && \
+ ${PREFIX}/brctl addif ${all_vnode_networks[1]} veth_mcp2 && \
+ while ${PREFIX}/ip rule del to ${SALT_MASTER} iif docker0 table 200 2>/dev/null; do true; done && \
+ ${PREFIX}/ip rule add to ${SALT_MASTER} iif docker0 table 200 && \
+ ${PREFIX}/ip route replace ${SALT_MASTER} dev ${all_vnode_networks[0]} table 200'
+ EOF
+ sudo ln -sf "${FUEL_VETHC_SERVICE}" "/etc/systemd/system/multi-user.target.wants/"
+ sudo ln -sf "${FUEL_VETHA_SERVICE}" "/etc/systemd/system/multi-user.target.wants/"
+ sudo systemctl daemon-reload
+ sudo systemctl restart opnfv-fuel-vethc
+ sudo systemctl restart opnfv-fuel-vetha
+}
+
+function cleanup_all {
+ local image_dir=$1; shift
+ local all_vnode_networks=("$@")
+ [ ! -e "${image_dir}/docker-compose" ] || COMPOSE_PREFIX="${image_dir}/"
+
+ cleanup_uefi
+ __cleanup_vms
+ sudo ip link del veth_mcp0 || true
+ sudo ip link del veth_mcp2 || true
+ for net in "mcpcontrol" "${all_vnode_networks[@]}"; do
+ if ${VIRSH} net-info "${net}" >/dev/null 2>&1; then
+ ${VIRSH} net-destroy "${net}" || true
+ ${VIRSH} net-undefine "${net}"
+ fi
done
+ sudo rm -f "/etc/systemd/system/multi-user.target.wants/opnfv-fuel"* \
+ "/etc/systemd/system/opnfv-fuel"*
+ sudo systemctl daemon-reload
+ "${COMPOSE_PREFIX}docker-compose" -f docker-compose/docker-compose.yaml down
}
function create_vms {
local image_dir=$1; shift
+ local image=base_image_opnfv_fuel.img
# vnode data should be serialized with the following format:
- # <name0>,<ram0>,<vcpu0>[,<sockets0>,<cores0>,<threads0>[,<cell0name0>,<cell0memory0>,
+ # <name0>,<disks0>,<ram0>,<vcpu0>[,<sockets0>,<cores0>,<threads0>[,<cell0name0>,<cell0memory0>,
# <cell0cpus0>,<cell1name0>,<cell1memory0>,<cell1cpus0>]]|<name1>,...'
IFS='|' read -r -a vnodes <<< "$1"; shift
for serialized_vnode_data in "${vnodes[@]}"; do
if [ -z "${serialized_vnode_data}" ]; then continue; fi
IFS=',' read -r -a vnode_data <<< "${serialized_vnode_data}"
+ IFS=';' read -r -a disks_data <<< "${vnode_data[1]}"
+
+ # Create config ISO and resize OS disk image for each foundation node VM
+ ./create-config-drive.sh -k "$(basename "${SSH_KEY}").pub" \
+ -u 'user-data.sh' -h "${vnode_data[0]}" "${image_dir}/mcp_${vnode_data[0]}.iso"
+ cp "${image_dir}/${image}" "${image_dir}/mcp_${vnode_data[0]}.qcow2"
+ qemu-img resize "${image_dir}/mcp_${vnode_data[0]}.qcow2" "${disks_data[0]}"
+ # Prepare additional drives if present
+ idx=0
+ virt_extra_storage=
+ for dsize in "${disks_data[@]:1}"; do
+ ((idx+=1))
+ qcow_file="${image_dir}/mcp_${vnode_data[0]}_${idx}.qcow2"
+ qemu-img create "${qcow_file}" "${dsize}"
+ virt_extra_storage+=" --disk path=${qcow_file},format=qcow2,bus=virtio,cache=none,io=native"
+ done
# prepare VM CPU model, count, topology (optional), NUMA cells (optional, requires topo)
local virt_cpu_args=' --cpu host-passthrough'
- local idx=6 # cell0.name index in serialized data
+ local idx=7 # cell0.name index in serialized data
while [ -n "${vnode_data[${idx}]}" ]; do
virt_cpu_args+=",${vnode_data[${idx}]}.memory=${vnode_data[$((idx + 1))]}"
virt_cpu_args+=",${vnode_data[${idx}]}.cpus=${vnode_data[$((idx + 2))]}"
idx=$((idx + 3))
done
- virt_cpu_args+=" --vcpus vcpus=${vnode_data[2]}"
- if [ -n "${vnode_data[5]}" ]; then
- virt_cpu_args+=",sockets=${vnode_data[3]},cores=${vnode_data[4]},threads=${vnode_data[5]}"
+ virt_cpu_args+=" --vcpus vcpus=${vnode_data[3]}"
+ if [ -n "${vnode_data[6]}" ]; then
+ virt_cpu_args+=",sockets=${vnode_data[4]},cores=${vnode_data[5]},threads=${vnode_data[6]}"
fi
# prepare network args
net_args="${net_args} --network bridge=${net},model=virtio"
done
- # dedicated storage drive for cinder on cmp nodes
- virt_extra_storage=
- if [[ "${vnode_data[0]}" =~ ^(cmp) ]]; then
- virt_extra_storage="--disk path=${image_dir}/mcp_${vnode_data[0]}_storage.qcow2,format=qcow2,bus=virtio,cache=none,io=native"
- fi
-
[ ! -e "${image_dir}/virt-manager" ] || VIRT_PREFIX="${image_dir}/virt-manager/"
# shellcheck disable=SC2086
${VIRT_PREFIX}${VIRSH/virsh/virt-install} --name "${vnode_data[0]}" \
${virt_cpu_args} --accelerate \
${net_args} \
- --ram "${vnode_data[1]}" \
+ --ram "${vnode_data[2]}" \
--disk path="${image_dir}/mcp_${vnode_data[0]}.qcow2",format=qcow2,bus=virtio,cache=none,io=native \
${virt_extra_storage} \
--os-type linux --os-variant none \
mkdir -p "${image_dir}/"{salt/master.d,salt/minion.d}
if grep -q -e 'maas' 'docker-compose/docker-compose.yaml'; then
- chmod +x docker-compose/files/entrypoint*.sh
# Apparmor workaround for bind9 inside Docker containers using AUFS
for profile in 'usr.sbin.ntpd' 'usr.sbin.named' \
- 'usr.sbin.dhcpd' 'usr.bin.tcpdump'; do
+ 'usr.sbin.dhcpd' 'usr.sbin.tcpdump' 'usr.bin.tcpdump'; do
if [ -e "/etc/apparmor.d/${profile}" ] && \
[ ! -e "/etc/apparmor.d/disable/${profile}" ]; then
sudo ln -sf "/etc/apparmor.d/${profile}" "/etc/apparmor.d/disable/"
local image_dir=$1
[ -n "${image_dir}" ] || exit 1
[ ! -e "${image_dir}/docker-compose" ] || COMPOSE_PREFIX="${image_dir}/"
+ if grep -q -e 'maas' 'docker-compose/docker-compose.yaml'; then
+ chmod +x docker-compose/files/entrypoint*.sh
+ fi
"${COMPOSE_PREFIX}docker-compose" -f docker-compose/docker-compose.yaml up -d
}
sudo sed -i -e 's/^\s*set root=.*$//g' -e 's/^\s*loopback.*$//g' \
"${OPNFV_MNT_DIR}/boot/grub/grub.cfg"
fi
- sudo rm -f "${OPNFV_MNT_DIR}/run/resolvconf/resolv.conf"
sync
if mountpoint -q "${OPNFV_MNT_DIR}"; then
sudo umount -l "${OPNFV_MNT_DIR}" || true
sudo losetup -d "${OPNFV_LOOP_DEV}"
fi
if [ -n "${OPNFV_NBD_DEV}" ]; then
+ sudo partx -d "${OPNFV_NBD_DEV}" || true
sudo kpartx -d "${OPNFV_NBD_DEV}" || true
sudo qemu-nbd -d "${OPNFV_NBD_DEV}" || true
fi