summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerena Feng <feng.xiaowei@zte.com.cn>2017-01-05 05:54:34 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-01-05 05:54:34 +0000
commitcc234da58259069d40f502751a4793bc00dd4fb2 (patch)
tree692941a560e4ce4491fbb7b7abe2306ed7c759fd
parentfd41180285d17f79adafd31cedb995bd5579dfcf (diff)
parent934706da3e662945dc56288e3438586b097ed745 (diff)
Merge "Create Jenkins Job for testapi automation"
-rw-r--r--testapi/htmlize/finish.sh15
-rw-r--r--testapi/htmlize/htmlize.py51
-rw-r--r--testapi/htmlize/prepare.sh30
-rw-r--r--testapi/htmlize/push-doc-artifact.sh25
4 files changed, 121 insertions, 0 deletions
diff --git a/testapi/htmlize/finish.sh b/testapi/htmlize/finish.sh
new file mode 100644
index 0000000..dc3aa86
--- /dev/null
+++ b/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/testapi/htmlize/htmlize.py b/testapi/htmlize/htmlize.py
new file mode 100644
index 0000000..68d02fe
--- /dev/null
+++ b/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/testapi/htmlize/prepare.sh b/testapi/htmlize/prepare.sh
new file mode 100644
index 0000000..3c265aa
--- /dev/null
+++ b/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/testapi/htmlize/push-doc-artifact.sh b/testapi/htmlize/push-doc-artifact.sh
new file mode 100644
index 0000000..383565d
--- /dev/null
+++ b/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