Skip to content

Commit

Permalink
Closes-Bug: #1491183, Move debugs to a log file for provision script
Browse files Browse the repository at this point in the history
Change-Id: Ib21b9fb01af5479e85d0b6061375313b0480d33c
  • Loading branch information
miriyalar committed Sep 1, 2015
1 parent 89d7c93 commit 5eea559
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions common/debian/contrail-server-manager-installer/debian/provision.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
set -x
set -e

datetime_string=$(date +%Y_%m_%d__%H_%M_%S)
Expand All @@ -18,9 +17,11 @@ NO_LOCAL_REPO=1
LOCAL_REPO_DIR=/opt/contrail/contrail_local_repo
CLUSTER_ID=""

space=" "
arrow="---->"

function usage()
{
set +x
echo "Usage"
echo ""
echo "$0"
Expand All @@ -32,12 +33,11 @@ function usage()
echo -e "\t-nr|--no-local-repo"
echo -e "\t-cid|--cluster-id <cluster-id>"
echo ""
set -x
}

if [ "$#" -eq 0 ]; then
usage
exit
exit
fi

while [[ $# > 0 ]]
Expand Down Expand Up @@ -86,7 +86,7 @@ fi

function unmount_contrail_local_repo()
{
echo "INFO: Removing Contrail Local Repo - $LOCAL_REPO_DIR"
echo "$arrow Removing contrail local repo - $LOCAL_REPO_DIR"
# Remove local repo dir
if [ -d $LOCAL_REPO_DIR ]; then
rm -rf $LOCAL_REPO_DIR
Expand All @@ -103,7 +103,7 @@ function unmount_contrail_local_repo()
set -e
if [ $exit_status == 0 ]; then
sed -i "s#deb file:$LOCAL_REPO_DIR ./##g" /etc/apt/sources.list
apt-get update
apt-get update >> $log_file 2>&1
fi
}

Expand All @@ -117,36 +117,36 @@ function mount_contrail_local_repo()
fi

# mount package and create local repo
echo "INFO: Creating Local Repo -- $LOCAL_REPO_DIR"
echo "$space$arrow Creating local lepo -- $LOCAL_REPO_DIR"
set +e
grep "^deb file:$LOCAL_REPO_DIR ./" /etc/apt/sources.list
exit_status=$?
set -e

if [ $exit_status != 0 ]; then
mkdir -p $LOCAL_REPO_DIR
dpkg -x $CONTRAIL_PKG $LOCAL_REPO_DIR
(cd $LOCAL_REPO_DIR && tar xfz opt/contrail/contrail_packages/*.tgz)
(cd $LOCAL_REPO_DIR && DEBIAN_FRONTEND=noninteractive dpkg -i binutils_*.deb dpkg-dev_*.deb libdpkg-perl_*.deb make_*.deb patch_*.deb)
(cd $LOCAL_REPO_DIR && dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz)
dpkg -x $CONTRAIL_PKG $LOCAL_REPO_DIR >> $log_file 2>&1
(cd $LOCAL_REPO_DIR && tar xfz opt/contrail/contrail_packages/*.tgz >> $log_file 2>&1)
(cd $LOCAL_REPO_DIR && DEBIAN_FRONTEND=noninteractive dpkg -i binutils_*.deb dpkg-dev_*.deb libdpkg-perl_*.deb make_*.deb patch_*.deb >> $log_file 2>&1)
(cd $LOCAL_REPO_DIR && dpkg-scanpackages . | gzip -9c > Packages.gz | >> $log_file 2>&1)
datetime_string=$(date +%Y_%m_%d__%H_%M_%S)
cp /etc/apt/sources.list /etc/apt/sources.list.contrail.$datetime_string
echo >> /etc/apt/sources.list
sed -i "1 i\deb file:$LOCAL_REPO_DIR ./" /etc/apt/sources.list
cp -v /opt/contrail/contrail_server_manager/contrail_local_preferences /etc/apt/preferences.d/contrail_local_repo
apt-get update
cp -v /opt/contrail/contrail_server_manager/contrail_local_preferences /etc/apt/preferences.d/contrail_local_repo >> $log_file 2>&1
apt-get update >> $log_file 2>&1
fi
}

function cleanup_puppet_agent()
{
set +e
apt-get -y --purge autoremove puppet puppet-common hiera
apt-get -y --purge autoremove puppet puppet-common hiera >> $log_file 2>&1
set -e
}

if [ "$CLEANUP_PUPPET_AGENT" != "" ]; then
echo "--> Remove puppet agent, if it is present"
echo "$arrow Remove puppet agent, if it is present"
cleanup_puppet_agent
fi

Expand All @@ -155,26 +155,26 @@ if [ "$INSTALL_SM_LITE" != "" ]; then
# Create a local repo from contrail-install packages
# so packages from this repo gets preferred
if [ $NO_LOCAL_REPO != 0 ]; then
echo "--> Provision contrail local repo"
echo "$arrow Provision contrail local repo"
mount_contrail_local_repo
LOCAL_REPO_MOUNTED=1
fi

echo "--> Install server manager lite"
pushd /opt/contrail/contrail_server_manager
echo "$arrow Install server manager without cobbler option"
pushd /opt/contrail/contrail_server_manager >> $log_file 2>&1
./setup.sh --all --smlite --nowebui --nosm-mon
popd
popd >> $log_file 2>&1
fi

echo "--> Convert testbed.py to server manager entities"
echo "$space$arrow Convert testbed.py to server manager entities"
# Convert testbed.py to server manager object json files
optional_args=""
if [ ! -z "$CLUSTER_ID" ]; then
optional_args="--cluster-id $CLUSTER_ID"
fi
/opt/contrail/server_manager/client/testbed_parser.py --testbed ${TESTBED} --contrail-packages ${CONTRAIL_PKG} $optional_args

echo "--> Pre provision checks to make sure setup is ready for contrail provisioning"
echo "$arrow Pre provision checks to make sure setup is ready for contrail provisioning"
# Precheck the targets to make sure that, ready for contrail provisioning
SERVER_MGR_IP=$(grep listen_ip_addr /opt/contrail/server_manager/sm-config.ini | grep -Po "listen_ip_addr = \K.*")
/opt/contrail/server_manager/client/preconfig.py --server-json server.json --server-manager-ip ${SERVER_MGR_IP}
Expand All @@ -184,19 +184,19 @@ if [[ $LOCAL_REPO_MOUNTED -eq 1 ]]; then
unmount_contrail_local_repo
fi

echo "--> Adding server manager objects to server manager database"
echo "$arrow Adding server manager objects to server manager database"
# Create package, cluster, server objects
server-manager add image -f image.json
server-manager add cluster -f cluster.json
server-manager add server -f server.json

echo "--> Provisioning the cluster"
echo "$arrow Provisioning the cluster"
# Provision the cluster
CONTRAIL_PKG_ID=$(python -c "import json; fid = open('image.json', 'r'); contents = fid.read(); cjson = json.loads(contents); print cjson['image'][0]['id']")
CLUSTER_ID=$(python -c "import json; fid = open('cluster.json', 'r'); data = json.load(fid); fid.close(); print data['cluster'][0]['id']")
server-manager provision -F --cluster_id $CLUSTER_ID ${CONTRAIL_PKG_ID}

end_time=$(date +"%s")
diff=$(($end_time-$start_time))
echo "--> Provisioning is issued, and took $(($diff / 60)) minutes and $(($diff % 60)) seconds."
echo "--> Check provisioning status using /opt/contrail/contrail_server_manager/provision_status.sh"
echo "$arrow Provisioning is issued, and took $(($diff / 60)) minutes and $(($diff % 60)) seconds."
echo "$arrow Check provisioning status using /opt/contrail/contrail_server_manager/provision_status.sh"

0 comments on commit 5eea559

Please sign in to comment.