Skip to content

Commit

Permalink
Partial-Bug: #1488259 smlite changes for packaging changes
Browse files Browse the repository at this point in the history
- Add server manager lite deb packaging changes
- Modify setup.sh to include server manager lite option
- Add provision shell script to install server manager, create server manager objects and issue provision
- Pre check/config for testbey.py specified servers for a cluster
- Local repo pinning changes

Change-Id: I45b4cf957a4c1f393e8068ee8eee2d9580d397a3
  • Loading branch information
miriyalar committed Aug 25, 2015
1 parent 66f9472 commit 2d45ba3
Show file tree
Hide file tree
Showing 19 changed files with 816 additions and 94 deletions.
7 changes: 7 additions & 0 deletions build/contrail_local_preferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Package: *
Pin: origin ""
Pin-Priority: 990

Package: *
Pin: release o=Debian
Pin-Priority: -10
345 changes: 254 additions & 91 deletions build/deb_server_manager_setup.sh

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ pkgs = contrail-server-manager
makeloc = tools/packaging/common/debian
target = contrail-server-manager-deb

[contrail-server-manager-lite]
pkgs = contrail-server-manager-lite
makeloc = tools/packaging/common/debian
target = contrail-server-manager-lite-deb

[contrail-server-manager-client]
pkgs = contrail-server-manager-client
makeloc = tools/packaging/common/debian
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ pkgs = contrail-server-manager
makeloc = tools/packaging/common/debian
target = contrail-server-manager-deb

[contrail-server-manager-lite]
pkgs = contrail-server-manager-lite
makeloc = tools/packaging/common/debian
target = contrail-server-manager-lite-deb

[contrail-server-manager-client]
pkgs = contrail-server-manager-client
makeloc = tools/packaging/common/debian
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ pkgs = contrail-server-manager
makeloc = tools/packaging/common/debian
target = contrail-server-manager-deb

[contrail-server-manager-lite]
pkgs = contrail-server-manager-lite
makeloc = tools/packaging/common/debian
target = contrail-server-manager-lite-deb

[contrail-server-manager-client]
pkgs = contrail-server-manager-client
makeloc = tools/packaging/common/debian
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ pkgs = contrail-server-manager
makeloc = tools/packaging/common/debian
target = contrail-server-manager-deb

[contrail-server-manager-lite]
pkgs = contrail-server-manager-lite
makeloc = tools/packaging/common/debian
target = contrail-server-manager-lite-deb

[contrail-server-manager-client]
pkgs = contrail-server-manager-client
makeloc = tools/packaging/common/debian
Expand Down
9 changes: 9 additions & 0 deletions common/debian/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ all_vmware: ${PACKAGES_VMWARE}
@echo "Build complete"

server-manager-all: contrail-server-manager-deb \
contrail-server-manager-lite-deb \
contrail-server-manager-client-deb \
contrail-server-manager-monitoring-deb \
contrail-server-manager-installer-deb
Expand Down Expand Up @@ -262,6 +263,14 @@ contrail-server-manager-deb:
(cd ${BUILDDIR}; fakeroot debian/rules clean)
(cd ${BUILDDIR}; fakeroot debian/rules binary)

contrail-server-manager-lite-deb:
$(eval BUILDDIR=${SB_TOP}/build/debian/contrail-server-manager-lite)
rm -rf ${BUILDDIR}
mkdir -p ${BUILDDIR}/debian
cp -ar ${SB_TOP}/tools/packaging/common/debian/contrail-server-manager-lite/debian ${BUILDDIR}
(cd ${BUILDDIR}; fakeroot debian/rules clean)
(cd ${BUILDDIR}; fakeroot debian/rules binary)

contrail-server-manager-client-deb:
$(eval BUILDDIR=${SB_TOP}/build/debian/contrail-server-manager-client)
rm -rf ${BUILDDIR}
Expand Down
202 changes: 202 additions & 0 deletions common/debian/contrail-server-manager-installer/debian/provision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#!/bin/bash
set -x
set -e

datetime_string=$(date +%Y_%m_%d__%H_%M_%S)
mkdir -p /var/log/contrail/install_logs/
log_file=/var/log/contrail/install_logs/provision_$datetime_string.log
exec &> >(tee -a "$log_file")

start_time=$(date +"%s")

SOURCES_LIST="sources_list"
TESTBED="testbed.py"
CONTRAIL_PKG=""
INSTALL_SM_LITE="install_sm_lite"
CLEANUP_PUPPET_AGENT=""
NO_LOCAL_REPO=1
LOCAL_REPO_DIR=/opt/contrail/contrail_local_repo
CLUSTER_ID=""

