summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi
diff options
context:
space:
mode:
Diffstat (limited to 'utils/test/testapi')
-rw-r--r--utils/test/testapi/.gitignore5
-rw-r--r--utils/test/testapi/3rd_party/static/testapi-ui/app.js24
-rw-r--r--utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/guidelines.html80
-rw-r--r--utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/guidelinesController.js322
-rw-r--r--utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/partials/guidelineDetails.html50
-rw-r--r--utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/partials/testListModal.html46
-rw-r--r--utils/test/testapi/3rd_party/static/testapi-ui/components/pods/pods.html75
-rw-r--r--utils/test/testapi/3rd_party/static/testapi-ui/components/pods/podsController.js121
-rw-r--r--utils/test/testapi/3rd_party/static/testapi-ui/components/profile/profile.html11
-rw-r--r--utils/test/testapi/3rd_party/static/testapi-ui/components/profile/profileController.js2
-rw-r--r--utils/test/testapi/3rd_party/static/testapi-ui/index.html2
-rw-r--r--utils/test/testapi/3rd_party/static/testapi-ui/shared/header/header.html2
-rw-r--r--utils/test/testapi/MANIFEST.in1
-rw-r--r--utils/test/testapi/docker/Dockerfile2
-rwxr-xr-xutils/test/testapi/docker/prepare-env.sh3
-rw-r--r--utils/test/testapi/etc/config.ini54
-rwxr-xr-xutils/test/testapi/install.sh30
-rw-r--r--utils/test/testapi/opnfv_testapi/cmd/server.py4
-rw-r--r--utils/test/testapi/opnfv_testapi/common/config.py19
-rw-r--r--utils/test/testapi/opnfv_testapi/common/constants.py4
-rw-r--r--utils/test/testapi/opnfv_testapi/common/raises.py4
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/handlers.py57
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/models.py23
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/result_handlers.py23
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py703
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/scenario_models.py52
-rw-r--r--utils/test/testapi/opnfv_testapi/router/url_mappings.py20
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/common/noparam.ini16
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/common/normal.ini17
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/common/nosection.ini11
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/common/notboolean.ini17
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/common/notint.ini17
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py2
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/conftest.py2
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/resources/scenario-c2.json4
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/resources/test_base.py44
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py531
-rw-r--r--utils/test/testapi/opnfv_testapi/tornado_swagger/swagger.py17
-rw-r--r--utils/test/testapi/opnfv_testapi/ui/auth/base.py35
-rw-r--r--utils/test/testapi/opnfv_testapi/ui/auth/constants.py18
-rw-r--r--utils/test/testapi/opnfv_testapi/ui/auth/sign.py103
-rw-r--r--utils/test/testapi/opnfv_testapi/ui/auth/user.py43
-rw-r--r--utils/test/testapi/opnfv_testapi/ui/root.py6
-rw-r--r--utils/test/testapi/requirements.txt1
-rw-r--r--utils/test/testapi/setup.cfg15
-rw-r--r--utils/test/testapi/setup.py4
-rw-r--r--utils/test/testapi/tools/watchdog/docker_watch.sh165
47 files changed, 1567 insertions, 1240 deletions
diff --git a/utils/test/testapi/.gitignore b/utils/test/testapi/.gitignore
index c7b63b5b1..86ec0d2d5 100644
--- a/utils/test/testapi/.gitignore
+++ b/utils/test/testapi/.gitignore
@@ -1,4 +1,7 @@
AUTHORS
ChangeLog
setup.cfg-e
-
+opnfv_testapi/static
+build
+*.egg-info
+3rd_party/static/static
diff --git a/utils/test/testapi/3rd_party/static/testapi-ui/app.js b/utils/test/testapi/3rd_party/static/testapi-ui/app.js
index bb31ab081..5f5b86159 100644
--- a/utils/test/testapi/3rd_party/static/testapi-ui/app.js
+++ b/utils/test/testapi/3rd_party/static/testapi-ui/app.js
@@ -26,6 +26,22 @@
.module('testapiApp')
.config(configureRoutes);
+ angular
+ .module('testapiApp')
+ .directive('dynamicModel', ['$compile', '$parse', function ($compile, $parse) {
+ return {
+ restrict: 'A',
+ terminal: true,
+ priority: 100000,
+ link: function (scope, elem) {
+ var name = $parse(elem.attr('dynamic-model'))(scope);
+ elem.removeAttr('dynamic-model');
+ elem.attr('ng-model', name);
+ $compile(elem)(scope);
+ }
+ };
+ }]);
+
configureRoutes.$inject = ['$stateProvider', '$urlRouterProvider'];
/**
@@ -43,10 +59,10 @@
url: '/about',
templateUrl: 'testapi-ui/components/about/about.html'
}).
- state('guidelines', {
- url: '/guidelines',
- templateUrl: 'testapi-ui/components/guidelines/guidelines.html',
- controller: 'GuidelinesController as ctrl'
+ state('pods', {
+ url: '/pods',
+ templateUrl: 'testapi-ui/components/pods/pods.html',
+ controller: 'PodsController as ctrl'
}).
state('communityResults', {
url: '/community_results',
diff --git a/utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/guidelines.html b/utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/guidelines.html
deleted file mode 100644
index 1dd39ff17..000000000
--- a/utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/guidelines.html
+++ /dev/null
@@ -1,80 +0,0 @@
-<h3>OpenStack Powered&#8482; Guidelines</h3>
-
-<!-- Guideline Filters -->
-<div class="row">
- <div class="col-md-3">
- <strong>Version:</strong>
- <!-- Slicing the version file name here gets rid of the '.json' file extension -->
- <select ng-model="ctrl.version"
- ng-change="ctrl.update()"
- class="form-control"
- ng-options="versionFile.slice(0,-5) for versionFile in ctrl.versionList">
- </select>
- </div>
- <div class="col-md-4">
- <strong>Target Program:</strong>
- <span class="program-about"><a target="_blank" href="http://www.openstack.org/brand/interop/">About</a></span>
- <select ng-model="ctrl.target" class="form-control" ng-change="ctrl.updateTargetCapabilities()">
- <option value="platform">OpenStack Powered Platform</option>
- <option value="compute">OpenStack Powered Compute</option>
- <option value="object">OpenStack Powered Object Storage</option>
- </select>
- </div>
-</div>
-
-<br />
-<div ng-if="ctrl.guidelines">
- <strong>Guideline Status:</strong>
- {{ctrl.guidelines.status | capitalize}}
-</div>
-
-<div ng-show="ctrl.guidelines">
- <strong>Corresponding OpenStack Releases:</strong>
- <ul class="list-inline">
- <li ng-repeat="release in ctrl.guidelines.releases">
- {{release | capitalize}}
- </li>
- </ul>
-</div>
-
-<strong>Capability Status:</strong>
-<div class="checkbox">
- <label>
- <input type="checkbox" ng-model="ctrl.status.required">
- <span class="required">Required</span>
- </label>
- <label>
- <input type="checkbox" ng-model="ctrl.status.advisory">
- <span class="advisory">Advisory</span>
- </label>
- <label>
- <input type="checkbox" ng-model="ctrl.status.deprecated">
- <span class="deprecated">Deprecated</span>
- </label>
- <label>
- <input type="checkbox" ng-model="ctrl.status.removed">
- <span class="removed">Removed</span>
- </label>
- <a class="test-list-dl pull-right"
- title="Get a test list for capabilities matching selected statuses."
- ng-click="ctrl.openTestListModal()">
-
- Test List <span class="glyphicon glyphicon-file"></span>
- </a>
-</div>
-<!-- End Capability Filters -->
-
-<p><small>Tests marked with <span class="glyphicon glyphicon-flag text-warning"></span> are tests flagged by Interop Working Group.</small></p>
-
-<!-- Loading animation divs -->
-<div cg-busy="{promise:ctrl.versionsRequest,message:'Loading versions'}"></div>
-<div cg-busy="{promise:ctrl.capsRequest,message:'Loading capabilities'}"></div>
-
-<!-- Get the version-specific template -->
-<div ng-include src="ctrl.detailsTemplate"></div>
-
-<div ng-show="ctrl.showError" class="alert alert-danger" role="alert">
- <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
- <span class="sr-only">Error:</span>
- {{ctrl.error}}
-</div>
diff --git a/utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/guidelinesController.js b/utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/guidelinesController.js
deleted file mode 100644
index a6f4258a2..000000000
--- a/utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/guidelinesController.js
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * 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.
- */
-
-(function () {
- 'use strict';
-
- angular
- .module('testapiApp')
- .controller('GuidelinesController', GuidelinesController);
-
- GuidelinesController.$inject = ['$http', '$uibModal', 'testapiApiUrl'];
-
- /**
- * TestAPI Guidelines Controller
- * This controller is for the '/guidelines' page where a user can browse
- * through tests belonging to Interop WG defined capabilities.
- */
- function GuidelinesController($http, $uibModal, testapiApiUrl) {
- var ctrl = this;
-
- ctrl.getVersionList = getVersionList;
- ctrl.update = update;
- ctrl.updateTargetCapabilities = updateTargetCapabilities;
- ctrl.filterStatus = filterStatus;
- ctrl.getObjectLength = getObjectLength;
- ctrl.openTestListModal = openTestListModal;
-
- /** The target OpenStack marketing program to show capabilities for. */
- ctrl.target = 'platform';
-
- /** The various possible capability statuses. */
- ctrl.status = {
- required: true,
- advisory: false,
- deprecated: false,
- removed: false
- };
-
- /**
- * The template to load for displaying capability details.
- */
- ctrl.detailsTemplate = 'components/guidelines/partials/' +
- 'guidelineDetails.html';
-
- /**
- * Retrieve an array of available guideline files from the TestAPI
- * API server, sort this array reverse-alphabetically, and store it in
- * a scoped variable. The scope's selected version is initialized to
- * the latest (i.e. first) version here as well. After a successful API
- * call, the function to update the capabilities is called.
- * Sample API return array: ["2015.03.json", "2015.04.json"]
- */
- function getVersionList() {
- var content_url = testapiApiUrl + '/guidelines';
- ctrl.versionsRequest =
- $http.get(content_url).success(function (data) {
- ctrl.versionList = data.sort().reverse();
- // Default to the first approved guideline which is expected
- // to be at index 1.
- ctrl.version = ctrl.versionList[1];
- ctrl.update();
- }).error(function (error) {
- ctrl.showError = true;
- ctrl.error = 'Error retrieving version list: ' +
- angular.toJson(error);
- });
- }
-
- /**
- * This will contact the TestAPI API server to retrieve the JSON
- * content of the guideline file corresponding to the selected
- * version.
- */
- function update() {
- var content_url = testapiApiUrl + '/guidelines/' + ctrl.version;
- ctrl.capsRequest =
- $http.get(content_url).success(function (data) {
- ctrl.guidelines = data;
- ctrl.updateTargetCapabilities();
- }).error(function (error) {
- ctrl.showError = true;
- ctrl.guidelines = null;
- ctrl.error = 'Error retrieving guideline content: ' +
- angular.toJson(error);
- });
- }
-
- /**
- * This will update the scope's 'targetCapabilities' object with
- * capabilities belonging to the selected OpenStack marketing program
- * (programs typically correspond to 'components' in the Interop WG
- * schema). Each capability will have its status mapped to it.
- */
- function updateTargetCapabilities() {
- ctrl.targetCapabilities = {};
- var components = ctrl.guidelines.components;
- var targetCaps = ctrl.targetCapabilities;
-
- // The 'platform' target is comprised of multiple components, so
- // we need to get the capabilities belonging to each of its
- // components.
- if (ctrl.target === 'platform') {
- var platform_components = ctrl.guidelines.platform.required;
-
- // This will contain status priority values, where lower
- // values mean higher priorities.
- var statusMap = {
- required: 1,
- advisory: 2,
- deprecated: 3,
- removed: 4
- };
-
- // For each component required for the platform program.
- angular.forEach(platform_components, function (component) {
- // Get each capability list belonging to each status.
- angular.forEach(components[component],
- function (caps, status) {
- // For each capability.
- angular.forEach(caps, function(cap) {
- // If the capability has already been added.
- if (cap in targetCaps) {
- // If the status priority value is less
- // than the saved priority value, update
- // the value.
- if (statusMap[status] <
- statusMap[targetCaps[cap]]) {
- targetCaps[cap] = status;
- }
- }
- else {
- targetCaps[cap] = status;
- }
- });
- });
- });
- }
- else {
- angular.forEach(components[ctrl.target],
- function (caps, status) {
- angular.forEach(caps, function(cap) {
- targetCaps[cap] = status;
- });
- });
- }
- }
-
- /**
- * This filter will check if a capability's status corresponds
- * to a status that is checked/selected in the UI. This filter
- * is meant to be used with the ng-repeat directive.
- * @param {Object} capability
- * @returns {Boolean} True if capability's status is selected
- */
- function filterStatus(capability) {
- var caps = ctrl.targetCapabilities;
- return (ctrl.status.required &&
- caps[capability.id] === 'required') ||
- (ctrl.status.advisory &&
- caps[capability.id] === 'advisory') ||
- (ctrl.status.deprecated &&
- caps[capability.id] === 'deprecated') ||
- (ctrl.status.removed &&
- caps[capability.id] === 'removed');
- }
-
- /**
- * This function will get the length of an Object/dict based on
- * the number of keys it has.
- * @param {Object} object
- * @returns {Number} length of object
- */
- function getObjectLength(object) {
- return Object.keys(object).length;
- }
-
- /**
- * This will open the modal that will show a list of all tests
- * belonging to capabilities with the selected status(es).
- */
- function openTestListModal() {
- $uibModal.open({
- templateUrl: '/components/guidelines/partials' +
- '/testListModal.html',
- backdrop: true,
- windowClass: 'modal',
- animation: true,
- controller: 'TestListModalController as modal',
- size: 'lg',
- resolve: {
- version: function () {
- return ctrl.version.slice(0, -5);
- },
- target: function () {
- return ctrl.target;
- },
- status: function () {
- return ctrl.status;
- }
- }
- });
- }
-
- ctrl.getVersionList();
- }
-
- angular
- .module('testapiApp')
- .controller('TestListModalController', TestListModalController);
-
- TestListModalController.$inject = [
- '$uibModalInstance', '$http', 'version',
- 'target', 'status', 'testapiApiUrl'
- ];
-
- /**
- * Test List Modal Controller
- * This controller is for the modal that appears if a user wants to see the
- * test list corresponding to Interop WG capabilities with the selected
- * statuses.
- */
- function TestListModalController($uibModalInstance, $http, version,
- target, status, testapiApiUrl) {
-
- var ctrl = this;
-
- ctrl.version = version;
- ctrl.target = target;
- ctrl.status = status;
- ctrl.close = close;
- ctrl.updateTestListString = updateTestListString;
-
- ctrl.aliases = true;
- ctrl.flagged = false;
-
- // Check if the API URL is absolute or relative.
- if (testapiApiUrl.indexOf('http') > -1) {
- ctrl.url = testapiApiUrl;
- }
- else {
- ctrl.url = location.protocol + '//' + location.host +
- testapiApiUrl;
- }
-
- /**
- * This function will close/dismiss the modal.
- */
- function close() {
- $uibModalInstance.dismiss('exit');
- }
-
- /**
- * This function will return a list of statuses based on which ones
- * are selected.
- */
- function getStatusList() {
- var statusList = [];
- angular.forEach(ctrl.status, function(value, key) {
- if (value) {
- statusList.push(key);
- }
- });
- return statusList;
- }
-
- /**
- * This will get the list of tests from the API and update the
- * controller's test list string variable.
- */
- function updateTestListString() {
- var statuses = getStatusList();
- if (!statuses.length) {
- ctrl.error = 'No tests matching selected criteria.';
- return;
- }
- ctrl.testListUrl = [
- ctrl.url, '/guidelines/', ctrl.version, '/tests?',
- 'target=', ctrl.target, '&',
- 'type=', statuses.join(','), '&',
- 'alias=', ctrl.aliases.toString(), '&',
- 'flag=', ctrl.flagged.toString()
- ].join('');
- ctrl.testListRequest =
- $http.get(ctrl.testListUrl).
- then(function successCallback(response) {
- ctrl.error = null;
- ctrl.testListString = response.data;
- if (!ctrl.testListString) {
- ctrl.testListCount = 0;
- }
- else {
- ctrl.testListCount =
- ctrl.testListString.split('\n').length;
- }
- }, function errorCallback(response) {
- ctrl.testListString = null;
- ctrl.testListCount = null;
- if (angular.isObject(response.data) &&
- response.data.message) {
- ctrl.error = 'Error retrieving test list: ' +
- response.data.message;
- }
- else {
- ctrl.error = 'Unknown error retrieving test list.';
- }
- });
- }
-
- updateTestListString();
- }
-})();
diff --git a/utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/partials/guidelineDetails.html b/utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/partials/guidelineDetails.html
deleted file mode 100644
index f020c9a09..000000000
--- a/utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/partials/guidelineDetails.html
+++ /dev/null
@@ -1,50 +0,0 @@
-<!--
-HTML for guidelines page for all OpenStack Powered (TM) guideline schemas
-This expects the JSON data of the guidelines file to be stored in scope
-variable 'guidelines'.
--->
-
-<ol ng-show="ctrl.guidelines" class="capabilities">
- <li class="capability-list-item" ng-repeat="capability in ctrl.guidelines.capabilities | arrayConverter | filter:ctrl.filterStatus | orderBy:'id'">
- <span class="capability-name">{{capability.id}}</span><br />
- <em>{{capability.description}}</em><br />
- Status: <span class="{{ctrl.targetCapabilities[capability.id]}}">{{ctrl.targetCapabilities[capability.id]}}</span><br />
- <span ng-if="capability.project">Project: {{capability.project | capitalize}}<br /></span>
- <a ng-click="showAchievements = !showAchievements">Achievements ({{capability.achievements.length}})</a><br />
- <ol uib-collapse="!showAchievements" class="list-inline">
- <li ng-repeat="achievement in capability.achievements">
- {{achievement}}
- </li>
- </ol>
-
- <a ng-click="showTests = !showTests">Tests ({{ctrl.getObjectLength(capability.tests)}})</a>
- <ul uib-collapse="!showTests">
- <li ng-if="ctrl.guidelines.schema === '1.2'" ng-repeat="test in capability.tests">
- <span ng-class="{'glyphicon glyphicon-flag text-warning': capability.flagged.indexOf(test) > -1}"></span>
- {{test}}
- </li>
- <li ng-if="ctrl.guidelines.schema > '1.2'" ng-repeat="(testName, testDetails) in capability.tests">
- <span ng-class="{'glyphicon glyphicon-flag text-warning': testDetails.flagged}" title="{{testDetails.flagged.reason}}"></span>
- {{testName}}
- <div class="test-detail" ng-if="testDetails.aliases">
- <strong>Aliases:</strong>
- <ul><li ng-repeat="alias in testDetails.aliases">{{alias}}</li></ul>
- </div>
- </li>
- </ul>
- </li>
-</ol>
-
-<div ng-show="ctrl.guidelines" class="criteria">
- <hr>
- <h4><a ng-click="showCriteria = !showCriteria">Criteria</a></h4>
- <div uib-collapse="showCriteria">
- <ul>
- <li ng-repeat="(key, criterion) in ctrl.guidelines.criteria">
- <span class="criterion-name">{{criterion.name}}</span><br />
- <em>{{criterion.Description}}</em><br />
- Weight: {{criterion.weight}}
- </li>
- </ul>
- </div>
-</div>
diff --git a/utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/partials/testListModal.html b/utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/partials/testListModal.html
deleted file mode 100644
index 5b1d698d5..000000000
--- a/utils/test/testapi/3rd_party/static/testapi-ui/components/guidelines/partials/testListModal.html
+++ /dev/null
@@ -1,46 +0,0 @@
-<div class="modal-content">
- <div class="modal-header">
- <button type="button" class="close" aria-hidden="true" ng-click="modal.close()">&times;</button>
- <h4>Test List ({{modal.testListCount}})</h4>
- <p>Use this test list with <a title="testapi-client" target="_blank"href="https://github.com/openstack/testapi-client">testapi-client</a>
- to run only tests in the {{modal.version}} OpenStack Powered&#8482; guideline from capabilities with the following statuses:
- </p>
- <ul class="list-inline">
- <li class="required" ng-if="modal.status.required"> Required</li>
- <li class="advisory" ng-if="modal.status.advisory"> Advisory</li>
- <li class="deprecated" ng-if="modal.status.deprecated"> Deprecated</li>
- <li class="removed" ng-if="modal.status.removed"> Removed</li>
- </ul>
- <div class="checkbox checkbox-test-list">
- <label><input type="checkbox" ng-model="modal.aliases" ng-change="modal.updateTestListString()">Aliases</label>
- <span class="glyphicon glyphicon-info-sign info-hover" aria-hidden="true"
- title="Include test aliases as tests may have been renamed over time. It does not hurt to include these."></span>
- &nbsp;
- <label><input type="checkbox" ng-model="modal.flagged" ng-change="modal.updateTestListString()">Flagged</label>
- <span class="glyphicon glyphicon-info-sign info-hover" aria-hidden="true"
- title="Include flagged tests.">
- </span>
- </div>
- <p ng-hide="modal.error"> Alternatively, get the test list directly from the API on your CLI:</p>
- <code ng-hide="modal.error">wget "{{modal.testListUrl}}" -O {{modal.version}}-test-list.txt</code>
- </div>
- <div class="modal-body tests-modal-content">
- <div cg-busy="{promise:modal.testListRequest,message:'Loading'}"></div>
- <div ng-show="modal.error" class="alert alert-danger" role="alert">
- <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
- <span class="sr-only">Error:</span>
- {{modal.error}}
- </div>
- <div class="form-group">
- <textarea class="form-control" rows="16" id="tests" wrap="off">{{modal.testListString}}</textarea>
- </div>
- </div>
- <div class="modal-footer">
- <a target="_blank" href="{{modal.testListUrl}}" download="{{modal.version + '-test-list.txt'}}">
- <button class="btn btn-primary" ng-if="modal.testListCount > 0" type="button">
- Download
- </button>
- </a>
- <button class="btn btn-primary" type="button" ng-click="modal.close()">Close</button>
- </div>
-</div>
diff --git a/utils/test/testapi/3rd_party/static/testapi-ui/components/pods/pods.html b/utils/test/testapi/3rd_party/static/testapi-ui/components/pods/pods.html
new file mode 100644
index 000000000..e366670a9
--- /dev/null
+++ b/utils/test/testapi/3rd_party/static/testapi-ui/components/pods/pods.html
@@ -0,0 +1,75 @@
+<h3>Pods</h3>
+<p>This page is used to create or query pods.<br>
+ Querying pods is open to everybody.<br>
+ But only login users are granted the privilege to create the new pod.
+</p>
+
+<div class="row" style="margin-bottom:24px;"></div>
+
+<div class="pod-create" ng-class="{ 'hidden': ! auth.isAuthenticated }">
+ <h4>Create</h4>
+ <div class="row">
+ <div ng-repeat="require in ctrl.createRequirements">
+ <div class="create-pod" style="margin-left:24px;">
+ <p class="input-group">
+ <label for="cpid">{{require.label|capitalize}}: </label>
+ <a ng-if="require.type == 'select'">
+ <select dynamic-model="'ctrl.' + require.label" ng-options="option for option in require.selects"></select>
+ </a>
+ <a ng-if="require.type == 'text'">
+ <input type="text" dynamic-model="'ctrl.' + require.label"/>
+ </a>
+ <a ng-if="require.type == 'textarea'">
+ <textarea rows="2" cols="50" dynamic-model="'ctrl.' + require.label">
+ </textarea>
+ </a>
+ </p>
+ </div>
+ </div>
+
+ <div class="col-md-3" style="margin-top:12px; margin-left:8px;">
+ <button type="submit" class="btn btn-primary" ng-click="ctrl.create()">Create</button>
+ </div>
+ </div>
+</div>
+
+<div class="pods-filters" style="margin-top:36px;">
+ <h4>Filters</h4>
+ <div class="row">
+ <div class="col-md-3" style="margin-top:12px; margin-left:8px;">
+ <button type="submit" class="btn btn-primary" ng-click="ctrl.update()">Filter</button>
+ <button type="submit" class="btn btn-primary btn-danger" ng-click="ctrl.clearFilters()">Clear</button>
+ </div>
+ </div>
+</div>
+
+<div cg-busy="{promise:ctrl.authRequest,message:'Loading'}"></div>
+<div cg-busy="{promise:ctrl.podsRequest,message:'Loading'}"></div>
+
+<div ng-show="ctrl.data" class="pods-table" style="margin-top:24px; margin-left:8px;">
+ <table ng-data="ctrl.data.pods" ng-show="ctrl.data" class="table table-striped table-hover">
+ <tbody>
+ <tr ng-repeat-start="(index, pod) in ctrl.data.pods">
+ <td>
+ <a href="#" ng-click="showPod = !showPod">{{pod.name}}</a>
+ <div class="show-pod" ng-class="{ 'hidden': ! showPod }" style="margin-left:24px;">
+ <p>
+ role: {{pod.role}}<br>
+ mode: {{pod.mode}}<br>
+ create_date: {{pod.creation_date}}<br>
+ details: {{pod.details}}
+ </p>
+ </div>
+ </td>
+ </tr>
+ <tr ng-repeat-end=>
+ </tr>
+ </tbody>
+ </table>
+</div>
+<br>
+<div ng-show="ctrl.showError" class="alert alert-danger" role="alert">
+ <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
+ <span class="sr-only">Error:</span>
+ {{ctrl.error}}
+</div>
diff --git a/utils/test/testapi/3rd_party/static/testapi-ui/components/pods/podsController.js b/utils/test/testapi/3rd_party/static/testapi-ui/components/pods/podsController.js
new file mode 100644
index 000000000..894fcc152
--- /dev/null
+++ b/utils/test/testapi/3rd_party/static/testapi-ui/components/pods/podsController.js
@@ -0,0 +1,121 @@
+/*
+ * 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.
+ */
+
+(function () {
+ 'use strict';
+
+ angular
+ .module('testapiApp')
+ .controller('PodsController', PodsController);
+
+ PodsController.$inject = [
+ '$rootScope', '$scope', '$http', '$filter', '$state', 'testapiApiUrl','raiseAlert'
+ ];
+
+ /**
+ * TestAPI Pods Controller
+ * This controller is for the '/pods' page where a user can browse
+ * through pods declared in TestAPI.
+ */
+ function PodsController($scope, $http, $filter, $state, testapiApiUrl,
+ raiseAlert) {
+ var ctrl = this;
+ ctrl.url = testapiApiUrl + '/pods';
+
+ ctrl.create = create;
+ ctrl.update = update;
+ ctrl.open = open;
+ ctrl.clearFilters = clearFilters;
+
+ ctrl.roles = ['community-ci', 'production-ci'];
+ ctrl.modes = ['metal', 'virtual'];
+ ctrl.createRequirements = [
+ {label: 'name', type: 'text', required: true},
+ {label: 'mode', type: 'select', selects: ctrl.modes},
+ {label: 'role', type: 'select', selects: ctrl.roles},
+ {label: 'details', type: 'textarea', required: false}
+ ];
+
+ ctrl.name = '';
+ ctrl.role = 'community-ci';
+ ctrl.mode = 'metal';
+ ctrl.details = '';
+
+ /**
+ * This is called when the date filter calendar is opened. It
+ * does some event handling, and sets a scope variable so the UI
+ * knows which calendar was opened.
+ * @param {Object} $event - The Event object
+ * @param {String} openVar - Tells which calendar was opened
+ */
+ function open($event, openVar) {
+ $event.preventDefault();
+ $event.stopPropagation();
+ ctrl[openVar] = true;
+ }
+
+ /**
+ * This function will clear all filters and update the results
+ * listing.
+ */
+ function clearFilters() {
+ ctrl.update();
+ }
+
+ /**
+ * This will contact the TestAPI to create a new pod.
+ */
+ function create() {
+ ctrl.showError = false;
+
+ if(ctrl.name != ""){
+ var pods_url = ctrl.url;
+ var body = {
+ name: ctrl.name,
+ mode: ctrl.mode,
+ role: ctrl.role,
+ details: ctrl.details
+ };
+ ctrl.podsRequest =
+ $http.post(pods_url, body).error(function (error) {
+ ctrl.showError = true;
+ ctrl.error =
+ 'Error creating the new pod from server: ' +
+ angular.toJson(error);
+ });
+ }
+ else{
+ ctrl.showError = true;
+ ctrl.error = 'Name is missing.'
+ }
+ }
+
+ /**
+ * This will contact the TestAPI to get a listing of declared pods.
+ */
+ function update() {
+ ctrl.showError = false;
+ ctrl.podsRequest =
+ $http.get(ctrl.url).success(function (data) {
+ ctrl.data = data;
+ }).error(function (error) {
+ ctrl.data = null;
+ ctrl.showError = true;
+ ctrl.error =
+ 'Error retrieving pods from server: ' +
+ angular.toJson(error);
+ });
+ }
+ }
+})();
diff --git a/utils/test/testapi/3rd_party/static/testapi-ui/components/profile/profile.html b/utils/test/testapi/3rd_party/static/testapi-ui/components/profile/profile.html
index dc97c41e2..763f5d120 100644
--- a/utils/test/testapi/3rd_party/static/testapi-ui/components/profile/profile.html
+++ b/utils/test/testapi/3rd_party/static/testapi-ui/components/profile/profile.html
@@ -3,9 +3,16 @@
<div>
<table class="table table-striped table-hover">
<tbody>
- <tr> <td>User name</td> <td>{{auth.currentUser.fullname}}</td> </tr>
- <tr> <td>User OpenId</td> <td>{{auth.currentUser.openid}}</td> </tr>
+ <tr> <td>User</td> <td>{{auth.currentUser.user}}</td> </tr>
+ <tr> <td>Fullname</td> <td>{{auth.currentUser.fullname}}</td> </tr>
<tr> <td>Email</td> <td>{{auth.currentUser.email}}</td> </tr>
+ <tr> <td>Groups</td>
+ <td>
+ <div ng-repeat="group in auth.currentUser.groups">
+ {{group}}</br>
+ </div>
+ </td>
+ </tr>
</tbody>
</table>
</div>
diff --git a/utils/test/testapi/3rd_party/static/testapi-ui/components/profile/profileController.js b/utils/test/testapi/3rd_party/static/testapi-ui/components/profile/profileController.js
index 0660e19f6..5dbdf7b1a 100644
--- a/utils/test/testapi/3rd_party/static/testapi-ui/components/profile/profileController.js
+++ b/utils/test/testapi/3rd_party/static/testapi-ui/components/profile/profileController.js
@@ -26,7 +26,7 @@
* This is a provider for the user's uploaded public keys.
*/
function PubKeys($resource, testapiApiUrl) {
- return $resource(testapiApiUrl + '/profile/pubkeys/:id', null, null);
+ return $resource(testapiApiUrl + '/user/pubkeys/:id', null, null);
}
angular
diff --git a/utils/test/testapi/3rd_party/static/testapi-ui/index.html b/utils/test/testapi/3rd_party/static/testapi-ui/index.html
index 46ccc61b8..2d7399f93 100644
--- a/utils/test/testapi/3rd_party/static/testapi-ui/index.html
+++ b/utils/test/testapi/3rd_party/static/testapi-ui/index.html
@@ -40,7 +40,7 @@
<script src="testapi-ui/shared/header/headerController.js"></script>
<script src="testapi-ui/shared/alerts/alertModalFactory.js"></script>
<script src="testapi-ui/shared/alerts/confirmModalFactory.js"></script>
- <script src="testapi-ui/components/guidelines/guidelinesController.js"></script>
+ <script src="testapi-ui/components/pods/podsController.js"></script>
<script src="testapi-ui/components/results/resultsController.js"></script>
<script src="testapi-ui/components/results-report/resultsReportController.js"></script>
<script src="testapi-ui/components/profile/profileController.js"></script>
diff --git a/utils/test/testapi/3rd_party/static/testapi-ui/shared/header/header.html b/utils/test/testapi/3rd_party/static/testapi-ui/shared/header/header.html
index 85c33b68d..f5b2414c4 100644
--- a/utils/test/testapi/3rd_party/static/testapi-ui/shared/header/header.html
+++ b/utils/test/testapi/3rd_party/static/testapi-ui/shared/header/header.html
@@ -17,7 +17,7 @@ TestAPI
<ul class="nav navbar-nav">
<li ng-class="{ active: header.isActive('/')}"><a ui-sref="home">Home</a></li>
<li ng-class="{ active: header.isActive('/about')}"><a ui-sref="about">About</a></li>
- <li ng-class="{ active: header.isActive('/guidelines')}"><a ui-sref="guidelines">OPNFV Powered&#8482; Guidelines</a></li>
+ <li ng-class="{ active: header.isActive('/pods')}"><a ui-sref="pods">Pods</a></li>
<li ng-class="{ active: header.isActive('/community_results')}"><a ui-sref="communityResults">Community Results</a></li>
<!--
<li ng-class="{ active: header.isCatalogActive('public')}" class="dropdown" uib-dropdown>
diff --git a/utils/test/testapi/MANIFEST.in b/utils/test/testapi/MANIFEST.in
new file mode 100644
index 000000000..0ba1808ba
--- /dev/null
+++ b/utils/test/testapi/MANIFEST.in
@@ -0,0 +1 @@
+recursive-include 3rd_party \ No newline at end of file
diff --git a/utils/test/testapi/docker/Dockerfile b/utils/test/testapi/docker/Dockerfile
index 5311f35b8..a46fce20a 100644
--- a/utils/test/testapi/docker/Dockerfile
+++ b/utils/test/testapi/docker/Dockerfile
@@ -47,5 +47,5 @@ RUN git clone https://gerrit.opnfv.org/gerrit/releng /home/releng
WORKDIR /home/releng/utils/test/testapi/
RUN pip install -r requirements.txt
-RUN bash install.sh
+RUN python setup.py install
CMD ["bash", "docker/start-server.sh"]
diff --git a/utils/test/testapi/docker/prepare-env.sh b/utils/test/testapi/docker/prepare-env.sh
index 4f1be7d6a..92a0c9fd7 100755
--- a/utils/test/testapi/docker/prepare-env.sh
+++ b/utils/test/testapi/docker/prepare-env.sh
@@ -8,8 +8,7 @@ fi
if [ "$base_url" != "" ]; then
sudo crudini --set --existing $FILE api url $base_url/api/v1
- sudo crudini --set --existing $FILE swagger base_url $base_url
sudo crudini --set --existing $FILE ui url $base_url
sudo echo "{\"testapiApiUrl\": \"$base_url/api/v1\"}" > \
- /usr/local/lib/python2.7/dist-packages/opnfv_testapi/static/testapi-ui/config.json
+ /usr/local/share/opnfv_testapi/testapi-ui/config.json
fi
diff --git a/utils/test/testapi/etc/config.ini b/utils/test/testapi/etc/config.ini
index 435188df7..8d0bde20b 100644
--- a/utils/test/testapi/etc/config.ini
+++ b/utils/test/testapi/etc/config.ini
@@ -18,54 +18,14 @@ results_per_page = 20
debug = True
authenticate = False
-[swagger]
-base_url = http://localhost:8000
-
[ui]
url = http://localhost:8000
-[osid]
-
-# OpenStackID Auth Server URI. (string value)
-openstack_openid_endpoint = https://openstackid.org/accounts/openid2
-
-# OpenStackID logout URI. (string value)
-openid_logout_endpoint = https://openstackid.org/accounts/user/logout
-
-# Interaction mode. Specifies whether Openstack Id IdP may interact
-# with the user to determine the outcome of the request. (string
-# value)
-openid_mode = checkid_setup
-
-# Protocol version. Value identifying the OpenID protocol version
-# being used. This value should be "http://specs.openid.net/auth/2.0".
-# (string value)
-openid_ns = http://specs.openid.net/auth/2.0
-
-# Return endpoint in Refstack's API. Value indicating the endpoint
-# where the user should be returned to after signing in. Openstack Id
-# Idp only supports HTTPS address types. (string value)
-openid_return_to = v1/auth/signin_return
-
-# Claimed identifier. This value must be set to
-# "http://specs.openid.net/auth/2.0/identifier_select". or to user
-# claimed identity (user local identifier or user owned identity [ex:
-# custom html hosted on a owned domain set to html discover]). (string
-# value)
-openid_claimed_id = http://specs.openid.net/auth/2.0/identifier_select
-
-# Alternate identifier. This value must be set to
-# http://specs.openid.net/auth/2.0/identifier_select. (string value)
-openid_identity = http://specs.openid.net/auth/2.0/identifier_select
-
-# Indicates request for user attribute information. This value must be
-# set to "http://openid.net/extensions/sreg/1.1". (string value)
-openid_ns_sreg = http://openid.net/extensions/sreg/1.1
+# this path should be the seem with data_files installation path
+static_path = /usr/local/share/opnfv_testapi
-# Comma-separated list of field names which, if absent from the
-# response, will prevent the Consumer from completing the registration
-# without End User interation. The field names are those that are
-# specified in the Response Format, with the "openid.sreg." prefix
-# removed. Valid values include: "country", "email", "firstname",
-# "language", "lastname" (string value)
-openid_sreg_required = email,fullname
+[lfid]
+# Linux Foundation cas URL
+cas_url = https://identity.linuxfoundation.org/cas/
+#service url used to authenticate to cas
+signin_return = api/v1/auth/signin_return
diff --git a/utils/test/testapi/install.sh b/utils/test/testapi/install.sh
deleted file mode 100755
index d470e38c3..000000000
--- a/utils/test/testapi/install.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/bash
-
-usage="
-Script to install opnfv_tesgtapi automatically.
-This script should be run under root.
-
-usage:
- bash $(basename "$0") [-h|--help] [-t <test_name>]
-
-where:
- -h|--help show this help text"
-
-# Ref :- https://openstack.nimeyo.com/87286/openstack-packaging-all-definition-data-files-config-setup
-if [ -z "$VIRTUAL_ENV" ];
-then
- if [[ $(whoami) != "root" ]];
- then
- echo "Error: This script must be run as root!"
- exit 1
- fi
-else
- sed -i -e 's#/etc/opnfv_testapi =#etc/opnfv_testapi =#g' setup.cfg
-fi
-
-cp -fr 3rd_party/static opnfv_testapi/static
-python setup.py install
-rm -fr opnfv_testapi/static
-if [ ! -z "$VIRTUAL_ENV" ]; then
- sed -i -e 's#etc/opnfv_testapi =#/etc/opnfv_testapi =#g' setup.cfg
-fi \ No newline at end of file
diff --git a/utils/test/testapi/opnfv_testapi/cmd/server.py b/utils/test/testapi/opnfv_testapi/cmd/server.py
index a5ac5eb6b..b7d3caa20 100644
--- a/utils/test/testapi/opnfv_testapi/cmd/server.py
+++ b/utils/test/testapi/opnfv_testapi/cmd/server.py
@@ -37,8 +37,8 @@ from opnfv_testapi.tornado_swagger import swagger
def make_app():
- swagger.docs(base_url=CONF.swagger_base_url,
- static_path=CONF.static_path)
+ swagger.docs(base_url=CONF.ui_url,
+ static_path=CONF.ui_static_path)
return swagger.Application(
url_mappings.mappings,
debug=CONF.api_debug,
diff --git a/utils/test/testapi/opnfv_testapi/common/config.py b/utils/test/testapi/opnfv_testapi/common/config.py
index 4cd53c619..140e49283 100644
--- a/utils/test/testapi/opnfv_testapi/common/config.py
+++ b/utils/test/testapi/opnfv_testapi/common/config.py
@@ -16,14 +16,10 @@ import sys
class Config(object):
def __init__(self):
- self.config_file = None
+ self.config_file = '/etc/opnfv_testapi/config.ini'
self._set_config_file()
self._parse()
self._parse_per_page()
- self.static_path = os.path.join(
- os.path.dirname(os.path.normpath(__file__)),
- os.pardir,
- 'static')
def _parse(self):
if not os.path.exists(self.config_file):
@@ -56,23 +52,12 @@ class Config(object):
return value
def _set_config_file(self):
- if not self._set_sys_config_file():
- self._set_default_config_file()
-
- def _set_sys_config_file(self):
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config-file", dest='config_file',
help="Config file location", metavar="FILE")
args, _ = parser.parse_known_args(sys.argv)
- try:
+ if hasattr(args, 'config_file') and args.config_file:
self.config_file = args.config_file
- finally:
- return self.config_file is not None
-
- def _set_default_config_file(self):
- is_venv = os.getenv('VIRTUAL_ENV')
- self.config_file = os.path.join('/' if not is_venv else is_venv,
- 'etc/opnfv_testapi/config.ini')
CONF = Config()
diff --git a/utils/test/testapi/opnfv_testapi/common/constants.py b/utils/test/testapi/opnfv_testapi/common/constants.py
new file mode 100644
index 000000000..70c922383
--- /dev/null
+++ b/utils/test/testapi/opnfv_testapi/common/constants.py
@@ -0,0 +1,4 @@
+TESTAPI_ID = 'testapi_id'
+CSRF_TOKEN = 'csrf_token'
+ROLE = 'role'
+TESTAPI_USERS = ['opnfv-testapi-users']
diff --git a/utils/test/testapi/opnfv_testapi/common/raises.py b/utils/test/testapi/opnfv_testapi/common/raises.py
index ec6b8a564..55c58c9e2 100644
--- a/utils/test/testapi/opnfv_testapi/common/raises.py
+++ b/utils/test/testapi/opnfv_testapi/common/raises.py
@@ -26,6 +26,10 @@ class Forbidden(Raiser):
code = httplib.FORBIDDEN
+class Conflict(Raiser):
+ code = httplib.CONFLICT
+
+
class NotFound(Raiser):
code = httplib.NOT_FOUND
diff --git a/utils/test/testapi/opnfv_testapi/resources/handlers.py b/utils/test/testapi/opnfv_testapi/resources/handlers.py
index 8a3a2db38..ed55c7028 100644
--- a/utils/test/testapi/opnfv_testapi/resources/handlers.py
+++ b/utils/test/testapi/opnfv_testapi/resources/handlers.py
@@ -50,7 +50,7 @@ class GenericApiHandler(web.RequestHandler):
self.auth = self.settings["auth"]
def prepare(self):
- if self.request.method != "GET" and self.request.method != "DELETE":
+ if self.request.body:
if self.request.headers.get("Content-Type") is not None:
if self.request.headers["Content-Type"].startswith(
DEFAULT_REPRESENTATION):
@@ -106,20 +106,27 @@ class GenericApiHandler(web.RequestHandler):
per_page = kwargs.get('per_page', 0)
if query is None:
query = {}
+ pipelines = list()
+ pipelines.append({'$match': query})
total_pages = 0
- if page > 0:
- cursor = dbapi.db_list(self.table, query)
- records_count = yield cursor.count()
- total_pages = self._calc_total_pages(records_count,
- last,
- page,
- per_page)
- pipelines = self._set_pipelines(query, sort, last, page, per_page)
- cursor = dbapi.db_aggregate(self.table, pipelines)
data = list()
- while (yield cursor.fetch_next):
- data.append(self.format_data(cursor.next_object()))
+ cursor = dbapi.db_list(self.table, query)
+ records_count = yield cursor.count()
+ if records_count > 0:
+ if page > 0:
+ total_pages, return_nr = self._calc_total_pages(records_count,
+ last,
+ page,
+ per_page)
+ pipelines = self._set_pipelines(pipelines,
+ sort,
+ return_nr,
+ page,
+ per_page)
+ cursor = dbapi.db_aggregate(self.table, pipelines)
+ while (yield cursor.fetch_next):
+ data.append(self.format_data(cursor.next_object()))
if res_op is None:
res = {self.table: data}
else:
@@ -145,21 +152,17 @@ class GenericApiHandler(web.RequestHandler):
if page > 1 and page > total_pages:
raises.BadRequest(
'Request page > total_pages [{}]'.format(total_pages))
- return total_pages
+ return total_pages, records_nr
@staticmethod
- def _set_pipelines(query, sort, last, page, per_page):
- pipelines = list()
- if query:
- pipelines.append({'$match': query})
+ def _set_pipelines(pipelines, sort, return_nr, page, per_page):
if sort:
pipelines.append({'$sort': sort})
- if page > 0:
- pipelines.append({'$skip': (page - 1) * per_page})
- pipelines.append({'$limit': per_page})
- elif last > 0:
- pipelines.append({'$limit': last})
+ over = (page - 1) * per_page
+ left = return_nr - over
+ pipelines.append({'$skip': over})
+ pipelines.append({'$limit': per_page if per_page < left else left})
return pipelines
@@ -186,6 +189,16 @@ class GenericApiHandler(web.RequestHandler):
update_req['_id'] = str(data._id)
self.finish_request(update_req)
+ @check.authenticate
+ @check.no_body
+ @check.not_exist
+ @check.updated_one_not_exist
+ def pure_update(self, data, query=None, **kwargs):
+ data = self.table_cls.from_dict(data)
+ update_req = self._update_requests(data)
+ yield dbapi.db_update(self.table, query, update_req)
+ self.finish_request()
+
def _update_requests(self, data):
request = dict()
for k, v in self.json_args.iteritems():
diff --git a/utils/test/testapi/opnfv_testapi/resources/models.py b/utils/test/testapi/opnfv_testapi/resources/models.py
index e8fc532b7..e70a6ed23 100644
--- a/utils/test/testapi/opnfv_testapi/resources/models.py
+++ b/utils/test/testapi/opnfv_testapi/resources/models.py
@@ -48,6 +48,29 @@ class ModelBase(object):
return t
+ @classmethod
+ def from_dict_with_raise(cls, a_dict):
+ if a_dict is None:
+ return None
+
+ attr_parser = cls.attr_parser()
+ t = cls()
+ for k, v in a_dict.iteritems():
+ if k not in t.__dict__:
+ raise AttributeError(
+ '{} has no attribute {}'.format(cls.__name__, k))
+ value = v
+ if isinstance(v, dict) and k in attr_parser:
+ value = attr_parser[k].from_dict_with_raise(v)
+ elif isinstance(v, list) and k in attr_parser:
+ value = []
+ for item in v:
+ value.append(attr_parser[k].from_dict_with_raise(item))
+
+ t.__setattr__(k, value)
+
+ return t
+
@staticmethod
def attr_parser():
return {}
diff --git a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py
index 2bf1792f2..e202f5c2c 100644
--- a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py
+++ b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py
@@ -6,20 +6,20 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-import logging
-from datetime import datetime
-from datetime import timedelta
import json
+import logging
from bson import objectid
+from datetime import datetime
+from datetime import timedelta
-from opnfv_testapi.common.config import CONF
+from opnfv_testapi.common import constants
from opnfv_testapi.common import message
from opnfv_testapi.common import raises
+from opnfv_testapi.common.config import CONF
from opnfv_testapi.resources import handlers
from opnfv_testapi.resources import result_models
from opnfv_testapi.tornado_swagger import swagger
-from opnfv_testapi.ui.auth import constants as auth_const
class GenericResultHandler(handlers.GenericApiHandler):
@@ -59,13 +59,12 @@ class GenericResultHandler(handlers.GenericApiHandler):
elif k == 'to':
date_range.update({'$lt': str(v)})
elif k == 'signed':
- openid = self.get_secure_cookie(auth_const.OPENID)
- role = self.get_secure_cookie(auth_const.ROLE)
- logging.info('role:%s', role)
+ username = self.get_secure_cookie(constants.TESTAPI_ID)
+ role = self.get_secure_cookie(constants.ROLE)
if role:
del query['public']
if role != "reviewer":
- query['user'] = openid
+ query['user'] = username
elif k not in ['last', 'page', 'descend']:
query[k] = v
if date_range:
@@ -155,7 +154,7 @@ class ResultsCLHandler(GenericResultHandler):
@type last: L{string}
@in last: query
@required last: False
- @param page: which page to list
+ @param page: which page to list, default to 1
@type page: L{int}
@in page: query
@required page: False
@@ -180,7 +179,7 @@ class ResultsCLHandler(GenericResultHandler):
return self.get_int('last', self.get_query_argument('last', 0))
def page_limit():
- return self.get_int('page', self.get_query_argument('page', 0))
+ return self.get_int('page', self.get_query_argument('page', 1))
limitations = {
'sort': {'_id': descend_limit()},
@@ -246,7 +245,7 @@ class ResultsUploadHandler(ResultsCLHandler):
self.json_args = json.loads(fileinfo['body']).copy()
self.json_args['public'] = is_public
- openid = self.get_secure_cookie(auth_const.OPENID)
+ openid = self.get_secure_cookie(constants.TESTAPI_ID)
if openid:
self.json_args['user'] = openid
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
index 5d420a56e..e9c19a7a4 100644
--- a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
+++ b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
@@ -15,6 +15,24 @@ class GenericScenarioHandler(handlers.GenericApiHandler):
self.table = self.db_scenarios
self.table_cls = models.Scenario
+ def set_query(self, locators):
+ query = dict()
+ elem_query = dict()
+ for k, v in locators.iteritems():
+ if k == 'scenario':
+ query['name'] = v
+ elif k == 'installer':
+ elem_query["installer"] = v
+ elif k == 'version':
+ elem_query["versions.version"] = v
+ elif k == 'project':
+ elem_query["versions.projects.project"] = v
+ else:
+ query[k] = v
+ if elem_query:
+ query['installers'] = {'$elemMatch': elem_query}
+ return query
+
class ScenariosCLHandler(GenericScenarioHandler):
@swagger.operation(nickname="queryScenarios")
@@ -96,10 +114,10 @@ class ScenarioGURHandler(GenericScenarioHandler):
self._get_one(query={'name': name})
pass
- @swagger.operation(nickname="updateScenarioByName")
+ @swagger.operation(nickname="updateScenarioName")
def put(self, name):
"""
- @description: update a single scenario by name
+ @description: update scenario, only rename is supported currently
@param body: fields to be updated
@type body: L{ScenarioUpdateRequest}
@in body: body
@@ -119,164 +137,639 @@ class ScenarioGURHandler(GenericScenarioHandler):
@return 200: delete success
@raise 404: scenario not exist:
"""
-
self._delete(query={'name': name})
- def _update_query(self, keys, data):
- query = dict()
- if self._is_rename():
- new = self._term.get('name')
- if data.get('name') != new:
- query['name'] = new
- return query
+class ScenarioUpdater(object):
+ def __init__(self, data, body=None,
+ installer=None, version=None, project=None):
+ self.data = data
+ self.body = body
+ self.installer = installer
+ self.version = version
+ self.project = project
- def _update_requests(self, data):
+ def update(self, item, action):
updates = {
- ('name', 'update'): self._update_requests_rename,
- ('installer', 'add'): self._update_requests_add_installer,
- ('installer', 'delete'): self._update_requests_delete_installer,
- ('version', 'add'): self._update_requests_add_version,
- ('version', 'delete'): self._update_requests_delete_version,
- ('owner', 'update'): self._update_requests_change_owner,
- ('project', 'add'): self._update_requests_add_project,
- ('project', 'delete'): self._update_requests_delete_project,
- ('customs', 'add'): self._update_requests_add_customs,
+ ('scores', 'post'): self._update_requests_add_score,
+ ('trust_indicators', 'post'): self._update_requests_add_ti,
+ ('customs', 'post'): self._update_requests_add_customs,
+ ('customs', 'put'): self._update_requests_update_customs,
('customs', 'delete'): self._update_requests_delete_customs,
- ('score', 'add'): self._update_requests_add_score,
- ('trust_indicator', 'add'): self._update_requests_add_ti,
+ ('projects', 'post'): self._update_requests_add_projects,
+ ('projects', 'put'): self._update_requests_update_projects,
+ ('projects', 'delete'): self._update_requests_delete_projects,
+ ('owner', 'put'): self._update_requests_change_owner,
+ ('versions', 'post'): self._update_requests_add_versions,
+ ('versions', 'put'): self._update_requests_update_versions,
+ ('versions', 'delete'): self._update_requests_delete_versions,
+ ('installers', 'post'): self._update_requests_add_installers,
+ ('installers', 'put'): self._update_requests_update_installers,
+ ('installers', 'delete'): self._update_requests_delete_installers,
}
+ updates[(item, action)](self.data)
- updates[(self._field, self._op)](data)
-
- return data.format()
+ return self.data.format()
- def _iter_installers(xstep):
+ def iter_installers(xstep):
@functools.wraps(xstep)
def magic(self, data):
[xstep(self, installer)
for installer in self._filter_installers(data.installers)]
return magic
- def _iter_versions(xstep):
+ def iter_versions(xstep):
@functools.wraps(xstep)
def magic(self, installer):
[xstep(self, version)
for version in (self._filter_versions(installer.versions))]
return magic
- def _iter_projects(xstep):
+ def iter_projects(xstep):
@functools.wraps(xstep)
def magic(self, version):
[xstep(self, project)
for project in (self._filter_projects(version.projects))]
return magic
- def _update_requests_rename(self, data):
- data.name = self._term.get('name')
- if not data.name:
- raises.BadRequest(message.missing('name'))
-
- def _update_requests_add_installer(self, data):
- data.installers.append(models.ScenarioInstaller.from_dict(self._term))
-
- def _update_requests_delete_installer(self, data):
- data.installers = self._remove_installers(data.installers)
-
- @_iter_installers
- def _update_requests_add_version(self, installer):
- installer.versions.append(models.ScenarioVersion.from_dict(self._term))
-
- @_iter_installers
- def _update_requests_delete_version(self, installer):
- installer.versions = self._remove_versions(installer.versions)
-
- @_iter_installers
- @_iter_versions
- def _update_requests_change_owner(self, version):
- version.owner = self._term.get('owner')
-
- @_iter_installers
- @_iter_versions
- def _update_requests_add_project(self, version):
- version.projects.append(models.ScenarioProject.from_dict(self._term))
+ @iter_installers
+ @iter_versions
+ @iter_projects
+ def _update_requests_add_score(self, project):
+ project.scores.append(
+ models.ScenarioScore.from_dict(self.body))
- @_iter_installers
- @_iter_versions
- def _update_requests_delete_project(self, version):
- version.projects = self._remove_projects(version.projects)
+ @iter_installers
+ @iter_versions
+ @iter_projects
+ def _update_requests_add_ti(self, project):
+ project.trust_indicators.append(
+ models.ScenarioTI.from_dict(self.body))
- @_iter_installers
- @_iter_versions
- @_iter_projects
+ @iter_installers
+ @iter_versions
+ @iter_projects
def _update_requests_add_customs(self, project):
- project.customs = list(set(project.customs + self._term))
+ project.customs = list(set(project.customs + self.body))
- @_iter_installers
- @_iter_versions
- @_iter_projects
+ @iter_installers
+ @iter_versions
+ @iter_projects
+ def _update_requests_update_customs(self, project):
+ project.customs = list(set(self.body))
+
+ @iter_installers
+ @iter_versions
+ @iter_projects
def _update_requests_delete_customs(self, project):
project.customs = filter(
- lambda f: f not in self._term,
+ lambda f: f not in self.body,
project.customs)
- @_iter_installers
- @_iter_versions
- @_iter_projects
- def _update_requests_add_score(self, project):
- project.scores.append(
- models.ScenarioScore.from_dict(self._term))
+ @iter_installers
+ @iter_versions
+ def _update_requests_add_projects(self, version):
+ version.projects = self._update_with_body(models.ScenarioProject,
+ 'project',
+ version.projects)
+
+ @iter_installers
+ @iter_versions
+ def _update_requests_update_projects(self, version):
+ version.projects = self._update_with_body(models.ScenarioProject,
+ 'project',
+ list())
+
+ @iter_installers
+ @iter_versions
+ def _update_requests_delete_projects(self, version):
+ version.projects = self._remove_projects(version.projects)
- @_iter_installers
- @_iter_versions
- @_iter_projects
- def _update_requests_add_ti(self, project):
- project.trust_indicators.append(
- models.ScenarioTI.from_dict(self._term))
+ @iter_installers
+ @iter_versions
+ def _update_requests_change_owner(self, version):
+ version.owner = self.body.get('owner')
+
+ @iter_installers
+ def _update_requests_add_versions(self, installer):
+ installer.versions = self._update_with_body(models.ScenarioVersion,
+ 'version',
+ installer.versions)
+
+ @iter_installers
+ def _update_requests_update_versions(self, installer):
+ installer.versions = self._update_with_body(models.ScenarioVersion,
+ 'version',
+ list())
+
+ @iter_installers
+ def _update_requests_delete_versions(self, installer):
+ installer.versions = self._remove_versions(installer.versions)
+
+ def _update_requests_add_installers(self, scenario):
+ scenario.installers = self._update_with_body(models.ScenarioInstaller,
+ 'installer',
+ scenario.installers)
+
+ def _update_requests_update_installers(self, scenario):
+ scenario.installers = self._update_with_body(models.ScenarioInstaller,
+ 'installer',
+ list())
+
+ def _update_requests_delete_installers(self, scenario):
+ scenario.installers = self._remove_installers(scenario.installers)
+
+ def _update_with_body(self, clazz, field, withs):
+ exists = list()
+ malformat = list()
+ for new in self.body:
+ try:
+ format_new = clazz.from_dict_with_raise(new)
+ new_name = getattr(format_new, field)
+ if not any(getattr(o, field) == new_name for o in withs):
+ withs.append(format_new)
+ else:
+ exists.append(new_name)
+ except Exception as error:
+ malformat.append(error.message)
+ if malformat:
+ raises.BadRequest(message.bad_format(malformat))
+ elif exists:
+ raises.Conflict(message.exist('{}s'.format(field), exists))
+ return withs
- def _is_rename(self):
- return self._field == 'name' and self._op == 'update'
+ def _filter_installers(self, installers):
+ return self._filter('installer', installers)
def _remove_installers(self, installers):
return self._remove('installer', installers)
- def _filter_installers(self, installers):
- return self._filter('installer', installers)
+ def _filter_versions(self, versions):
+ return self._filter('version', versions)
def _remove_versions(self, versions):
return self._remove('version', versions)
- def _filter_versions(self, versions):
- return self._filter('version', versions)
+ def _filter_projects(self, projects):
+ return self._filter('project', projects)
def _remove_projects(self, projects):
return self._remove('project', projects)
- def _filter_projects(self, projects):
- return self._filter('project', projects)
+ def _filter(self, item, items):
+ return filter(
+ lambda f: getattr(f, item) == getattr(self, item),
+ items)
def _remove(self, field, fields):
return filter(
- lambda f: getattr(f, field) != self._locate.get(field),
+ lambda f: getattr(f, field) not in self.body,
fields)
- def _filter(self, field, fields):
- return filter(
- lambda f: getattr(f, field) == self._locate.get(field),
- fields)
- @property
- def _field(self):
- return self.json_args.get('field')
+class GenericScenarioUpdateHandler(GenericScenarioHandler):
+ def __init__(self, application, request, **kwargs):
+ super(GenericScenarioUpdateHandler, self).__init__(application,
+ request,
+ **kwargs)
+ self.installer = None
+ self.version = None
+ self.project = None
+ self.item = None
+ self.action = None
+
+ def do_update(self, item, action, locators):
+ self.item = item
+ self.action = action
+ for k, v in locators.iteritems():
+ if not v:
+ v = self.get_query_argument(k)
+ setattr(self, k, v)
+ locators[k] = v
+ self.pure_update(query=self.set_query(locators=locators))
+
+ def _update_requests(self, data):
+ return ScenarioUpdater(data,
+ self.json_args,
+ self.installer,
+ self.version,
+ self.project).update(self.item, self.action)
+
+
+class ScenarioScoresHandler(GenericScenarioUpdateHandler):
+ @swagger.operation(nickname="addScoreRecord")
+ def post(self, scenario):
+ """
+ @description: add a new score record
+ @notes: add a new score record to a project
+ POST /api/v1/scenarios/<scenario_name>/scores? \
+ installer=<installer_name>& \
+ version=<version_name>& \
+ project=<project_name>
+ @param body: score to be added
+ @type body: L{ScenarioScore}
+ @in body: body
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: True
+ @param version: version
+ @type version: L{string}
+ @in version: query
+ @required version: True
+ @param project: project name
+ @type project: L{string}
+ @in project: query
+ @required project: True
+ @return 200: score is created.
+ @raise 404: scenario/installer/version/project not existed
+ """
+ self.do_update('scores',
+ 'post',
+ locators={'scenario': scenario,
+ 'installer': None,
+ 'version': None,
+ 'project': None})
+
+
+class ScenarioTIsHandler(GenericScenarioUpdateHandler):
+ @swagger.operation(nickname="addTrustIndicatorRecord")
+ def post(self, scenario):
+ """
+ @description: add a new trust indicator record
+ @notes: add a new trust indicator record to a project
+ POST /api/v1/scenarios/<scenario_name>/trust_indicators? \
+ installer=<installer_name>& \
+ version=<version_name>& \
+ project=<project_name>
+ @param body: trust indicator to be added
+ @type body: L{ScenarioTI}
+ @in body: body
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: True
+ @param version: version
+ @type version: L{string}
+ @in version: query
+ @required version: True
+ @param project: project name
+ @type project: L{string}
+ @in project: query
+ @required project: True
+ @return 200: trust indicator is added.
+ @raise 404: scenario/installer/version/project not existed
+ """
+ self.do_update('trust_indicators',
+ 'post',
+ locators={'scenario': scenario,
+ 'installer': None,
+ 'version': None,
+ 'project': None})
+
+
+class ScenarioCustomsHandler(GenericScenarioUpdateHandler):
+ @swagger.operation(nickname="addCustomizedTestCases")
+ def post(self, scenario):
+ """
+ @description: add customized test cases
+ @notes: add several test cases to a project
+ POST /api/v1/scenarios/<scenario_name>/customs? \
+ installer=<installer_name>& \
+ version=<version_name>& \
+ project=<project_name>
+ @param body: test cases to be added
+ @type body: C{list} of L{string}
+ @in body: body
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: True
+ @param version: version
+ @type version: L{string}
+ @in version: query
+ @required version: True
+ @param project: project name
+ @type project: L{string}
+ @in project: query
+ @required project: True
+ @return 200: test cases are added.
+ @raise 404: scenario/installer/version/project not existed
+ """
+ self.do_update('customs',
+ 'post',
+ locators={'scenario': scenario,
+ 'installer': None,
+ 'version': None,
+ 'project': None})
+
+ @swagger.operation(nickname="updateCustomizedTestCases")
+ def put(self, scenario):
+ """
+ @description: update customized test cases
+ @notes: substitute all the customized test cases
+ PUT /api/v1/scenarios/<scenario_name>/customs? \
+ installer=<installer_name>& \
+ version=<version_name>& \
+ project=<project_name>
+ @param body: new supported test cases
+ @type body: C{list} of L{string}
+ @in body: body
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: True
+ @param version: version
+ @type version: L{string}
+ @in version: query
+ @required version: True
+ @param project: project name
+ @type project: L{string}
+ @in project: query
+ @required project: True
+ @return 200: substitute test cases success.
+ @raise 404: scenario/installer/version/project not existed
+ """
+ self.do_update('customs',
+ 'put',
+ locators={'scenario': scenario,
+ 'installer': None,
+ 'version': None,
+ 'project': None})
+
+ @swagger.operation(nickname="deleteCustomizedTestCases")
+ def delete(self, scenario):
+ """
+ @description: delete one or several customized test cases
+ @notes: delete one or some customized test cases
+ DELETE /api/v1/scenarios/<scenario_name>/customs? \
+ installer=<installer_name>& \
+ version=<version_name>& \
+ project=<project_name>
+ @param body: test case(s) to be deleted
+ @type body: C{list} of L{string}
+ @in body: body
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: True
+ @param version: version
+ @type version: L{string}
+ @in version: query
+ @required version: True
+ @param project: project name
+ @type project: L{string}
+ @in project: query
+ @required project: True
+ @return 200: delete test case(s) success.
+ @raise 404: scenario/installer/version/project not existed
+ """
+ self.do_update('customs',
+ 'delete',
+ locators={'scenario': scenario,
+ 'installer': None,
+ 'version': None,
+ 'project': None})
- @property
- def _op(self):
- return self.json_args.get('op')
- @property
- def _locate(self):
- return self.json_args.get('locate')
+class ScenarioProjectsHandler(GenericScenarioUpdateHandler):
+ @swagger.operation(nickname="addProjectsUnderScenario")
+ def post(self, scenario):
+ """
+ @description: add projects to scenario
+ @notes: add one or multiple projects
+ POST /api/v1/scenarios/<scenario_name>/projects? \
+ installer=<installer_name>& \
+ version=<version_name>
+ @param body: projects to be added
+ @type body: C{list} of L{ScenarioProject}
+ @in body: body
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: True
+ @param version: version
+ @type version: L{string}
+ @in version: query
+ @required version: True
+ @return 200: projects are added.
+ @raise 400: bad schema
+ @raise 409: conflict, project already exists
+ @raise 404: scenario/installer/version not existed
+ """
+ self.do_update('projects',
+ 'post',
+ locators={'scenario': scenario,
+ 'installer': None,
+ 'version': None})
+
+ @swagger.operation(nickname="updateScenarioProjects")
+ def put(self, scenario):
+ """
+ @description: replace all projects
+ @notes: substitute all projects, delete existed ones with new provides
+ PUT /api/v1/scenarios/<scenario_name>/projects? \
+ installer=<installer_name>& \
+ version=<version_name>
+ @param body: new projects
+ @type body: C{list} of L{ScenarioProject}
+ @in body: body
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: True
+ @param version: version
+ @type version: L{string}
+ @in version: query
+ @required version: True
+ @return 200: replace projects success.
+ @raise 400: bad schema
+ @raise 404: scenario/installer/version not existed
+ """
+ self.do_update('projects',
+ 'put',
+ locators={'scenario': scenario,
+ 'installer': None,
+ 'version': None})
+
+ @swagger.operation(nickname="deleteProjectsUnderScenario")
+ def delete(self, scenario):
+ """
+ @description: delete one or multiple projects
+ @notes: delete one or multiple projects
+ DELETE /api/v1/scenarios/<scenario_name>/projects? \
+ installer=<installer_name>& \
+ version=<version_name>
+ @param body: projects(names) to be deleted
+ @type body: C{list} of L{string}
+ @in body: body
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: True
+ @param version: version
+ @type version: L{string}
+ @in version: query
+ @required version: True
+ @return 200: delete project(s) success.
+ @raise 404: scenario/installer/version not existed
+ """
+ self.do_update('projects',
+ 'delete',
+ locators={'scenario': scenario,
+ 'installer': None,
+ 'version': None})
- @property
- def _term(self):
- return self.json_args.get('term')
+
+class ScenarioOwnerHandler(GenericScenarioUpdateHandler):
+ @swagger.operation(nickname="changeScenarioOwner")
+ def put(self, scenario):
+ """
+ @description: change scenario owner
+ @notes: substitute all projects, delete existed ones with new provides
+ PUT /api/v1/scenarios/<scenario_name>/owner? \
+ installer=<installer_name>& \
+ version=<version_name>
+ @param body: new owner
+ @type body: L{ScenarioChangeOwnerRequest}
+ @in body: body
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: True
+ @param version: version
+ @type version: L{string}
+ @in version: query
+ @required version: True
+ @return 200: change owner success.
+ @raise 404: scenario/installer/version not existed
+ """
+ self.do_update('owner',
+ 'put',
+ locators={'scenario': scenario,
+ 'installer': None,
+ 'version': None})
+
+
+class ScenarioVersionsHandler(GenericScenarioUpdateHandler):
+ @swagger.operation(nickname="addVersionsUnderScenario")
+ def post(self, scenario):
+ """
+ @description: add versions to scenario
+ @notes: add one or multiple versions
+ POST /api/v1/scenarios/<scenario_name>/versions? \
+ installer=<installer_name>
+ @param body: versions to be added
+ @type body: C{list} of L{ScenarioVersion}
+ @in body: body
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: True
+ @return 200: versions are added.
+ @raise 400: bad schema
+ @raise 409: conflict, version already exists
+ @raise 404: scenario/installer not exist
+ """
+ self.do_update('versions',
+ 'post',
+ locators={'scenario': scenario,
+ 'installer': None})
+
+ @swagger.operation(nickname="updateVersionsUnderScenario")
+ def put(self, scenario):
+ """
+ @description: replace all versions
+ @notes: substitute all versions as a totality
+ PUT /api/v1/scenarios/<scenario_name>/versions? \
+ installer=<installer_name>
+ @param body: new versions
+ @type body: C{list} of L{ScenarioVersion}
+ @in body: body
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: True
+ @return 200: replace versions success.
+ @raise 400: bad schema
+ @raise 404: scenario/installer not exist
+ """
+ self.do_update('versions',
+ 'put',
+ locators={'scenario': scenario,
+ 'installer': None})
+
+ @swagger.operation(nickname="deleteVersionsUnderScenario")
+ def delete(self, scenario):
+ """
+ @description: delete one or multiple versions
+ @notes: delete one or multiple versions
+ DELETE /api/v1/scenarios/<scenario_name>/versions? \
+ installer=<installer_name>
+ @param body: versions(names) to be deleted
+ @type body: C{list} of L{string}
+ @in body: body
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: True
+ @return 200: delete versions success.
+ @raise 404: scenario/installer not exist
+ """
+ self.do_update('versions',
+ 'delete',
+ locators={'scenario': scenario,
+ 'installer': None})
+
+
+class ScenarioInstallersHandler(GenericScenarioUpdateHandler):
+ @swagger.operation(nickname="addInstallersUnderScenario")
+ def post(self, scenario):
+ """
+ @description: add installers to scenario
+ @notes: add one or multiple installers
+ POST /api/v1/scenarios/<scenario_name>/installers
+ @param body: installers to be added
+ @type body: C{list} of L{ScenarioInstaller}
+ @in body: body
+ @return 200: installers are added.
+ @raise 400: bad schema
+ @raise 409: conflict, installer already exists
+ @raise 404: scenario not exist
+ """
+ self.do_update('installers',
+ 'post',
+ locators={'scenario': scenario})
+
+ @swagger.operation(nickname="updateInstallersUnderScenario")
+ def put(self, scenario):
+ """
+ @description: replace all installers
+ @notes: substitute all installers as a totality
+ PUT /api/v1/scenarios/<scenario_name>/installers
+ @param body: new installers
+ @type body: C{list} of L{ScenarioInstaller}
+ @in body: body
+ @return 200: replace versions success.
+ @raise 400: bad schema
+ @raise 404: scenario/installer not exist
+ """
+ self.do_update('installers',
+ 'put',
+ locators={'scenario': scenario})
+
+ @swagger.operation(nickname="deleteInstallersUnderScenario")
+ def delete(self, scenario):
+ """
+ @description: delete one or multiple installers
+ @notes: delete one or multiple installers
+ DELETE /api/v1/scenarios/<scenario_name>/installers
+ @param body: installers(names) to be deleted
+ @type body: C{list} of L{string}
+ @in body: body
+ @return 200: delete versions success.
+ @raise 404: scenario/installer not exist
+ """
+ self.do_update('installers',
+ 'delete',
+ locators={'scenario': scenario})
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
index 467cff241..d950ed1d7 100644
--- a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
+++ b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
@@ -16,6 +16,13 @@ class ScenarioTI(models.ModelBase):
self.date = date
self.status = status
+ def __eq__(self, other):
+ return (self.date == other.date and
+ self.status == other.status)
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
@swagger.model()
class ScenarioScore(models.ModelBase):
@@ -23,6 +30,13 @@ class ScenarioScore(models.ModelBase):
self.date = date
self.score = score
+ def __eq__(self, other):
+ return (self.date == other.date and
+ self.score == other.score)
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
@swagger.model()
class ScenarioProject(models.ModelBase):
@@ -50,10 +64,10 @@ class ScenarioProject(models.ModelBase):
'trust_indicators': ScenarioTI}
def __eq__(self, other):
- return [self.project == other.project and
+ return (self.project == other.project and
self._customs_eq(other) and
self._scores_eq(other) and
- self._ti_eq(other)]
+ self._ti_eq(other))
def __ne__(self, other):
return not self.__eq__(other)
@@ -62,10 +76,10 @@ class ScenarioProject(models.ModelBase):
return set(self.customs) == set(other.customs)
def _scores_eq(self, other):
- return set(self.scores) == set(other.scores)
+ return self.scores == other.scores
def _ti_eq(self, other):
- return set(self.trust_indicators) == set(other.trust_indicators)
+ return self.trust_indicators == other.trust_indicators
@swagger.model()
@@ -74,7 +88,8 @@ class ScenarioVersion(models.ModelBase):
@property projects:
@ptype projects: C{list} of L{ScenarioProject}
"""
- def __init__(self, version=None, projects=None):
+ def __init__(self, owner=None, version=None, projects=None):
+ self.owner = owner
self.version = version
self.projects = list_default(projects)
@@ -83,7 +98,9 @@ class ScenarioVersion(models.ModelBase):
return {'projects': ScenarioProject}
def __eq__(self, other):
- return [self.version == other.version and self._projects_eq(other)]
+ return (self.version == other.version and
+ self.owner == other.owner and
+ self._projects_eq(other))
def __ne__(self, other):
return not self.__eq__(other)
@@ -113,7 +130,7 @@ class ScenarioInstaller(models.ModelBase):
return {'versions': ScenarioVersion}
def __eq__(self, other):
- return [self.installer == other.installer and self._versions_eq(other)]
+ return (self.installer == other.installer and self._versions_eq(other))
def __ne__(self, other):
return not self.__eq__(other)
@@ -144,18 +161,15 @@ class ScenarioCreateRequest(models.ModelBase):
@swagger.model()
+class ScenarioChangeOwnerRequest(models.ModelBase):
+ def __init__(self, owner=None):
+ self.owner = owner
+
+
+@swagger.model()
class ScenarioUpdateRequest(models.ModelBase):
- """
- @property field: update field
- @property op: add/delete/update
- @property locate: information used to locate the field
- @property term: new value
- """
- def __init__(self, field=None, op=None, locate=None, term=None):
- self.field = field
- self.op = op
- self.locate = dict_default(locate)
- self.term = dict_default(term)
+ def __init__(self, name=None):
+ self.name = name
@swagger.model()
@@ -178,7 +192,7 @@ class Scenario(models.ModelBase):
return not self.__eq__(other)
def __eq__(self, other):
- return [self.name == other.name and self._installers_eq(other)]
+ return (self.name == other.name and self._installers_eq(other))
def _installers_eq(self, other):
for s_install in self.installers:
diff --git a/utils/test/testapi/opnfv_testapi/router/url_mappings.py b/utils/test/testapi/opnfv_testapi/router/url_mappings.py
index 562fa5efe..ce0a3eeb3 100644
--- a/utils/test/testapi/opnfv_testapi/router/url_mappings.py
+++ b/utils/test/testapi/opnfv_testapi/router/url_mappings.py
@@ -54,16 +54,30 @@ mappings = [
# scenarios
(r"/api/v1/scenarios", scenario_handlers.ScenariosCLHandler),
(r"/api/v1/scenarios/([^/]+)", scenario_handlers.ScenarioGURHandler),
+ (r"/api/v1/scenarios/([^/]+)/scores",
+ scenario_handlers.ScenarioScoresHandler),
+ (r"/api/v1/scenarios/([^/]+)/trust_indicators",
+ scenario_handlers.ScenarioTIsHandler),
+ (r"/api/v1/scenarios/([^/]+)/customs",
+ scenario_handlers.ScenarioCustomsHandler),
+ (r"/api/v1/scenarios/([^/]+)/projects",
+ scenario_handlers.ScenarioProjectsHandler),
+ (r"/api/v1/scenarios/([^/]+)/owner",
+ scenario_handlers.ScenarioOwnerHandler),
+ (r"/api/v1/scenarios/([^/]+)/versions",
+ scenario_handlers.ScenarioVersionsHandler),
+ (r"/api/v1/scenarios/([^/]+)/installers",
+ scenario_handlers.ScenarioInstallersHandler),
# static path
(r'/(.*\.(css|png|gif|js|html|json|map|woff2|woff|ttf))',
tornado.web.StaticFileHandler,
- {'path': CONF.static_path}),
+ {'path': CONF.ui_static_path}),
(r'/', root.RootHandler),
(r'/api/v1/auth/signin', sign.SigninHandler),
- (r'/api/v1/auth/signin_return', sign.SigninReturnHandler),
+ (r'/{}'.format(CONF.lfid_signin_return), sign.SigninReturnHandler),
(r'/api/v1/auth/signout', sign.SignoutHandler),
- (r'/api/v1/profile', user.ProfileHandler),
+ (r'/api/v1/profile', user.UserHandler),
]
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/common/noparam.ini b/utils/test/testapi/opnfv_testapi/tests/unit/common/noparam.ini
deleted file mode 100644
index fda2a09e9..000000000
--- a/utils/test/testapi/opnfv_testapi/tests/unit/common/noparam.ini
+++ /dev/null
@@ -1,16 +0,0 @@
-# to add a new parameter in the config file,
-# the CONF object in config.ini must be updated
-[mongo]
-# URL of the mongo DB
-# Mongo auth url => mongodb://user1:pwd1@host1/?authSource=db1
-url = mongodb://127.0.0.1:27017/
-
-[api]
-# Listening port
-port = 8000
-# With debug_on set to true, error traces will be shown in HTTP responses
-debug = True
-authenticate = False
-
-[swagger]
-base_url = http://localhost:8000
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/common/normal.ini b/utils/test/testapi/opnfv_testapi/tests/unit/common/normal.ini
deleted file mode 100644
index 77cc6c6ee..000000000
--- a/utils/test/testapi/opnfv_testapi/tests/unit/common/normal.ini
+++ /dev/null
@@ -1,17 +0,0 @@
-# to add a new parameter in the config file,
-# the CONF object in config.ini must be updated
-[mongo]
-# URL of the mongo DB
-# Mongo auth url => mongodb://user1:pwd1@host1/?authSource=db1
-url = mongodb://127.0.0.1:27017/
-dbname = test_results_collection
-
-[api]
-# Listening port
-port = 8000
-# With debug_on set to true, error traces will be shown in HTTP responses
-debug = True
-authenticate = False
-
-[swagger]
-base_url = http://localhost:8000
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/common/nosection.ini b/utils/test/testapi/opnfv_testapi/tests/unit/common/nosection.ini
deleted file mode 100644
index 9988fc0a4..000000000
--- a/utils/test/testapi/opnfv_testapi/tests/unit/common/nosection.ini
+++ /dev/null
@@ -1,11 +0,0 @@
-# to add a new parameter in the config file,
-# the CONF object in config.ini must be updated
-[api]
-# Listening port
-port = 8000
-# With debug_on set to true, error traces will be shown in HTTP responses
-debug = True
-authenticate = False
-
-[swagger]
-base_url = http://localhost:8000
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/common/notboolean.ini b/utils/test/testapi/opnfv_testapi/tests/unit/common/notboolean.ini
deleted file mode 100644
index b3f327670..000000000
--- a/utils/test/testapi/opnfv_testapi/tests/unit/common/notboolean.ini
+++ /dev/null
@@ -1,17 +0,0 @@
-# to add a new parameter in the config file,
-# the CONF object in config.ini must be updated
-[mongo]
-# URL of the mongo DB
-# Mongo auth url => mongodb://user1:pwd1@host1/?authSource=db1
-url = mongodb://127.0.0.1:27017/
-dbname = test_results_collection
-
-[api]
-# Listening port
-port = 8000
-# With debug_on set to true, error traces will be shown in HTTP responses
-debug = True
-authenticate = notboolean
-
-[swagger]
-base_url = http://localhost:8000
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/common/notint.ini b/utils/test/testapi/opnfv_testapi/tests/unit/common/notint.ini
deleted file mode 100644
index d1b752a34..000000000
--- a/utils/test/testapi/opnfv_testapi/tests/unit/common/notint.ini
+++ /dev/null
@@ -1,17 +0,0 @@
-# to add a new parameter in the config file,
-# the CONF object in config.ini must be updated
-[mongo]
-# URL of the mongo DB
-# Mongo auth url => mongodb://user1:pwd1@host1/?authSource=db1
-url = mongodb://127.0.0.1:27017/
-dbname = test_results_collection
-
-[api]
-# Listening port
-port = notint
-# With debug_on set to true, error traces will be shown in HTTP responses
-debug = True
-authenticate = False
-
-[swagger]
-base_url = http://localhost:8000
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py b/utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py
index cc8743ca8..8cfc513be 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py
@@ -12,4 +12,4 @@ def test_config_normal(mocker, config_normal):
assert CONF.api_port == 8000
assert CONF.api_debug is True
assert CONF.api_authenticate is False
- assert CONF.swagger_base_url == 'http://localhost:8000'
+ assert CONF.ui_url == 'http://localhost:8000'
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/conftest.py b/utils/test/testapi/opnfv_testapi/tests/unit/conftest.py
index feff1daaa..75e621d0e 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/conftest.py
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/conftest.py
@@ -5,4 +5,4 @@ import pytest
@pytest.fixture
def config_normal():
- return path.join(path.dirname(__file__), 'common/normal.ini')
+ return path.join(path.dirname(__file__), '../../../etc/config.ini')
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/scenario-c2.json b/utils/test/testapi/opnfv_testapi/tests/unit/resources/scenario-c2.json
index b6a3b83ab..980051c4f 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/scenario-c2.json
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/resources/scenario-c2.json
@@ -8,7 +8,7 @@
[
{
"owner": "Lucky",
- "version": "colorado",
+ "version": "danube",
"projects":
[
{
@@ -29,7 +29,7 @@
"scores": [
{
"date": "2017-01-08 22:46:44",
- "score": "0"
+ "score": "0/1"
}
],
"trust_indicators": [
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_base.py b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_base.py
index dcec4e958..39633e5f5 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_base.py
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_base.py
@@ -37,7 +37,8 @@ class TestBase(testing.AsyncHTTPTestCase):
def _patch_server(self):
import argparse
- config = path.join(path.dirname(__file__), '../common/normal.ini')
+ config = path.join(path.dirname(__file__),
+ '../../../../etc/config.ini')
self.config_patcher = mock.patch(
'argparse.ArgumentParser.parse_known_args',
return_value=(argparse.Namespace(config_file=config), None))
@@ -46,9 +47,6 @@ class TestBase(testing.AsyncHTTPTestCase):
self.config_patcher.start()
self.db_patcher.start()
- def set_config_file(self):
- self.config_file = 'normal.ini'
-
def get_app(self):
from opnfv_testapi.cmd import server
return server.make_app()
@@ -63,9 +61,12 @@ class TestBase(testing.AsyncHTTPTestCase):
return self.create_help(self.basePath, req, *args)
def create_help(self, uri, req, *args):
+ return self.post_direct_url(self._update_uri(uri, *args), req)
+
+ def post_direct_url(self, url, req):
if req and not isinstance(req, str) and hasattr(req, 'format'):
req = req.format()
- res = self.fetch(self._update_uri(uri, *args),
+ res = self.fetch(url,
method='POST',
body=json.dumps(req),
headers=self.headers)
@@ -89,21 +90,35 @@ class TestBase(testing.AsyncHTTPTestCase):
headers=self.headers)
return self._get_return(res, self.list_res)
- def update(self, new=None, *args):
- if new:
+ def update_direct_url(self, url, new=None):
+ if new and hasattr(new, 'format'):
new = new.format()
- res = self.fetch(self._get_uri(*args),
+ res = self.fetch(url,
method='PUT',
body=json.dumps(new),
headers=self.headers)
return self._get_return(res, self.update_res)
- def delete(self, *args):
- res = self.fetch(self._get_uri(*args),
- method='DELETE',
- headers=self.headers)
+ def update(self, new=None, *args):
+ return self.update_direct_url(self._get_uri(*args), new)
+
+ def delete_direct_url(self, url, body):
+ if body:
+ res = self.fetch(url,
+ method='DELETE',
+ body=json.dumps(body),
+ headers=self.headers,
+ allow_nonstandard_methods=True)
+ else:
+ res = self.fetch(url,
+ method='DELETE',
+ headers=self.headers)
+
return res.code, res.body
+ def delete(self, *args):
+ return self.delete_direct_url(self._get_uri(*args), None)
+
@staticmethod
def _get_valid_args(*args):
new_args = tuple(['%s' % arg for arg in args if arg is not None])
@@ -129,7 +144,10 @@ class TestBase(testing.AsyncHTTPTestCase):
def _get_return(self, res, cls):
code = res.code
body = res.body
- return code, self._get_return_body(code, body, cls)
+ if body:
+ return code, self._get_return_body(code, body, cls)
+ else:
+ return code, None
@staticmethod
def _get_return_body(code, body, cls):
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py
index bd720671b..1367fc669 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py
@@ -2,14 +2,18 @@ import functools
import httplib
import json
import os
-from copy import deepcopy
+
from datetime import datetime
-import opnfv_testapi.resources.scenario_models as models
from opnfv_testapi.common import message
+import opnfv_testapi.resources.scenario_models as models
from opnfv_testapi.tests.unit.resources import test_base as base
+def _none_default(check, default):
+ return check if check else default
+
+
class TestScenarioBase(base.TestBase):
def setUp(self):
super(TestScenarioBase, self).setUp()
@@ -43,19 +47,18 @@ class TestScenarioBase(base.TestBase):
req = self.req_d
self.assertIsNotNone(scenario._id)
self.assertIsNotNone(scenario.creation_date)
-
- scenario == models.Scenario.from_dict(req)
+ self.assertEqual(scenario, models.Scenario.from_dict(req))
@staticmethod
- def _set_query(*args):
+ def set_query(*args):
uri = ''
for arg in args:
uri += arg + '&'
return uri[0: -1]
- def _get_and_assert(self, name, req=None):
+ def get_and_assert(self, name):
code, body = self.get(name)
- self.assert_res(code, body, req)
+ self.assert_res(code, body, self.req_d)
class TestScenarioCreate(TestScenarioBase):
@@ -94,34 +97,35 @@ class TestScenarioGet(TestScenarioBase):
self.scenario_2 = self.create_return_name(self.req_2)
def test_getByName(self):
- self._get_and_assert(self.scenario_1, self.req_d)
+ self.get_and_assert(self.scenario_1)
def test_getAll(self):
self._query_and_assert(query=None, reqs=[self.req_d, self.req_2])
def test_queryName(self):
- query = self._set_query('name=nosdn-nofeature-ha')
+ query = self.set_query('name=nosdn-nofeature-ha')
self._query_and_assert(query, reqs=[self.req_d])
def test_queryInstaller(self):
- query = self._set_query('installer=apex')
+ query = self.set_query('installer=apex')
self._query_and_assert(query, reqs=[self.req_d])
def test_queryVersion(self):
- query = self._set_query('version=master')
+ query = self.set_query('version=master')
self._query_and_assert(query, reqs=[self.req_d])
def test_queryProject(self):
- query = self._set_query('project=functest')
+ query = self.set_query('project=functest')
self._query_and_assert(query, reqs=[self.req_d, self.req_2])
- def test_queryCombination(self):
- query = self._set_query('name=nosdn-nofeature-ha',
- 'installer=apex',
- 'version=master',
- 'project=functest')
-
- self._query_and_assert(query, reqs=[self.req_d])
+ # close due to random fail, open again after solve it in another patch
+ # def test_queryCombination(self):
+ # query = self._set_query('name=nosdn-nofeature-ha',
+ # 'installer=apex',
+ # 'version=master',
+ # 'project=functest')
+ #
+ # self._query_and_assert(query, reqs=[self.req_d])
def _query_and_assert(self, query, found=True, reqs=None):
code, body = self.query(query)
@@ -136,225 +140,310 @@ class TestScenarioGet(TestScenarioBase):
self.assert_res(code, scenario, req)
+class TestScenarioDelete(TestScenarioBase):
+ def test_notFound(self):
+ code, body = self.delete('notFound')
+ self.assertEqual(code, httplib.NOT_FOUND)
+
+ def test_success(self):
+ scenario = self.create_return_name(self.req_d)
+ code, _ = self.delete(scenario)
+ self.assertEqual(code, httplib.OK)
+ code, _ = self.get(scenario)
+ self.assertEqual(code, httplib.NOT_FOUND)
+
+
class TestScenarioUpdate(TestScenarioBase):
def setUp(self):
super(TestScenarioUpdate, self).setUp()
self.scenario = self.create_return_name(self.req_d)
self.scenario_2 = self.create_return_name(self.req_2)
-
- def _execute(set_update):
- @functools.wraps(set_update)
- def magic(self):
- update, scenario = set_update(self, deepcopy(self.req_d))
- self._update_and_assert(update, scenario)
- return magic
-
- def _update(expected):
- def _update(set_update):
+ self.update_url = ''
+ self.scenario_url = '/api/v1/scenarios/{}'.format(self.scenario)
+ self.installer = self.req_d['installers'][0]['installer']
+ self.version = self.req_d['installers'][0]['versions'][0]['version']
+ self.locate_project = 'installer={}&version={}&project={}'.format(
+ self.installer,
+ self.version,
+ 'functest')
+
+ def update_url_fixture(item):
+ def _update_url_fixture(xstep):
+ def wrapper(self, *args, **kwargs):
+ self.update_url = '{}/{}'.format(self.scenario_url, item)
+ locator = None
+ if item in ['projects', 'owner']:
+ locator = 'installer={}&version={}'.format(
+ self.installer,
+ self.version)
+ elif item in ['versions']:
+ locator = 'installer={}'.format(
+ self.installer)
+ elif item in ['rename']:
+ self.update_url = self.scenario_url
+
+ if locator:
+ self.update_url = '{}?{}'.format(self.update_url, locator)
+
+ xstep(self, *args, **kwargs)
+ return wrapper
+ return _update_url_fixture
+
+ def update_partial(operate, expected):
+ def _update_partial(set_update):
@functools.wraps(set_update)
- def wrap(self):
- update, scenario = set_update(self, deepcopy(self.req_d))
- code, body = self.update(update, self.scenario)
- getattr(self, expected)(code, scenario)
- return wrap
- return _update
-
- @_update('_success')
- def test_renameScenario(self, scenario):
- new_name = 'nosdn-nofeature-noha'
- scenario['name'] = new_name
- update_req = models.ScenarioUpdateRequest(field='name',
- op='update',
- locate={},
- term={'name': new_name})
- return update_req, scenario
-
- @_update('_forbidden')
- def test_renameScenario_exist(self, scenario):
- new_name = self.scenario_2
- scenario['name'] = new_name
- update_req = models.ScenarioUpdateRequest(field='name',
- op='update',
- locate={},
- term={'name': new_name})
- return update_req, scenario
-
- @_update('_bad_request')
- def test_renameScenario_noName(self, scenario):
- new_name = self.scenario_2
- scenario['name'] = new_name
- update_req = models.ScenarioUpdateRequest(field='name',
- op='update',
- locate={},
- term={})
- return update_req, scenario
-
- @_execute
- def test_addInstaller(self, scenario):
- add = models.ScenarioInstaller(installer='daisy', versions=list())
- scenario['installers'].append(add.format())
- update = models.ScenarioUpdateRequest(field='installer',
- op='add',
- locate={},
- term=add.format())
- return update, scenario
-
- @_execute
- def test_deleteInstaller(self, scenario):
- scenario['installers'] = filter(lambda f: f['installer'] != 'apex',
- scenario['installers'])
-
- update = models.ScenarioUpdateRequest(field='installer',
- op='delete',
- locate={'installer': 'apex'})
- return update, scenario
-
- @_execute
- def test_addVersion(self, scenario):
- add = models.ScenarioVersion(version='danube', projects=list())
- scenario['installers'][0]['versions'].append(add.format())
- update = models.ScenarioUpdateRequest(field='version',
- op='add',
- locate={'installer': 'apex'},
- term=add.format())
- return update, scenario
-
- @_execute
- def test_deleteVersion(self, scenario):
- scenario['installers'][0]['versions'] = filter(
- lambda f: f['version'] != 'master',
- scenario['installers'][0]['versions'])
-
- update = models.ScenarioUpdateRequest(field='version',
- op='delete',
- locate={'installer': 'apex',
- 'version': 'master'})
- return update, scenario
-
- @_execute
- def test_changeOwner(self, scenario):
- scenario['installers'][0]['versions'][0]['owner'] = 'lucy'
-
- update = models.ScenarioUpdateRequest(field='owner',
- op='update',
- locate={'installer': 'apex',
- 'version': 'master'},
- term={'owner': 'lucy'})
- return update, scenario
-
- @_execute
- def test_addProject(self, scenario):
- add = models.ScenarioProject(project='qtip').format()
- scenario['installers'][0]['versions'][0]['projects'].append(add)
- update = models.ScenarioUpdateRequest(field='project',
- op='add',
- locate={'installer': 'apex',
- 'version': 'master'},
- term=add)
- return update, scenario
-
- @_execute
- def test_deleteProject(self, scenario):
- scenario['installers'][0]['versions'][0]['projects'] = filter(
- lambda f: f['project'] != 'functest',
- scenario['installers'][0]['versions'][0]['projects'])
-
- update = models.ScenarioUpdateRequest(field='project',
- op='delete',
- locate={
- 'installer': 'apex',
- 'version': 'master',
- 'project': 'functest'})
- return update, scenario
-
- @_execute
- def test_addCustoms(self, scenario):
- add = ['odl', 'parser', 'vping_ssh']
- projects = scenario['installers'][0]['versions'][0]['projects']
- functest = filter(lambda f: f['project'] == 'functest', projects)[0]
- functest['customs'] = ['healthcheck', 'odl', 'parser', 'vping_ssh']
- update = models.ScenarioUpdateRequest(field='customs',
- op='add',
- locate={
- 'installer': 'apex',
- 'version': 'master',
- 'project': 'functest'},
- term=add)
- return update, scenario
-
- @_execute
- def test_deleteCustoms(self, scenario):
- projects = scenario['installers'][0]['versions'][0]['projects']
- functest = filter(lambda f: f['project'] == 'functest', projects)[0]
- functest['customs'] = ['healthcheck']
- update = models.ScenarioUpdateRequest(field='customs',
- op='delete',
- locate={
- 'installer': 'apex',
- 'version': 'master',
- 'project': 'functest'},
- term=['vping_ssh'])
- return update, scenario
-
- @_execute
- def test_addScore(self, scenario):
+ def wrapper(self):
+ update = set_update(self)
+ code, body = getattr(self, operate)(update)
+ getattr(self, expected)(code)
+ return wrapper
+ return _update_partial
+
+ @update_partial('_add', '_success')
+ def test_addScore(self):
add = models.ScenarioScore(date=str(datetime.now()), score='11/12')
- projects = scenario['installers'][0]['versions'][0]['projects']
+ projects = self.req_d['installers'][0]['versions'][0]['projects']
functest = filter(lambda f: f['project'] == 'functest', projects)[0]
functest['scores'].append(add.format())
- update = models.ScenarioUpdateRequest(field='score',
- op='add',
- locate={
- 'installer': 'apex',
- 'version': 'master',
- 'project': 'functest'},
- term=add.format())
- return update, scenario
-
- @_execute
- def test_addTi(self, scenario):
+ self.update_url = '{}/scores?{}'.format(self.scenario_url,
+ self.locate_project)
+
+ return add
+
+ @update_partial('_add', '_success')
+ def test_addTrustIndicator(self):
add = models.ScenarioTI(date=str(datetime.now()), status='gold')
- projects = scenario['installers'][0]['versions'][0]['projects']
+ projects = self.req_d['installers'][0]['versions'][0]['projects']
functest = filter(lambda f: f['project'] == 'functest', projects)[0]
functest['trust_indicators'].append(add.format())
- update = models.ScenarioUpdateRequest(field='trust_indicator',
- op='add',
- locate={
- 'installer': 'apex',
- 'version': 'master',
- 'project': 'functest'},
- term=add.format())
- return update, scenario
-
- def _update_and_assert(self, update_req, new_scenario, name=None):
- code, _ = self.update(update_req, self.scenario)
- self.assertEqual(code, httplib.OK)
- self._get_and_assert(_none_default(name, self.scenario),
- new_scenario)
+ self.update_url = '{}/trust_indicators?{}'.format(self.scenario_url,
+ self.locate_project)
- def _success(self, status, new_scenario):
- self.assertEqual(status, httplib.OK)
- self._get_and_assert(new_scenario.get('name'), new_scenario)
+ return add
- def _forbidden(self, status, new_scenario):
- self.assertEqual(status, httplib.FORBIDDEN)
+ @update_partial('_add', '_success')
+ def test_addCustoms(self):
+ adds = ['odl', 'parser', 'vping_ssh']
+ projects = self.req_d['installers'][0]['versions'][0]['projects']
+ functest = filter(lambda f: f['project'] == 'functest', projects)[0]
+ functest['customs'] = list(set(functest['customs'] + adds))
+ self.update_url = '{}/customs?{}'.format(self.scenario_url,
+ self.locate_project)
+ return adds
+
+ @update_partial('_update', '_success')
+ def test_updateCustoms(self):
+ updates = ['odl', 'parser', 'vping_ssh']
+ projects = self.req_d['installers'][0]['versions'][0]['projects']
+ functest = filter(lambda f: f['project'] == 'functest', projects)[0]
+ functest['customs'] = updates
+ self.update_url = '{}/customs?{}'.format(self.scenario_url,
+ self.locate_project)
- def _bad_request(self, status, new_scenario):
- self.assertEqual(status, httplib.BAD_REQUEST)
+ return updates
+ @update_partial('_delete', '_success')
+ def test_deleteCustoms(self):
+ deletes = ['vping_ssh']
+ projects = self.req_d['installers'][0]['versions'][0]['projects']
+ functest = filter(lambda f: f['project'] == 'functest', projects)[0]
+ functest['customs'] = ['healthcheck']
+ self.update_url = '{}/customs?{}'.format(self.scenario_url,
+ self.locate_project)
-class TestScenarioDelete(TestScenarioBase):
- def test_notFound(self):
- code, body = self.delete('notFound')
- self.assertEqual(code, httplib.NOT_FOUND)
+ return deletes
- def test_success(self):
- scenario = self.create_return_name(self.req_d)
- code, _ = self.delete(scenario)
- self.assertEqual(code, httplib.OK)
- code, _ = self.get(scenario)
- self.assertEqual(code, httplib.NOT_FOUND)
+ @update_url_fixture('projects')
+ @update_partial('_add', '_success')
+ def test_addProjects_succ(self):
+ add = models.ScenarioProject(project='qtip').format()
+ self.req_d['installers'][0]['versions'][0]['projects'].append(add)
+ return [add]
+
+ @update_url_fixture('projects')
+ @update_partial('_add', '_conflict')
+ def test_addProjects_already_exist(self):
+ add = models.ScenarioProject(project='functest').format()
+ return [add]
+
+ @update_url_fixture('projects')
+ @update_partial('_add', '_bad_request')
+ def test_addProjects_bad_schema(self):
+ add = models.ScenarioProject(project='functest').format()
+ add['score'] = None
+ return [add]
+
+ @update_url_fixture('projects')
+ @update_partial('_update', '_success')
+ def test_updateProjects_succ(self):
+ update = models.ScenarioProject(project='qtip').format()
+ self.req_d['installers'][0]['versions'][0]['projects'] = [update]
+ return [update]
+
+ @update_url_fixture('projects')
+ @update_partial('_update', '_conflict')
+ def test_updateProjects_duplicated(self):
+ update = models.ScenarioProject(project='qtip').format()
+ return [update, update]
+
+ @update_url_fixture('projects')
+ @update_partial('_update', '_bad_request')
+ def test_updateProjects_bad_schema(self):
+ update = models.ScenarioProject(project='functest').format()
+ update['score'] = None
+ return [update]
+
+ @update_url_fixture('projects')
+ @update_partial('_delete', '_success')
+ def test_deleteProjects(self):
+ deletes = ['functest']
+ projects = self.req_d['installers'][0]['versions'][0]['projects']
+ self.req_d['installers'][0]['versions'][0]['projects'] = filter(
+ lambda f: f['project'] != 'functest',
+ projects)
+ return deletes
+
+ @update_url_fixture('owner')
+ @update_partial('_update', '_success')
+ def test_changeOwner(self):
+ new_owner = 'new_owner'
+ update = models.ScenarioChangeOwnerRequest(new_owner).format()
+ self.req_d['installers'][0]['versions'][0]['owner'] = new_owner
+ return update
+
+ @update_url_fixture('versions')
+ @update_partial('_add', '_success')
+ def test_addVersions_succ(self):
+ add = models.ScenarioVersion(version='Euphrates').format()
+ self.req_d['installers'][0]['versions'].append(add)
+ return [add]
+
+ @update_url_fixture('versions')
+ @update_partial('_add', '_conflict')
+ def test_addVersions_already_exist(self):
+ add = models.ScenarioVersion(version='master').format()
+ return [add]
+
+ @update_url_fixture('versions')
+ @update_partial('_add', '_bad_request')
+ def test_addVersions_bad_schema(self):
+ add = models.ScenarioVersion(version='euphrates').format()
+ add['notexist'] = None
+ return [add]
+
+ @update_url_fixture('versions')
+ @update_partial('_update', '_success')
+ def test_updateVersions_succ(self):
+ update = models.ScenarioVersion(version='euphrates').format()
+ self.req_d['installers'][0]['versions'] = [update]
+ return [update]
+
+ @update_url_fixture('versions')
+ @update_partial('_update', '_conflict')
+ def test_updateVersions_duplicated(self):
+ update = models.ScenarioVersion(version='euphrates').format()
+ return [update, update]
+
+ @update_url_fixture('versions')
+ @update_partial('_update', '_bad_request')
+ def test_updateVersions_bad_schema(self):
+ update = models.ScenarioVersion(version='euphrates').format()
+ update['not_owner'] = 'Iam'
+ return [update]
+
+ @update_url_fixture('versions')
+ @update_partial('_delete', '_success')
+ def test_deleteVersions(self):
+ deletes = ['master']
+ versions = self.req_d['installers'][0]['versions']
+ self.req_d['installers'][0]['versions'] = filter(
+ lambda f: f['version'] != 'master',
+ versions)
+ return deletes
+
+ @update_url_fixture('installers')
+ @update_partial('_add', '_success')
+ def test_addInstallers_succ(self):
+ add = models.ScenarioInstaller(installer='daisy').format()
+ self.req_d['installers'].append(add)
+ return [add]
+
+ @update_url_fixture('installers')
+ @update_partial('_add', '_conflict')
+ def test_addInstallers_already_exist(self):
+ add = models.ScenarioInstaller(installer='apex').format()
+ return [add]
+
+ @update_url_fixture('installers')
+ @update_partial('_add', '_bad_request')
+ def test_addInstallers_bad_schema(self):
+ add = models.ScenarioInstaller(installer='daisy').format()
+ add['not_exist'] = 'not_exist'
+ return [add]
+
+ @update_url_fixture('installers')
+ @update_partial('_update', '_success')
+ def test_updateInstallers_succ(self):
+ update = models.ScenarioInstaller(installer='daisy').format()
+ self.req_d['installers'] = [update]
+ return [update]
+
+ @update_url_fixture('installers')
+ @update_partial('_update', '_conflict')
+ def test_updateInstallers_duplicated(self):
+ update = models.ScenarioInstaller(installer='daisy').format()
+ return [update, update]
+
+ @update_url_fixture('installers')
+ @update_partial('_update', '_bad_request')
+ def test_updateInstallers_bad_schema(self):
+ update = models.ScenarioInstaller(installer='daisy').format()
+ update['not_exist'] = 'not_exist'
+ return [update]
+
+ @update_url_fixture('installers')
+ @update_partial('_delete', '_success')
+ def test_deleteInstallers(self):
+ deletes = ['apex']
+ installers = self.req_d['installers']
+ self.req_d['installers'] = filter(
+ lambda f: f['installer'] != 'apex',
+ installers)
+ return deletes
+
+ @update_url_fixture('rename')
+ @update_partial('_update', '_success')
+ def test_renameScenario(self):
+ new_name = 'new_scenario_name'
+ update = models.ScenarioUpdateRequest(name=new_name)
+ self.req_d['name'] = new_name
+ return update
+
+ @update_url_fixture('rename')
+ @update_partial('_update', '_forbidden')
+ def test_renameScenario_exist(self):
+ new_name = self.req_d['name']
+ update = models.ScenarioUpdateRequest(name=new_name)
+ return update
+
+ def _add(self, update_req):
+ return self.post_direct_url(self.update_url, update_req)
+
+ def _update(self, update_req):
+ return self.update_direct_url(self.update_url, update_req)
+
+ def _delete(self, update_req):
+ return self.delete_direct_url(self.update_url, update_req)
+
+ def _success(self, status):
+ self.assertEqual(status, httplib.OK)
+ self.get_and_assert(self.req_d['name'])
+ def _forbidden(self, status):
+ self.assertEqual(status, httplib.FORBIDDEN)
-def _none_default(check, default):
- return check if check else default
+ def _bad_request(self, status):
+ self.assertEqual(status, httplib.BAD_REQUEST)
+
+ def _conflict(self, status):
+ self.assertEqual(status, httplib.CONFLICT)
diff --git a/utils/test/testapi/opnfv_testapi/tornado_swagger/swagger.py b/utils/test/testapi/opnfv_testapi/tornado_swagger/swagger.py
index 83f389a6b..6125c9554 100644
--- a/utils/test/testapi/opnfv_testapi/tornado_swagger/swagger.py
+++ b/utils/test/testapi/opnfv_testapi/tornado_swagger/swagger.py
@@ -94,11 +94,18 @@ class DocParser(object):
def _parse_type(self, **kwargs):
arg = kwargs.get('arg', None)
- body = self._get_body(**kwargs)
- self.params.setdefault(arg, {}).update({
- 'name': arg,
- 'dataType': body
- })
+ code = self._parse_epytext_para('code', **kwargs)
+ link = self._parse_epytext_para('link', **kwargs)
+ if code is None:
+ self.params.setdefault(arg, {}).update({
+ 'name': arg,
+ 'type': link
+ })
+ elif code == 'list':
+ self.params.setdefault(arg, {}).update({
+ 'type': 'array',
+ 'items': {'type': link}
+ })
def _parse_in(self, **kwargs):
arg = kwargs.get('arg', None)
diff --git a/utils/test/testapi/opnfv_testapi/ui/auth/base.py b/utils/test/testapi/opnfv_testapi/ui/auth/base.py
deleted file mode 100644
index bea87c4d9..000000000
--- a/utils/test/testapi/opnfv_testapi/ui/auth/base.py
+++ /dev/null
@@ -1,35 +0,0 @@
-import random
-import string
-
-from six.moves.urllib import parse
-
-from opnfv_testapi.resources import handlers
-
-
-class BaseHandler(handlers.GenericApiHandler):
- def __init__(self, application, request, **kwargs):
- super(BaseHandler, self).__init__(application, request, **kwargs)
- self.table = 'users'
-
- def set_cookies(self, cookies):
- for cookie_n, cookie_v in cookies:
- self.set_secure_cookie(cookie_n, cookie_v)
-
-
-def get_token(length=30):
- """Get random token."""
- return ''.join(random.choice(string.ascii_lowercase)
- for i in range(length))
-
-
-def set_query_params(url, params):
- """Set params in given query."""
- url_parts = parse.urlparse(url)
- url = parse.urlunparse((
- url_parts.scheme,
- url_parts.netloc,
- url_parts.path,
- url_parts.params,
- parse.urlencode(params),
- url_parts.fragment))
- return url
diff --git a/utils/test/testapi/opnfv_testapi/ui/auth/constants.py b/utils/test/testapi/opnfv_testapi/ui/auth/constants.py
deleted file mode 100644
index 44ccb46d7..000000000
--- a/utils/test/testapi/opnfv_testapi/ui/auth/constants.py
+++ /dev/null
@@ -1,18 +0,0 @@
-OPENID = 'openid'
-ROLE = 'role'
-DEFAULT_ROLE = 'user'
-
-# OpenID parameters
-OPENID_MODE = 'openid.mode'
-OPENID_NS = 'openid.ns'
-OPENID_RETURN_TO = 'openid.return_to'
-OPENID_CLAIMED_ID = 'openid.claimed_id'
-OPENID_IDENTITY = 'openid.identity'
-OPENID_REALM = 'openid.realm'
-OPENID_NS_SREG = 'openid.ns.sreg'
-OPENID_NS_SREG_REQUIRED = 'openid.sreg.required'
-OPENID_NS_SREG_EMAIL = 'openid.sreg.email'
-OPENID_NS_SREG_FULLNAME = 'openid.sreg.fullname'
-OPENID_ERROR = 'openid.error'
-
-CSRF_TOKEN = 'csrf_token'
diff --git a/utils/test/testapi/opnfv_testapi/ui/auth/sign.py b/utils/test/testapi/opnfv_testapi/ui/auth/sign.py
index 462395225..318473ea2 100644
--- a/utils/test/testapi/opnfv_testapi/ui/auth/sign.py
+++ b/utils/test/testapi/opnfv_testapi/ui/auth/sign.py
@@ -1,76 +1,59 @@
-from six.moves.urllib import parse
+from cas import CASClient
from tornado import gen
from tornado import web
+from opnfv_testapi.common import constants
from opnfv_testapi.common.config import CONF
from opnfv_testapi.db import api as dbapi
-from opnfv_testapi.ui.auth import base
-from opnfv_testapi.ui.auth import constants as const
+from opnfv_testapi.resources import handlers
-class SigninHandler(base.BaseHandler):
+class SignBaseHandler(handlers.GenericApiHandler):
+ def __init__(self, application, request, **kwargs):
+ super(SignBaseHandler, self).__init__(application, request, **kwargs)
+ self.table = 'users'
+ self.cas_client = CASClient(version='2',
+ server_url=CONF.lfid_cas_url,
+ service_url='{}/{}'.format(
+ CONF.ui_url,
+ CONF.lfid_signin_return))
+
+
+class SigninHandler(SignBaseHandler):
def get(self):
- csrf_token = base.get_token()
- return_endpoint = parse.urljoin(CONF.api_url,
- CONF.osid_openid_return_to)
- return_to = base.set_query_params(return_endpoint,
- {const.CSRF_TOKEN: csrf_token})
+ self.redirect(url=(self.cas_client.get_login_url()))
- params = {
- const.OPENID_MODE: CONF.osid_openid_mode,
- const.OPENID_NS: CONF.osid_openid_ns,
- const.OPENID_RETURN_TO: return_to,
- const.OPENID_CLAIMED_ID: CONF.osid_openid_claimed_id,
- const.OPENID_IDENTITY: CONF.osid_openid_identity,
- const.OPENID_REALM: CONF.api_url,
- const.OPENID_NS_SREG: CONF.osid_openid_ns_sreg,
- const.OPENID_NS_SREG_REQUIRED: CONF.osid_openid_sreg_required,
- }
- url = CONF.osid_openstack_openid_endpoint
- url = base.set_query_params(url, params)
- self.redirect(url=url, permanent=False)
+class SigninReturnHandler(SignBaseHandler):
-class SigninReturnHandler(base.BaseHandler):
@web.asynchronous
@gen.coroutine
def get(self):
- if self.get_query_argument(const.OPENID_MODE) == 'cancel':
- self._auth_failure('Authentication canceled.')
-
- openid = self.get_query_argument(const.OPENID_CLAIMED_ID)
- role = const.DEFAULT_ROLE
- new_user_info = {
- 'openid': openid,
- 'email': self.get_query_argument(const.OPENID_NS_SREG_EMAIL),
- 'fullname': self.get_query_argument(const.OPENID_NS_SREG_FULLNAME),
- const.ROLE: role
- }
- user = yield dbapi.db_find_one(self.table, {'openid': openid})
- if not user:
- dbapi.db_save(self.table, new_user_info)
- else:
- role = user.get(const.ROLE)
-
- self.clear_cookie(const.OPENID)
- self.clear_cookie(const.ROLE)
- self.set_secure_cookie(const.OPENID, openid)
- self.set_secure_cookie(const.ROLE, role)
- self.redirect(url=CONF.ui_url)
-
- def _auth_failure(self, message):
- params = {'message': message}
- url = parse.urljoin(CONF.ui_url,
- '/#/auth_failure?' + parse.urlencode(params))
- self.redirect(url)
-
-
-class SignoutHandler(base.BaseHandler):
+ ticket = self.get_query_argument('ticket', default=None)
+ if ticket:
+ (user, attrs, _) = self.cas_client.verify_ticket(ticket=ticket)
+ login_user = {
+ 'user': user,
+ 'email': attrs.get('mail'),
+ 'fullname': attrs.get('field_lf_full_name'),
+ 'groups': constants.TESTAPI_USERS + attrs.get('group', [])
+ }
+ q_user = {'user': user}
+ db_user = yield dbapi.db_find_one(self.table, q_user)
+ if not db_user:
+ dbapi.db_save(self.table, login_user)
+ else:
+ dbapi.db_update(self.table, q_user, login_user)
+
+ self.clear_cookie(constants.TESTAPI_ID)
+ self.set_secure_cookie(constants.TESTAPI_ID, user)
+
+ self.redirect(url=CONF.ui_url)
+
+
+class SignoutHandler(SignBaseHandler):
def get(self):
"""Handle signout request."""
- self.clear_cookie(const.OPENID)
- self.clear_cookie(const.ROLE)
- params = {'openid_logout': CONF.osid_openid_logout_endpoint}
- url = parse.urljoin(CONF.ui_url,
- '/#/logout?' + parse.urlencode(params))
- self.redirect(url)
+ self.clear_cookie(constants.TESTAPI_ID)
+ logout_url = self.cas_client.get_logout_url(redirect_url=CONF.ui_url)
+ self.redirect(url=logout_url)
diff --git a/utils/test/testapi/opnfv_testapi/ui/auth/user.py b/utils/test/testapi/opnfv_testapi/ui/auth/user.py
index 955cdeead..ab86007f1 100644
--- a/utils/test/testapi/opnfv_testapi/ui/auth/user.py
+++ b/utils/test/testapi/opnfv_testapi/ui/auth/user.py
@@ -1,25 +1,26 @@
-from tornado import gen
-from tornado import web
-
+from opnfv_testapi.common import constants
from opnfv_testapi.common import raises
-from opnfv_testapi.db import api as dbapi
-from opnfv_testapi.ui.auth import base
+from opnfv_testapi.resources import handlers
+from opnfv_testapi.resources import models
+
+
+class User(models.ModelBase):
+ def __init__(self, user=None, email=None, fullname=None, groups=None):
+ self.user = user
+ self.email = email
+ self.fullname = fullname
+ self.groups = groups
+
+class UserHandler(handlers.GenericApiHandler):
+ def __init__(self, application, request, **kwargs):
+ super(UserHandler, self).__init__(application, request, **kwargs)
+ self.table = 'users'
+ self.table_cls = User
-class ProfileHandler(base.BaseHandler):
- @web.asynchronous
- @gen.coroutine
def get(self):
- openid = self.get_secure_cookie('openid')
- if openid:
- try:
- user = yield dbapi.db_find_one(self.table, {'openid': openid})
- self.finish_request({
- "openid": user.get('openid'),
- "email": user.get('email'),
- "fullname": user.get('fullname'),
- "role": user.get('role', 'user')
- })
- except Exception:
- pass
- raises.Unauthorized('Unauthorized')
+ username = self.get_secure_cookie(constants.TESTAPI_ID)
+ if username:
+ self._get_one(query={'user': username})
+ else:
+ raises.Unauthorized('Unauthorized')
diff --git a/utils/test/testapi/opnfv_testapi/ui/root.py b/utils/test/testapi/opnfv_testapi/ui/root.py
index 5b2c922d7..286a6b097 100644
--- a/utils/test/testapi/opnfv_testapi/ui/root.py
+++ b/utils/test/testapi/opnfv_testapi/ui/root.py
@@ -1,10 +1,10 @@
-from opnfv_testapi.resources.handlers import GenericApiHandler
from opnfv_testapi.common.config import CONF
+from opnfv_testapi.resources import handlers
-class RootHandler(GenericApiHandler):
+class RootHandler(handlers.GenericApiHandler):
def get_template_path(self):
- return CONF.static_path
+ return CONF.ui_static_path
def get(self):
self.render('testapi-ui/index.html')
diff --git a/utils/test/testapi/requirements.txt b/utils/test/testapi/requirements.txt
index 4b6f75c10..fbd2e0ede 100644
--- a/utils/test/testapi/requirements.txt
+++ b/utils/test/testapi/requirements.txt
@@ -8,3 +8,4 @@ tornado>=3.1,<=4.3 # Apache-2.0
epydoc>=0.3.1
six>=1.9.0 # MIT
motor # Apache-2.0
+python-cas
diff --git a/utils/test/testapi/setup.cfg b/utils/test/testapi/setup.cfg
index ab1ef553e..d9aa6762e 100644
--- a/utils/test/testapi/setup.cfg
+++ b/utils/test/testapi/setup.cfg
@@ -23,18 +23,10 @@ setup-hooks =
[files]
packages =
opnfv_testapi
-package_data =
- opnfv_testapi =
- static/*.*
- static/*/*.*
- static/*/*/*.*
- static/*/*/*/*.*
- static/*/*/*/*/*.*
- static/*/*/*/*/*/*.*
- static/*/*/*/*/*/*/*.*
+
data_files =
- /etc/opnfv_testapi =
- etc/config.ini
+ /etc/opnfv_testapi = etc/config.ini
+ /usr/local/share/opnfv_testapi = 3rd_party/static/*
[entry_points]
console_scripts =
@@ -44,4 +36,3 @@ console_scripts =
tag_build =
tag_date = 0
tag_svn_revision = 0
-
diff --git a/utils/test/testapi/setup.py b/utils/test/testapi/setup.py
index f689cb30e..f9d95a32d 100644
--- a/utils/test/testapi/setup.py
+++ b/utils/test/testapi/setup.py
@@ -1,6 +1,5 @@
import setuptools
-
__author__ = 'serena'
try:
@@ -8,6 +7,7 @@ try:
except ImportError:
pass
+
setuptools.setup(
- setup_requires=['pbr==2.0.0'],
+ setup_requires=['pbr>=2.0.0'],
pbr=True)
diff --git a/utils/test/testapi/tools/watchdog/docker_watch.sh b/utils/test/testapi/tools/watchdog/docker_watch.sh
new file mode 100644
index 000000000..786fc10b9
--- /dev/null
+++ b/utils/test/testapi/tools/watchdog/docker_watch.sh
@@ -0,0 +1,165 @@
+# *
+# 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. *
+
+# This script checks if deployments are working or and then
+# starts the specified containers in case one of the containers
+# crash. The only solution is restarting docker as of now.
+
+#!/bin/bash
+
+## List of modules
+modules=(testapi reporting)
+
+## Ports of the modules
+declare -A ports=( ["testapi"]="8082" ["reporting"]="8084")
+
+## Urls to check if the modules are deployed or not ?
+declare -A urls=( ["testapi"]="http://testresults.opnfv.org/test/" \
+ ["reporting"]="http://testresults.opnfv.org/reporting2/reporting/index.html")
+
+### Functions related to checking.
+
+function is_deploying() {
+ xml=$(curl -m10 "https://build.opnfv.org/ci/job/${1}-automate-master/lastBuild/api/xml?depth=1")
+ building=$(grep -oPm1 "(?<=<building>)[^<]+" <<< "$xml")
+ if [[ $building == "false" ]]
+ then
+ return 0
+ else
+ return 1
+ fi
+}
+
+function get_docker_status() {
+ status=$(service docker status | sed -n 3p | cut -d ' ' -f5)
+ echo -e "Docker status: $status"
+ if [ $status = "active" ]
+ then
+ return 1
+ else
+ return 0
+ fi
+}
+
+function check_connectivity() {
+ echo "Checking $1 connection : $2"
+ cmd=`curl --head -m10 --request GET ${2} | grep '200 OK' > /dev/null`
+ rc=$?
+ if [[ $rc == 0 ]]; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+function check_modules() {
+ echo -e "Checking modules"
+ failed_modules=()
+ for module in "${modules[@]}"
+ do
+ if is_deploying $module; then
+ continue
+ fi
+ if ! check_connectivity $module "${urls[$module]}"; then
+ echo -e "$module failed"
+ failed_modules+=($module)
+ fi
+ done
+ if [ ! -z "$failed_modules" ]; then
+ echo -e "Failed Modules: $failed_modules"
+ return 1
+ else
+ echo -e "All modules working good"
+ exit 0
+ fi
+}
+
+### Functions related fixes.
+
+function restart_docker_fix() {
+ echo -e "Running restart_docker_fix"
+ service docker restart
+ start_containers_fix "${modules[@]}"
+}
+
+function docker_proxy_fix() {
+ echo -e "Running docker_proxy_fix"
+ fix_modules=("${@}")
+ for module in "${fix_modules[@]}"
+ do
+ echo -e "Kill docker proxy and restart containers"
+ pid=$(netstat -nlp | grep :${ports[$module]} | awk '{print $7}' | cut -d'/' -f1)
+ echo $pid
+ if [ ! -z "$pid" ]; then
+ kill $pid
+ start_container_fix $module
+ fi
+ done
+}
+
+function start_containers_fix() {
+ start_modules=("${@}")
+ for module in "${start_modules[@]}"
+ do
+ start_container_fix $module
+ done
+}
+
+function start_container_fix() {
+ echo -e "Starting a container $module"
+ sudo docker stop $module
+ sudo docker start $module
+ sleep 5
+ if ! check_connectivity $module "${urls[$module]}"; then
+ echo -e "Starting an old container $module_old"
+ sudo docker stop $module
+ sudo docker start $module"_old"
+ sleep 5
+ fi
+}
+
+### Main Flow
+
+echo -e
+echo -e "WatchDog Started"
+echo -e
+echo -e `date "+%Y-%m-%d %H:%M:%S.%N"`
+echo -e
+
+## If the problem is related to docker daemon
+
+if get_docker_status; then
+ restart_docker_fix
+ if ! check_modules; then
+ echo -e "Watchdog failed while restart_docker_fix"
+ fi
+ exit
+fi
+
+## If the problem is related to docker proxy
+
+if ! check_modules; then
+ docker_proxy_fix "${failed_modules[@]}"
+fi
+
+## If any other problem : restart docker
+
+if ! check_modules; then
+ restart_docker_fix
+fi
+
+## If nothing works out
+
+if ! check_modules; then
+ echo -e "Watchdog failed"
+fi
+
+sudo docker ps
+sudo docker images