Skip to content
Snippets Groups Projects
Commit a32d4eaf authored by MJB's avatar MJB
Browse files

#44 refactored container scripts into one script fixtures.sh, supports all of...

#44 refactored container scripts into one script fixtures.sh, supports all of single container management
parent e2a31da1
Branches
Tags
No related merge requests found
...@@ -59,16 +59,30 @@ SSH into the VM ...@@ -59,16 +59,30 @@ SSH into the VM
`vagrant ssh` `vagrant ssh`
Create the services needed for integration tests The containers are controlled using a script called /vagrant/scripts/test/fixtures.sh
```
Usage: fixturs.sh create|start|stop|destroy [-f config_file] [-r repo_root] [-c service_name]"
```
To create all the services needed for integration tests
``` ```
sudo su sudo su
/vagrant/scripts/test/conts-create.sh /vagrant/scripts/test/fixtures.sh create -f /vagrant/src/test/clmctest/rspec.json
``` ```
All of the containers created are defined in the file `/vagrant/src/test/clmctest/rspec.json` The containers created are defined an rspec.json file, there's an example here `/vagrant/src/test/clmctest/rspec.json`
The `fixtures.sh` script defaults to look for a rspec.json in the current directory, you can specify a specific rspec.json file using the -f option
To create|start|stop|destroy specific services use the -c option e.g.
```
/vagrant/scripts/test/fixtures.sh create -f /vagrant/src/test/clmctest/rspec.json -c clmc-service
```
Attach to the test-runner Attach to the test-runner to run the tests
`lxc-attach -n test-runner` `lxc-attach -n test-runner`
......
...@@ -95,9 +95,6 @@ systemctl start chronograf ...@@ -95,9 +95,6 @@ systemctl start chronograf
## CLMC-SERVICE ## CLMC-SERVICE
## ---------------------------------------------------------------------------------- ## ----------------------------------------------------------------------------------
echo "----> Configuring virtualenvwrapper" echo "----> Configuring virtualenvwrapper"
export WORKON_HOME=$HOME/.virtualenvs export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh source /usr/local/bin/virtualenvwrapper.sh
...@@ -150,15 +147,33 @@ if [ $? -ne 0 ] ; then ...@@ -150,15 +147,33 @@ if [ $? -ne 0 ] ; then
exit 1 exit 1
fi fi
# start the service # Install minioclmc as systemctl service
echo "----> Starting CLMC web service" # -----------------------------------------------------------------------
nohup pserve production.ini > /dev/null 2>&1 & mkdir -p /opt/flame/clmc
if [ $? -ne 0 ] ; then start_script_file="/opt/flame/clmc/start.sh"
echo "Failed: starting clmc-webservice" echo "#!/bin/bash" > $start_script_file
exit 1 echo "export WORKON_HOME=${HOME}/.virtualenvs" >> $start_script_file
else echo "source /usr/local/bin/virtualenvwrapper.sh" >> $start_script_file
echo "CLMC service started." echo "workon CLMC" >> $start_script_file
fi echo "pserve ${REPO_ROOT}/src/service/production.ini > /dev/null 2>&1 &" >> $start_script_file
chmod 755 $start_script_file
file="/lib/systemd/system/flameclmc.service"
echo "[Unit]" > $file
echo "Description=flameclmc" >> $file
echo "After=network.target" >> $file
echo "" >> $file
echo "[Service]" >> $file
echo "Type=forking" >> $file
echo "ExecStart=${start_script_file}" >> $file
echo "" >> $file
echo "[Install]" >> $file
echo "WantedBy=multi-user.target" >> $file
systemctl daemon-reload
systemctl enable flameclmc.service
systemctl start flameclmc.service
# wait for the clmc service to start # wait for the clmc service to start
while ! nc -z localhost 9080 while ! nc -z localhost 9080
......
#!/bin/bash
set -eu -o pipefail
cd `dirname $0`
source conts-env.sh
service_names=$(jq -r '.[].name' ${rspec_file})
for service_name in $service_names; do
if lxc-info -n ${service_name}; then
echo "Stopping container: ${service_name}"
lxc-stop -n ${service_name}
echo "Destroying container: ${service_name}"
lxc-destroy -n ${service_name}
ip=$(jq -r --arg NAME ${service_name} '.[] | select(.name==$NAME) | .ip_address' ${rspec_file})
sed -i "/dhcp-host=${service_name},/d" /etc/lxc/dnsmasq.conf
fi
done
#!/bin/bash
repo_root="/vagrant"
rspec_file=$repo_root"/src/test/clmctest/rspec.json"
\ No newline at end of file
#!/bin/bash
set -eu -o pipefail
cd `dirname $0`
source conts-env.sh
service_names=$(jq -r '.[].name' ${rspec_file})
for service_name in $service_names; do
if lxc-info -n ${service_name}; then
echo "Starting container: ${service_name}"
lxc-start -n ${service_name}
fi
done
#!/bin/bash
set -eu -o pipefail
cd `dirname $0`
source conts-env.sh
service_names=$(jq -r '.[].name' ${rspec_file})
for service_name in $service_names; do
if lxc-info -n ${service_name}; then
echo "Stopping container: ${service_name}"
lxc-stop -n ${service_name}
fi
done
\ No newline at end of file
#!/bin/bash #!/bin/bash
set -eu -o pipefail
cd `dirname $0`
source conts-env.sh usage() {
echo "Usage: $0 create|start|stop|destroy [-f config_file] [-r repo_root] [-c service_name]" 1>&2
exit 1
}
# iterate through each service required for integration testing create() {
service_names=$(jq -r '.[].name' ${rspec_file}) service_name=$1
for service_name in $service_names; do config_file=$2
repo_root=$3
if ! lxc-info -n ${service_name}; then if ! lxc-info -n ${service_name}; then
# create a container with a static ip address # create a container with a static ip address
echo "Creating container: ${service_name}" echo "Creating container: ${service_name}"
SERVICE=$(jq --arg NAME ${service_name} '.[] | select(.name==$NAME)' ${rspec_file}) SERVICE=$(jq --arg NAME ${service_name} '.[] | select(.name==$NAME)' ${config_file})
echo $SERVICE echo $SERVICE
ip=$(echo $SERVICE | jq -r '.ip_address') ip=$(echo $SERVICE | jq -r '.ip_address')
echo "dhcp-host=${service_name},${ip}" >> /etc/lxc/dnsmasq.conf echo "dhcp-host=${service_name},${ip}" >> /etc/lxc/dnsmasq.conf
...@@ -83,10 +85,92 @@ for service_name in $service_names; do ...@@ -83,10 +85,92 @@ for service_name in $service_names; do
lxc-attach -n ${service_name} -- service telegraf restart lxc-attach -n ${service_name} -- service telegraf restart
fi fi
fi fi
}
start() {
service_name=$1
if lxc-info -n ${service_name}; then
echo "Starting container: ${service_name}"
lxc-start -n ${service_name}
fi
}
stop() {
service_name=$1
if lxc-info -n ${service_name}; then
echo "Stopping container: ${service_name}"
lxc-stop -n ${service_name}
fi
}
destroy() {
service_name=$1
config_file=$2
if lxc-info -n ${service_name}; then
echo "Stopping container: ${service_name}"
lxc-stop -n ${service_name}
echo "Destroying container: ${service_name}"
lxc-destroy -n ${service_name}
ip=$(jq -r --arg NAME ${service_name} '.[] | select(.name==$NAME) | .ip_address' ${config_file})
sed -i "/dhcp-host=${service_name},/d" /etc/lxc/dnsmasq.conf
fi
}
# inc option index by 1 as first argument is the command and not parsed by getopts
if [ $# -gt 1 ]; then
OPTIND=$((OPTIND+1))
fi
repo_root="/vagrant"
config_file="rspec.json"
# collect the optional arguments
while getopts "hf:r:c:" opt; do
case $opt in
h) usage; exit ;;
f) config_file=${OPTARG} ;;
r) repo_root=${OPTARG} ;;
c) container=${OPTARG} ;;
\?) usage ;;
esac
done done
#./conts-stop.sh # check configuration file exists
if [ ! -f ${config_file} ]; then
echo "Configuration file does not exist: ${config_file}" >&2
usage
exit 1
fi
#service lxc-net restart # check repo root directory exists
if [ ! -d ${repo_root} ]; then
echo "Repo root directory does not exist: ${repo_root}" >&2
usage
exit 1
fi
#./conts-start.sh # iterate of list of services in configuration file
\ No newline at end of file command=$1
service_names=$(jq -r '.[].name' ${config_file})
for service_name in $service_names; do
# if all or specific container
if [ -z ${container} ] || [ ${container} == ${service_name} ]; then
case "${command}" in
create)
create ${service_name} ${config_file} ${repo_root}
;;
start)
start ${service_name} ${config_file} ${repo_root}
;;
stop)
stop ${service_name} ${config_file} ${repo_root}
;;
destroy)
destroy ${service_name} ${config_file} ${repo_root}
;;
*)
usage
;;
esac
fi
done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment