add status check and timeout for fastesturl

also simplified some code to retrieve a result.
add huawei source for chef-server and client packages.
upgrade chef-client to 11.10 to take advantage of
concurrency option in knife cookbook upload.
Change-Id: Ic2c771b377918622da88f7243374056d5e0b3dc2
Partial-bug: #1397309
This commit is contained in:
zhaoxinyu 2014-11-27 23:27:25 -08:00
parent afba46ce6b
commit a5259401e2
6 changed files with 45 additions and 98 deletions

View File

@ -19,7 +19,8 @@ sudo mkdir -p /root/backup/chef
sudo rpm -q chef-server
if [[ "$?" != "0" ]]; then
download $CHEF_SRV chef-server install || exit $?
CHEF_SRV_SOURCE=`fastesturl "$CHEF_SRV" "$CHEF_SRV_HUAWEI"`
download $CHEF_SRV_SOURCE chef-server install || exit $?
else
echo "chef-server has already installed"
fi
@ -41,12 +42,13 @@ fi
echo "configure chef client and knife"
# configure chef client and knife
rpm -q chef
if [[ "$?" != "0" ]]; then
download $CHEF_CLIENT `basename $CHEF_CLIENT` install || exit $?
if [[ `rpm -q chef` ]]; then
sudo rpm -e `rpm -q chef`
else
echo "chef has already installed"
echo "going to install chef client"
fi
CENTOS_CHEF_CLIENT_SOURCE=`fastesturl "$CENTOS_CHEF_CLIENT" "$CENTOS_CHEF_CLIENT_HUAWEI"`
download $CENTOS_CHEF_CLIENT_SOURCE `basename $CENTOS_CHEF_CLIENT_SOURCE` install || exit $?
sudo mkdir -p ~/.chef
@ -71,7 +73,9 @@ if [ $? -ne 0 ]; then
exit 1
fi
knife cookbook upload --all --cookbook-path /var/chef/cookbooks
# Fix after bug 1397309 is fixed by upgrading chef-server
# work around by reducing concurrency to 1
knife cookbook upload --all --cookbook-path /var/chef/cookbooks --concurrency 1
if [[ "$?" != "0" ]]; then
echo "failed to add cookbooks"
exit 1

View File

@ -235,12 +235,7 @@ fi
# download packages
cd /var/lib/cobbler/repo_mirror/centos_ppa_repo/
fastesturl http://mirrors.hustunique.com http://mirror.centos.org
if [[ "$?" != "0" ]]; then
echo "failed to determine the fastest url for downloading centos ppa packages"
exit 1
fi
read -r PPA_REPO_URL</tmp/url
PPA_REPO_URL=`fastesturl http://mirrors.hustunique.com http://mirror.centos.org`
centos_ppa_repo_packages="
ntp-4.2.6p5-1.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_TYPE,,}.${CENTOS_IMAGE_ARCH}.rpm
openssh-clients-5.3p1-94.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_ARCH}.rpm
@ -264,7 +259,8 @@ for f in $centos_ppa_repo_rsyslog_packages; do
done
# download chef client for centos ppa repo
download $CENTOS_CHEF_CLIENT `basename $CENTOS_CHEF_CLIENT` copy /var/lib/cobbler/repo_mirror/centos_ppa_repo/
CENTOS_CHEF_CLIENT_SOURCE=`fastesturl "$CENTOS_CHEF_CLIENT" "$CENTOS_CHEF_CLIENT_HUAWEI"`
download $CENTOS_CHEF_CLIENT_SOURCE `basename $CENTOS_CHEF_CLIENT_SOURCE` copy /var/lib/cobbler/repo_mirror/centos_ppa_repo/
# create centos repo
cd ..
@ -318,7 +314,8 @@ else
fi
# download chef client for ubuntu ppa repo
download $UBUNTU_CHEF_CLIENT `basename $UBUNTU_CHEF_CLIENT` copy /var/lib/cobbler/repo_mirror/ubuntu_ppa_repo/ || exit $?
UBUNTU_CHEF_CLIENT_SOURCE=`fastesturl "$UBUNTU_CHEF_CLIENT" "$UBUNTU_CHEF_CLIENT_HUAWEI"`
download $UBUNTU_CHEF_CLIENT_SOURCE `basename $UBUNTU_CHEF_CLIENT` copy /var/lib/cobbler/repo_mirror/ubuntu_ppa_repo/ || exit $?
cd ..
find ubuntu_ppa_repo -name \*.deb -exec reprepro -Vb ubuntu_ppa_repo includedeb ppa {} \;
@ -339,12 +336,7 @@ fi
# import cobbler distro
sudo mkdir -p /var/lib/cobbler/iso
fastesturl $CENTOS_IMAGE_SOURCE_ASIA $CENTOS_SOURCE_MIRROR
if [[ "$?" != "0" ]]; then
echo "failed to determine the fastest source for centos iso"
exit 1
fi
read -r CENTOS_SOURCE</tmp/url
CENTOS_SOURCE=`fastesturl $CENTOS_IMAGE_SOURCE_ASIA $CENTOS_IMAGE_SOURCE`
download "$CENTOS_SOURCE" ${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}.iso copy /var/lib/cobbler/iso/ || exit $?
sudo mkdir -p /mnt/${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}
if [ $(mount | grep -c "/mnt/${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH} ") -eq 0 ]; then
@ -359,12 +351,7 @@ else
echo "/mnt/${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH} has already mounted"
fi
fastesturl $UBUNTU_IMAGE_SOURCE_ASIA $UBUNTU_IMAGE_SOURCE
if [[ "$?" != "0" ]]; then
echo "failed to determine the fastest source for ubuntu iso"
exit 1
fi
read -r UBUNTU_SOURCE</tmp/url
UBUNTU_SOURCE=`fastesturl $UBUNTU_IMAGE_SOURCE_ASIA $UBUNTU_IMAGE_SOURCE`
download "$UBUNTU_SOURCE" ${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH}.iso copy /var/lib/cobbler/iso/ || exit $?
sudo mkdir -p /mnt/${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH}
if [ $(mount | grep -c "/mnt/${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH} ") -eq 0 ]; then

