diff options
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/fetch_os_creds.sh | 11 | ||||
-rw-r--r-- | utils/push-test-logs.sh | 4 | ||||
-rw-r--r-- | utils/test/declaration/addtestcase.php | 40 | ||||
-rw-r--r-- | utils/test/declaration/index.php | 221 | ||||
-rw-r--r-- | utils/test/declaration/testcases.php | 36 | ||||
-rw-r--r-- | utils/test/testapi/docker/Dockerfile | 2 | ||||
-rw-r--r-- | utils/test/testapi/htmlize/doc-build.sh | 9 | ||||
-rw-r--r-- | utils/test/testapi/htmlize/finish.sh | 2 | ||||
-rw-r--r-- | utils/test/testapi/htmlize/prepare.sh | 3 | ||||
-rw-r--r-- | utils/test/testapi/htmlize/push-doc-artifact.sh | 6 | ||||
-rw-r--r-- | utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py | 18 | ||||
-rw-r--r-- | utils/test/testapi/opnfv_testapi/resources/scenario_models.py | 13 | ||||
-rw-r--r-- | utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py | 1 | ||||
-rw-r--r-- | utils/test/testapi/opnfv_testapi/tests/unit/scenario-create.json | 38 | ||||
-rw-r--r-- | utils/test/testapi/opnfv_testapi/tests/unit/test_base.py | 17 | ||||
-rw-r--r-- | utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py | 55 |
16 files changed, 163 insertions, 313 deletions
diff --git a/utils/fetch_os_creds.sh b/utils/fetch_os_creds.sh index 3667dbe6c..856f69a27 100755 --- a/utils/fetch_os_creds.sh +++ b/utils/fetch_os_creds.sh @@ -38,6 +38,16 @@ verify_connectivity() { error "Can not talk to $ip." } + +swap_to_public() { + if [ "$1" != "" ]; then + info "Exchanging keystone public IP in rc file to $public_ip" + sed -i "/OS_AUTH_URL/c\export OS_AUTH_URL=\'$public_ip'" $dest_path + sed -i 's/internalURL/publicURL/g' $dest_path + fi +} + + : ${DEPLOY_TYPE:=''} #Get options @@ -151,6 +161,7 @@ elif [ "$installer_type" == "compass" ]; then | grep identity | awk '{print $14}') fi info "public_ip: $public_ip" + swap_to_public $public_ip elif [ "$installer_type" == "joid" ]; then diff --git a/utils/push-test-logs.sh b/utils/push-test-logs.sh index 913748f03..61a6c327d 100644 --- a/utils/push-test-logs.sh +++ b/utils/push-test-logs.sh @@ -27,7 +27,9 @@ node_list=(\ 'ericsson-virtual1' 'ericsson-virtual2' 'ericsson-virtual3' \ 'ericsson-virtual4' 'ericsson-virtual5' \ 'arm-pod1' 'arm-pod3' \ -'huawei-pod1' 'huawei-pod2' 'huawei-virtual1' 'huawei-virtual2' 'huawei-virtual3' 'huawei-virtual4') +'huawei-pod1' 'huawei-pod2' 'huawei-pod3' 'huawei-pod4' 'huawei-pod5' \ +'huawei-pod6' 'huawei-pod7' \ +'huawei-virtual1' 'huawei-virtual2' 'huawei-virtual3' 'huawei-virtual4') if [[ ! " ${node_list[@]} " =~ " ${testbed} " ]]; then diff --git a/utils/test/declaration/addtestcase.php b/utils/test/declaration/addtestcase.php deleted file mode 100644 index 0e5bed689..000000000 --- a/utils/test/declaration/addtestcase.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php -function sendPostData($url, $post){ - $ch = curl_init($url); - $headers= array('Accept: application/json','Content-Type: application/json'); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_POSTFIELDS,$post); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); - $result = curl_exec($ch); - curl_close($ch); - return $result; -} - -if(isset($_REQUEST['url'])){ - $url=$_REQUEST['url']; -} -if(isset($_REQUEST['name'])){ - $name=$_REQUEST['name']; -} -if(isset($_REQUEST['desc'])){ - $desc=$_REQUEST['desc']; -} -if(isset($_REQUEST['project'])){ - - $url_send=$_REQUEST['project']; - $url_send="http://testresults.opnfv.org:80/test/api/v1/projects/".$url_send."/cases"; - $str_data=array('url'=>$url,'name'=>$name,'description'=>$desc); - $str_data=json_encode($str_data); - $res=sendPostData($url_send, $str_data); - echo '<div class="alert alert-success"> <strong>Success!</strong> Added New test Case </div>'; - -}else{ - - echo '<div class="alert alert-danger"> <strong>Error!</strong> Failed to Add New test Case </div>'; - -} - -?> - diff --git a/utils/test/declaration/index.php b/utils/test/declaration/index.php deleted file mode 100644 index b2c5d0370..000000000 --- a/utils/test/declaration/index.php +++ /dev/null @@ -1,221 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <title>OPNFV DashBoard</title> - <meta charset="utf-8"> - <meta name="viewport" content="width=device-width, initial-scale=1"> - <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> - <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> - <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> -<script> -$(function() { - - $('form#new_testcase').on('submit', function(){ - var selected = $('select#sel_pro2').find("option:selected").val(); - var uri = $('input#uri').val(); - var name = $('input#name').val(); - var desc = $('textarea#desc').val(); - var new_url="http://testresults.opnfv.org:80/test/api/v1/projects/"+selected+"/cases"; - $.post("addtestcase.php", {"project":selected,"url":uri,"name":name,"description":desc}, function(result){ - $("div#result").html(result); - }); - }); - -}); - -$(function() { - - $('select#sel1').on('change', function(){ - var selected = $(this).find("option:selected").val(); - var new_url="http://testresults.opnfv.org:80/test/api/v1/projects/"+selected+"/cases"; - //$.post('testcases.php', {project: selected}); - console.log(selected); - $.post("testcases.php", {project: selected}, function(result){ - $("div#4a").html(result); - }); - - }); - -}); -</script> -<style> -body { - padding : 10px ; -} - -#exTab1 .tab-content { - color : black; - padding : 5px 15px; -} - -#exTab2 h3 { - color : white; - background-color: #428bca; - padding : 5px 15px; -} - -/* remove border radius for the tab */ - -#exTab1 .nav-pills > li > a { - border-radius: 0; -} - -/* change border radius for the tab , apply corners on top*/ - -#exTab3 .nav-pills > li > a { - border-radius: 4px 4px 0 0 ; -} - -#exTab3 .tab-content { - color : white; - background-color: #428bca; - padding : 5px 15px; -} - -</style> -</head> -<body> - -<div class="container"> - <h1>OPNFV DASHBOARD: </h1></div> -<div id="exTab1" class="container"> - <ul class="nav nav-pills"> - <li class="active"> - <a href="#1a" data-toggle="tab">PODS</a> - </li> - <li><a href="#2a" data-toggle="tab">PROJECTS</a> - </li> - <li><a href="#3a" data-toggle="tab">TESTCASES</a> - </li> - <li><a href="#5a" data-toggle="tab">ADD TESTCASE</a> - </li> - <li><a href="http://testresults.opnfv.org/kibana_dashboards/" >RESULTS</a> - </li> - </ul> - <div class="tab-content clearfix"> - <div class="tab-pane active" id="1a"> - <table class="table table-striped"> - <thead> - <tr> - <th>#</th> - <th>Pod Name</th> - <th>Creation Date</th> - <th>Role</th> - <th>Mode</th> - </tr> - </thead> - <?php - $url = "http://testresults.opnfv.org:80/test/api/v1/pods"; - $response = file_get_contents($url); - $data = json_decode($response); - $pods = $data->pods; - $i=1; - foreach ( $pods as $pod ){ - - $column_str=""; - $column_str="<tr><td>".$i."</td>"; - $column_str=$column_str."<td>".$pod->name."</td>"; - $column_str= $column_str."<td>".$pod->creation_date."</td>"; - $column_str= $column_str."<td>".$pod->role."</td>"; - $column_str= $column_str."<td>".$pod->mode."</td>"; - $column_str= $column_str."</tr>"; - echo $column_str; - $i=$i+1; - } - ?> - </table> - </div> - <div class="tab-pane" id="2a"> - <table class="table table-striped"> - <thead> - <tr> - <th>#</th> - <th>Project</th> - <th>Creation Date</th> - </tr> - </thead> - <?php - $url = "http://testresults.opnfv.org:80/test/api/v1/projects"; - $response = file_get_contents($url); - $data = json_decode($response); - $projects=$data->projects; - $i=0; - foreach ( $projects as $project ){ - - $column_str=""; - $column_str="<tr><td>".$i."</td>"; - $column_str=$column_str."<td>".$project->name."</td>"; - $column_str= $column_str."<td>".$project->creation_date."</td>"; - $column_str= $column_str."</tr>"; - echo $column_str; - $i=$i+1; - } -?> - </table> - </div> - <div class="tab-pane" id="3a"> -<div class="form-group"> - <label for="sel1">Select list:</label> - <select class="form-control" id="sel1"> -<?php - $url = "http://testresults.opnfv.org:80/test/api/v1/projects"; - $response = file_get_contents($url); - $data = json_decode($response); - $projects=$data->projects; - $i=0; - $firstvalue=$projects[0]->name; - foreach ( $projects as $project ){ - $column_str=""; - $column_str="<option>".$project->name."</option>"; - echo $column_str; - } - -?> -</select> -</div> - <div class="tab-pane" id="4a"> - <?php - require "testcases.php"; - ?> - </div> - </div> - <div class="tab-pane" id="5a"> - <form role="form" id="new_testcase"> -<div class="form-group"> - <label for="sel1">Select list:</label> - <select class="form-control" id="sel_pro2"> -<?php - $url = "http://testresults.opnfv.org:80/test/api/v1/projects"; - $response = file_get_contents($url); - $data = json_decode($response); - $projects=$data->projects; - $i=0; - $firstvalue=$projects[0]->name; - foreach ( $projects as $project ){ - $column_str=""; - $column_str="<option>".$project->name."</option>"; - echo $column_str; - } -?> -</select> -</div> -<div class="form-group"> <!-- Name field --> - <label class="control-label " for="name">TestCase URI</label> - <input class="form-control" id="uri" name="uri" type="text"/> - </div> -<div class="form-group"> <!-- Name field --> - <label class="control-label " for="name">TestCase Name</label> - <input class="form-control" id="name" name="name" type="text"/> - </div> -<div class="form-group"> <!-- Name field --> - <label class="control-label " for="name">Description</label> - <textarea class="form-control" rows="5" id="desc"></textarea> - </div> - <button type="submit" class="btn btn-default">Submit</button> -</form> - </div> -<div class="container" id="result"></div> - </div> -</div> -</body> -</html> diff --git a/utils/test/declaration/testcases.php b/utils/test/declaration/testcases.php deleted file mode 100644 index 20645807e..000000000 --- a/utils/test/declaration/testcases.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - if(isset($_REQUEST['project'])){ - $selected=$_REQUEST['project']; - } - else{ - $url = "http://testresults.opnfv.org:80/test/api/v1/projects"; - $response = file_get_contents($url); - $data = json_decode($response); - $projects=$data->projects; - $selected=$projects[0]->name; - } - $new_url="http://testresults.opnfv.org:80/test/api/v1/projects/".$selected."/cases"; - $response = file_get_contents($new_url); - $data = json_decode($response); - $testcases=$data->testcases; - $i=0; - $column_str=""; - $column_str=$column_str."<table class=\"table table-striped\"><tr>"; - $column_str=$column_str."<th>#</th><th>Test Case Name</th>"; - $column_str=$column_str."<th>Creation Date</th>"; - $column_str=$column_str."<th>Description</th></tr>"; - foreach ( $testcases as $testcase ){ - $i=$i+1; - $column_str=$column_str."<tr>"; - $column_str=$column_str."<td>".$i."</td>"; - $column_str=$column_str."<td>".$testcase->name."</td>"; - $column_str=$column_str."<td>".$testcase->creation_date."</td>"; - $column_str=$column_str."<td>".$testcase->description."</td>"; - $column_str=$column_str."</tr>"; - - } - $column_str=$column_str."</table>"; - echo $column_str; - -?> - diff --git a/utils/test/testapi/docker/Dockerfile b/utils/test/testapi/docker/Dockerfile index b0272e609..86513e05b 100644 --- a/utils/test/testapi/docker/Dockerfile +++ b/utils/test/testapi/docker/Dockerfile @@ -48,5 +48,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 python setup.py install +RUN bash install.sh CMD ["bash", "docker/start-server.sh"] diff --git a/utils/test/testapi/htmlize/doc-build.sh b/utils/test/testapi/htmlize/doc-build.sh new file mode 100644 index 000000000..e492c97b5 --- /dev/null +++ b/utils/test/testapi/htmlize/doc-build.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Create virtual environment +source $WORKSPACE/testapi_venv/bin/activate + +# Install Pre-requistics +pip install requests + +python ./utils/test/testapi/htmlize/htmlize.py -o ${WORKSPACE}/ diff --git a/utils/test/testapi/htmlize/finish.sh b/utils/test/testapi/htmlize/finish.sh index d24ae056c..dc3aa868b 100644 --- a/utils/test/testapi/htmlize/finish.sh +++ b/utils/test/testapi/htmlize/finish.sh @@ -13,5 +13,3 @@ if [ $proc_number -gt 0 ]; then echo "Kill opnfv-testapi server $procs" ps -ef | grep opnfv-testapi | grep -v grep | awk '{print $2}' | xargs kill -kill &>/dev/null fi - -deactivate diff --git a/utils/test/testapi/htmlize/prepare.sh b/utils/test/testapi/htmlize/prepare.sh index 67158f211..e79ac5693 100644 --- a/utils/test/testapi/htmlize/prepare.sh +++ b/utils/test/testapi/htmlize/prepare.sh @@ -9,9 +9,6 @@ virtualenv testapi_venv source testapi_venv/bin/activate -# Install Pre-requisites -pip install requests - # Swgger Codegen Tool url="http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.2.1/swagger-codegen-cli-2.2.1.jar" diff --git a/utils/test/testapi/htmlize/push-doc-artifact.sh b/utils/test/testapi/htmlize/push-doc-artifact.sh index 383565df1..4cf1988b0 100644 --- a/utils/test/testapi/htmlize/push-doc-artifact.sh +++ b/utils/test/testapi/htmlize/push-doc-artifact.sh @@ -7,19 +7,21 @@ export PATH=$PATH:/usr/local/bin/ project=$PROJECT workspace=$WORKSPACE -artifact_dir="functest/docs" +artifact_dir="$project/docs" 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 document to artifact $artifact_dir" gsutil cp "$workspace"/index.html gs://artifacts.opnfv.org/"$artifact_dir"/testapi.html >/dev/null 2>&1 - echo "Document can be found at http://artifacts.opnfv.org/functest/docs/testapi.html" + echo "Document can be found at http://artifacts.opnfv.org/releng/docs/testapi.html" fi fi diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py index 75754d8b9..7bf3d5d53 100644 --- a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py @@ -1,3 +1,4 @@ +from opnfv_testapi.common.constants import HTTP_FORBIDDEN from opnfv_testapi.resources.handlers import GenericApiHandler from opnfv_testapi.resources.scenario_models import Scenario from opnfv_testapi.tornado_swagger import swagger @@ -29,10 +30,23 @@ class ScenariosCLHandler(GenericScenarioHandler): """ @description: create a new scenario by name @param body: scenario to be created - @type body: L{string} + @type body: L{ScenarioCreateRequest} + @in body: body @rtype: L{CreateResponse} + @return 200: scenario is created. + @raise 403: scenario already exists + @raise 400: body or name not provided """ - pass + def query(data): + return {'name': data.name} + + def error(data): + message = '{} already exists as a scenario'.format(data.name) + return HTTP_FORBIDDEN, message + + miss_checks = ['name'] + db_checks = [(self.table, False, query, error)] + self._create(miss_checks=miss_checks, db_checks=db_checks) class ScenarioGURHandler(GenericScenarioHandler): diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py index 0748a3738..b4bb3634b 100644 --- a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py +++ b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py @@ -61,6 +61,17 @@ class ScenarioInstaller(models.ModelBase): @swagger.model() +class ScenarioCreateRequest(models.ModelBase): + """ + @property installers: + @ptype installers: C{list} of L{ScenarioInstaller} + """ + def __init__(self, name='', installers=None): + self.name = name + self.installers = installers if installers else list() + + +@swagger.model() class Scenario(models.ModelBase): """ @property installers: @@ -69,7 +80,7 @@ class Scenario(models.ModelBase): def __init__(self, name='', create_date='', _id='', installers=None): self.name = name self._id = _id - self.create_date = create_date + self.creation_date = create_date self.installers = installers if installers else list() 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 3dd87e603..d86d8eadf 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py @@ -189,3 +189,4 @@ pods = MemDb() projects = MemDb() testcases = MemDb() results = MemDb() +scenarios = MemDb() diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/scenario-create.json b/utils/test/testapi/opnfv_testapi/tests/unit/scenario-create.json new file mode 100644 index 000000000..eba8b6c0a --- /dev/null +++ b/utils/test/testapi/opnfv_testapi/tests/unit/scenario-create.json @@ -0,0 +1,38 @@ +{ + "name": "nosdn-nofeature-ha", + "installers": + [ + { + "installer": "apex", + "versions": + [ + { + "owner": "Luke", + "version": "master", + "projects": + [ + { + "project": "functest", + "customs": [ "healthcheck", "vping_ssh"], + "scores": + [ + { + "date": "2017-01-08 22:46:44", + "score": "12/14" + } + + ], + "trust_indicators": [] + }, + { + "project": "yardstick", + "customs": [], + "scores": [], + "trust_indicators": [] + } + ] + } + ] + } + ] +}
\ No newline at end of file diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py b/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py index ff1a1932c..9343ab2fb 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py @@ -47,11 +47,11 @@ class TestBase(AsyncHTTPTestCase): return self.create_help(self.basePath, req, *args) def create_help(self, uri, req, *args): - if req: - req = req.format() + if req and not isinstance(req, str): + req = json.dumps(req.format()) res = self.fetch(self._update_uri(uri, *args), method='POST', - body=json.dumps(req), + body=req if req else json.dumps(None), headers=self.headers) return self._get_return(res, self.create_res) @@ -123,9 +123,17 @@ class TestBase(AsyncHTTPTestCase): self.assertIn(self.basePath, body.href) def assert_create_body(self, body, req=None, *args): + import inspect if not req: req = self.req_d - new_args = args + tuple([req.name]) + resource_name = '' + if inspect.isclass(req): + resource_name = req.name + elif isinstance(req, dict): + resource_name = req['name'] + elif isinstance(req, str): + resource_name = json.loads(req)['name'] + new_args = args + tuple([resource_name]) self.assertIn(self._get_uri(*new_args), body.href) @staticmethod @@ -134,3 +142,4 @@ class TestBase(AsyncHTTPTestCase): fake_pymongo.projects.clear() fake_pymongo.testcases.clear() fake_pymongo.results.clear() + fake_pymongo.scenarios.clear() diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py b/utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py new file mode 100644 index 000000000..8e827813c --- /dev/null +++ b/utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py @@ -0,0 +1,55 @@ +import json +import os + +from opnfv_testapi.common.constants import HTTP_BAD_REQUEST +from opnfv_testapi.common.constants import HTTP_FORBIDDEN +from opnfv_testapi.common.constants import HTTP_OK +from opnfv_testapi.resources.scenario_models import ScenarioCreateRequest +from test_testcase import TestBase + + +class TestScenarioBase(TestBase): + def setUp(self): + super(TestScenarioBase, self).setUp() + self.basePath = '/api/v1/scenarios' + self.load_request('scenario-create.json') + + def tearDown(self): + pass + + def assert_body(self, project, req=None): + pass + + def load_request(self, f_req): + with open(os.path.join(os.path.dirname(__file__), f_req), 'r') as f: + self.req_d = json.dumps(json.load(f)) + f.close() + + +class TestScenarioCreate(TestScenarioBase): + def test_withoutBody(self): + (code, body) = self.create() + self.assertEqual(code, HTTP_BAD_REQUEST) + + def test_emptyName(self): + req_empty = ScenarioCreateRequest('') + (code, body) = self.create(req_empty) + self.assertEqual(code, HTTP_BAD_REQUEST) + self.assertIn('name missing', body) + + def test_noneName(self): + req_none = ScenarioCreateRequest(None) + (code, body) = self.create(req_none) + self.assertEqual(code, HTTP_BAD_REQUEST) + self.assertIn('name missing', body) + + def test_success(self): + (code, body) = self.create_d() + self.assertEqual(code, HTTP_OK) + self.assert_create_body(body) + + def test_alreadyExist(self): + self.create_d() + (code, body) = self.create_d() + self.assertEqual(code, HTTP_FORBIDDEN) + self.assertIn('already exists', body) |