function usage()
{
set +x
echo "Usage"
echo ""
echo "$0"
echo -e "\t-h --help"
echo -e "\t-c|--contrail-package <pkg>"
echo -e "\t-t|--testbed <testbed.py>"
echo -e "\t-ni|--no-install-sm-lite"
echo -e "\t-cp|--cleanup-puppet-agent"
echo -e "\t-nr|--no-local-repo"
echo -e "\t-cid|--cluster-id <cluster-id>"
echo ""
set -x
}

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

while [[ $# > 0 ]]
do
key="$1"

case $key in
-c|--contrail-package)
CONTRAIL_PKG="$2"
shift # past argument
;;
-t|--testbed)
TESTBED="$2"
shift # past argument
;;
-nr|--no-local-repo)
NO_LOCAL_REPO=0
;;
-ni|--no-install-sm-lite)
INSTALL_SM_LITE=""
;;
-cp|--no-cleanup-puppet-agent)
CLEANUP_PUPPET_AGENT="cleanup_puppet_agent"
;;
-cid|--cluster-id)
CLUSTER_ID="$2"
shift # past argument
;;
-h|--help)
usage
exit
;;
*)
# unknown option
echo "ERROR: unknown parameter $key"
usage
exit 1
;;
esac
shift # past argument or value
done

if [ "$TESTBED" == "" ] || [ "$CONTRAIL_PKG" == "" ]; then
exit
fi

function unmount_contrail_local_repo()
{
echo "INFO: Removing Contrail Local Repo - $LOCAL_REPO_DIR"
# Remove local repo dir
if [ -d $LOCAL_REPO_DIR ]; then
rm -rf $LOCAL_REPO_DIR
fi

# Remove preference file
if [ -f /etc/apt/preferences.d/contrail_local_repo ]; then
rm -f /etc/apt/preferences.d/contrail_local_repo
fi

set +e
grep "^deb file:$LOCAL_REPO_DIR ./" /etc/apt/sources.list
exit_status=$?
set -e
if [ $exit_status == 0 ]; then
sed -i "s#deb file:$LOCAL_REPO_DIR ./##g" /etc/apt/sources.list
apt-get update
fi
}

function mount_contrail_local_repo()
{
set -e
# check if package is available
if [ ! -f "$CONTRAIL_PKG" ]; then
echo "ERROR: $CONTRAIL_PKG : No Such file..."
exit 2
fi

# mount package and create local repo
echo "INFO: Creating Local Repo -- $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)
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
fi
}

function cleanup_puppet_agent()
{
set +e
apt-get -y --purge autoremove puppet puppet-common hiera
set -e
}

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

# Install sever manager
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"
mount_contrail_local_repo
LOCAL_REPO_MOUNTED=1
fi

echo "--> Install server manager lite"
pushd /opt/contrail/contrail_server_manager
./setup.sh --all --smlite --nowebui --nosm-mon
popd
fi

echo "--> 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"
# 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}

# Remove contrail local repo if any
if [[ $LOCAL_REPO_MOUNTED -eq 1 ]]; then
unmount_contrail_local_repo
fi

echo "--> 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"
# 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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
server-manager show cluster --select provision_role_sequence
server-manager status server
19 changes: 19 additions & 0 deletions common/debian/contrail-server-manager-installer/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ SPEC_DIR := $(shell pwd)
export SB_TOP := $(shell pwd | sed -re "s/\/build\/debian\/contrail-server-manager-installer//g")
export BUILDTIME := $(shell date -u +%y%m%d%H%M)
export DISTRIB_RELEASE = $(shell grep -Po "DISTRIB_RELEASE=\K.*" /etc/lsb-release)
export src_path := $(SB_TOP)/tools/contrail-server-manager/src/
export buildroot := $(SB_TOP)/build/debian/contrail-server-manager-installer/debian/contrail-server-manager-installer
export _contrailopt := /opt/contrail

Expand All @@ -31,10 +32,24 @@ ifdef FILE_LIST
TGZ_FILE = $(FILE_LIST)
endif

ifdef OS_VER
os_ver := $(echo $(_osVer) | sed 's,[-|.],,g')
else
os_ver := $(shell PYTHONPATH=$(PYTHONPATH):$(src_path)/../../../tools/packaging/tools/scripts/ python -c "import package_utils; print package_utils.get_platform()")
endif

ifdef PKG_DIRS
pkg_sources := $(_pkgDirs)
else
pkg_sources := /cs-shared/builder/cache/$(os_ver)/server-manager/
endif

