Add tox job for building LXD image

Add additional tox job 'buildimage-lxd' which produces
lxd metadata package and rootfs with installs
nfs-ganesha, unfs3 and cifs.

Co-Authored-By: Alexey Ovchinnikov <aovchinnikov@mirantis.com>

Change-Id: Ia5a4701a828aeef93840f9c0a0e1d0bc0f4a5a2e
This commit is contained in:
Igor Malinovskiy 2015-12-16 15:03:52 +02:00 committed by Alexey Ovchinnikov
parent 642783c98d
commit 796f168c5c
18 changed files with 375 additions and 5 deletions

View File

@ -13,6 +13,20 @@ else
fi
export ELEMENTS_PATH=$_PREFIX/elements
# Detect which image should be created
# generic - qcow image for VM
# lxd - tar for LXD
MANILA_IMAGE_TYPE=${1:-"generic"}
if [ "$MANILA_IMAGE_TYPE" != "generic" ] && [ "$MANILA_IMAGE_TYPE" != "lxd" ]; then
echo -e "Image type $MANILA_IMAGE_TYPE is not supported."
exit 2
fi
echo
echo "Build image: $MANILA_IMAGE_TYPE"
echo
# Collect configuration
# --------------------
# Development options:
@ -30,7 +44,8 @@ MANILA_USER_AUTHORIZED_KEYS="None"
MANILA_IMG_ARCH=${MANILA_IMG_ARCH:-"i386"}
MANILA_IMG_OS=${MANILA_IMG_OS:-"manila-ubuntu-core"}
MANILA_IMG_OS_VER=${MANILA_IMG_OS_VER:-"trusty"}
MANILA_IMG_NAME=${MANILA_IMG_NAME:-"manila-service-image.qcow2"}
MANILA_IMG_NAME=${MANILA_IMG_NAME:-"manila-service-image"}
MANILA_LXD_METADATA_PACKAGE_NAME=${MANILA_LXD_METADATA_PACKAGE_NAME:-"manila-lxd-meta"}
# Manila features
MANILA_ENABLE_NFS_SUPPORT=${MANILA_ENABLE_NFS_SUPPORT:-"yes"}
@ -41,7 +56,15 @@ MANILA_ENABLE_ZFS_SUPPORT=${MANILA_ENABLE_ZFS_SUPPORT:-"yes"}
# Verify configuration
# --------------------
REQUIRED_ELEMENTS="manila-ssh vm $MANILA_IMG_OS dhcp-all-interfaces cleanup-kernel-initrd"
if [ "$MANILA_IMAGE_TYPE" = "lxd" ]; then
REQUIRED_ELEMENTS="manila-container $MANILA_IMG_OS"
IMAGE_FORMAT="tar"
MANILA_ENABLE_ZFS_SUPPORT="no"
export INSTALL_KERNEL=false
else
REQUIRED_ELEMENTS="manila-ssh vm $MANILA_IMG_OS dhcp-all-interfaces cleanup-kernel-initrd"
IMAGE_FORMAT="qcow"
fi
OPTIONAL_ELEMENTS=
OPTIONAL_DIB_ARGS=
@ -50,7 +73,11 @@ if [ "$MANILA_ENABLE_CIFS_SUPPORT" != "yes" ] && [ "$MANILA_ENABLE_NFS_SUPPORT"
fi
if [ "$MANILA_ENABLE_NFS_SUPPORT" = "yes" ]; then
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS manila-nfs"
if [ "$MANILA_IMAGE_TYPE" = "lxd" ]; then
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS manila-ganesha-nfs manila-unfs3"
else
OPTIONAL_ELEMENTS="$OPTIONAL_ELEMENTS manila-nfs"
fi
fi
if [ "$MANILA_ENABLE_CIFS_SUPPORT" = "yes" ]; then
@ -184,5 +211,44 @@ export DIB_MANILA_USER_AUTHORIZED_KEYS=$MANILA_USER_AUTHORIZED_KEYS
# Build image
# -----------
disk-image-create -a $MANILA_IMG_ARCH $OPTIONAL_DIB_ARGS -o $MANILA_IMG_NAME\
disk-image-create \
-t $IMAGE_FORMAT \
-a $MANILA_IMG_ARCH \
$OPTIONAL_DIB_ARGS \
-o $MANILA_IMG_NAME \
$OPTIONAL_ELEMENTS $REQUIRED_ELEMENTS
if [ "$MANILA_IMAGE_TYPE" = "lxd" ]; then
LXD_IMAGE_DIR=$_PREFIX/lxd-image.d
mkdir $LXD_IMAGE_DIR >/dev/null 2>&1 || rm -fR $LXD_IMAGE_DIR/*
mkdir $LXD_IMAGE_DIR/rootfs >/dev/null 2>&1 || rm -fR $LXD_IMAGE_DIR/rootfs/*
# Create LXD metadata package
cp -R $_PREFIX/data/lxd/meta/* $LXD_IMAGE_DIR
# Update creation timestamp in metafile
sed -i "s/%CREATION_DATE%/$(date +%s)/g" $LXD_IMAGE_DIR/metadata.yaml
# Create package
echo "Creating LXD metadata package..."
tar -cf $_PREFIX/$MANILA_LXD_METADATA_PACKAGE_NAME.tar \
-C $LXD_IMAGE_DIR templates metadata.yaml
echo "Done. Metadata could be found here: $_PREFIX/$MANILA_LXD_METADATA_PACKAGE_NAME.tar"
# Create sys and proc directories required by LXD
mkdir -p $LXD_IMAGE_DIR/tmp/sys >/dev/null 2>&1 || echo "sys folder already exists in rootfs."
mkdir -p $LXD_IMAGE_DIR/tmp/proc >/dev/null 2>&1 || echo "proc folder already exists in rootfs."
sudo $_PREFIX/tools/add_to_rootfs_tar $_PREFIX/$MANILA_IMG_NAME.tar \
$LXD_IMAGE_DIR/tmp/sys /./sys/
sudo $_PREFIX/tools/add_to_rootfs_tar $_PREFIX/$MANILA_IMG_NAME.tar \
$LXD_IMAGE_DIR/tmp/proc /./proc/
rm -fR $LXD_IMAGE_DIR/tmp
# Compress rootfs
echo "Compressing rootfs package..."
sudo xz -f $_PREFIX/$MANILA_IMG_NAME.tar
echo "Done. rootfs could be found here: $_PREFIX/$MANILA_IMG_NAME.tar.xz"
fi

View File

@ -0,0 +1,56 @@
{
"architecture": "i686",
"creation_date": %CREATION_DATE%,
"properties": {
"architecture": "i686",
"description": "Openstack Manila LXD image (ubuntu trusty i686).",
"name": "manila-lxd-ubuntu-trusty-i686",
"os": "ubuntu",
"release": "trusty",
"variant": "default"
},
"templates": {
"/etc/hostname": {
"template": "hostname.tpl",
"when": [
"create"
]
},
"/etc/hosts": {
"template": "hosts.tpl",
"when": [
"create"
]
},
"/etc/init/console.override": {
"template": "upstart-override.tpl",
"when": [
"create"
]
},
"/etc/init/tty1.override": {
"template": "upstart-override.tpl",
"when": [
"create"
]
},
"/etc/init/tty2.override": {
"template": "upstart-override.tpl",
"when": [
"create"
]
},
"/etc/init/tty3.override": {
"template": "upstart-override.tpl",
"when": [
"create"
]
},
"/etc/init/tty4.override": {
"template": "upstart-override.tpl",
"when": [
"create"
]
}
}
}

View File

@ -0,0 +1 @@
{{ container.name }}

View File

@ -0,0 +1,10 @@
127.0.0.1 localhost
127.0.0.1 localhost.localdomain
127.0.1.1 {{ container.name }}
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

View File

@ -0,0 +1 @@
manual

View File

@ -0,0 +1,15 @@
#!/bin/bash
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
echo "" > /etc/network/interfaces
echo "auto lo" >> /etc/network/interfaces
echo "iface lo inet loopback" >> /etc/network/interfaces
echo "" >> /etc/network/interfaces
echo "auto eth0" >> /etc/network/interfaces
echo "iface eth0 inet dhcp" >> /etc/network/interfaces

View File

@ -0,0 +1,35 @@
#!/bin/bash
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
SCRIPTDIR=$(dirname $0)
# Install required packages
install-packages git-core cmake build-essential libkrb5-dev bison flex
# Build nfs-ganesha
cd /usr/src
# TODO(u_glide): Move branch to config option through "environment.d"
git config --global http.sslVerify false
git clone --depth 5 --recursive -b "V2.2-stable" \
https://github.com/nfs-ganesha/nfs-ganesha.git
cd nfs-ganesha
mkdir build && cd build
cmake ../src && make
# Install nfs-ganesha
sudo make install
# (aovchinnikov): This will be used later on when all peculiarities of
# running ganesha inside a container are sorted out.
#sudo cp ../src/scripts/ganeshactl/org.ganesha.nfsd.conf /etc/dbus-1/system.d/
#install -D -g root -o root -m 0755 \
# ${SCRIPTDIR}/nfs-ganesha /etc/init.d/nfs-ganesha
#sudo update-rc.d nfs-ganesha defaults
# Remove sources
cd /usr/src && rm -fR nfs-ganesha

View File

@ -0,0 +1,71 @@
#!/bin/bash
# nfs-ganesha init script for ubuntu
# source function library
. /lib/lsb/init-functions
PATHPROG=/usr/bin/ganesha.nfsd
LOGFILE=/var/log/ganesha.log
CONFFILE=/etc/ganesha/ganesha.conf
prog=ganesha.nfsd
PID_FILE=${PID_FILE:=/var/run/${prog}.pid}
LOCK_FILE=${LOCK_FILE:=/var/lock/subsys/${prog}}
[ -f /etc/sysconfig/ganesha ] && . /etc/sysconfig/ganesha
OPTIONS="-L $LOGFILE -f $CONFFILE -N NIV_EVENT"
RETVAL=0
start() {
log_daemon_msg "Starting $prog"
start-stop-daemon \
--start --oknodo --pidfile "$PID_FILE" --exec $PATHPROG -- $OPTIONS
status=$?
[ $status = 0 ]
log_end_msg $status
echo
}
stop() {
log_daemon_msg "Stopping $prog"
start-stop-daemon \
--stop --quiet --retry 5 --oknodo --pidfile $PID_FILE
status=$?
log_end_msg $status
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
status)
if pidof ganesha.nfsd >/dev/null
then
echo "ganesha.nfsd running"
exit 0
else
echo "ganesha.nfsd not running"
exit 3
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|try-restart|status}"
RETVAL=1
esac
exit $RETVAL

View File

@ -0,0 +1,9 @@
cmake:
phase: post-install.d
uninstall: True
build-essential:
phase: post-install.d
uninstall: True
git-core:
phase: post-install.d
uninstall: True

View File

@ -1,2 +1,3 @@
export DISTRO_NAME=ubuntu
export DIB_RELEASE=${DIB_RELEASE:-trusty}
export INSTALL_KERNEL=${INSTALL_KERNEL:-true}

View File

@ -1 +0,0 @@
linux-image-generic:

View File

@ -7,4 +7,5 @@ set -eu
set -o pipefail
# Set 'bash' as default shell for 'manila' user.
id -u manila &>/dev/null || adduser manila --gecos Foo,Foo,Foo,Foo --disabled-password --quiet
sudo chsh -s /bin/bash manila

View File

@ -10,6 +10,11 @@ sudo sed -i -E "s/#\s(deb.+universe)$/\1/g" /etc/apt/sources.list
apt-get update
apt-get upgrade -y
if $INSTALL_KERNEL ; then
apt-get install linux-image-generic -y
fi
apt-get install \
python \
sudo \

View File

@ -0,0 +1,31 @@
#!/bin/bash
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
SCRIPTDIR=$(dirname $0)
# Install required packages
install-packages wget
# Build unfs3
cd /usr/src
mkdir unfs3 && cd unfs3
wget --no-check-certificate https://sourceforge.net/projects/unfs3/files/unfs3/0.9.22/unfs3-0.9.22.tar.gz
tar -xzf unfs3-0.9.22.tar.gz && cd unfs3-0.9.22
./configure
make
make install
# Prepare /etc/exports
echo "# unfs3 exports should be defined here" >> /etc/exports
install -D -g root -o root -m 0755 \
${SCRIPTDIR}/unfs3 /etc/init.d/unfs3
sudo update-rc.d unfs3 defaults
# Remove sources
cd /usr/src && rm -fR unfs3

View File

@ -0,0 +1,43 @@
#!/bin/sh
SCRIPT=/usr/local/sbin/unfsd
RUNAS=root
PIDFILE=/var/run/unfs3.pid
LOGFILE=/var/log/unfs3.log
start() {
if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then
echo 'Service already running' >&2
return 1
fi
echo 'Starting service...' >&2
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
su -c "$CMD" $RUNAS > "$PIDFILE"
echo 'Service started' >&2
}
stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
echo 'Service not running' >&2
return 1
fi
echo 'Stopping service...' >&2
kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
echo 'Service stopped' >&2
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac

21
tools/add_to_rootfs_tar Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env python
from __future__ import print_function
import tarfile
import sys
def main(tar_path, folder_path, target_name):
try:
tar = tarfile.open(tar_path, mode="a")
tar.add(folder_path, arcname=target_name)
tar.close()
except Exception as e:
print("Error: ", e)
if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage: "
"add_to_rootfs_tar <path_to_tar> <path_to_folder> <target_name>")
main(sys.argv[1], sys.argv[2], sys.argv[3])

View File

@ -4,4 +4,6 @@ IMAGE=$1
if [ "$IMAGE" = "generic" ]; then
tox -v -e buildimage
elif [ "$IMAGE" = "lxd" ]; then
tox -v -e buildimage-lxd
fi

View File

@ -32,6 +32,9 @@ commands = manila-image-create
deps =
-r{toxinidir}/requirements.txt
[testenv:buildimage-lxd]
commands = manila-image-create lxd
[flake8]
show-source = true
builtins = _