From 1ed2a12f27155089098f14765452cd1dcfd57694 Mon Sep 17 00:00:00 2001
From: Simon Crowle <sgc@it-innovation.soton.ac.uk>
Date: Wed, 30 May 2018 13:58:34 +0100
Subject: [PATCH] Plugins in CLMC web service into install.sh

---
 clmctest/monitoring/rspec.yml       |  2 +
 docs/clmc-service.md                |  2 +-
 scripts/clmc-service/install.sh     | 81 +++++++++++++++++++++++++++--
 src/clmc-webservice/development.ini |  2 +-
 src/clmc-webservice/production.ini  |  2 +-
 src/clmc-webservice/setup.py        |  2 +-
 src/clmc-webservice/tox.ini         |  2 +-
 7 files changed, 84 insertions(+), 9 deletions(-)

diff --git a/clmctest/monitoring/rspec.yml b/clmctest/monitoring/rspec.yml
index 43fd381..7d7c38d 100644
--- a/clmctest/monitoring/rspec.yml
+++ b/clmctest/monitoring/rspec.yml
@@ -31,6 +31,8 @@ hosts:
         host: 8888
       - guest: 9092
         host: 9092
+      - guest: 9080
+        host: 9080
     ip_address: "172.40.231.51"
   - name: ipendpoint1
     cpus: 1
diff --git a/docs/clmc-service.md b/docs/clmc-service.md
index 37a41bd..a179f0e 100644
--- a/docs/clmc-service.md
+++ b/docs/clmc-service.md
@@ -231,4 +231,4 @@ Finally, start the service on localhost by using pyramid's **pserve**:
 pserve development.ini --reload
 ```
 
-You should now be able to make requests to the CLMC service on http://localhost:8080/aggregator/config and http://localhost:8080/aggregator/control.
+You should now be able to make requests to the CLMC service on http://localhost:9080/aggregator/config and http://localhost:9080/aggregator/control.
diff --git a/scripts/clmc-service/install.sh b/scripts/clmc-service/install.sh
index 900c943..4f47288 100755
--- a/scripts/clmc-service/install.sh
+++ b/scripts/clmc-service/install.sh
@@ -24,8 +24,8 @@
 #//
 #/////////////////////////////////////////////////////////////////////////
 
-# Force fail on command fail
-set -euo pipefail
+# Force fail on command fail (off for now as virtualenvwrapper install fails)
+# set -euo pipefail
 
 # Define tickstack software versions
 INFLUX_VERSION=1.5.2
@@ -37,9 +37,7 @@ KAPACITOR_CHECKSUM=eea9b215f241906570eafe3857e1d4c5
 CHRONOGRAF_VERSION=1.4.4.2
 CHRONOGRAF_CHECKSUM=eea6915aa6db8f134fcd3b095e863b773bfb3a16a26e346dd65904a07df97963
 
-# install python for the simulator
 apt-get update
-apt-get -y install python
 
 # install influx
 wget https://dl.influxdata.com/influxdb/releases/influxdb_${INFLUX_VERSION}_amd64.deb 2> /dev/null
@@ -71,3 +69,78 @@ dpkg -i chronograf_${CHRONOGRAF_VERSION}_amd64.deb
 systemctl start influxdb
 systemctl start kapacitor
 systemctl start chronograf
+
+## CLMC-SERVICE
+## ----------------------------------------------------------------------------------
+
+# install virtualenvwrapper to manage python environments - and check
+echo "----> Installing Python3 and Pip3"
+apt-get install -y python3 python3-pip
+update-alternatives --install /usr/bin/python python /usr/bin/python3 10
+
+echo "----> Installing virtualenv and wrapper"
+apt-get install -y python3-virtualenv virtualenvwrapper
+pip3 install virtualenv
+pip3 install virtualenvwrapper
+
+echo "----> Configuring virtualenvwrapper"
+export WORKON_HOME=$HOME/.virtualenvs
+source /usr/local/bin/virtualenvwrapper.sh
+
+# check the mkvirtualenv with a return value of 1 if version comes back correctly
+mkvirtualenv --version
+if [ $? -ne 1 ] ; then
+        echo "Failed: installing virtualenvwrapper"
+		exit 1
+fi
+
+# create CLMC virtual environment - and check
+echo "----> Making CLMC Python environment"
+mkvirtualenv CLMC
+if [ $? -ne 0 ] ; then
+        echo "Failed: creating CLMC python environment"
+		exit 1
+fi
+
+# switch the CLMC environment - and check
+echo "----> Switching to use CLMC python environment"
+workon CLMC
+if [ $? -ne 0 ] ; then
+        echo "Failed: switching to CLMC python environment"
+		exit 1
+fi
+
+# install tox - and check
+echo "----> Installing TOX"
+pip3 install tox
+tox --version
+if [ $? -ne 0 ] ; then
+        echo "Failed: installing tox"
+		exit 1
+fi
+
+# navigate to the clmc-webservice - and check
+echo "----> Moving to CLMC webservice"
+cd /vagrant/src/clmc-webservice
+if [ $? -ne 0 ] ; then
+        echo "Failed: could not find clmc-webservice"
+		exit 1
+fi
+
+# install the service
+echo "----> Installing CLMC web service"
+pip3 install -e .
+if [ $? -ne 0 ] ; then
+        echo "Failed: installing clmc-webservice"
+		exit 1
+fi
+
+# start the service
+echo "----> Starting CLMC web service"
+pserve development.ini --reload
+if [ $? -ne 0 ] ; then
+        echo "Failed: starting clmc-webservice"
+		exit 1
+else
+	echo "CLMC service started."
+fi
\ No newline at end of file
diff --git a/src/clmc-webservice/development.ini b/src/clmc-webservice/development.ini
index 9ec4dc5..4b5384d 100644
--- a/src/clmc-webservice/development.ini
+++ b/src/clmc-webservice/development.ini
@@ -27,7 +27,7 @@ aggregator_database_url = http://172.40.231.51:8086
 
 [server:main]
 use = egg:waitress#main
-listen = localhost:8080
+listen = localhost:9080
 
 ###
 # logging configuration
diff --git a/src/clmc-webservice/production.ini b/src/clmc-webservice/production.ini
index 7f5e323..5f1d9dc 100644
--- a/src/clmc-webservice/production.ini
+++ b/src/clmc-webservice/production.ini
@@ -22,7 +22,7 @@ aggregator_database_url = http://172.40.231.51:8086
 
 [server:main]
 use = egg:waitress#main
-listen = *:8080
+listen = *:9080
 
 ###
 # logging configuration
diff --git a/src/clmc-webservice/setup.py b/src/clmc-webservice/setup.py
index 817d1bd..0b195c5 100644
--- a/src/clmc-webservice/setup.py
+++ b/src/clmc-webservice/setup.py
@@ -1,5 +1,5 @@
 """
-// © University of Southampton IT Innovation Centre, 2018
+// (c) University of Southampton IT Innovation Centre, 2018
 //
 // Copyright in this software belongs to University of Southampton
 // IT Innovation Centre of Gamma House, Enterprise Road,
diff --git a/src/clmc-webservice/tox.ini b/src/clmc-webservice/tox.ini
index b7fe1ea..49efb9f 100644
--- a/src/clmc-webservice/tox.ini
+++ b/src/clmc-webservice/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py36
+envlist = py35
 [testenv]
 deps=pytest
 commands=pytest
\ No newline at end of file
-- 
GitLab