summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore6
-rw-r--r--pom.xml62
-rwxr-xr-xsonar.sh83
-rw-r--r--vio/assembly.xml2
-rwxr-xr-xvio/docker/instance-config.sh8
-rwxr-xr-xvio/docker/instance-run.sh4
-rw-r--r--vio/requirements.txt3
-rwxr-xr-xvio/run.sh8
-rw-r--r--vio/tox.ini1
-rw-r--r--vio/vio/pub/config/log.yml26
-rw-r--r--vio/vio/settings.py38
11 files changed, 206 insertions, 35 deletions
diff --git a/.gitignore b/.gitignore
index 56ab27e..bd4f0b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,9 @@
target/
logs/*.log
*.pyc
+
+# Test related files
+vio/.coverage
+vio/.tox/
+vio/logs/*.log
+vio/test-reports/
diff --git a/pom.xml b/pom.xml
index e0f05d9..a52ab10 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,7 +33,69 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<nexusproxy>https://nexus.onap.org</nexusproxy>
+
+ <sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>
+ <sonar.sources>.</sonar.sources>
+ <sonar.junit.reportsPath>xunit-results.xml</sonar.junit.reportsPath>
+ <sonar.python.coverage.reportPath>vio/coverage.xml</sonar.python.coverage.reportPath>
+ <sonar.language>py</sonar.language>
+ <sonar.pluginName>Python</sonar.pluginName>
+ <sonar.inclusions>**/*.py</sonar.inclusions>
+ <sonar.exclusions>tests/*,setup.py</sonar.exclusions>
</properties>
<build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.2.1</version>
+ <configuration>
+ <executable>${session.executionRootDirectory}/sonar.sh</executable>
+ <environmentVariables>
+ <!-- make mvn properties as env for our script -->
+ <MVN_PROJECT_GROUPID>${project.groupId}</MVN_PROJECT_GROUPID>
+ <MVN_PROJECT_ARTIFACTID>${project.artifactId}</MVN_PROJECT_ARTIFACTID>
+ <MVN_PROJECT_VERSION>${project.version}</MVN_PROJECT_VERSION>
+ </environmentVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.2.1</version>
+ <executions>
+ <execution>
+ <id>clean phase script</id>
+ <phase>clean</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <arguments>
+ <argument>__</argument>
+ <argument>clean</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ <execution>
+ <id>test script</id>
+ <phase>test</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <arguments>
+ <argument>__</argument>
+ <argument>test</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
</build>
</project>
diff --git a/sonar.sh b/sonar.sh
new file mode 100755
index 0000000..91f09f0
--- /dev/null
+++ b/sonar.sh
@@ -0,0 +1,83 @@
+#!/bin/bash
+# Copyright 2018 VMware Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+set -e
+
+echo "running script: [$0] for module [$1] at stage [$2]"
+
+export SETTINGS_FILE=${SETTINGS_FILE:-$HOME/.m2/settings.xml}
+MVN_PROJECT_MODULEID="$1"
+MVN_PHASE="$2"
+
+
+FQDN="${MVN_PROJECT_GROUPID}.${MVN_PROJECT_ARTIFACTID}"
+if [ "$MVN_PROJECT_MODULEID" == "__" ]; then
+ MVN_PROJECT_MODULEID=""
+fi
+
+if [ -z "$WORKSPACE" ]; then
+ WORKSPACE=$(pwd)
+fi
+
+# mvn phase in life cycle
+MVN_PHASE="$2"
+
+
+echo "MVN_PROJECT_MODULEID is [$MVN_PROJECT_MODULEID]"
+echo "MVN_PHASE is [$MVN_PHASE]"
+echo "MVN_PROJECT_GROUPID is [$MVN_PROJECT_GROUPID]"
+echo "MVN_PROJECT_ARTIFACTID is [$MVN_PROJECT_ARTIFACTID]"
+echo "MVN_PROJECT_VERSION is [$MVN_PROJECT_VERSION]"
+
+run_tox_test()
+{
+ set -x
+ cd vio
+ CURDIR=$(pwd)
+ TOXINIS=$(find . -name "tox.ini")
+ cd ..
+ for TOXINI in "${TOXINIS[@]}"; do
+ DIR=$(echo "$TOXINI" | rev | cut -f2- -d'/' | rev)
+ cd "${CURDIR}/${DIR}"
+ rm -rf ./venv-tox ./.tox
+ virtualenv ./venv-tox
+ source ./venv-tox/bin/activate
+ pip install --upgrade pip
+ pip install --upgrade tox argparse
+ pip freeze
+ cd vio
+ tox -e cover
+ deactivate
+ cd ..
+ rm -rf ./venv-tox ./.tox
+ done
+}
+
+
+case $MVN_PHASE in
+clean)
+ echo "==> clean phase script"
+ rm -rf ./venv-*
+ ;;
+test)
+ echo "==> test phase script"
+ run_tox_test
+ ;;
+*)
+ echo "==> unprocessed phase"
+ ;;
+esac
+
diff --git a/vio/assembly.xml b/vio/assembly.xml
index 376c9af..5f3755c 100644
--- a/vio/assembly.xml
+++ b/vio/assembly.xml
@@ -29,6 +29,7 @@
<include>**/*.wsdl</include>
<include>**/*.xsd</include>
<include>**/*.bpel</include>
+ <include>**/*.yml</include>
</includes>
</fileSet>
<fileSet>
@@ -55,6 +56,7 @@
<include>*.sh</include>
<include>*.ini</include>
<include>*.md</include>
+ <include>*.yml</include>
</includes>
</fileSet>
</fileSets>
diff --git a/vio/docker/instance-config.sh b/vio/docker/instance-config.sh
index 5623109..3952a03 100755
--- a/vio/docker/instance-config.sh
+++ b/vio/docker/instance-config.sh
@@ -39,4 +39,10 @@ sed -i "s|DB_PORT.*|DB_PORT = $MYSQL_PORT|" vio/vio/pub/config/config.py
cat vio/vio/pub/config/config.py
sed -i "s/sip=.*/sip=$SERVICE_IP/g" vio/run.sh
-sed -i "s/sip=.*/sip=$SERVICE_IP/g" vio/stop.sh \ No newline at end of file
+sed -i "s/sip=.*/sip=$SERVICE_IP/g" vio/stop.sh
+
+# Create log directory
+logDir="/var/log/onap/multicloud/vio"
+if [ ! -x $logDir ]; then
+ mkdir -p $logDir
+fi
diff --git a/vio/docker/instance-run.sh b/vio/docker/instance-run.sh
index 9dabfa2..e5c6ec8 100755
--- a/vio/docker/instance-run.sh
+++ b/vio/docker/instance-run.sh
@@ -16,7 +16,7 @@
cd ./vio
./run.sh
-while [ ! -f logs/runtime_vio.log ]; do
+while [ ! -f /var/log/onap/multicloud/vio/vio.log ]; do
sleep 1
done
-tail -F logs/runtime_vio.log
+tail -F /var/log/onap/multicloud/vio/vio.log
diff --git a/vio/requirements.txt b/vio/requirements.txt
index b98759a..9c2a4b4 100644
--- a/vio/requirements.txt
+++ b/vio/requirements.txt
@@ -21,3 +21,6 @@ django-nose>=1.4.0
coverage==4.2
mock==2.0.0
unittest_xml_reporting==1.12.0
+
+# for onap logging
+onappylog>=1.0.5
diff --git a/vio/run.sh b/vio/run.sh
index 0c767aa..1c392e4 100755
--- a/vio/run.sh
+++ b/vio/run.sh
@@ -21,10 +21,14 @@ sed -i "s/AAI_SCHEMA_VERSION =.*/AAI_SCHEMA_VERSION = \"${AAI_SCHEMA_VERSION}\"/
sed -i "s/AAI_USERNAME =.*/AAI_USERNAME = \"${AAI_USERNAME}\"/g" vio/pub/config/config.py
sed -i "s/AAI_PASSWORD =.*/AAI_PASSWORD = \"${AAI_PASSWORD}\"/g" vio/pub/config/config.py
+
+
+logDir="/var/log/onap/multicloud/vio"
+
nohup python manage.py runserver 0.0.0.0:9004 2>&1 &
-while [ ! -f logs/runtime_vio.log ]; do
+while [ ! -f $logDir/vio.log ]; do
sleep 1
done
-tail -F logs/runtime_vio.log
+tail -F $logDir/vio.log
diff --git a/vio/tox.ini b/vio/tox.ini
index 966b7bb..f2df905 100644
--- a/vio/tox.ini
+++ b/vio/tox.ini
@@ -25,3 +25,4 @@ setenv=
commands =
coverage erase
{[testenv]commands}
+ coverage xml -i \ No newline at end of file
diff --git a/vio/vio/pub/config/log.yml b/vio/vio/pub/config/log.yml
new file mode 100644
index 0000000..82eb814
--- /dev/null
+++ b/vio/vio/pub/config/log.yml
@@ -0,0 +1,26 @@
+version: 1
+disable_existing_loggers: False
+
+loggers:
+ vio:
+ handlers: [vio_handler]
+ level: "DEBUG"
+ propagate: False
+handlers:
+ vio_handler:
+ level: "DEBUG"
+ class: "logging.handlers.RotatingFileHandler"
+ filename: "/var/log/onap/multicloud/vio/vio.log"
+ formatter: "mdcFormat"
+ maxBytes: 1024*1024*50
+ backupCount: 10
+formatters:
+ standard:
+ format: "%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s"
+ mdcFormat:
+ format: "%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:[%(mdc)s]: %(message)s"
+ mdcfmt: "{requestID}"
+ datefmt: "%Y-%m-%d %H:%M:%S"
+ (): onaplogging.mdcformatter.MDCFormatter
+
+
diff --git a/vio/vio/settings.py b/vio/vio/settings.py
index c0a9209..e82b523 100644
--- a/vio/vio/settings.py
+++ b/vio/vio/settings.py
@@ -12,7 +12,9 @@
import os
import sys
-
+from logging import config
+from onaplogging import monkey
+monkey.patch_all()
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -83,36 +85,12 @@ TIME_ZONE = 'UTC'
STATIC_URL = '/static/'
-LOGGING = {
- 'version': 1,
- 'disable_existing_loggers': True,
- 'formatters': {
- 'standard': {
- 'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d]\
- [%(levelname)s]:%(message)s',
- },
- },
- 'filters': {
- },
- 'handlers': {
- 'vio_handler': {
- 'level': 'DEBUG',
- 'class': 'logging.handlers.RotatingFileHandler',
- 'filename': os.path.join(BASE_DIR, 'logs/runtime_vio.log'),
- 'formatter': 'standard',
- 'maxBytes': 1024 * 1024 * 50,
- 'backupCount': 5,
- },
- },
- 'loggers': {
- 'vio': {
- 'handlers': ['vio_handler'],
- 'level': 'DEBUG',
- 'propagate': False
- },
- }
-}
+LOGGING_CONFIG = None
+# yaml configuration of logging
+LOGGING_FILE = os.path.join(BASE_DIR, 'vio/pub/config/log.yml')
+config.yamlConfig(filepath=LOGGING_FILE, watchDog=True)
+
if 'test' in sys.argv:
from vio.pub.config import config