Add fake env support to baremetal
Use bm_poseur to create VM and network bridge
so that, in the absence of physical hardware,
baremetal driver still has something to manipulate.
Change-Id: Id80ede13a35e4380f358b47f08d41ff98ea9d70f
diff --git a/lib/baremetal b/lib/baremetal
index f82633a..62605fb 100644
--- a/lib/baremetal
+++ b/lib/baremetal
@@ -71,10 +71,24 @@
# These should be customized to your environment and hardware
# -----------------------------------------------------------
-# BM_DNSMASQ_* options must be changed to suit your network environment
-BM_DNSMASQ_IFACE=${BM_DNSMASQ_IFACE:-$PUBLIC_INTERFACE}
-BM_DNSMASQ_IFACE=${BM_DNSMASQ_IFACE:-eth0}
-BM_DNSMASQ_RANGE=${BM_DNSMASQ_RANGE:-192.0.2.32,192.0.2.48}
+# whether to create a fake environment, eg. for devstack-gate
+BM_USE_FAKE_ENV=`trueorfalse False $BM_USE_FAKE_ENV`
+
+# Extra options to pass to bm_poseur
+# change the bridge name or IP: --bridge br99 --bridge-ip 192.0.2.1
+# change the virtualization type: --engine qemu
+BM_POSEUR_EXTRA_OPTS=${BM_POSEUR_EXTRA_OPTS:-}
+
+# BM_DNSMASQ_IFACE should match FLAT_NETWORK_BRIDGE
+if [ "$BM_USE_FAKE_ENV" ]; then
+ BM_DNSMASQ_IFACE=${BM_DNSMASQ_IFACE:-br99}
+ BM_DNSMASQ_RANGE=${BM_DNSMASQ_RANGE:-192.0.2.32,192.0.2.48}
+else
+ BM_DNSMASQ_IFACE=${BM_DNSMASQ_IFACE:-eth0}
+ # if testing on a physical network,
+ # BM_DNSMASQ_RANGE must be changed to suit your network
+ BM_DNSMASQ_RANGE=${BM_DNSMASQ_RANGE:-}
+fi
# BM_FIRST_MAC *must* be set to the MAC address of the node you will boot.
# This is passed to dnsmasq along with the kernel/ramdisk to
@@ -108,8 +122,8 @@
# Below this, we set some path and filenames.
# Defaults are probably sufficient.
-
BM_IMAGE_BUILD_DIR=${BM_IMAGE_BUILD_DIR:-$DEST/diskimage-builder}
+BM_POSEUR_DIR=${BM_POSEUR_DIR:-$DEST/bm_poseur}
BM_HOST_CURRENT_KERNEL=$(uname -r)
BM_DEPLOY_RAMDISK=${BM_DEPLOY_RAMDISK:-bm-deploy-$BM_HOST_CURRENT_KERNEL-initrd}
@@ -140,6 +154,7 @@
# so that we can build the deployment kernel & ramdisk
function prepare_baremetal_toolchain() {
git_clone $BM_IMAGE_BUILD_REPO $BM_IMAGE_BUILD_DIR $BM_IMAGE_BUILD_BRANCH
+ git_clone $BM_POSEUR_REPO $BM_POSEUR_DIR $BM_POSEUR_BRANCH
local shellinabox_basename=$(basename $BM_SHELL_IN_A_BOX)
if [[ ! -e $DEST/$shellinabox_basename ]]; then
@@ -158,6 +173,27 @@
fi
}
+# set up virtualized environment for devstack-gate testing
+function create_fake_baremetal_env() {
+ local bm_poseur="$BM_POSEUR_DIR/bm_poseur"
+ # TODO(deva): add support for >1 VM
+ sudo $bm_poseur $BM_POSEUR_EXTRA_OPTS create-bridge
+ sudo $bm_poseur $BM_POSEUR_EXTRA_OPTS create-vm
+ BM_FIRST_MAC=$(sudo $bm_poseur get-macs)
+
+ # NOTE: there is currently a limitation in baremetal driver
+ # that requires second MAC even if it is not used.
+ # Passing a fake value allows this to work.
+ # TODO(deva): remove this after driver issue is fixed.
+ BM_SECOND_MAC='12:34:56:78:90:12'
+}
+
+function cleanup_fake_baremetal_env() {
+ local bm_poseur="$BM_POSEUR_DIR/bm_poseur"
+ sudo $bm_poseur $BM_POSEUR_EXTRA_OPTS destroy-vm
+ sudo $bm_poseur $BM_POSEUR_EXTRA_OPTS destroy-bridge
+}
+
# prepare various directories needed by baremetal hypervisor
function configure_baremetal_nova_dirs() {
# ensure /tftpboot is prepared
diff --git a/stack.sh b/stack.sh
index 53b892f..87c193a 100755
--- a/stack.sh
+++ b/stack.sh
@@ -1145,6 +1145,9 @@
echo_summary "Preparing for nova baremetal"
prepare_baremetal_toolchain
configure_baremetal_nova_dirs
+ if [[ "$BM_USE_FAKE_ENV" = "True" ]]; then
+ create_fake_baremetal_env
+ fi
fi
# Launch Services
diff --git a/stackrc b/stackrc
index 49ccaa8..0e84db8 100644
--- a/stackrc
+++ b/stackrc
@@ -115,6 +115,13 @@
BM_IMAGE_BUILD_REPO=https://github.com/stackforge/diskimage-builder.git
BM_IMAGE_BUILD_BRANCH=master
+# bm_poseur
+# Used to simulate a hardware environment for baremetal
+# Only used if BM_USE_FAKE_ENV is set
+BM_POSEUR_REPO=https://github.com/tripleo/bm_poseur.git
+BM_POSEUR_BRANCH=master
+
+
# Nova hypervisor configuration. We default to libvirt with **kvm** but will
# drop back to **qemu** if we are unable to load the kvm module. ``stack.sh`` can
# also install an **LXC** or **OpenVZ** based system.
diff --git a/unstack.sh b/unstack.sh
index 2a0a40a..fd70916 100755
--- a/unstack.sh
+++ b/unstack.sh
@@ -25,6 +25,7 @@
DATA_DIR=${DATA_DIR:-${DEST}/data}
# Get project function libraries
+source $TOP_DIR/lib/baremetal
source $TOP_DIR/lib/cinder
source $TOP_DIR/lib/horizon
source $TOP_DIR/lib/swift
@@ -67,6 +68,11 @@
killall stud
fi
+# baremetal might have created a fake environment
+if is_service_enabled baremetal && [[ "$BM_USE_FAKE_ENV" = "True" ]]; then
+ cleanup_fake_baremetal_env
+fi
+
SCSI_PERSIST_DIR=$CINDER_STATE_PATH/volumes/*
# Get the iSCSI volumes