summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi
diff options
context:
space:
mode:
authorrohitsakala <rohitsakala@gmail.com>2016-12-16 00:38:41 +0530
committerrohitsakala <rohitsakala@gmail.com>2017-01-04 17:41:38 +0530
commit0d87caa1b785588ffb9a92f37420bc688ebed01d (patch)
treede1800996bf81f687c4fa5aba28dac74f99711bb /utils/test/testapi
parent508f72a1bec40410e1c008f13fbdfaf2cf56611d (diff)
Create Jenkins Job for testapi automation
Right now, only builder for creating testapi doc is included JIRA: FUNCTEST-664 Change-Id: If0a34154084c1d01ed6b997d2226779da43bcb14 Signed-off-by: rohitsakala <rohitsakala@gmail.com>
Diffstat (limited to 'utils/test/testapi')
-rw-r--r--utils/test/testapi/htmlize/finish.sh15
-rw-r--r--utils/test/testapi/htmlize/htmlize.py51
-rw-r--r--utils/test/testapi/htmlize/prepare.sh30
-rw-r--r--utils/test/testapi/htmlize/push-doc-artifact.sh25
4 files changed, 121 insertions, 0 deletions
diff --git a/utils/test/testapi/htmlize/finish.sh b/utils/test/testapi/htmlize/finish.sh
new file mode 100644
index 000000000..dc3aa868b
--- /dev/null
+++ b/utils/test/testapi/htmlize/finish.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Stop opnfv-testapi server
+proc_number=`ps -ef | grep opnfv-testapi | grep -v grep | wc -l`
+
+if [ $proc_number -gt 0 ]; then
+ procs=`ps -ef | grep opnfv-testapi | grep -v grep`
+ echo "Kill opnfv-testapi server $procs"
+ ps -ef | grep opnfv-testapi | grep -v grep | awk '{print $2}' | xargs kill -kill &>/dev/null
+fi
diff --git a/utils/test/testapi/htmlize/htmlize.py b/utils/test/testapi/htmlize/htmlize.py
new file mode 100644
index 000000000..68d02febd
--- /dev/null
+++ b/utils/test/testapi/htmlize/htmlize.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+import argparse
+import requests
+import json
+import os
+
+
+def main(args):
+
+ # Merging two specs
+ api_response = requests.get(args.api_declaration_url)
+ api_response = json.loads(api_response.content)
+ resource_response = requests.get(args.resource_listing_url)
+ resource_response = json.loads(resource_response.content)
+ resource_response['models'] = api_response['models']
+ resource_response['apis'] = api_response['apis']
+
+ # Storing the swagger specs
+ with open('specs.json', 'w') as outfile:
+ json.dump(resource_response, outfile)
+
+ # Generating html page
+ cmd = 'java -jar swagger-codegen-cli.jar generate \
+ -i specs.json -l html2 -o %s' % (args.output_directory)
+ os.system(cmd)
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description='Create \
+ Swagger Spec documentation')
+ parser.add_argument('-ru', '--resource-listing-url',
+ type=str,
+ required=False,
+ default='http://localhost:8000/swagger/spec.json',
+ help='Resource Listing Spec File')
+ parser.add_argument('-au', '--api-declaration-url',
+ type=str,
+ required=False,
+ default='http://localhost:8000/swagger/spec',
+ help='API Declaration Spec File')
+ parser.add_argument('-o', '--output-directory',
+ required=True,
+ default='./',
+ help='Output Directory where the \
+ file should be stored')
+ main(parser.parse_args())
diff --git a/utils/test/testapi/htmlize/prepare.sh b/utils/test/testapi/htmlize/prepare.sh
new file mode 100644
index 000000000..3c265aaa0
--- /dev/null
+++ b/utils/test/testapi/htmlize/prepare.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+#Creating virtual environment
+virtualenv testapi_venv
+source testapi_venv/bin/activate
+
+# Install Pre-requisites
+pip install requests
+
+# Swgger Codegen Tool
+url="http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.2.1/swagger-codegen-cli-2.2.1.jar"
+
+#Check for jar file locally and in the repo
+if [ ! -f swagger-codegen-cli.jar ];
+then
+ wget http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.2.1/swagger-codegen-cli-2.2.1.jar -O swagger-codegen-cli.jar
+fi
+
+# Start OPNFV Test API Server
+cd utils/test/testapi/
+pip install -r requirements.txt
+./install.sh
+opnfv-testapi -c ../../../testapi_venv/etc/opnfv_testapi/config.ini &
+
+deactivate
diff --git a/utils/test/testapi/htmlize/push-doc-artifact.sh b/utils/test/testapi/htmlize/push-doc-artifact.sh
new file mode 100644
index 000000000..383565df1
--- /dev/null
+++ b/utils/test/testapi/htmlize/push-doc-artifact.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+set -e
+set -o pipefail
+
+export PATH=$PATH:/usr/local/bin/
+
+project=$PROJECT
+workspace=$WORKSPACE
+artifact_dir="functest/docs"
+
+set +e
+gsutil&>/dev/null
+if [ $? != 0 ]; then
+ echo "Not possible to push results to artifact: gsutil not installed"
+else
+ gsutil ls gs://artifacts.opnfv.org/"$project"/ &>/dev/null
+ if [ $? != 0 ]; then
+ echo "Not possible to push results to artifact: gsutil not installed."
+ else
+ echo "Uploading document to artifact $artifact_dir"
+ gsutil cp "$workspace"/index.html gs://artifacts.opnfv.org/"$artifact_dir"/testapi.html >/dev/null 2>&1
+ echo "Document can be found at http://artifacts.opnfv.org/functest/docs/testapi.html"
+ fi
+fi