diff options
Diffstat (limited to 'utils')
29 files changed, 610 insertions, 460 deletions
diff --git a/utils/fetch_os_creds.sh b/utils/fetch_os_creds.sh index 993c0b948..285f838db 100755 --- a/utils/fetch_os_creds.sh +++ b/utils/fetch_os_creds.sh @@ -153,36 +153,40 @@ elif [ "$installer_type" == "apex" ]; then sudo scp $ssh_options root@$installer_ip:/home/stack/overcloudrc.v3 $dest_path elif [ "$installer_type" == "compass" ]; then - verify_connectivity $installer_ip - controller_ip=$(sshpass -p'root' ssh 2>/dev/null $ssh_options root@${installer_ip} \ - 'mysql -ucompass -pcompass -Dcompass -e"select * from cluster;"' \ - | awk -F"," '{for(i=1;i<NF;i++)if($i~/\"127.0.0.1\"/) {print $(i+2);break;}}' \ - | grep -oP "\d+.\d+.\d+.\d+") - - if [ -z $controller_ip ]; then - error "The controller $controller_ip is not up. Please check that the POD is correctly deployed." - fi - - info "Fetching rc file from controller $controller_ip..." - sshpass -p root ssh 2>/dev/null $ssh_options root@${installer_ip} \ - "scp $ssh_options ${controller_ip}:/opt/admin-openrc.sh ." &> /dev/null - sshpass -p root scp 2>/dev/null $ssh_options root@${installer_ip}:~/admin-openrc.sh $dest_path &> /dev/null + if [ "${BRANCH}" == "master" ]; then + sudo docker cp compass-tasks:/opt/openrc $dest_path &> /dev/null + sudo chown $(whoami):$(whoami) $dest_path + else + verify_connectivity $installer_ip + controller_ip=$(sshpass -p'root' ssh 2>/dev/null $ssh_options root@${installer_ip} \ + 'mysql -ucompass -pcompass -Dcompass -e"select * from cluster;"' \ + | awk -F"," '{for(i=1;i<NF;i++)if($i~/\"127.0.0.1\"/) {print $(i+2);break;}}' \ + | grep -oP "\d+.\d+.\d+.\d+") - info "This file contains the mgmt keystone API, we need the public one for our rc file" + if [ -z $controller_ip ]; then + error "The controller $controller_ip is not up. Please check that the POD is correctly deployed." + fi - if grep "OS_AUTH_URL.*v2" $dest_path > /dev/null 2>&1 ; then - public_ip=$(sshpass -p root ssh $ssh_options root@${installer_ip} \ - "ssh ${controller_ip} 'source /opt/admin-openrc.sh; openstack endpoint show identity '" \ - | grep publicurl | awk '{print $4}') - else - public_ip=$(sshpass -p root ssh $ssh_options root@${installer_ip} \ - "ssh ${controller_ip} 'source /opt/admin-openrc.sh; \ - openstack endpoint list --interface public --service identity '" \ - | grep identity | awk '{print $14}') + info "Fetching rc file from controller $controller_ip..." + sshpass -p root ssh 2>/dev/null $ssh_options root@${installer_ip} \ + "scp $ssh_options ${controller_ip}:/opt/admin-openrc.sh ." &> /dev/null + sshpass -p root scp 2>/dev/null $ssh_options root@${installer_ip}:~/admin-openrc.sh $dest_path &> /dev/null + + info "This file contains the mgmt keystone API, we need the public one for our rc file" + + if grep "OS_AUTH_URL.*v2" $dest_path > /dev/null 2>&1 ; then + public_ip=$(sshpass -p root ssh $ssh_options root@${installer_ip} \ + "ssh ${controller_ip} 'source /opt/admin-openrc.sh; openstack endpoint show identity '" \ + | grep publicurl | awk '{print $4}') + else + public_ip=$(sshpass -p root ssh $ssh_options root@${installer_ip} \ + "ssh ${controller_ip} 'source /opt/admin-openrc.sh; \ + openstack endpoint list --interface public --service identity '" \ + | grep identity | awk '{print $14}') + fi + info "public_ip: $public_ip" + swap_to_public $public_ip fi - info "public_ip: $public_ip" - swap_to_public $public_ip - elif [ "$installer_type" == "joid" ]; then # do nothing...for the moment diff --git a/utils/jenkins-jnlp-connect.sh b/utils/jenkins-jnlp-connect.sh index 8fce2e021..c46ca89f5 100755 --- a/utils/jenkins-jnlp-connect.sh +++ b/utils/jenkins-jnlp-connect.sh @@ -61,8 +61,8 @@ main () { #make pid dir pidfile="/var/run/$jenkinsuser/jenkins_jnlp_pid" if ! [ -d /var/run/$jenkinsuser/ ]; then - mkdir /var/run/$jenkinsuser/ - chown $jenkinsuser:$jenkinsuser /var/run/$jenkinsuser/ + sudo mkdir /var/run/$jenkinsuser/ + sudo chown $jenkinsuser:$jenkinsuser /var/run/$jenkinsuser/ fi if [[ $skip_monit != true ]]; then diff --git a/utils/push-test-logs.sh b/utils/push-test-logs.sh index f0c488a5a..5021b7832 100644 --- a/utils/push-test-logs.sh +++ b/utils/push-test-logs.sh @@ -30,7 +30,8 @@ node_list=(\ 'arm-pod1' 'arm-pod3' \ '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-virtual1' 'huawei-virtual2' 'huawei-virtual3' 'huawei-virtual4'\ +'zte-virtual1') if [[ ! " ${node_list[@]} " =~ " ${testbed} " ]]; then diff --git a/utils/test/reporting/docker/reporting.sh b/utils/test/reporting/docker/reporting.sh index 49f4517f7..7fe97a88e 100755 --- a/utils/test/reporting/docker/reporting.sh +++ b/utils/test/reporting/docker/reporting.sh @@ -98,3 +98,5 @@ echo "daemon off;" >> /etc/nginx/nginx.conf cp /home/opnfv/utils/test/reporting/docker/supervisor.conf /etc/supervisor/conf.d/ ln -s /usr/bin/nodejs /usr/bin/node + +cd pages && /bin/bash angular.sh diff --git a/utils/test/reporting/docker/requirements.pip b/utils/test/reporting/docker/requirements.pip index 6de856e35..aeee3ba96 100644 --- a/utils/test/reporting/docker/requirements.pip +++ b/utils/test/reporting/docker/requirements.pip @@ -12,3 +12,4 @@ PyYAML==3.11 simplejson==3.8.1 jinja2==2.8 tornado==4.4.2 +requests==2.12.5 diff --git a/utils/test/reporting/docker/supervisor.conf b/utils/test/reporting/docker/supervisor.conf index 5e315babe..b323dd029 100644 --- a/utils/test/reporting/docker/supervisor.conf +++ b/utils/test/reporting/docker/supervisor.conf @@ -1,22 +1,19 @@ [supervisord] nodaemon = true -[program:reporting_tornado] +[program:tornado] user = root directory = /home/opnfv/utils/test/reporting/api/api command = python server.py --port=800%(process_num)d process_name=%(program_name)s%(process_num)d numprocs=4 numprocs_start=1 -autorestart = true -[program:reporting_nginx] +[program:nginx] user = root command = service nginx restart -autorestart = true -[program:reporting_angular] +[program:configuration] user = root directory = /home/opnfv/utils/test/reporting/pages -command = bash angular.sh -autorestart = true +command = bash config.sh diff --git a/utils/test/reporting/functest/reporting-status.py b/utils/test/reporting/functest/reporting-status.py index e700e047f..77ab7840f 100755 --- a/utils/test/reporting/functest/reporting-status.py +++ b/utils/test/reporting/functest/reporting-status.py @@ -107,7 +107,6 @@ for version in versions: scenario_results = rp_utils.getScenarios(healthcheck, installer, version) - # get nb of supported architecture (x86, aarch64) architectures = rp_utils.getArchitectures(scenario_results) logger.info("Supported architectures: {}".format(architectures)) diff --git a/utils/test/reporting/pages/angular.sh b/utils/test/reporting/pages/angular.sh index 080f27bb7..0e00ea635 100755 --- a/utils/test/reporting/pages/angular.sh +++ b/utils/test/reporting/pages/angular.sh @@ -1,8 +1,3 @@ -: ${SERVER_URL:='http://testresults.opnfv.org/reporting/api'} - -echo "var BASE_URL = 'http://${SERVER_URL}/landing-page'" >> app/scripts/app.config.js -echo "var PROJECT_URL = 'http://${SERVER_URL}'" >> app/scripts/app.config.js - apt-get install -y nodejs apt-get install -y npm npm install diff --git a/utils/test/reporting/pages/app/index.html b/utils/test/reporting/pages/app/index.html index f4eb65adf..843a6230e 100644 --- a/utils/test/reporting/pages/app/index.html +++ b/utils/test/reporting/pages/app/index.html @@ -87,10 +87,9 @@ <script src="scripts/controllers/auth.controller.js"></script> <script src="scripts/controllers/admin.controller.js"></script> <script src="scripts/controllers/main.controller.js"></script> - <script src="scripts/app.config.js"></script> <script src="scripts/controllers/testvisual.controller.js"></script> <!-- endbuild --> </body> -</html>
\ No newline at end of file +</html> diff --git a/utils/test/reporting/pages/app/scripts/app.config.js b/utils/test/reporting/pages/app/scripts/app.config.js deleted file mode 100644 index e69de29bb..000000000 --- a/utils/test/reporting/pages/app/scripts/app.config.js +++ /dev/null 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 0f3a17a03..44d9441de 100644 --- a/utils/test/reporting/pages/app/scripts/controllers/table.controller.js +++ b/utils/test/reporting/pages/app/scripts/controllers/table.controller.js @@ -8,378 +8,399 @@ * Controller of the opnfvdashBoardAngularApp */ angular.module('opnfvApp') - .controller('TableController', ['$scope', '$state', '$stateParams', '$http', 'TableFactory', function($scope, $state, $stateParams, $http, TableFactory) { - - $scope.filterlist = []; - $scope.selection = []; - $scope.statusList = []; - $scope.projectList = []; - $scope.installerList = []; - $scope.versionlist = []; - $scope.loopci = []; - $scope.time = []; - $scope.tableDataAll = {}; - $scope.tableInfoAll = {}; - $scope.scenario = {}; - - $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(); + .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(); + } } - } - $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.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.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.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(); + } } - } - init(); + init(); - function init() { - $scope.toggleSelection = toggleSelection; - getScenarioData(); - // radioSetting(); - getFilters(); - } + function init() { + $scope.toggleSelection = toggleSelection; + getScenarioData(); + getFilters(); + } - function getFilters() { - TableFactory.getFilter().get({ + 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); + + } else { + alert("网络错误"); + } + }) + } + function getScenarioData() { - }).$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; + // 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 + }; - $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); + TableFactory.getScenario(data).then(function(response) { + if (response.status == 200) { + $scope.scenario = response.data; - } else { - alert("网络错误"); - } - }) - } + reSettingcolspan(); + } + + }, function(error) { + + }) - 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 - }; - var config = { - headers: { - 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;' - } } - $http.post(utl, data, config).then(function(response) { - if (response.status == 200) { - $scope.scenario = response.data; + + function reSettingcolspan() { + if ($scope.selectProjects == undefined || $scope.selectProjects == null) { constructJson(); - } - }) - } + $scope.colspan = $scope.tableDataAll.colspan; - //construct json - function constructJson() { + } else { + constructJson(); + $scope.colspan = $scope.tempColspan; + } + // console.log("test") + } - var colspan; - var InstallerData; - var projectsInfo; - $scope.tableDataAll["scenario"] = []; + //construct json + function constructJson(selectProject) { + var colspan; + var InstallerData; + var projectsInfo; + $scope.tableDataAll["scenario"] = []; - for (var item in $scope.scenario.scenarios) { - var headData = Object.keys($scope.scenario.scenarios[item].installers).sort(); - var scenarioStatus = $scope.scenario.scenarios[item].status; - var scenarioStatusDisplay; - if (scenarioStatus == "success") { - scenarioStatusDisplay = "navy"; - } else if (scenarioStatus == "danger") { - scenarioStatusDisplay = "danger"; - } else if (scenarioStatus == "warning") { - scenarioStatusDisplay = "warning"; - } + for (var item in $scope.scenario.scenarios) { - InstallerData = headData; - var projectData = []; - var datadisplay = []; - var projects = []; + var headData = Object.keys($scope.scenario.scenarios[item].installers).sort(); + var scenarioStatus = $scope.scenario.scenarios[item].status; + var scenarioStatusDisplay; + if (scenarioStatus == "success") { + scenarioStatusDisplay = "navy"; + } else if (scenarioStatus == "danger") { + scenarioStatusDisplay = "danger"; + } else if (scenarioStatus == "warning") { + scenarioStatusDisplay = "warning"; + } - for (var j = 0; j < headData.length; j++) { + InstallerData = headData; + var projectData = []; + var datadisplay = []; + var projects = []; - 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]); - } + 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"); + } + + datadisplay.push(temArray); - 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"); } - datadisplay.push(temArray); - } - } + colspan = projects.length / headData.length; - colspan = projects.length / headData.length; - - var tabledata = { - scenarioName: item, - Installer: InstallerData, - projectData: projectData, - projects: projects, - datadisplay: datadisplay, - colspan: colspan, - status: scenarioStatus, - statusDisplay: scenarioStatusDisplay - }; + 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); + JSON.stringify(tabledata); + $scope.tableDataAll.scenario.push(tabledata); - // console.log(tabledata); - } + // console.log(tabledata); + + } - projectsInfo = $scope.tableDataAll.scenario[0].projects; + projectsInfo = $scope.tableDataAll.scenario[0].projects; - var tempHeadData = []; + var tempHeadData = []; - for (var i = 0; i < InstallerData.length; i++) { - for (var j = 0; j < colspan; j++) { - tempHeadData.push(InstallerData[i]); + for (var i = 0; i < InstallerData.length; i++) { + for (var j = 0; j < colspan; j++) { + tempHeadData.push(InstallerData[i]); + } } - } - //console.log(tempHeadData); + //console.log(tempHeadData); - var projectsInfoAll = []; + var projectsInfoAll = []; - for (var i = 0; i < projectsInfo.length; i++) { - var tempA = []; - tempA.push(projectsInfo[i]); - tempA.push(tempHeadData[i]); - projectsInfoAll.push(tempA); + for (var i = 0; i < projectsInfo.length; i++) { + var tempA = []; + tempA.push(projectsInfo[i]); + tempA.push(tempHeadData[i]); + projectsInfoAll.push(tempA); - } - //console.log(projectsInfoAll); + } + //console.log(projectsInfoAll); - $scope.tableDataAll["colspan"] = colspan; - $scope.tableDataAll["Installer"] = InstallerData; - $scope.tableDataAll["Projects"] = 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); + $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++; + //get json element size + function getSize(jsondata) { + var size = 0; + for (var item in jsondata) { + size++; + } + return size; } - return size; - } - $scope.colspan = $scope.tableDataAll.colspan; - // console.log($scope.colspan); + // 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); - } - //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); + //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); + } + //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); - 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); } - for (var i = 0; i < array3.length; i++) { - var temp = { - title: array3[i] - }; - tempTime.push(temp); + + 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); + } + 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; } - $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; + //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; + } } } - } - //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); + //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); + } } } - } - function toggleSelection(status) { - var idx = $scope.selection.indexOf(status); + function toggleSelection(status) { + var idx = $scope.selection.indexOf(status); + + if (idx > -1) { + $scope.selection.splice(idx, 1); + filterData($scope.selection) + } else { + $scope.selection.push(status); + filterData($scope.selection) + } + // console.log($scope.selection); - if (idx > -1) { - $scope.selection.splice(idx, 1); - filterData($scope.selection) - } else { - $scope.selection.push(status); - filterData($scope.selection) } - // console.log($scope.selection); - } + //filter function + function filterData(selection) { - //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.colspan = $scope.selectProjects.length; + //when some selection is empty, we set it full + if ($scope.selectInstallers.length == 0) { + $scope.selectInstallers = $scope.installerList; - $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.selectProjects.length == 0) { + $scope.selectProjects = $scope.projectList; + $scope.colspan = $scope.tableDataAll.colspan; + } else { + $scope.colspan = $scope.selectProjects.length; + $scope.tempColspan = $scope.colspan; } - if ($scope.installerListString.indexOf(selection[i]) > -1) { - $scope.selectInstallers.push(selection[i]); + if ($scope.selectStatus.length == 0) { + $scope.selectStatus = $scope.statusList } - } - $scope.colspan = $scope.selectProjects.length; - //when some selection is empty, we set it full - if ($scope.selectInstallers.length == 0) { - $scope.selectInstallers = $scope.installerList; + // console.log($scope.selectStatus); + // console.log($scope.selectProjects); } - if ($scope.selectProjects.length == 0) { - $scope.selectProjects = $scope.projectList; - $scope.colspan = $scope.tableDataAll.colspan; - } - if ($scope.selectStatus.length == 0) { - $scope.selectStatus = $scope.statusList - } - // console.log($scope.selectStatus); - // console.log($scope.selectProjects); } - - - }]);
\ No newline at end of file + ]);
\ No newline at end of file diff --git a/utils/test/reporting/pages/app/scripts/controllers/testvisual.controller.js b/utils/test/reporting/pages/app/scripts/controllers/testvisual.controller.js index def8e7293..894e10f77 100644 --- a/utils/test/reporting/pages/app/scripts/controllers/testvisual.controller.js +++ b/utils/test/reporting/pages/app/scripts/controllers/testvisual.controller.js @@ -16,7 +16,7 @@ angular.module('opnfvApp') $scope.vsperf = "542,185,640,414"; $scope.stor = "658,187,750,410"; $scope.qtip = "769,190,852,416"; - $scope.bootleneck = "870,192,983,419"; + $scope.bottlenecks = "870,192,983,419"; $scope.noPopArea1 = "26,8,1190,180"; $scope.noPopArea2 = "1018,193,1190,590"; $scope.noPopArea3 = "37,455,1003,584"; @@ -41,25 +41,18 @@ angular.module('opnfvApp') $scope.tableData = null; $scope.modalName = name; - var url = PROJECT_URL + '/projects/' + name + '/cases'; - - var config = { - headers: { - 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;' - } - } - $http.get(url, config).then(function(response) { + TableFactory.getProjectTestCases(name).then(function(response) { if (response.status == 200) { $scope.tableData = response.data; $scope.tableData = constructObjectArray($scope.tableData); console.log($scope.tableData); $loading.finish('Key'); - - - } + }, function(error) { + }) + } //construct key value for tableData 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 2a8cbd046..f0af34fb2 100644 --- a/utils/test/reporting/pages/app/scripts/factory/table.factory.js +++ b/utils/test/reporting/pages/app/scripts/factory/table.factory.js @@ -4,11 +4,24 @@ * get data factory */ angular.module('opnfvApp') - .factory('TableFactory', function($resource, $rootScope) { + .factory('TableFactory', function($resource, $rootScope, $http) { + + var BASE_URL = 'http://testresults.opnfv.org/reporting2'; + $.ajax({ + url: 'config.json', + async: false, + dataType: 'json', + success: function (response) { + BASE_URL = response.url; + }, + error: function (response){ + alert('fail to get api url, using default: http://testresults.opnfv.org/reporting2') + } + }); return { getFilter: function() { - return $resource(BASE_URL + '/filters', {}, { + return $resource(BASE_URL + '/landing-page/filters', {}, { 'get': { method: 'GET', @@ -16,33 +29,42 @@ angular.module('opnfvApp') }); }, getScenario: function() { - return $resource(BASE_URL + '/scenarios', {}, { - 'post': { - method: 'POST', + + var config = { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;' } - }) + } + + return $http.post(BASE_URL + '/landing-page/scenarios', {}, config); }, + + getProjectUrl: function() { - return $resource(PROJECT_URL + '/projects-page/projects', {}, { + return $resource(BASE_URL + '/projects-page/projects', {}, { 'get': { method: 'GET' } }) }, - getProjectTestCases: function() { - return $resource(PROJECT_URL + '/projects/:project/cases', { project: '@project' }, { - 'get': { - method: 'GET' + getProjectTestCases: function(name) { + var config = { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;' } - }) + }; + return $http.get(BASE_URL + '/projects/' + name + '/cases', {}, config) + + }, getProjectTestCaseDetail: function() { - return $resource(PROJECT_URL + '/projects/:project/cases/:testcase', { project: '@project', testcase: '@testcase' }, { + return $resource(BASE_URL + '/projects/:project/cases/:testcase', { project: '@project', testcase: '@testcase' }, { 'get': { method: 'GET' } }) } + }; - });
\ No newline at end of file + }); diff --git a/utils/test/reporting/pages/app/views/commons/testCaseVisual.html b/utils/test/reporting/pages/app/views/commons/testCaseVisual.html index 74eb56eba..4de4e187f 100644 --- a/utils/test/reporting/pages/app/views/commons/testCaseVisual.html +++ b/utils/test/reporting/pages/app/views/commons/testCaseVisual.html @@ -20,7 +20,7 @@ <area shape="rect" coords={{vsperf}} alt="test" href="{{vsperfurl}}" onmouseover="pop(event)" ng-mouseover="myTrigger('vsperf')" /> <area shape="rect" coords={{stor}} alt="test" href="{{storperfurl}}" onmouseover="pop(event)" ng-mouseover="myTrigger('storperf')"/> <area shape="rect" coords={{qtip}} alt="test" href="{{qtipurl}}" onmouseover="pop(event)" ng-mouseover="myTrigger('qtip')" /> - <area shape="rect" coords={{bootleneck}} alt="test" href="{{bottlenecksurl}}" onmouseover="pop(event)" ng-mouseover="myTrigger('bootlenecks')" /> + <area shape="rect" coords={{bottlenecks}} alt="test" href="{{bottlenecksurl}}" onmouseover="pop(event)" ng-mouseover="myTrigger('bottlenecks')" /> <area shape="rect" coords={{noPopArea1}} alt="test" onmouseover="pophide(event)" /> <area shape="rect" coords={{noPopArea2}} alt="test" onmouseover="pophide(event)" /> <area shape="rect" coords={{noPopArea3}} alt="test" onmouseover="pophide(event)" /> @@ -124,4 +124,4 @@ $('#popup').hide(); return true; } - </script>
\ No newline at end of file + </script> diff --git a/utils/test/reporting/pages/config.sh b/utils/test/reporting/pages/config.sh new file mode 100755 index 000000000..f9bb89ac8 --- /dev/null +++ b/utils/test/reporting/pages/config.sh @@ -0,0 +1,3 @@ +: ${SERVER_URL:='testresults.opnfv.org/reporting2'} + +echo "{\"url\": \"http://${SERVER_URL}\"}" > dist/config.json diff --git a/utils/test/reporting/run_test.sh b/utils/test/reporting/run_test.sh new file mode 100755 index 000000000..8c674ce5f --- /dev/null +++ b/utils/test/reporting/run_test.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -o errexit +set -o pipefail + + +# Get script directory +SCRIPTDIR=`dirname $0` + +# Creating virtual environment +if [ ! -z $VIRTUAL_ENV ]; then + venv=$VIRTUAL_ENV +else + venv=$SCRIPTDIR/.venv + virtualenv $venv +fi + +source $venv/bin/activate + +export CONFIG_REPORTING_YAML=$SCRIPTDIR/reporting.yaml + +# *************** +# Run unit tests +# *************** +echo "Running unit tests..." + +# install python packages +easy_install -U setuptools +easy_install -U pip +pip install -r $SCRIPTDIR/docker/requirements.pip +pip install -e $SCRIPTDIR + +python $SCRIPTDIR/setup.py develop + +# unit tests +# TODO: remove cover-erase +# To be deleted when all functest packages will be listed +nosetests --with-xunit \ + --cover-package=$SCRIPTDIR/utils \ + --with-coverage \ + --cover-xml \ + $SCRIPTDIR/tests/unit +rc=$? + +deactivate diff --git a/utils/test/reporting/run_unit_tests.sh b/utils/test/reporting/run_unit_tests.sh deleted file mode 100755 index 6b0e3b2b1..000000000 --- a/utils/test/reporting/run_unit_tests.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -set -o errexit -set -o pipefail - -# ****************************** -# prepare the env for the tests -# ****************************** -# Either Workspace is set (CI) -if [ -z $WORKSPACE ] -then - WORKSPACE="." -fi - -export CONFIG_REPORTING_YAML=./reporting.yaml - -# *************** -# Run unit tests -# *************** -echo "Running unit tests..." - -# start vitual env -virtualenv $WORKSPACE/reporting_venv -source $WORKSPACE/reporting_venv/bin/activate - -# install python packages -easy_install -U setuptools -easy_install -U pip -pip install -r $WORKSPACE/docker/requirements.pip -pip install -e $WORKSPACE - -python $WORKSPACE/setup.py develop - -# unit tests -# TODO: remove cover-erase -# To be deleted when all functest packages will be listed -nosetests --with-xunit \ - --cover-package=utils \ - --with-coverage \ - --cover-xml \ - tests/unit -rc=$? - -deactivate diff --git a/utils/test/reporting/utils/reporting_utils.py b/utils/test/reporting/utils/reporting_utils.py index 599a93818..0a178ba1f 100644 --- a/utils/test/reporting/utils/reporting_utils.py +++ b/utils/test/reporting/utils/reporting_utils.py @@ -117,19 +117,29 @@ def getScenarios(case, installer, version): url = ("http://" + url_base + "?case=" + case + "&period=" + str(period) + "&installer=" + installer + "&version=" + version) - request = Request(url) try: + request = Request(url) response = urlopen(request) k = response.read() results = json.loads(k) test_results = results['results'] - except URLError as e: - print('Got an error code:', e) + + page = results['pagination']['total_pages'] + if page > 1: + test_results = [] + for i in range(1, page + 1): + url_page = url + "&page=" + str(i) + request = Request(url_page) + response = urlopen(request) + k = response.read() + results = json.loads(k) + test_results += results['results'] + except URLError as err: + print('Got an error code:', err) if test_results is not None: test_results.reverse() - scenario_results = {} for r in test_results: @@ -157,7 +167,6 @@ def getScenarioStats(scenario_results): return scenario_stats -# TODO convergence with above function getScenarios def getScenarioStatus(installer, version): period = get_config('general.period') url_base = get_config('testapi.url') @@ -213,8 +222,8 @@ def getQtipResults(version, installer): k = response.read() response.close() results = json.loads(k)['results'] - except URLError as e: - print('Got an error code:', e) + except URLError as err: + print('Got an error code:', err) result_dict = {} if results: @@ -427,9 +436,9 @@ def export_csv(scenario_file_name, installer, version): "/functest/scenario_history_" + installer + ".csv") scenario_installer_file = open(scenario_installer_file_name, "a") - with open(scenario_file_name, "r") as f: + with open(scenario_file_name, "r") as scenario_file: scenario_installer_file.write("date,scenario,installer,detail,score\n") - for line in f: + for line in scenario_file: if installer in line: scenario_installer_file.write(line) scenario_installer_file.close diff --git a/utils/test/testapi/3rd_party/static/testapi-ui/config.json b/utils/test/testapi/3rd_party/static/testapi-ui/config.json index 9fdd85fbb..5d48c7b12 100644 --- a/utils/test/testapi/3rd_party/static/testapi-ui/config.json +++ b/utils/test/testapi/3rd_party/static/testapi-ui/config.json @@ -1 +1 @@ -{"testapiApiUrl": "http://testresults.opnfv.org/test/api/v1"} +{"testapiApiUrl": "http://localhost:8000/api/v1"} diff --git a/utils/test/testapi/deployment/deploy.py b/utils/test/testapi/deployment/deploy.py index 748bd34f8..6433fa6b2 100644 --- a/utils/test/testapi/deployment/deploy.py +++ b/utils/test/testapi/deployment/deploy.py @@ -8,10 +8,10 @@ docker_compose_yml = './docker-compose.yml' docker_compose_template = './docker-compose.yml.template' -def render_docker_compose(port, swagger_url): +def render_docker_compose(port, base_url): vars = { "expose_port": port, - "swagger_url": swagger_url, + "base_url": base_url, } template = env.get_template(docker_compose_template) yml = template.render(vars=vars) @@ -22,7 +22,7 @@ def render_docker_compose(port, swagger_url): def main(args): - render_docker_compose(args.expose_port, args.swagger_url) + render_docker_compose(args.expose_port, args.base_url) os.system('docker-compose -f {} up -d'.format(docker_compose_yml)) @@ -33,8 +33,8 @@ if __name__ == '__main__': required=False, default=8000, help='testapi exposed port') - parser.add_argument('-su', '--swagger-url', + parser.add_argument('-l', '--base-url', type=str, required=True, - help='testapi exposed swagger-url') + help='testapi exposed base-url') main(parser.parse_args()) diff --git a/utils/test/testapi/deployment/docker-compose.yml.template b/utils/test/testapi/deployment/docker-compose.yml.template index 5b131f747..cd684048e 100644 --- a/utils/test/testapi/deployment/docker-compose.yml.template +++ b/utils/test/testapi/deployment/docker-compose.yml.template @@ -8,7 +8,7 @@ services: container_name: opnfv-testapi environment: - mongodb_url=mongodb://mongo:27017/ - - swagger_url={{ vars.swagger_url }} + - base_url={{ vars.base_url }} ports: - "{{ vars.expose_port }}:8000" links: diff --git a/utils/test/testapi/docker/Dockerfile b/utils/test/testapi/docker/Dockerfile index e031e194c..5311f35b8 100644 --- a/utils/test/testapi/docker/Dockerfile +++ b/utils/test/testapi/docker/Dockerfile @@ -9,7 +9,7 @@ # # Execution: # $ docker run -dti -p 8001:8000 \ -# -e "swagger_url=http://10.63.243.17:8001" \ +# -e "base_url=http://10.63.243.17:8001" \ # -e "mongodb_url=mongodb://10.63.243.17:27017/" \ # opnfv/testapi:tag # diff --git a/utils/test/testapi/docker/prepare-env.sh b/utils/test/testapi/docker/prepare-env.sh index 9f07efbd1..4f1be7d6a 100755 --- a/utils/test/testapi/docker/prepare-env.sh +++ b/utils/test/testapi/docker/prepare-env.sh @@ -6,6 +6,10 @@ if [ "$mongodb_url" != "" ]; then sudo crudini --set --existing $FILE mongo url $mongodb_url fi -if [ "$swagger_url" != "" ]; then - sudo crudini --set --existing $FILE swagger base_url $swagger_url +if [ "$base_url" != "" ]; then + sudo crudini --set --existing $FILE api url $base_url/api/v1 + sudo crudini --set --existing $FILE swagger base_url $base_url + sudo crudini --set --existing $FILE ui url $base_url + sudo echo "{\"testapiApiUrl\": \"$base_url/api/v1\"}" > \ + /usr/local/lib/python2.7/dist-packages/opnfv_testapi/static/testapi-ui/config.json fi diff --git a/utils/test/testapi/etc/config.ini b/utils/test/testapi/etc/config.ini index dad59d2d0..9ae25209d 100644 --- a/utils/test/testapi/etc/config.ini +++ b/utils/test/testapi/etc/config.ini @@ -8,7 +8,7 @@ dbname = test_results_collection [api] # Listening port -url = http://testresults.opnfv.org/test/api/v1 +url = http://localhost:8000/api/v1 port = 8000 # Number of results for one page (integer value) @@ -22,7 +22,7 @@ authenticate = False base_url = http://localhost:8000 [ui] -url = http://testresults.opnfv.org/test +url = http://localhost:8000 [osid] diff --git a/utils/test/testapi/htmlize/htmlize.py b/utils/test/testapi/htmlize/htmlize.py index b8c4fb43f..4576d9bb0 100644 --- a/utils/test/testapi/htmlize/htmlize.py +++ b/utils/test/testapi/htmlize/htmlize.py @@ -40,13 +40,13 @@ if __name__ == '__main__': type=str, required=False, default=('http://testresults.opnfv.org' - '/test/swagger/spec.json'), + '/test/swagger/resources.json'), help='Resource Listing Spec File') parser.add_argument('-au', '--api-declaration-url', type=str, required=False, default=('http://testresults.opnfv.org' - '/test/swagger/spec'), + '/test/swagger/APIs'), help='API Declaration Spec File') parser.add_argument('-o', '--output-directory', required=True, diff --git a/utils/test/testapi/opnfv_testapi/resources/handlers.py b/utils/test/testapi/opnfv_testapi/resources/handlers.py index 42372e837..c7fed8f17 100644 --- a/utils/test/testapi/opnfv_testapi/resources/handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/handlers.py @@ -101,40 +101,71 @@ class GenericApiHandler(web.RequestHandler): @web.asynchronous @gen.coroutine def _list(self, query=None, res_op=None, *args, **kwargs): + sort = kwargs.get('sort') + page = kwargs.get('page', 0) + last = kwargs.get('last', 0) + per_page = kwargs.get('per_page', 0) if query is None: query = {} - data = [] - sort = kwargs.get('sort') - page = kwargs.get('page') - last = kwargs.get('last') - per_page = kwargs.get('per_page') - cursor = self._eval_db(self.table, 'find', query) - if sort: - cursor = cursor.sort(sort) - if last and last != 0: - cursor = cursor.limit(last) - if page: - records_count = yield cursor.count() - total_pages, remainder = divmod(records_count, per_page) - if remainder > 0: - total_pages += 1 - cursor = cursor.skip((page - 1) * per_page).limit(per_page) + 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 = self._eval_db(self.table, + 'aggregate', + pipelines, + allowDiskUse=True) + data = list() while (yield cursor.fetch_next): data.append(self.format_data(cursor.next_object())) if res_op is None: res = {self.table: data} else: res = res_op(data, *args) - if page: + if total_pages > 0: res.update({ 'pagination': { - 'current_page': page, + 'current_page': kwargs.get('page'), 'total_pages': total_pages } }) self.finish_request(res) + @staticmethod + def _calc_total_pages(records_count, last, page, per_page): + records_nr = records_count + if (records_count > last) and (last > 0): + records_nr = last + + total_pages = 0 + if page > 0: + total_pages, remainder = divmod(records_nr, per_page) + if remainder > 0: + total_pages += 1 + if page > total_pages: + raises.BadRequest( + 'Request page > total_pages [{}]'.format(total_pages)) + return total_pages + + @staticmethod + def _set_pipelines(query, sort, last, page, per_page): + pipelines = list() + if query: + pipelines.append({'$match': query}) + 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}) + + return pipelines + @web.asynchronous @gen.coroutine @check.not_exist diff --git a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py index 208af6da2..1773216c0 100644 --- a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py @@ -147,13 +147,13 @@ class ResultsCLHandler(GenericResultHandler): @in trust_indicator: query @required trust_indicator: False """ - limitations = {'sort': [('start_date', -1)]} + limitations = {'sort': {'start_date': -1}} last = self.get_query_argument('last', 0) if last is not None: last = self.get_int('last', last) limitations.update({'last': last}) - page = self.get_query_argument('page', 1) + page = self.get_query_argument('page', None) if page is not None: page = self.get_int('page', page) limitations.update({'page': page, diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py b/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py index b2564a6de..adaf6f7c3 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py @@ -35,15 +35,14 @@ class MemCursor(object): return self.collection.pop() def sort(self, key_or_list): - key = key_or_list[0][0] - if key_or_list[0][1] == -1: - reverse = True - else: - reverse = False + for k, v in key_or_list.iteritems(): + if v == -1: + reverse = True + else: + reverse = False - if key_or_list is not None: self.collection = sorted(self.collection, - key=itemgetter(key), reverse=reverse) + key=itemgetter(k), reverse=reverse) return self def limit(self, limit): @@ -202,6 +201,27 @@ class MemDb(object): def find(self, *args): return MemCursor(self._find(*args)) + def _aggregate(self, *args, **kwargs): + res = self.contents + print args + for arg in args[0]: + for k, v in arg.iteritems(): + if k == '$match': + res = self._find(v) + cursor = MemCursor(res) + for arg in args[0]: + for k, v in arg.iteritems(): + if k == '$sort': + cursor = cursor.sort(v) + elif k == '$skip': + cursor = cursor.skip(v) + elif k == '$limit': + cursor = cursor.limit(v) + return cursor + + def aggregate(self, *args, **kwargs): + return self._aggregate(*args, **kwargs) + def _update(self, spec, document, check_keys=True): updated = False diff --git a/utils/upload-artifact.sh b/utils/upload-artifact.sh new file mode 100644 index 000000000..b66cdb7e1 --- /dev/null +++ b/utils/upload-artifact.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# SPDX-license-identifier: Apache-2.0 +############################################################################## +# Copyright (c) 2016 Orange and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +set -e +set -o pipefail + +export PATH=$PATH:/usr/local/bin/ + +# 2 paramters +# - $1: the source directory where the files to be uploaded are located +# - $2: the target on artifact http://artifact.opnfv.org/<project>/$2 +# if not set, default value is <project>/docs +project=$PROJECT +if [ -z "$2" ] + then + artifact_dir="$project/docs" + else + artifact_dir="$project/$2" +fi +DIRECTORY="$1" + + +# check that the API doc directory does exist before pushing it to artifact +if [ ! -d "$DIRECTORY" ]; then + echo "Directory to be uploaded "$DIRECTORY" does not exist" + exit 1 +fi +set +e +gsutil&>/dev/null +if [ $? != 0 ]; then + echo "Not possible to push results to artifact: gsutil not installed" + exit 1 +else + gsutil ls gs://artifacts.opnfv.org/"$project"/ &>/dev/null + if [ $? != 0 ]; then + echo "Not possible to push results to artifact: gsutil not installed." + exit 1 + else + echo "Uploading file(s) to artifact $artifact_dir" + gsutil -m cp -r "$DIRECTORY"/* gs://artifacts.opnfv.org/"$artifact_dir"/ >/dev/null 2>&1 + fi +fi |