diff --git a/scripts/clmc-service/install-clmc-service.sh b/scripts/clmc-service/install-clmc-service.sh index c1d93d99b34af7389ea81ec26868cbd19142f304..e0df440998980a0997429b6cf8b9b3f3808d802a 100755 --- a/scripts/clmc-service/install-clmc-service.sh +++ b/scripts/clmc-service/install-clmc-service.sh @@ -11,6 +11,25 @@ INFLUX_URL=$1 DATABASE_NAME=$2 REPORT_PERIOD=$3 +apt-get update + +# Create the database for the WHOAMI API +apt-get install -y postgresql postgresql-contrib +sudo -u postgres bash -c "psql -c \"CREATE USER clmc WITH PASSWORD 'clmc_service';\"" +sudo -u postgres bash -c "psql -c \"ALTER USER clmc CREATEDB;\"" +sudo -u postgres createdb whoamidb +sudo -u postgres bash -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE \"whoamidb\" to clmc;\"" + +# install virtualenvwrapper to manage python environments - and check +echo "----> Installing Python3 and Pip3" +apt-get install -y python3 python3-pip wget curl +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 + ## CLMC-SERVICE ## ---------------------------------------------------------------------------------- echo "----> Configuring virtualenvwrapper" @@ -50,10 +69,10 @@ if [ $? -ne 0 ] ; then fi # navigate to the clmc-webservice - and check -echo "----> Moving to CLMC webservice" +echo "----> Moving to CLMC service" cd ${REPO_ROOT}/src/service if [ $? -ne 0 ] ; then - echo "Failed: could not find clmc-webservice" + echo "Failed: could not find clmc-service" exit 1 fi @@ -80,6 +99,14 @@ fi echo "----> Creating CLMC web service log directory" mkdir -p /var/log/flame/clmc +# initialise the CLMC service database with the model tables +echo "----> Initialising CLMC database" +initialize_clmcservice_db production.ini +if [ $? -ne 0 ] ; then + echo "Failed: switching to CLMC python environment" + exit 1 +fi + # Install minioclmc as systemctl service # ----------------------------------------------------------------------- mkdir -p /opt/flame/clmc diff --git a/scripts/clmc-service/install-tick-stack.sh b/scripts/clmc-service/install-tick-stack.sh index f52fce9a09827b71237ba915eb0543acaa2fd9a1..d90405e1527d43b5d1d69c3703abb487d7a52359 100755 --- a/scripts/clmc-service/install-tick-stack.sh +++ b/scripts/clmc-service/install-tick-stack.sh @@ -11,17 +11,6 @@ KAPACITOR_CHECKSUM=eea9b215f241906570eafe3857e1d4c5 CHRONOGRAF_VERSION=1.4.4.2 CHRONOGRAF_CHECKSUM=eea6915aa6db8f134fcd3b095e863b773bfb3a16a26e346dd65904a07df97963 -# install virtualenvwrapper to manage python environments - and check -apt-get update -echo "----> Installing Python3 and Pip3" -apt-get install -y python3 python3-pip wget curl -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 - # install influx echo "----> Installing InfluxDB" wget https://dl.influxdata.com/influxdb/releases/influxdb_${INFLUX_VERSION}_amd64.deb 2> /dev/null diff --git a/src/service/clmcservice/whoamiapi/tests.py b/src/service/clmcservice/whoamiapi/tests.py index 74e9379d2ae8e680cb88fa16bdd154689450b8d8..4bf89605a3b7016b9ead0860bd15519b180d65ea 100644 --- a/src/service/clmcservice/whoamiapi/tests.py +++ b/src/service/clmcservice/whoamiapi/tests.py @@ -204,7 +204,38 @@ class TestWhoamiAPI(object): WhoamiAPI(request).put() except HTTPConflict: error_raised = True - assert error_raised, "PUT request validates unique constraint" + assert error_raised, "PUT request breaks unique constraint" + + @pytest.mark.parametrize("body, valid", [ + ('{"location": "DC1", "sfc": "sfc1", "sfc_i": "sfc_i1", "sf": "sf1", "sf_i": "sf_i1", "sf_endpoint": "sf_endpoint1", "sr": "sr1"}', True), + ('{"location": "DC2", "sfc": "sfc2", "sfc_i": "sfc_i2", "sf": "sf2", "sf_i": "sf_i2", "sf_endpoint": "sf_endpoint2", "sr": "sr2"}', True), + ('{}', False), + ('{"location": "DC1", "sfc": "sfc1", "sfc_i": "sfc_i1", "sf": "sf1", "sf_i": "sf_i1"}', False), + ('{"place": "DC2", "sfc": "sfc2", "sfc_i": "sfc_i2", "sf": "sf2", "sf_i": "sf_i2", "sf_endpoint": "sf_endpoint2", "sr": "sr2"}', False), + ('{invalid json}', False), + ]) + def test_put_body_validation(self, body, valid): + """ + Tests the PUT request validation of the body content. + + :param body: The request body to be validated + :param valid: True if body is valid, False otherwise + """ + + sf_e = ServiceFunctionEndpoint(location="DC1", sfc="sfc1", sfc_i="sfc_i1", sf="sf1", sf_i="sf_i1", sf_endpoint="sf_endpoint1", sr="sr1") + ServiceFunctionEndpoint.add(sf_e) # adds the new instance of the model to the database + + request = testing.DummyRequest() + request.params["sf_endpoint"] = "sf_endpoint1" + request.params["sf_i"] = "sf_i1" + request.params["sr"] = "sr1" + request.body = body.encode(request.charset) + error_raised = False + try: + WhoamiAPI(request).put() + except HTTPBadRequest: + error_raised = True + assert error_raised == (not valid), "An error must be raised in case of an invalid request body" def test_delete(self): """