View File

@ -67,9 +67,11 @@ export JS_MVC=${JS_MVC:-"javascriptmvc-3.2.4"}
# set the chef packages download path
export CHEF_SRV=${CHEF_SRV:-"http://opscode-omnibus-packages.s3.amazonaws.com/${IMAGE_TYPE_OTHER}/${IMAGE_VERSION_MAJOR}/${IMAGE_ARCH}/chef-server-11.0.8-1.${IMAGE_TYPE_OTHER}${IMAGE_VERSION_MAJOR}.${IMAGE_ARCH}.rpm"}
export CHEF_CLIENT=${CHEF_CLIENT:-"http://opscode-omnibus-packages.s3.amazonaws.com/${IMAGE_TYPE_OTHER}/${IMAGE_VERSION_MAJOR}/${IMAGE_ARCH}/chef-11.8.0-1.${IMAGE_TYPE_OTHER}${IMAGE_VERSION_MAJOR}.${IMAGE_ARCH}.rpm"}
export CENTOS_CHEF_CLIENT=${CENTOS_CHEF_CLIENT:-"http://opscode-omnibus-packages.s3.amazonaws.com/${CENTOS_IMAGE_TYPE_OTHER}/${CENTOS_IMAGE_VERSION_MAJOR}/${CENTOS_IMAGE_ARCH}/chef-11.8.0-1.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_ARCH}.rpm"}
export UBUNTU_CHEF_CLIENT=${UBUNTU_CHEF_CLIENT:-"http://opscode-omnibus-packages.s3.amazonaws.com/${UBUNTU_IMAGE_TYPE,,}/${UBUNTU_IMAGE_VERSION}/${UBUNTU_IMAGE_ARCH}/chef_11.8.0-1.${UBUNTU_IMAGE_TYPE,,}.${UBUNTU_IMAGE_VERSION}_${UBUNTU_IMAGE_ARCH_OTHER}.deb"}
export CHEF_SRV_HUAWEI=${CHEF_SRV_HUAWEI:-"http://huawei-repo.uubright.com/repos/compass/${IMAGE_TYPE_OTHER}/${IMAGE_VERSION_MAJOR}/${IMAGE_ARCH}/chef-server-11.0.8-1.${IMAGE_TYPE_OTHER}${IMAGE_VERSION_MAJOR}.${IMAGE_ARCH}.rpm"}
export CENTOS_CHEF_CLIENT=${CENTOS_CHEF_CLIENT:-"http://opscode-omnibus-packages.s3.amazonaws.com/${CENTOS_IMAGE_TYPE_OTHER}/${CENTOS_IMAGE_VERSION_MAJOR}/${CENTOS_IMAGE_ARCH}/chef-11.10.4-1.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_ARCH}.rpm"}
export CENTOS_CHEF_CLIENT_HUAWEI=${CENTOS_CHEF_CLIENT_HUAWEI:-"http://huawei-repo.uubright.com/repos/compass/${CENTOS_IMAGE_TYPE_OTHER}/${CENTOS_IMAGE_VERSION_MAJOR}/${CENTOS_IMAGE_ARCH}/chef-11.10.4-1.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_ARCH}.rpm"}
export UBUNTU_CHEF_CLIENT=${UBUNTU_CHEF_CLIENT:-"http://opscode-omnibus-packages.s3.amazonaws.com/${UBUNTU_IMAGE_TYPE,,}/${UBUNTU_IMAGE_VERSION}/${UBUNTU_IMAGE_ARCH}/chef_11.10.4-1.${UBUNTU_IMAGE_TYPE,,}.${UBUNTU_IMAGE_VERSION}_${UBUNTU_IMAGE_ARCH_OTHER}.deb"}
export UBUNTU_CHEF_CLIENT_HUAWEI=${UBUNTU_CHEF_CLIENT_HUAWEI:-"http://huawei-repo.uubright.com/repos/compass/${UBUNTU_IMAGE_TYPE,,}/${UBUNTU_IMAGE_VERSION}/${UBUNTU_IMAGE_ARCH}/chef_11.10.4-1.${UBUNTU_IMAGE_TYPE,,}.${UBUNTU_IMAGE_VERSION}_${UBUNTU_IMAGE_ARCH_OTHER}.deb"}
# Set Chef password for Chef web UI
export CHEF_PASSWD=${CHEF_PASSWD:-"root1234"}

