xenapi: /boot/guest should point to local SR

Fixes bug 1037516

This patch creates a directory os-guest-kernels inside the local SR, and
sets up /boot/guest to be a symlink to that directory. This way
OpenStack won't pollute Dom0's filesystem.

Change-Id: If8dfe24355bd782a401fed0f2c4b423efd9c11ba
This commit is contained in:
Mate Lakat 2013-03-28 15:02:27 +00:00
parent fe51a90005
commit fe586b1cbe
3 changed files with 115 additions and 7 deletions

View File

@ -1,10 +1,8 @@
#!/bin/bash
function xapi_plugin_location {
for PLUGIN_DIR in "/etc/xapi.d/plugins/" "/usr/lib/xcp/plugins/"
do
if [ -d $PLUGIN_DIR ]
then
for PLUGIN_DIR in "/etc/xapi.d/plugins/" "/usr/lib/xcp/plugins/"; do
if [ -d $PLUGIN_DIR ]; then
echo $PLUGIN_DIR
return 0
fi
@ -17,7 +15,13 @@ function zip_snapshot_location {
}
function create_directory_for_kernels {
mkdir -p "/boot/guest"
if [ -d "/boot/guest" ]; then
echo "INFO: /boot/guest directory already exists, using that" >&2
else
local LOCALPATH="$(get_local_sr_path)/os-guest-kernels"
mkdir -p $LOCALPATH
ln -s $LOCALPATH /boot/guest
fi
}
function extract_remote_zipball {
@ -53,3 +57,11 @@ function install_xapi_plugins_from_zipball {
rm -rf $EXTRACTED_FILES
chmod a+x ${XAPI_PLUGIN_DIR}*
}
function get_local_sr {
xe sr-list name-label="Local storage" --minimal
}
function get_local_sr_path {
echo "/var/run/sr-mount/$(get_local_sr)"
}

View File

@ -12,6 +12,18 @@ test ! -e "$LIST_OF_DIRECTORIES" && {
exit 1
}
test ! -e "$XE_RESPONSE" && {
echo "Mocking is not set up properly."
echo "XE_RESPONSE should point to an existing file."
exit 1
}
test ! -e "$XE_CALLS" && {
echo "Mocking is not set up properly."
echo "XE_CALLS should point to an existing file."
exit 1
}
function mktemp {
if test "${1:-}" = "-d";
then
@ -41,6 +53,10 @@ function rm {
echo "rm $@" >> $LIST_OF_ACTIONS
}
function ln {
echo "ln $@" >> $LIST_OF_ACTIONS
}
function [ {
if test "${1:-}" = "-d";
then
@ -57,3 +73,13 @@ function [ {
echo "Mock test does not implement the requested function"
exit 1
}
function xe {
cat $XE_RESPONSE
{
for i in $(seq "$#")
do
eval "echo \"\$$i\""
done
} >> $XE_CALLS
}

View File

@ -23,15 +23,27 @@ function before_each_test {
LIST_OF_ACTIONS=$(mktemp)
truncate -s 0 $LIST_OF_ACTIONS
XE_RESPONSE=$(mktemp)
truncate -s 0 $XE_RESPONSE
XE_CALLS=$(mktemp)
truncate -s 0 $XE_CALLS
}
# Teardown
function after_each_test {
rm -f $LIST_OF_DIRECTORIES
rm -f $LIST_OF_ACTIONS
rm -f $XE_RESPONSE
rm -f $XE_CALLS
}
# Helpers
function setup_xe_response {
echo "$1" > $XE_RESPONSE
}
function given_directory_exists {
echo "$1" >> $LIST_OF_DIRECTORIES
}
@ -44,6 +56,30 @@ function assert_previous_command_failed {
[ "$?" != "0" ] || exit 1
}
function assert_xe_min {
grep -qe "^--minimal\$" $XE_CALLS
}
function assert_xe_param {
grep -qe "^$1\$" $XE_CALLS
}
function mock_out {
local FNNAME="$1"
local OUTPUT="$2"
. <(cat << EOF
function $FNNAME {
echo "$OUTPUT"
}
EOF
)
}
function assert_symlink {
grep -qe "^ln -s $2 $1\$" $LIST_OF_ACTIONS
}
# Tests
function test_plugin_directory_on_xenserver {
given_directory_exists "/etc/xapi.d/plugins/"
@ -80,9 +116,26 @@ function test_zip_snapshot_location {
}
function test_create_directory_for_kernels {
(. mocks && create_directory_for_kernels)
(
. mocks
mock_out get_local_sr uuid1
create_directory_for_kernels
)
assert_directory_exists "/boot/guest"
assert_directory_exists "/var/run/sr-mount/uuid1/os-guest-kernels"
assert_symlink "/boot/guest" "/var/run/sr-mount/uuid1/os-guest-kernels"
}
function test_create_directory_for_kernels_existing_dir {
(
. mocks
given_directory_exists "/boot/guest"
create_directory_for_kernels
)
diff -u $LIST_OF_ACTIONS - << EOF
[ -d /boot/guest ]
EOF
}
function test_extract_remote_zipball {
@ -107,6 +160,23 @@ function test_find_nova_plugins {
rm -rf $tmpdir
}
function test_get_local_sr {
setup_xe_response "uuid123"
local RESULT=$(. mocks && get_local_sr)
[ "$RESULT" == "uuid123" ]
assert_xe_min
assert_xe_param "sr-list" "name-label=Local storage"
}
function test_get_local_sr_path {
local RESULT=$(mock_out get_local_sr "uuid1" && get_local_sr_path)
[ "/var/run/sr-mount/uuid1" == "$RESULT" ]
}
# Test runner
[ "$1" = "" ] && {
grep -e "^function *test_" $0 | cut -d" " -f2