summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/create_pod_file.py4
-rwxr-xr-xutils/fetch_os_creds.sh13
-rw-r--r--utils/push-test-logs.sh3
-rw-r--r--utils/test/reporting/api/handlers/landing.py78
-rw-r--r--utils/test/reporting/docker/Dockerfile17
-rwxr-xr-xutils/test/reporting/docker/web_server.sh2
-rw-r--r--utils/test/reporting/pages/app/scripts/controllers/table.controller.js504
-rw-r--r--utils/test/reporting/pages/app/scripts/factory/table.factory.js4
-rw-r--r--utils/test/reporting/pages/app/views/commons/table.html28
-rwxr-xr-xutils/test/reporting/reporting/functest/reporting-status.py2
-rwxr-xr-xutils/test/reporting/reporting/functest/reporting-tempest.py92
-rw-r--r--utils/test/reporting/reporting/functest/template/index-status-tmpl.html30
-rw-r--r--utils/test/reporting/reporting/qtip/reporting-status.py3
-rw-r--r--utils/test/reporting/reporting/qtip/template/index-status-tmpl.html9
-rw-r--r--utils/test/reporting/reporting/reporting.yaml1
-rw-r--r--utils/test/reporting/setup.py1
-rw-r--r--utils/test/testapi/.gitignore3
-rw-r--r--utils/test/testapi/3rd_party/static/testapi-ui/components/pods/pods.html2
-rw-r--r--utils/test/testapi/3rd_party/static/testapi-ui/components/pods/podsController.js35
-rw-r--r--utils/test/testapi/docker/Dockerfile2
-rwxr-xr-xutils/test/testapi/install.sh30
-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.py4
-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.py14
-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.py38
-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/setup.py9
33 files changed, 1455 insertions, 864 deletions
diff --git a/utils/create_pod_file.py b/utils/create_pod_file.py
index e2c57d23f..def5ecca8 100644
--- a/utils/create_pod_file.py
+++ b/utils/create_pod_file.py
@@ -12,6 +12,8 @@ parser.add_argument("-u", "--user", help="Give username of this pod")
parser.add_argument("-k", "--key", help="Give key file of the user")
parser.add_argument("-p", "--password", help="Give password of the user")
parser.add_argument("-f", "--filepath", help="Give dest path of output file")
+parser.add_argument("-s", "--sshkey", default="/root/.ssh/id_rsa",
+ help="Give the path for ssh key")
args = parser.parse_args()
@@ -92,7 +94,7 @@ def create_file(handler, INSTALLER_TYPE):
item['password'] = 'root'
else:
for item in node_list:
- item['key_filename'] = '/root/.ssh/id_rsa'
+ item['key_filename'] = args.sshkey
data = {'nodes': node_list}
with open(args.filepath, "w") as fw:
yaml.dump(data, fw)
diff --git a/utils/fetch_os_creds.sh b/utils/fetch_os_creds.sh
index 8374edbbd..72bebade1 100755
--- a/utils/fetch_os_creds.sh
+++ b/utils/fetch_os_creds.sh
@@ -107,11 +107,15 @@ if [ "$installer_type" == "fuel" ]; then
# retrieving controller vip
controller_ip=$(ssh 2>/dev/null ${ssh_options} ubuntu@${installer_ip} \
- "sudo salt --out txt 'ctl01*' pillar.get _param:openstack_control_address | awk '{print \$2}'" | \
+ "sudo salt --out txt 'ctl*' pillar.get _param:openstack_control_address | awk '{print \$2; exit}'" | \
sed 's/ //g') &> /dev/null
info "Fetching rc file from controller $controller_ip..."
ssh ${ssh_options} ubuntu@${controller_ip} "sudo cat /root/keystonercv3" > $dest_path
+
+ if [[ $BUILD_TAG =~ "baremetal" ]]; then
+ ssh ${ssh_options} ubuntu@${installer_ip} "cat /etc/ssl/certs/os_cacert" > $os_cacert
+ fi
else
#ip_fuel="10.20.0.2"
env=$(sshpass -p r00tme ssh 2>/dev/null ${ssh_options} root@${installer_ip} \
@@ -144,6 +148,13 @@ if [ "$installer_type" == "fuel" ]; then
echo $auth_url >> $dest_path
elif [ "$installer_type" == "apex" ]; then
+ if ! ipcalc -c $installer_ip; then
+ installer_ip=$(virsh domifaddr undercloud | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')
+ if [ -z "$installer_ip" ] || ! $(ipcalc -c $installer_ip); then
+ echo "Unable to find valid IP for Apex undercloud: ${installer_ip}"
+ exit 1
+ fi
+ fi
verify_connectivity $installer_ip
# The credentials file is located in the Instack VM (192.0.2.1)
diff --git a/utils/push-test-logs.sh b/utils/push-test-logs.sh
index eb57deb7b..518d20ae5 100644
--- a/utils/push-test-logs.sh
+++ b/utils/push-test-logs.sh
@@ -27,10 +27,11 @@ node_list=(\
'ericsson-pod1' 'ericsson-pod2' \
'ericsson-virtual1' 'ericsson-virtual2' 'ericsson-virtual3' \
'ericsson-virtual4' 'ericsson-virtual5' 'ericsson-virtual12' \
-'arm-pod1' 'arm-pod3' \
+'arm-pod1' 'arm-pod5' \
'huawei-pod1' 'huawei-pod2' 'huawei-pod3' 'huawei-pod4' 'huawei-pod5' \
'huawei-pod6' 'huawei-pod7' 'huawei-pod12' \
'huawei-virtual1' 'huawei-virtual2' 'huawei-virtual3' 'huawei-virtual4' \
+'huawei-virtual5' 'huawei-virtual8' 'huawei-virtual9' \
'zte-pod2' \
'zte-virtual1')
diff --git a/utils/test/reporting/api/handlers/landing.py b/utils/test/reporting/api/handlers/landing.py
index 749916fb6..0bf602dc9 100644
--- a/utils/test/reporting/api/handlers/landing.py
+++ b/utils/test/reporting/api/handlers/landing.py
@@ -7,6 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import requests
+import time
from tornado.escape import json_encode
from tornado.escape import json_decode
@@ -24,7 +25,7 @@ class FiltersHandler(BaseHandler):
'status': ['success', 'warning', 'danger'],
'projects': ['functest', 'yardstick'],
'installers': ['apex', 'compass', 'fuel', 'joid'],
- 'version': ['colorado', 'master'],
+ 'version': ['master', 'colorado', 'danube'],
'loops': ['daily', 'weekly', 'monthly'],
'time': ['10 days', '30 days']
}
@@ -53,27 +54,27 @@ class ScenariosHandler(BaseHandler):
def _get_scenario_result(self, scenario, data, args):
result = {
'status': data.get('status'),
- 'installers': self._get_installers_result(data['installers'], args)
+ 'installers': self._get_installers_result(data, args)
}
return result
def _get_installers_result(self, data, args):
func = self._get_installer_result
- return {k: func(k, data.get(k, {}), args) for k in args['installers']}
+ return {k: func(data.get(k, {}), args) for k in args['installers']}
- def _get_installer_result(self, installer, data, args):
- projects = data.get(args['version'], [])
- return [self._get_project_data(projects, p) for p in args['projects']]
+ def _get_installer_result(self, data, args):
+ return self._get_version_data(data.get(args['version'], {}), args)
- def _get_project_data(self, projects, project):
+ def _get_version_data(self, data, args):
+ return {k: self._get_project_data(data.get(k, {}))
+ for k in args['projects']}
+
+ def _get_project_data(self, data):
atom = {
- 'project': project,
- 'score': None,
- 'status': None
+ 'score': data.get('score', ''),
+ 'status': data.get('status', '')
}
- for p in projects:
- if p['project'] == project:
- return p
+
return atom
def _get_scenarios(self):
@@ -88,41 +89,42 @@ class ScenariosHandler(BaseHandler):
[])
) for a in data}
scenario = {
- 'status': self._get_status(),
- 'installers': installers
+ 'status': self._get_status()
}
+ scenario.update(installers)
+
return scenario
def _get_status(self):
return 'success'
def _get_installer(self, data):
- return {a.get('version'): self._get_version(a) for a in data}
+ return {a.get('version'): self._get_version(a.get('projects'))
+ for a in data}
def _get_version(self, data):
+ return {a.get('project'): self._get_project(a) for a in data}
+
+ def _get_project(self, data):
+ scores = data.get('scores', [])
+ trusts = data.get('trust_indicators', [])
+
try:
- scores = data.get('score', {}).get('projects')[0]
- trusts = data.get('trust_indicator', {}).get('projects')[0]
- except (TypeError, IndexError):
- return []
- else:
- scores = {key: [dict(date=a.get('date')[:10],
- score=a.get('score')
- ) for a in scores[key]] for key in scores}
- trusts = {key: [dict(date=a.get('date')[:10],
- status=a.get('status')
- ) for a in trusts[key]] for key in trusts}
- atom = self._get_atom(scores, trusts)
- return [dict(project=k,
- score=sorted(atom[k], reverse=True)[0].get('score'),
- status=sorted(atom[k], reverse=True)[0].get('status')
- ) for k in atom if atom[k]]
-
- def _get_atom(self, scores, trusts):
- s = {k: {a['date']: a['score'] for a in scores[k]} for k in scores}
- t = {k: {a['date']: a['status'] for a in trusts[k]} for k in trusts}
- return {k: [dict(score=s[k][a], status=t[k][a], data=a
- ) for a in s[k] if a in t[k]] for k in s}
+ date = sorted(scores, reverse=True)[0].get('date')
+ except IndexError:
+ data = time.time()
+
+ try:
+ score = sorted(scores, reverse=True)[0].get('score')
+ except IndexError:
+ score = None
+
+ try:
+ status = sorted(trusts, reverse=True)[0].get('status')
+ except IndexError:
+ status = None
+
+ return {'date': date, 'score': score, 'status': status}
def _change_to_utf8(self, obj):
if isinstance(obj, dict):
diff --git a/utils/test/reporting/docker/Dockerfile b/utils/test/reporting/docker/Dockerfile
index f5168d1ae..f2357909d 100644
--- a/utils/test/reporting/docker/Dockerfile
+++ b/utils/test/reporting/docker/Dockerfile
@@ -27,19 +27,28 @@ ENV CONFIG_REPORTING_YAML ${working_dir}/reporting.yaml
WORKDIR ${HOME}
# Packaged dependencies
RUN apt-get update && apt-get install -y \
+build-essential \
ssh \
+curl \
+gnupg \
python-pip \
+python-dev \
+python-setuptools \
git-core \
-nodejs \
-npm \
supervisor \
--no-install-recommends
-RUN pip install --upgrade pip
+RUN pip install --upgrade pip && easy_install -U setuptools==30.0.0
-RUN git clone --depth 1 https://gerrit.opnfv.org/gerrit/releng ${HOME}/releng
+RUN git clone --depth 1 https://gerrit.opnfv.org/gerrit/releng /home/opnfv/releng
RUN pip install -r ${working_dir}/requirements.txt
+RUN sh -c 'curl -sL https://deb.nodesource.com/setup_8.x | bash -' \
+ && apt-get install -y nodejs \
+ && npm install -g bower \
+ && npm install -g grunt \
+ && npm install -g grunt-cli
+
WORKDIR ${working_dir}
RUN python setup.py install
RUN docker/reporting.sh
diff --git a/utils/test/reporting/docker/web_server.sh b/utils/test/reporting/docker/web_server.sh
index a34c11dd7..0dd8df73d 100755
--- a/utils/test/reporting/docker/web_server.sh
+++ b/utils/test/reporting/docker/web_server.sh
@@ -9,8 +9,6 @@ echo "daemon off;" >> /etc/nginx/nginx.conf
# supervisor config
cp /home/opnfv/releng/utils/test/reporting/docker/supervisor.conf /etc/supervisor/conf.d/
-ln -s /usr/bin/nodejs /usr/bin/node
-
# Manage Angular front end
cd pages && /bin/bash angular.sh
diff --git a/utils/test/reporting/pages/app/scripts/controllers/table.controller.js b/utils/test/reporting/pages/app/scripts/controllers/table.controller.js
index 44d9441de..8d494c3ae 100644
--- a/utils/test/reporting/pages/app/scripts/controllers/table.controller.js
+++ b/utils/test/reporting/pages/app/scripts/controllers/table.controller.js
@@ -11,396 +11,268 @@ angular.module('opnfvApp')
.controller('TableController', ['$scope', '$state', '$stateParams', '$http', 'TableFactory', '$timeout',
function($scope, $state, $stateParams, $http, TableFactory, $timeout) {
- $scope.filterlist = [];
- $scope.selection = [];
- $scope.statusList = [];
- $scope.projectList = [];
- $scope.installerList = [];
- $scope.versionlist = [];
- $scope.loopci = [];
- $scope.time = [];
- $scope.tableDataAll = {};
- $scope.tableInfoAll = {};
- $scope.scenario = {};
- // $scope.selectProjects = [];
-
-
- $scope.VersionConfig = {
- create: true,
- valueField: 'title',
- labelField: 'title',
- delimiter: '|',
- maxItems: 1,
- placeholder: 'Version',
- onChange: function(value) {
- checkElementArrayValue($scope.selection, $scope.VersionOption);
- $scope.selection.push(value);
- // console.log($scope.selection);
- getScenarioData();
+ init();
- }
- }
+ function init() {
+ $scope.filterlist = [];
+ $scope.selection = [];
- $scope.LoopConfig = {
- create: true,
- valueField: 'title',
- labelField: 'title',
- delimiter: '|',
- maxItems: 1,
- placeholder: 'Loop',
- onChange: function(value) {
- checkElementArrayValue($scope.selection, $scope.LoopOption);
- $scope.selection.push(value);
- // console.log($scope.selection);
- getScenarioData();
+ $scope.statusList = [];
+ $scope.projectList = [];
+ $scope.installerList = [];
+ $scope.versionlist = [];
+ $scope.loopList = [];
+ $scope.timeList = [];
- }
- }
+ $scope.selectStatus = [];
+ $scope.selectProjects = [];
+ $scope.selectInstallers = [];
+ $scope.selectVersion = null;
+ $scope.selectLoop = null;
+ $scope.selectTime = null;
+
+ $scope.statusClicked = false;
+ $scope.installerClicked = false;
+ $scope.projectClicked = false;
- $scope.TimeConfig = {
- create: true,
- valueField: 'title',
- labelField: 'title',
- delimiter: '|',
- maxItems: 1,
- placeholder: 'Time',
- onChange: function(value) {
- checkElementArrayValue($scope.selection, $scope.TimeOption);
- $scope.selection.push(value);
- // console.log($scope.selection)
- getScenarioData();
+ $scope.scenarios = {};
+ $scope.VersionConfig = {
+ create: true,
+ valueField: 'title',
+ labelField: 'title',
+ delimiter: '|',
+ maxItems: 1,
+ placeholder: 'Version',
+ onChange: function(value) {
+ $scope.selectVersion = value;
+ getScenarioData();
+
+ }
}
- }
+ $scope.LoopConfig = {
+ create: true,
+ valueField: 'title',
+ labelField: 'title',
+ delimiter: '|',
+ maxItems: 1,
+ placeholder: 'Loop',
+ onChange: function(value) {
+ $scope.selectLoop = value;
- init();
+ getScenarioData();
+
+ }
+ }
+
+ $scope.TimeConfig = {
+ create: true,
+ valueField: 'title',
+ labelField: 'title',
+ delimiter: '|',
+ maxItems: 1,
+ placeholder: 'Time',
+ onChange: function(value) {
+ $scope.selectTime = value;
+
+ getScenarioData();
+ }
+ }
- function init() {
- $scope.toggleSelection = toggleSelection;
- getScenarioData();
getFilters();
}
function getFilters() {
TableFactory.getFilter().get({
-
}).$promise.then(function(response) {
if (response != null) {
$scope.statusList = response.filters.status;
$scope.projectList = response.filters.projects;
$scope.installerList = response.filters.installers;
- $scope.versionlist = response.filters.version;
- $scope.loopci = response.filters.loops;
- $scope.time = response.filters.time;
-
- $scope.statusListString = $scope.statusList.toString();
- $scope.projectListString = $scope.projectList.toString();
- $scope.installerListString = $scope.installerList.toString();
- $scope.VersionSelected = $scope.versionlist[1];
- $scope.LoopCiSelected = $scope.loopci[0];
- $scope.TimeSelected = $scope.time[0];
- radioSetting($scope.versionlist, $scope.loopci, $scope.time);
+ $scope.versionList = toSelectList(response.filters.version);
+ $scope.loopList = toSelectList(response.filters.loops);
+ $scope.timeList = toSelectList(response.filters.time);
+
+ $scope.selectStatus = copy($scope.statusList);
+ $scope.selectInstallers = copy($scope.installerList);
+ $scope.selectProjects = copy($scope.projectList);
+ $scope.selectVersion = response.filters.version[0];
+ $scope.selectLoop = response.filters.loops[0];
+ $scope.selectTime = response.filters.time[0];
+
+ getScenarioData();
} else {
- alert("网络错误");
}
- })
+ });
+ }
+
+ function toSelectList(arr){
+ var tempList = [];
+ angular.forEach(arr, function(ele){
+ tempList.push({'title': ele});
+ });
+ return tempList;
+ }
+
+ function copy(arr){
+ var tempList = [];
+ angular.forEach(arr, function(ele){
+ tempList.push(ele);
+ });
+ return tempList;
}
function getScenarioData() {
- // var utl = BASE_URL + '/scenarios';
var data = {
- 'status': ['success', 'danger', 'warning'],
- 'projects': ['functest', 'yardstick'],
- 'installers': ['apex', 'compass', 'fuel', 'joid'],
- 'version': $scope.VersionSelected,
- 'loops': $scope.LoopCiSelected,
- 'time': $scope.TimeSelected
+ 'status': $scope.selectStatus,
+ 'projects': $scope.selectProjects,
+ 'installers': $scope.selectInstallers,
+ 'version': $scope.selectVersion,
+ 'loops': $scope.selectLoop,
+ 'time': $scope.selectTime
};
TableFactory.getScenario(data).then(function(response) {
if (response.status == 200) {
- $scope.scenario = response.data;
-
- reSettingcolspan();
+ $scope.scenarios = response.data.scenarios;
+ getScenario();
}
}, function(error) {
-
- })
+ });
}
- function reSettingcolspan() {
- if ($scope.selectProjects == undefined || $scope.selectProjects == null) {
- constructJson();
- $scope.colspan = $scope.tableDataAll.colspan;
+ function getScenario(){
- } else {
- constructJson();
- $scope.colspan = $scope.tempColspan;
- }
- // console.log("test")
- }
-
- //construct json
- function constructJson(selectProject) {
+ $scope.project_row = [];
+ angular.forEach($scope.selectInstallers, function(installer){
+ angular.forEach($scope.selectProjects, function(project){
+ var temp = {
+ 'installer': installer,
+ 'project': project
+ }
+ $scope.project_row.push(temp);
- var colspan;
- var InstallerData;
- var projectsInfo;
- $scope.tableDataAll["scenario"] = [];
+ });
+ });
- for (var item in $scope.scenario.scenarios) {
+ $scope.scenario_rows = [];
+ angular.forEach($scope.scenarios, function(scenario, name){
+ var scenario_row = {
+ 'name': null,
+ 'status': null,
+ 'statusDisplay': null,
+ 'datadisplay': [],
+ };
+ scenario_row.name = name;
+ scenario_row.status = scenario.status;
- var headData = Object.keys($scope.scenario.scenarios[item].installers).sort();
- var scenarioStatus = $scope.scenario.scenarios[item].status;
var scenarioStatusDisplay;
- if (scenarioStatus == "success") {
+ if (scenario.status == "success") {
scenarioStatusDisplay = "navy";
- } else if (scenarioStatus == "danger") {
+ } else if (scenario.status == "danger") {
scenarioStatusDisplay = "danger";
- } else if (scenarioStatus == "warning") {
+ } else if (scenario.status == "warning") {
scenarioStatusDisplay = "warning";
}
-
- InstallerData = headData;
- var projectData = [];
- var datadisplay = [];
- var projects = [];
-
- for (var j = 0; j < headData.length; j++) {
-
- projectData.push($scope.scenario.scenarios[item].installers[headData[j]]);
- }
- for (var j = 0; j < projectData.length; j++) {
-
- for (var k = 0; k < projectData[j].length; k++) {
- projects.push(projectData[j][k].project);
- var temArray = [];
- if (projectData[j][k].score == null) {
- temArray.push("null");
- temArray.push(projectData[j][k].project);
- temArray.push(headData[j]);
- } else {
- temArray.push(projectData[j][k].score);
- temArray.push(projectData[j][k].project);
- temArray.push(headData[j]);
- }
-
-
- if (projectData[j][k].status == "platinium") {
- temArray.push("primary");
- temArray.push("P");
- } else if (projectData[j][k].status == "gold") {
- temArray.push("danger");
- temArray.push("G");
- } else if (projectData[j][k].status == "silver") {
- temArray.push("warning");
- temArray.push("S");
- } else if (projectData[j][k].status == null) {
- temArray.push("null");
+ scenario_row.statusDisplay = scenarioStatusDisplay;
+
+ angular.forEach($scope.selectInstallers, function(installer){
+ angular.forEach($scope.selectProjects, function(project){
+ var datadisplay = {
+ 'installer': null,
+ 'project': null,
+ 'value': null,
+ 'label': null,
+ 'label_value': null
+ };
+ datadisplay.installer = installer;
+ datadisplay.project = project;
+ datadisplay.value = scenario.installers[installer][project].score;
+
+ var single_status = scenario.installers[installer][project].status;
+ if (single_status == "platinium") {
+ datadisplay.label = 'primary';
+ datadisplay.label_value = 'P';
+ } else if (single_status == "gold") {
+ datadisplay.label = 'danger';
+ datadisplay.label_value = 'G';
+ } else if (single_status == "silver") {
+ datadisplay.label = 'warning';
+ datadisplay.label_value = 'S';
+ } else if (single_status == null) {
}
+ scenario_row.datadisplay.push(datadisplay);
- datadisplay.push(temArray);
-
- }
-
- }
-
- colspan = projects.length / headData.length;
-
- var tabledata = {
- scenarioName: item,
- Installer: InstallerData,
- projectData: projectData,
- projects: projects,
- datadisplay: datadisplay,
- colspan: colspan,
- status: scenarioStatus,
- statusDisplay: scenarioStatusDisplay
- };
-
- JSON.stringify(tabledata);
- $scope.tableDataAll.scenario.push(tabledata);
-
-
- // console.log(tabledata);
-
- }
-
-
- projectsInfo = $scope.tableDataAll.scenario[0].projects;
-
- var tempHeadData = [];
-
- for (var i = 0; i < InstallerData.length; i++) {
- for (var j = 0; j < colspan; j++) {
- tempHeadData.push(InstallerData[i]);
- }
- }
-
- //console.log(tempHeadData);
-
- var projectsInfoAll = [];
-
- for (var i = 0; i < projectsInfo.length; i++) {
- var tempA = [];
- tempA.push(projectsInfo[i]);
- tempA.push(tempHeadData[i]);
- projectsInfoAll.push(tempA);
-
- }
- //console.log(projectsInfoAll);
-
- $scope.tableDataAll["colspan"] = colspan;
- $scope.tableDataAll["Installer"] = InstallerData;
- $scope.tableDataAll["Projects"] = projectsInfoAll;
-
- // console.log($scope.tableDataAll);
- $scope.colspan = $scope.tableDataAll.colspan;
- console.log($scope.tableDataAll);
-
- }
-
- //get json element size
- function getSize(jsondata) {
- var size = 0;
- for (var item in jsondata) {
- size++;
- }
- return size;
+ });
+ });
+ $scope.scenario_rows.push(scenario_row);
+ });
}
- // console.log($scope.colspan);
-
-
- //find all same element index
- function getSameElementIndex(array, element) {
- var indices = [];
- var idx = array.indexOf(element);
- while (idx != -1) {
- indices.push(idx);
- idx = array.indexOf(element, idx + 1);
+ function clickBase(eleList, ele){
+ var idx = eleList.indexOf(ele);
+ if(idx > -1){
+ eleList.splice(idx, 1);
+ }else{
+ eleList.push(ele);
}
- //return indices;
- var result = { element: element, index: indices };
- JSON.stringify(result);
- return result;
}
- //delete element in array
- function deletElement(array, index) {
- array.splice(index, 1);
+ $scope.clickStatus = function(status){
+ if($scope.selectStatus.length == $scope.statusList.length && $scope.statusClicked == false){
+ $scope.selectStatus = [];
+ $scope.statusClicked = true;
+ }
- }
+ clickBase($scope.selectStatus, status);
- function radioSetting(array1, array2, array3) {
- var tempVersion = [];
- var tempLoop = [];
- var tempTime = [];
- for (var i = 0; i < array1.length; i++) {
- var temp = {
- title: array1[i]
- };
- tempVersion.push(temp);
- }
- for (var i = 0; i < array2.length; i++) {
- var temp = {
- title: array2[i]
- };
- tempLoop.push(temp);
+ if($scope.selectStatus.length == 0 && $scope.statusClicked == true){
+ $scope.selectStatus = copy($scope.statusList);
+ $scope.statusClicked = false;
}
- for (var i = 0; i < array3.length; i++) {
- var temp = {
- title: array3[i]
- };
- tempTime.push(temp);
- }
- $scope.VersionOption = tempVersion;
- $scope.LoopOption = tempLoop;
- $scope.TimeOption = tempTime;
- }
- //remove element in the array
- function removeArrayValue(arr, value) {
- for (var i = 0; i < arr.length; i++) {
- if (arr[i] == value) {
- arr.splice(i, 1);
- break;
- }
- }
+ getScenarioData();
}
- //check if exist element
- function checkElementArrayValue(arrayA, arrayB) {
- for (var i = 0; i < arrayB.length; i++) {
- if (arrayA.indexOf(arrayB[i].title) > -1) {
- removeArrayValue(arrayA, arrayB[i].title);
- }
+ $scope.clickInstaller = function(installer){
+ if($scope.selectInstallers.length == $scope.installerList.length && $scope.installerClicked == false){
+ $scope.selectInstallers = [];
+ $scope.installerClicked = true;
}
- }
- function toggleSelection(status) {
- var idx = $scope.selection.indexOf(status);
+ clickBase($scope.selectInstallers, installer);
- if (idx > -1) {
- $scope.selection.splice(idx, 1);
- filterData($scope.selection)
- } else {
- $scope.selection.push(status);
- filterData($scope.selection)
+ if($scope.selectInstallers.length == 0 && $scope.installerClicked == true){
+ $scope.selectInstallers = copy($scope.installerList);
+ $scope.installerClicked = false;
}
- // console.log($scope.selection);
+ getScenarioData();
}
- //filter function
- function filterData(selection) {
-
- $scope.selectInstallers = [];
- $scope.selectProjects = [];
- $scope.selectStatus = [];
- for (var i = 0; i < selection.length; i++) {
- if ($scope.statusListString.indexOf(selection[i]) > -1) {
- $scope.selectStatus.push(selection[i]);
- }
- if ($scope.projectListString.indexOf(selection[i]) > -1) {
- $scope.selectProjects.push(selection[i]);
- }
- if ($scope.installerListString.indexOf(selection[i]) > -1) {
- $scope.selectInstallers.push(selection[i]);
- }
+ $scope.clickProject = function(project){
+ if($scope.selectProjects.length == $scope.projectList.length && $scope.projectClicked == false){
+ $scope.selectProjects = [];
+ $scope.projectClicked = true;
}
+ clickBase($scope.selectProjects, project);
- // $scope.colspan = $scope.selectProjects.length;
- //when some selection is empty, we set it full
- if ($scope.selectInstallers.length == 0) {
- $scope.selectInstallers = $scope.installerList;
-
- }
- if ($scope.selectProjects.length == 0) {
- $scope.selectProjects = $scope.projectList;
- $scope.colspan = $scope.tableDataAll.colspan;
- } else {
- $scope.colspan = $scope.selectProjects.length;
- $scope.tempColspan = $scope.colspan;
- }
- if ($scope.selectStatus.length == 0) {
- $scope.selectStatus = $scope.statusList
+ if($scope.selectProjects.length == 0 && $scope.projectClicked == true){
+ $scope.selectProjects = copy($scope.projectList);
+ $scope.projectClicked = false;
}
- // console.log($scope.selectStatus);
- // console.log($scope.selectProjects);
-
+ getScenarioData();
}
-
}
- ]); \ No newline at end of file
+ ]);
diff --git a/utils/test/reporting/pages/app/scripts/factory/table.factory.js b/utils/test/reporting/pages/app/scripts/factory/table.factory.js
index f0af34fb2..e715c5c28 100644
--- a/utils/test/reporting/pages/app/scripts/factory/table.factory.js
+++ b/utils/test/reporting/pages/app/scripts/factory/table.factory.js
@@ -28,7 +28,7 @@ angular.module('opnfvApp')
}
});
},
- getScenario: function() {
+ getScenario: function(data) {
var config = {
headers: {
@@ -36,7 +36,7 @@ angular.module('opnfvApp')
}
}
- return $http.post(BASE_URL + '/landing-page/scenarios', {}, config);
+ return $http.post(BASE_URL + '/landing-page/scenarios', data, config);
},
diff --git a/utils/test/reporting/pages/app/views/commons/table.html b/utils/test/reporting/pages/app/views/commons/table.html
index f504bd76b..a33c48312 100644
--- a/utils/test/reporting/pages/app/views/commons/table.html
+++ b/utils/test/reporting/pages/app/views/commons/table.html
@@ -29,9 +29,9 @@
<div class=" col-md-12" data-toggle="buttons" aria-pressed="false">
<label> Status </label> &nbsp;&nbsp; &nbsp;
- <label class="btn btn-outline btn-success btn-sm" style="height:25px; margin-right: 5px;" ng-repeat="status in statusList" value={{status}} ng-checked="selection.indexOf(status)>-1" ng-click="toggleSelection(status)">
+ <label class="btn btn-outline btn-success btn-sm" style="height:25px; margin-right: 5px;" ng-repeat="status in statusList" value={{status}} ng-checked="selectStatus.indexOf(status)>-1" ng-click="clickStatus(status)">
<input type="checkbox" disabled="disabled" > {{status}}
-
+
</label>
</div>
@@ -39,7 +39,7 @@
<div class=" col-md-12" data-toggle="buttons">
<label> Projects </label> &nbsp;
- <label class="btn btn-outline btn-success btn-sm " style="height:25px;margin-right: 5px;" ng-repeat="project in projectList" value={{project}} ng-checked="selection.indexOf(project)>-1" ng-click="toggleSelection(project)">
+ <label class="btn btn-outline btn-success btn-sm " style="height:25px;margin-right: 5px;" ng-repeat="project in projectList" value={{project}} ng-checked="selectProjects.indexOf(project)>-1" ng-click="clickProject(project)">
<input type="checkbox" disabled="disabled"> {{project}}
</label>
@@ -47,7 +47,7 @@
<hr class="myhr">
<div class=" col-md-12" data-toggle="buttons">
<label> Installers </label>
- <label class="btn btn-outline btn-success btn-sm" style="height:25px;margin-right: 5px;" ng-repeat="installer in installerList" value={{installer}} ng-checked="selection.indexOf(installer)>-1" ng-click="toggleSelection(installer)">
+ <label class="btn btn-outline btn-success btn-sm" style="height:25px;margin-right: 5px;" ng-repeat="installer in installerList" value={{installer}} ng-checked="selectInstallers.indexOf(installer)>-1" ng-click="clickInstaller(installer)">
<input type="checkbox" disabled="disabled"> {{installer}}
</label>
</div>
@@ -56,17 +56,17 @@
<div class=" col-md-1" style="margin-top:5px;margin-right: 5px;">
- <selectize options="VersionOption" ng-model="VersionSelected" config="VersionConfig"></selectize>
+ <selectize options="versionList" ng-model="selectVersion" config="VersionConfig"></selectize>
</div>
<div class=" col-md-1" style="margin-top:5px;margin-right: 5px;">
- <selectize options="LoopOption" ng-model="LoopCiSelected" config="LoopConfig"></selectize>
+ <selectize options="loopList" ng-model="selectLoop" config="LoopConfig"></selectize>
</div>
<div class=" col-md-1" style="margin-top:5px;margin-right: 5px;">
- <selectize options="TimeOption" ng-model="TimeSelected" config="TimeConfig"></selectize>
+ <selectize options="timeList" ng-model="selectTime" config="TimeConfig"></selectize>
</div>
</div>
<div class="table-responsive">
@@ -75,25 +75,25 @@
<thead class="thead">
<tr>
<th>Scenario </th>
- <th colspan={{colspan}} ng-show="selectInstallers.indexOf(key)!=-1" value={{key}} ng-repeat="key in tableDataAll.Installer"><a href="notfound.html">{{key}}</a> </th>
+ <th colspan={{selectProjects.length}} ng-show="selectInstallers.indexOf(key)!=-1" value={{key}} ng-repeat="key in selectInstallers"><a href="notfound.html">{{key}}</a> </th>
</tr>
<tr>
<td></td>
- <td ng-show="selectProjects.indexOf(project[0])!=-1 && selectInstallers.indexOf(project[1])!=-1" ng-repeat="project in tableDataAll.Projects track by $index" data={{project[1]}} value={{project[0]}}>{{project[0]}}</td>
+ <td ng-show="selectProjects.indexOf(project.project)!=-1 && selectInstallers.indexOf(project.installer)!=-1" ng-repeat="project in project_row track by $index" data={{project.installer}} value={{project.project}}>{{ project.project }}</td>
</tr>
</thead>
<tbody class="tbody">
- <tr ng-repeat="scenario in tableDataAll.scenario" ng-show="selectStatus.indexOf(scenario.status)!=-1">
+ <tr ng-repeat="scenario in scenario_rows" ng-show="selectStatus.indexOf(scenario.status)!=-1">
- <td nowrap="nowrap" data={{scenario.status}}><span class="fa fa-circle text-{{scenario.statusDisplay}}"></span> <a href="notfound.html">{{scenario.scenarioName}}</a> </td>
+ <td nowrap="nowrap" data={{scenario.status}}><span class="fa fa-circle text-{{scenario.statusDisplay}}"></span> <a href="notfound.html">{{scenario.name}}</a> </td>
<!--<td style="background-color:#e7eaec" align="justify" ng-if="data[0]=='Not Support'" ng-repeat="data in scenario.datadisplay track by $index" data={{data[1]}} value={{data[2]}}></td>-->
- <td nowrap="nowrap" ng-show="selectInstallers.indexOf(data[2])!=-1 && selectProjects.indexOf(data[1])!=-1" ng-repeat="data in scenario.datadisplay track by $index" data={{data[1]}} value={{data[2]}} class={{data[0]}}>
- <span class="label label-{{data[3]}}">{{data[4]}}</a></span> {{data[0]}}</td>
+ <td nowrap="nowrap" ng-show="selectInstallers.indexOf(data.installer)!=-1 && selectProjects.indexOf(data.project)!=-1" ng-repeat="data in scenario.datadisplay track by $index" data={{data.project}} value={{data.installer}} class={{data.value}}>
+ <span class="label label-{{data.label}}">{{data.label_value}}</a></span> {{data.value}}</td>
</tr>
@@ -110,4 +110,4 @@
</div>
</div>
-</section> \ No newline at end of file
+</section>
diff --git a/utils/test/reporting/reporting/functest/reporting-status.py b/utils/test/reporting/reporting/functest/reporting-status.py
index 48c4bb1c7..c7c2051a3 100755
--- a/utils/test/reporting/reporting/functest/reporting-status.py
+++ b/utils/test/reporting/reporting/functest/reporting-status.py
@@ -126,7 +126,7 @@ for version in versions:
# in case of more than 1 architecture supported
# precise the architecture
installer_display = installer
- if (len(architectures) > 1):
+ if "fuel" in installer:
installer_display = installer + "@" + architecture
# For all the scenarios get results
diff --git a/utils/test/reporting/reporting/functest/reporting-tempest.py b/utils/test/reporting/reporting/functest/reporting-tempest.py
index bc2885639..d78d9a19d 100755
--- a/utils/test/reporting/reporting/functest/reporting-tempest.py
+++ b/utils/test/reporting/reporting/functest/reporting-tempest.py
@@ -8,58 +8,57 @@
# http://www.apache.org/licenses/LICENSE-2.0
# SPDX-license-identifier: Apache-2.0
-from urllib2 import Request, urlopen, URLError
from datetime import datetime
import json
-import jinja2
import os
-# manage conf
-import utils.reporting_utils as rp_utils
+from urllib2 import Request, urlopen, URLError
+import jinja2
+
+import reporting.utils.reporting_utils as rp_utils
-installers = rp_utils.get_config('general.installers')
-items = ["tests", "Success rate", "duration"]
+INSTALLERS = rp_utils.get_config('general.installers')
+ITEMS = ["tests", "Success rate", "duration"]
CURRENT_DIR = os.getcwd()
PERIOD = rp_utils.get_config('general.period')
-criteria_nb_test = 165
-criteria_duration = 1800
-criteria_success_rate = 90
+CRITERIA_NB_TEST = 100
+CRITERIA_DURATION = 1800
+CRITERIA_SUCCESS_RATE = 100
logger = rp_utils.getLogger("Tempest")
logger.info("************************************************")
logger.info("* Generating reporting Tempest_smoke_serial *")
-logger.info("* Data retention = %s days *" % PERIOD)
+logger.info("* Data retention = %s days *", PERIOD)
logger.info("* *")
logger.info("************************************************")
logger.info("Success criteria:")
-logger.info("nb tests executed > %s s " % criteria_nb_test)
-logger.info("test duration < %s s " % criteria_duration)
-logger.info("success rate > %s " % criteria_success_rate)
+logger.info("nb tests executed > %s s ", CRITERIA_NB_TEST)
+logger.info("test duration < %s s ", CRITERIA_DURATION)
+logger.info("success rate > %s ", CRITERIA_SUCCESS_RATE)
# For all the versions
for version in rp_utils.get_config('general.versions'):
- for installer in installers:
+ for installer in INSTALLERS:
# we consider the Tempest results of the last PERIOD days
url = ("http://" + rp_utils.get_config('testapi.url') +
- "?case=tempest_smoke_serial")
- request = Request(url + '&period=' + str(PERIOD) +
- '&installer=' + installer +
- '&version=' + version)
- logger.info("Search tempest_smoke_serial results for installer %s"
- " for version %s"
- % (installer, version))
+ "?case=tempest_smoke_serial&period=" + str(PERIOD) +
+ "&installer=" + installer + "&version=" + version)
+ request = Request(url)
+ logger.info(("Search tempest_smoke_serial results for installer %s"
+ " for version %s"), installer, version)
try:
response = urlopen(request)
k = response.read()
results = json.loads(k)
- except URLError as e:
- logger.error("Error code: %s" % e)
-
+ except URLError as err:
+ logger.error("Error code: %s", err)
+ logger.debug("request sent: %s", url)
+ logger.debug("Results from API: %s", results)
test_results = results['results']
-
+ logger.debug("Test results: %s", test_results)
scenario_results = {}
criteria = {}
errors = {}
@@ -72,27 +71,37 @@ for version in rp_utils.get_config('general.versions'):
scenario_results[r['scenario']] = []
scenario_results[r['scenario']].append(r)
+ logger.debug("Scenario results: %s", scenario_results)
+
for s, s_result in scenario_results.items():
scenario_results[s] = s_result[0:5]
# For each scenario, we build a result object to deal with
# results, criteria and error handling
for result in scenario_results[s]:
result["start_date"] = result["start_date"].split(".")[0]
+ logger.debug("start_date= %s", result["start_date"])
# retrieve results
# ****************
nb_tests_run = result['details']['tests']
nb_tests_failed = result['details']['failures']
- if nb_tests_run != 0:
- success_rate = 100 * ((int(nb_tests_run) -
+ logger.debug("nb_tests_run= %s", nb_tests_run)
+ logger.debug("nb_tests_failed= %s", nb_tests_failed)
+
+ try:
+ success_rate = (100 * (int(nb_tests_run) -
int(nb_tests_failed)) /
- int(nb_tests_run))
- else:
+ int(nb_tests_run))
+ except ZeroDivisionError:
success_rate = 0
result['details']["tests"] = nb_tests_run
result['details']["Success rate"] = str(success_rate) + "%"
+ logger.info("nb_tests_run= %s", result['details']["tests"])
+ logger.info("test rate = %s",
+ result['details']["Success rate"])
+
# Criteria management
# *******************
crit_tests = False
@@ -100,11 +109,11 @@ for version in rp_utils.get_config('general.versions'):
crit_time = False
# Expect that at least 165 tests are run
- if nb_tests_run >= criteria_nb_test:
+ if nb_tests_run >= CRITERIA_NB_TEST:
crit_tests = True
# Expect that at least 90% of success
- if success_rate >= criteria_success_rate:
+ if success_rate >= CRITERIA_SUCCESS_RATE:
crit_rate = True
# Expect that the suite duration is inferior to 30m
@@ -114,28 +123,27 @@ for version in rp_utils.get_config('general.versions'):
'%Y-%m-%d %H:%M:%S')
delta = stop_date - start_date
- if (delta.total_seconds() < criteria_duration):
+
+ if delta.total_seconds() < CRITERIA_DURATION:
crit_time = True
result['criteria'] = {'tests': crit_tests,
'Success rate': crit_rate,
'duration': crit_time}
try:
- logger.debug("Scenario %s, Installer %s"
- % (s_result[1]['scenario'], installer))
- logger.debug("Nb Test run: %s" % nb_tests_run)
- logger.debug("Test duration: %s"
- % result['details']['duration'])
- logger.debug("Success rate: %s" % success_rate)
- except:
+ logger.debug("Nb Test run: %s", nb_tests_run)
+ logger.debug("Test duration: %s", delta)
+ logger.debug("Success rate: %s", success_rate)
+ except Exception: # pylint: disable=broad-except
logger.error("Data format error")
# Error management
# ****************
try:
errors = result['details']['errors']
- result['errors'] = errors.replace('{0}', '')
- except:
+ logger.info("errors: %s", errors)
+ result['errors'] = errors
+ except Exception: # pylint: disable=broad-except
logger.error("Error field not present (Brahamputra runs?)")
templateLoader = jinja2.FileSystemLoader(".")
@@ -146,7 +154,7 @@ for version in rp_utils.get_config('general.versions'):
template = templateEnv.get_template(TEMPLATE_FILE)
outputText = template.render(scenario_results=scenario_results,
- items=items,
+ items=ITEMS,
installer=installer)
with open("./display/" + version +
diff --git a/utils/test/reporting/reporting/functest/template/index-status-tmpl.html b/utils/test/reporting/reporting/functest/template/index-status-tmpl.html
index cc4edaac5..50fc648aa 100644
--- a/utils/test/reporting/reporting/functest/template/index-status-tmpl.html
+++ b/utils/test/reporting/reporting/functest/template/index-status-tmpl.html
@@ -72,6 +72,7 @@ $(document).ready(function (){
<li class="active"><a href="../../index.html">Home</a></li>
<li><a href="status-apex.html">Apex</a></li>
<li><a href="status-compass.html">Compass</a></li>
+ <li><a href="status-daisy.html">Daisy</a></li>
<li><a href="status-fuel@x86.html">fuel@x86</a></li>
<li><a href="status-fuel@aarch64.html">fuel@aarch64</a></li>
<li><a href="status-joid.html">Joid</a></li>
@@ -89,7 +90,7 @@ $(document).ready(function (){
<div class="panel-heading"><h4><b>List of last scenarios ({{version}}) run over the last {{period}} days </b></h4></div>
<table class="table">
<tr>
- <th width="40%">Scenario</th>
+ <th width="40%">HA Scenario</th>
<th width="20%">Status</th>
<th width="20%">Trend</th>
<th width="10%">Score</th>
@@ -97,14 +98,39 @@ $(document).ready(function (){
</tr>
{% for scenario,iteration in scenario_stats.iteritems() -%}
<tr class="tr-ok">
+ {% if '-ha' in scenario -%}
<td><a href={{scenario_results[scenario].getUrlLastRun()}}>{{scenario}}</a></td>
<td><div id="gaugeScenario{{loop.index}}"></div></td>
<td><div id="trend_svg{{loop.index}}"></div></td>
<td>{{scenario_results[scenario].getScore()}}</td>
<td>{{iteration}}</td>
+ {%- endif %}
+ </tr>
+ {%- endfor %}
+ <br>
+ </table>
+ <br>
+ <table class="table">
+ <tr>
+ <th width="40%">NOHA Scenario</th>
+ <th width="20%">Status</th>
+ <th width="20%">Trend</th>
+ <th width="10%">Score</th>
+ <th width="10%">Iteration</th>
+ </tr>
+ {% for scenario,iteration in scenario_stats.iteritems() -%}
+ <tr class="tr-ok">
+ {% if '-noha' in scenario -%}
+ <td><a href={{scenario_results[scenario].getUrlLastRun()}}>{{scenario}}</a></td>
+ <td><div id="gaugeScenario{{loop.index}}"></div></td>
+ <td><div id="trend_svg{{loop.index}}"></div></td>
+ <td>{{scenario_results[scenario].getScore()}}</td>
+ <td>{{iteration}}</td>
+ {%- endif %}
</tr>
{%- endfor %}
- </table>
+ </table>
+
</div>
diff --git a/utils/test/reporting/reporting/qtip/reporting-status.py b/utils/test/reporting/reporting/qtip/reporting-status.py
index f0127b50f..56f9e0aee 100644
--- a/utils/test/reporting/reporting/qtip/reporting-status.py
+++ b/utils/test/reporting/reporting/qtip/reporting-status.py
@@ -33,8 +33,7 @@ def prepare_profile_file(version):
if not os.path.exists(profile_dir):
os.makedirs(profile_dir)
- profile_file = "{}/{}/scenario_history.txt".format(profile_dir,
- version)
+ profile_file = "{}/scenario_history.txt".format(profile_dir)
if not os.path.exists(profile_file):
with open(profile_file, 'w') as f:
info = 'date,scenario,installer,details,score\n'
diff --git a/utils/test/reporting/reporting/qtip/template/index-status-tmpl.html b/utils/test/reporting/reporting/qtip/template/index-status-tmpl.html
index 26da36ceb..92f3395dc 100644
--- a/utils/test/reporting/reporting/qtip/template/index-status-tmpl.html
+++ b/utils/test/reporting/reporting/qtip/template/index-status-tmpl.html
@@ -46,10 +46,11 @@
<nav>
<ul class="nav nav-justified">
<li class="active"><a href="http://testresults.opnfv.org/reporting/index.html">Home</a></li>
- <li><a href="index-status-apex.html">Apex</a></li>
- <li><a href="index-status-compass.html">Compass</a></li>
- <li><a href="index-status-fuel.html">Fuel</a></li>
- <li><a href="index-status-joid.html">Joid</a></li>
+ <li><a href="status-apex.html">Apex</a></li>
+ <li><a href="status-compass.html">Compass</a></li>
+ <li><a href="status-daisy.html">Daisy</a></li>
+ <li><a href="status-fuel.html">Fuel</a></li>
+ <li><a href="status-joid.html">Joid</a></li>
</ul>
</nav>
</div>
diff --git a/utils/test/reporting/reporting/reporting.yaml b/utils/test/reporting/reporting/reporting.yaml
index 1692f481d..26feb31d3 100644
--- a/utils/test/reporting/reporting/reporting.yaml
+++ b/utils/test/reporting/reporting/reporting.yaml
@@ -3,6 +3,7 @@ general:
installers:
- apex
- compass
+ - daisy
- fuel
- joid
diff --git a/utils/test/reporting/setup.py b/utils/test/reporting/setup.py
index a52d90555..17849f67b 100644
--- a/utils/test/reporting/setup.py
+++ b/utils/test/reporting/setup.py
@@ -8,7 +8,6 @@
# http://www.apache.org/licenses/LICENSE-2.0
# pylint: disable=missing-docstring
-
import setuptools
# In python < 2.7.4, a lazy loading of package `pbr` will break
diff --git a/utils/test/testapi/.gitignore b/utils/test/testapi/.gitignore
index c7b63b5b1..00f8a03d0 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
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
index cdfcfaf36..7ce36ca7c 100644
--- 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
@@ -63,7 +63,7 @@
</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>
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
index 53e8b1eff..201258619 100644
--- 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
@@ -31,7 +31,6 @@
function PodsController($scope, $http, $filter, $state, testapiApiUrl,
raiseAlert) {
var ctrl = this;
-
ctrl.url = testapiApiUrl + '/pods';
ctrl.create = create;
@@ -82,21 +81,27 @@
*/
function create() {
ctrl.showError = false;
- 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);
- });
+ 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.'
+ }
}
/**
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/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/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..9389d266d 100644
--- a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py
+++ b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py
@@ -155,7 +155,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 +180,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()},
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..3e3ab87aa 100644
--- a/utils/test/testapi/opnfv_testapi/router/url_mappings.py
+++ b/utils/test/testapi/opnfv_testapi/router/url_mappings.py
@@ -54,6 +54,20 @@ 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))',
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..77a8d18c1 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
@@ -63,9 +63,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 +92,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 +146,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/setup.py b/utils/test/testapi/setup.py
index f689cb30e..dd52373fd 100644
--- a/utils/test/testapi/setup.py
+++ b/utils/test/testapi/setup.py
@@ -1,5 +1,7 @@
-import setuptools
+import os
+import subprocess
+import setuptools
__author__ = 'serena'
@@ -8,6 +10,11 @@ try:
except ImportError:
pass
+dirpath = os.path.dirname(os.path.abspath(__file__))
+subprocess.call(['ln', '-s',
+ '{}/3rd_party/static'.format(dirpath),
+ '{}/opnfv_testapi/static'.format(dirpath)])
+
setuptools.setup(
setup_requires=['pbr==2.0.0'],
pbr=True)