View File

@ -34,46 +34,11 @@ export ADAPTERS_SOURCE='http://git.openstack.org/stackforge/compass-adapters'
# set the default cobbler user "cobbler" password, if not set, the default will be cobbler/cobbler
export CBLR_USER=cobbler
export CBLR_PASSWD=cobbler
# IMAGE_SOURCE is where you host your CentOS image
export IMAGE_TYPE=${IMAGE_TYPE:-"CentOS"}
export IMAGE_TYPE_OTHER=${IMAGE_TYPE_OTHER:-"el"}
export IMAGE_VERSION_MAJOR=${IMAGE_VERSION_MAJOR:-"6"}
export IMAGE_VERSION_MINOR=${IMAGE_VERSION_MINOR:-"5"}
export IMAGE_VERSION=${IMAGE_VERSION:-"${IMAGE_VERSION_MAJOR}.${IMAGE_VERSION_MINOR}"}
export IMAGE_NAME=${IMAGE_NAME:-"${IMAGE_TYPE}-${IMAGE_VERSION}"}
export IMAGE_ARCH=${IMAGE_ARCH:-"x86_64"}
export CENTOS_IMAGE_TYPE=${CENTOS_IMAGE_TYPE:-"CentOS"}
export CENTOS_IMAGE_TYPE_OTHER=${CENTOS_IMAGE_TYPE_OTHER:-"el"}
export CENTOS_IMAGE_VERSION_MAJOR=${CENTOS_IMAGE_VERSION_MAJOR:-"6"}
export CENTOS_IMAGE_VERSION_MINOR=${CENTOS_IMAGE_VERSION_MINOR:-"5"}
export CENTOS_IMAGE_VERSION=${CENTOS_IMAGE_VERSION:-"${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_VERSION_MINOR}"}
export CENTOS_IMAGE_NAME=${CENTOS_IMAGE_NAME:-"${CENTOS_IMAGE_TYPE}-${CENTOS_IMAGE_VERSION}"}
export CENTOS_IMAGE_ARCH=${CENTOS_IMAGE_ARCH:-"x86_64"}
export CENTOS_IMAGE_SOURCE=${CENTOS_IMAGE_SOURCE:-"http://mirror.rackspace.com/${CENTOS_IMAGE_TYPE,,}/${CENTOS_IMAGE_VERSION}/isos/${CENTOS_IMAGE_ARCH}/${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}-minimal.iso"}
export UBUNTU_IMAGE_TYPE=${UBUNTU_IMAGE_TYPE:-"Ubuntu"}
export UBUNTU_IMAGE_VERSION_MAJOR=${UBUNTU_IMAGE_VERSION_MAJOR:-"12"}
export UBUNTU_IMAGE_VERSION_MINOR=${UBUNTU_IMAGE_VERSION_MINOR:-"04"}
export UBUNTU_IMAGE_PATCH_VERSION=${UBUNTU_IMAGE_PATCH_VERSION:=".4"}
export UBUNTU_IMAGE_VERSION=${UBUNTU_IMAGE_VERSION:-"${UBUNTU_IMAGE_VERSION_MAJOR}.${UBUNTU_IMAGE_VERSION_MINOR}"}
export UBUNTU_IMAGE_NAME=${UBUNTU_IMAGE_NAME:-"${UBUNTU_IMAGE_TYPE}-${UBUNTU_IMAGE_VERSION}"}
export UBUNTU_IMAGE_ARCH=${UBUNTU_IMAGE_ARCH:-"x86_64"}
export UBUNTU_IMAGE_ARCH_OTHER=${UBUNTU_IMAGE_ARCH_OTHER:-"amd64"}
export UBUNTU_IMAGE_SOURCE=${UBUNTU_IMAGE_SOURCE:-"http://releases.ubuntu.com/${UBUNTU_IMAGE_VERSION}/${UBUNTU_IMAGE_TYPE,,}-${UBUNTU_IMAGE_VERSION}${UBUNTU_IMAGE_PATCH_VERSION}-server-${UBUNTU_IMAGE_ARCH_OTHER}.iso"}
export COBBLER_PASSWORD=${COBBLER_PASSWORD:-"cobbler"}
# Currently the use of Javascript MVC is set to version 3.2.4
export JS_MVC=javascriptmvc-3.2.4
# set the chef packages download path
export CHEF_SRV=${CHEF_SRV:-"http://opscode-omnibus-packages.s3.amazonaws.com/${IMAGE_TYPE_OTHER}/${IMAGE_VERSION_MAJOR}/${IMAGE_ARCH}/chef-server-11.0.8-1.${IMAGE_TYPE_OTHER}${IMAGE_VERSION_MAJOR}.${IMAGE_ARCH}.rpm"}
export CHEF_CLIENT=${CHEF_CLIENT:-"http://opscode-omnibus-packages.s3.amazonaws.com/${IMAGE_TYPE_OTHER}/${IMAGE_VERSION_MAJOR}/${IMAGE_ARCH}/chef-11.8.0-1.${IMAGE_TYPE_OTHER}${IMAGE_VERSION_MAJOR}.${IMAGE_ARCH}.rpm"}
export CENTOS_CHEF_CLIENT=${CENTOS_CHEF_CLIENT:-"http://opscode-omnibus-packages.s3.amazonaws.com/${CENTOS_IMAGE_TYPE_OTHER}/${CENTOS_IMAGE_VERSION_MAJOR}/${CENTOS_IMAGE_ARCH}/chef-11.8.0-1.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_ARCH}.rpm"}
export UBUNTU_CHEF_CLIENT=${UBUNTU_CHEF_CLIENT:-"http://opscode-omnibus-packages.s3.amazonaws.com/${UBUNTU_IMAGE_TYPE,,}/${UBUNTU_IMAGE_VERSION}/${UBUNTU_IMAGE_ARCH}/chef_11.8.0-1.${UBUNTU_IMAGE_TYPE,,}.${UBUNTU_IMAGE_VERSION}_${UBUNTU_IMAGE_ARCH_OTHER}.deb"}
# Set Chef password for Chef web UI
export CHEF_PASSWD=root1234