ifndef SETUP_FILE
SETUP_FILE := $(SB_TOP)/tools/packaging/build/deb_server_manager_setup.sh
endif

provision_file_location := $(src_path)../../../tools/packaging/common/debian/contrail-server-manager-installer/debian

%:
dh $@ --tmpdir=${buildroot} --destdir=${SB_TOP}/build/debian

Expand All @@ -49,14 +64,18 @@ override_dh_auto_install:
install -d -m 755 $(buildroot)$(_contrailopt)
install -d -m 755 $(buildroot)$(_contrailopt)/contrail_server_manager
# Install files
install -p -m 755 $(src_path)../../../tools/packaging/build/contrail_local_preferences $(buildroot)$(_contrailopt)/contrail_server_manager/contrail_local_preferences
install -p -m 755 $(SETUP_FILE) $(buildroot)$(_contrailopt)/contrail_server_manager/setup.sh
install -p -m 755 $(provision_file_location)/provision.sh $(buildroot)$(_contrailopt)/contrail_server_manager/provision.sh
install -p -m 755 $(provision_file_location)/provision_status.sh $(buildroot)$(_contrailopt)/contrail_server_manager/provision_status.sh
install -p -m 755 $(SB_TOP)/tools/packaging/build/ubuntu_12_04_3_sources.list $(buildroot)$(_contrailopt)/contrail_server_manager/ubuntu_12_04_3_sources.list
install -p -m 755 $(SB_TOP)/tools/packaging/build/ubuntu_14_04_1_sources.list $(buildroot)$(_contrailopt)/contrail_server_manager/ubuntu_14_04_1_sources.list
install -p -m 755 $(SB_TOP)/tools/packaging/build/puppetmaster $(buildroot)$(_contrailopt)/contrail_server_manager/puppetmaster
install -p -m 755 $(SB_TOP)/tools/packaging/build/cobbler.conf $(buildroot)$(_contrailopt)/contrail_server_manager/cobbler.conf
install -p -m 755 $(SB_TOP)/tools/packaging/build/cobbler_web.conf $(buildroot)$(_contrailopt)/contrail_server_manager/cobbler_web.conf
install -p -m 755 $(SB_TOP)/tools/packaging/build/cobbler_14.conf $(buildroot)$(_contrailopt)/contrail_server_manager/cobbler_14.conf
install -p -m 755 $(SB_TOP)/tools/packaging/build/cobbler_web_14.conf $(buildroot)$(_contrailopt)/contrail_server_manager/cobbler_web_14.conf

# install TGZ file and packages list file
if [ -f $(TGZ_FILE) ]; then echo "Using TGZ FILE = $(TGZ_FILE)"; install -p -m 644 $(TGZ_FILE) $(buildroot)$(_contrailopt)/contrail_server_manager/contrail_server_manager_packages.tgz; else echo "ERROR: TGZ file containing all debs is not supplied or not present"; echo "Supply Argument: FILE_LIST=<TGZ FILE>"; exit 1; fi
override_dh_shlibdeps:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
contrail-server-manager-lite (BUILDTAG) tsurendra; urgency=low

[tsurendra ]
* debian/changelog: changelog

-- tsurendra <tsurendra@juniper.net> Wed Jun 11 17:39:50 PDT 2014
1 change: 1 addition & 0 deletions common/debian/contrail-server-manager-lite/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8
14 changes: 14 additions & 0 deletions common/debian/contrail-server-manager-lite/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Source: contrail-server-manager-lite
Maintainer: tsurendra <tsurendra@juniper.net>
Section: misc
Priority: optional
Standards-Version: 1.0
Build-Depends: debhelper (>= 8)

Package: contrail-server-manager-lite
Architecture: all
Maintainer: tsurendra <tsurendra@juniper.net>
Depends: python, apache2, sqlite, puppetmaster-passenger (=3.7.3-1puppetlabs1), xinetd, python-pip, python-gevent, ntp,autoconf, gcc, tftp, sendmail, dpkg-dev, syslinux, ipmitool, createrepo, libapache2-mod-wsgi, python-urlgrabber, python-django, selinux-utils, python-simplejson, python-dev, fence-agents, python-requests, reprepro, python-netaddr
Section: contrail-server-manager-lite
Priority: extra
Description: Contrail Server Manager - Server Package, without cobbler, only provisioning supported package.
5 changes: 5 additions & 0 deletions common/debian/contrail-server-manager-lite/debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Name: contrail-server-manager-lite
Maintainer: tsurendra <tsurendra@juniper.net>
License: Commercial
Files: *
Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.

0 comments on commit 2d45ba3

Please sign in to comment.