From 2781f3bfc3e0ceca29457f65adfddb63f01d8059 Mon Sep 17 00:00:00 2001 From: Mate Lakat Date: Wed, 11 Dec 2013 13:41:54 +0000 Subject: [PATCH] Workaround missing zip snapshot At the moment, xenserver installation depends on github snapshots. Unfortunately, git.openstack.org does not have that capability. This fix includes: - Exit with error code, if a download fails - create proper urls, even if they are using the git protocol - set git base to github - so we are able to do snapshots Fixes bug: 1259905 Change-Id: I8d0cf8bf8abb16ee0a4b138a6719409c75e7a146 --- tools/xen/README.md | 3 +++ tools/xen/functions | 15 +++++++++++++-- tools/xen/mocks | 6 +++++- tools/xen/test_functions.sh | 21 +++++++++++++++++---- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/tools/xen/README.md b/tools/xen/README.md index 06192ed2b7..ee1abcc091 100644 --- a/tools/xen/README.md +++ b/tools/xen/README.md @@ -70,6 +70,9 @@ the `XENAPI_PASSWORD` must be your dom0 root password. Of course, use real passwords if this machine is exposed. cat > ./localrc <&2 + exit 1 +} + function xapi_plugin_location { for PLUGIN_DIR in "/etc/xapi.d/plugins/" "/usr/lib/xcp/plugins/" "/usr/lib/xapi/plugins"; do if [ -d $PLUGIN_DIR ]; then @@ -11,7 +20,7 @@ function xapi_plugin_location { } function zip_snapshot_location { - echo $1 | sed "s:\.git$::;s:$:/zipball/$2:g" + echo $1 | sed "s,^git://,http://,g;s:\.git$::;s:$:/zipball/$2:g" } function create_directory_for_kernels { @@ -41,7 +50,9 @@ function extract_remote_zipball { local EXTRACTED_FILES=$(mktemp -d) { - wget -nv $ZIPBALL_URL -O $LOCAL_ZIPBALL --no-check-certificate + if ! wget -nv $ZIPBALL_URL -O $LOCAL_ZIPBALL --no-check-certificate; then + die_with_error "Failed to download [$ZIPBALL_URL]" + fi unzip -q -o $LOCAL_ZIPBALL -d $EXTRACTED_FILES rm -f $LOCAL_ZIPBALL } >&2 diff --git a/tools/xen/mocks b/tools/xen/mocks index ec8679e816..3b9b05c747 100644 --- a/tools/xen/mocks +++ b/tools/xen/mocks @@ -35,7 +35,7 @@ function mktemp { function wget { if [[ $@ =~ "failurl" ]]; then - exit 1 + return 1 fi echo "wget $@" >> $LIST_OF_ACTIONS } @@ -77,6 +77,10 @@ function [ { exit 1 } +function die_with_error { + echo "$1" >> $DEAD_MESSAGES +} + function xe { cat $XE_RESPONSE { diff --git a/tools/xen/test_functions.sh b/tools/xen/test_functions.sh index 14551868e1..373d996760 100755 --- a/tools/xen/test_functions.sh +++ b/tools/xen/test_functions.sh @@ -29,6 +29,9 @@ function before_each_test { XE_CALLS=$(mktemp) truncate -s 0 $XE_CALLS + + DEAD_MESSAGES=$(mktemp) + truncate -s 0 $DEAD_MESSAGES } # Teardown @@ -64,6 +67,10 @@ function assert_xe_param { grep -qe "^$1\$" $XE_CALLS } +function assert_died_with { + diff -u <(echo "$1") $DEAD_MESSAGES +} + function mock_out { local FNNAME="$1" local OUTPUT="$2" @@ -109,10 +116,16 @@ function test_no_plugin_directory_found { grep "[ -d /usr/lib/xcp/plugins/ ]" $LIST_OF_ACTIONS } -function test_zip_snapshot_location { +function test_zip_snapshot_location_http { diff \ - <(zip_snapshot_location "git://git.openstack.org/openstack/nova.git" "master") \ - <(echo "git://git.openstack.org/openstack/nova/zipball/master") + <(zip_snapshot_location "http://github.com/openstack/nova.git" "master") \ + <(echo "http://github.com/openstack/nova/zipball/master") +} + +function test_zip_snapsot_location_git { + diff \ + <(zip_snapshot_location "git://github.com/openstack/nova.git" "master") \ + <(echo "http://github.com/openstack/nova/zipball/master") } function test_create_directory_for_kernels { @@ -179,7 +192,7 @@ function test_extract_remote_zipball_wget_fail { local IGNORE IGNORE=$(. mocks && extract_remote_zipball "failurl") - assert_previous_command_failed + assert_died_with "Failed to download [failurl]" } function test_find_nova_plugins {