View File

@ -5,17 +5,24 @@ fastesturl()
{
shortest=99999
fastest_url=""
good_code=[200,206]
while [ $1 ]; do
url=$1
time=`curl -o /dev/null --header "Range: bytes=0-20000" -s -w %{time_total} $url`
if [ $(echo "$shortest > $time" | bc) -eq 1 ]; then
shortest=$time
echo "$url" > /tmp/url
fastest_url=$url
result=($(curl --max-time 20 -o /dev/null --header "Range: bytes=0-20000" -s -w "%{http_code} %{time_total}" $url))
code=${result[0]}
time=${result[1]}
if [[ ${good_code[*]} =~ $code ]]; then
if [ $(echo "$shortest > $time" | bc) -eq 1 ]; then
shortest=$time
fastest_url=$url
fi
fi
shift
done
echo "$fastest_url is the fastest source, using it"
if [[ -z $fastest_url ]]; then
exit 1
fi
echo "$fastest_url"
}
copy2dir()

View File

@ -236,12 +236,7 @@ else
fi
# download cobbler related packages
fastesturl "http://mirrors.hustunique.com" "http://mirror.centos.org"
if [[ "$?" != "0" ]]; then
echo "failed to determine the fastest source for centos ppa rpms"
exit 1
fi
read -r CENTOS_PPA_SOURCE</tmp/url
CENTOS_PPA_SOURCE=`fastesturl "http://mirrors.hustunique.com" "http://mirror.centos.org"`
centos_ppa_repo_packages="
ntp-4.2.6p5-1.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_TYPE,,}.${CENTOS_IMAGE_ARCH}.rpm
openssh-clients-5.3p1-94.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_ARCH}.rpm
@ -265,38 +260,25 @@ for f in $centos_ppa_repo_rsyslog_packages; do
download http://rpms.adiscon.com/v7-stable/epel-${CENTOS_IMAGE_VERSION_MAJOR}/${CENTOS_IMAGE_ARCH}/RPMS/$f $f || exit $?
done
download $CHEF_CLIENT `basename $CHEF_CLIENT` || exit $?
download $CENTOS_CHEF_CLIENT `basename $CENTOS_CHEF_CLIENT` || exit $?
download $UBUNTU_CHEF_CLIENT `basename $UBUNTU_CHEF_CLIENT` || exit $?
CENTOS_CHEF_CLIENT_SOURCE=`fastesturl "$CENTOS_CHEF_CLIENT" "$CENTOS_CHEF_CLIENT_HUAWEI"`
download $CENTOS_CHEF_CLIENT_SOURCE `basename $CENTOS_CHEF_CLIENT_SOURCE` || exit $?
UBUNTU_CHEF_CLIENT_SOURCE=`fastesturl "$UBUNTU_CHEF_CLIENT" "$UBUNTU_CHEF_CLIENT_HUAWEI"`
download $UBUNTU_CHEF_CLIENT_SOURCE `basename $UBUNTU_CHEF_CLIENT_SOURCE` || exit $?
# download chef related packages
download $CHEF_SRV chef-server || exit $?
CHEF_SRV_SOURCE=`fastesturl "$CHEF_SRV" "$CHEF_SRV_HUAWEI"`
download $CHEF_SRV_SOURCE chef-server || exit $?
# download os images
fastesturl $CENTOS_IMAGE_SOURCE $CENTOS_IMAGE_SOURCE_ASIA
if [[ "$?" != "0" ]]; then
echo "failed to determine the fastest source for centos image"
exit 1
fi
read -r CENTOS_ISO_SOURCE</tmp/url
CENTOS_ISO_SOURCE=`fastesturl $CENTOS_IMAGE_SOURCE $CENTOS_IMAGE_SOURCE_ASIA`
download $CENTOS_ISO_SOURCE ${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}.iso || exit $?
fastesturl $UBUNTU_IMAGE_SOURCE $UBUNTU_IMAGE_SOURCE_ASIA
if [[ "$?" != "0" ]]; then
echo "failed to determine the fastest source for ubuntu image"
exit 1
fi
read -r UBUNTU_ISO_SOURCE</tmp/url
UBUNTU_ISO_SOURCE=`fastesturl $UBUNTU_IMAGE_SOURCE $UBUNTU_IMAGE_SOURCE_ASIA`
download $UBUNTU_ISO_SOURCE ${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH}.iso || exit $?
# download local repo
if [[ $LOCAL_REPO = "y" ]]; then
fastesturl $LOCAL_REPO_US $LOCAL_REPO_HUAWEI
if [[ "$?" != "0" ]]; then
echo "failed to determine the fastest source for local repo"
exit 1
fi
read -r LOCAL_REPO_SOURCE</tmp/url
LOCAL_REPO_SOURCE=`fastesturl $LOCAL_REPO_US $LOCAL_REPO_HUAWEI`
download $LOCAL_REPO_SOURCE local_repo.tar.gz || exit $?
fi
# Install net-snmp