diff options
16 files changed, 168 insertions, 108 deletions
diff --git a/jjb/fuel/fuel-daily-jobs.yml b/jjb/fuel/fuel-daily-jobs.yml index c8c3746b0..4bdfa5b01 100644 --- a/jjb/fuel/fuel-daily-jobs.yml +++ b/jjb/fuel/fuel-daily-jobs.yml @@ -630,7 +630,7 @@ - trigger: name: 'fuel-os-nosdn-nofeature-ha-zte-pod3-daily-master-trigger' triggers: - - timed: '0 10 * * *' + - timed: '' # '0 10 * * *' - trigger: name: 'fuel-os-odl-nofeature-ha-zte-pod3-daily-master-trigger' triggers: diff --git a/jjb/functest/functest-alpine.sh b/jjb/functest/functest-alpine.sh index 33a64a414..35311c3a9 100755 --- a/jjb/functest/functest-alpine.sh +++ b/jjb/functest/functest-alpine.sh @@ -71,7 +71,11 @@ set +e if [ ${FUNCTEST_SUITE_NAME} == 'healthcheck' ]; then tiers=(healthcheck) else - tiers=(healthcheck smoke features vnf) + if [ ${DEPLOY_TYPE} == 'baremetal' ]; then + tiers=(healthcheck smoke features vnf) + else + tiers=(healthcheck smoke features) + fi fi cmd_opt='prepare_env start && run_tests -r -t all' @@ -80,7 +84,7 @@ for tier in ${tiers[@]}; do FUNCTEST_IMAGE=opnfv/functest-${tier} echo "Functest: Pulling Functest Docker image ${FUNCTEST_IMAGE} ..." docker pull ${FUNCTEST_IMAGE}>/dev/null - cmd="docker run ${envs} ${volumes} ${FUNCTEST_IMAGE} /bin/bash -c '${cmd_opt}'" + cmd="docker run --privileged=true ${envs} ${volumes} ${FUNCTEST_IMAGE} /bin/bash -c '${cmd_opt}'" echo "Running Functest tier '${tier}'. CMD: ${cmd}" eval ${cmd} done diff --git a/jjb/functest/functest-daily-jobs.yml b/jjb/functest/functest-daily-jobs.yml index cbf175567..23c6e490a 100644 --- a/jjb/functest/functest-daily-jobs.yml +++ b/jjb/functest/functest-daily-jobs.yml @@ -378,7 +378,6 @@ name: functest-daily-builder builders: - 'functest-cleanup' - - 'set-functest-env-alpine' - 'functest-daily' - 'functest-store-results' @@ -412,7 +411,10 @@ name: functest-daily builders: - shell: - !include-raw: ./functest-alpine.sh + !include-raw: + - ./functest-env-presetup.sh + - ../../utils/fetch_os_creds.sh + - ./functest-alpine.sh - builder: name: functest-arm-daily diff --git a/jjb/xci/bifrost-verify-jobs.yml b/jjb/xci/bifrost-verify-jobs.yml index d6eb5ffdb..f9106831c 100644 --- a/jjb/xci/bifrost-verify-jobs.yml +++ b/jjb/xci/bifrost-verify-jobs.yml @@ -21,19 +21,19 @@ #-------------------------------- distro: - 'xenial': - disabled: false + disabled: true dib-os-release: 'xenial' dib-os-element: 'ubuntu-minimal' dib-os-packages: 'vlan,vim,less,bridge-utils,language-pack-en,iputils-ping,rsyslog,curl' extra-dib-elements: 'openssh-server' - 'centos7': - disabled: false + disabled: true dib-os-release: '7' dib-os-element: 'centos-minimal' dib-os-packages: 'vim,less,bridge-utils,iputils,rsyslog,curl' extra-dib-elements: 'openssh-server' - 'suse': - disabled: false + disabled: true dib-os-release: '42.3' dib-os-element: 'opensuse-minimal' dib-os-packages: 'vim,less,bridge-utils,iputils,rsyslog,curl' 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 e366670a9..22f29347b 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 @@ -54,6 +54,7 @@ <a href="#" ng-click="showPod = !showPod">{{pod.name}}</a> <div class="show-pod" ng-class="{ 'hidden': ! showPod }" style="margin-left:24px;"> <p> + owner: {{pod.owner}}<br> role: {{pod.role}}<br> mode: {{pod.mode}}<br> create_date: {{pod.creation_date}}<br> diff --git a/utils/test/testapi/opnfv_testapi/common/check.py b/utils/test/testapi/opnfv_testapi/common/check.py index acd331784..e80b1c6b7 100644 --- a/utils/test/testapi/opnfv_testapi/common/check.py +++ b/utils/test/testapi/opnfv_testapi/common/check.py @@ -10,19 +10,33 @@ import functools import re from tornado import gen -from tornado import web +from opnfv_testapi.common import constants from opnfv_testapi.common import message from opnfv_testapi.common import raises from opnfv_testapi.db import api as dbapi -def authenticate(method): - @web.asynchronous - @gen.coroutine +def is_authorized(method): @functools.wraps(method) def wrapper(self, *args, **kwargs): - if self.auth: + if self.table in ['pods']: + testapi_id = self.get_secure_cookie(constants.TESTAPI_ID) + if not testapi_id: + raises.Unauthorized(message.not_login()) + user_info = yield dbapi.db_find_one('users', {'user': testapi_id}) + if not user_info: + raises.Unauthorized(message.not_lfid()) + kwargs['owner'] = testapi_id + ret = yield gen.coroutine(method)(self, *args, **kwargs) + raise gen.Return(ret) + return wrapper + + +def valid_token(method): + @functools.wraps(method) + def wrapper(self, *args, **kwargs): + if self.auth and self.table == 'results': try: token = self.request.headers['X-Auth-Token'] except KeyError: diff --git a/utils/test/testapi/opnfv_testapi/common/message.py b/utils/test/testapi/opnfv_testapi/common/message.py index 951cbaf9c..8b5c3fb7a 100644 --- a/utils/test/testapi/opnfv_testapi/common/message.py +++ b/utils/test/testapi/opnfv_testapi/common/message.py @@ -42,6 +42,14 @@ def invalid_token(): return 'Invalid Token' +def not_login(): + return 'TestAPI id is not provided' + + +def not_lfid(): + return 'Not a valid Linux Foundation Account' + + def no_update(): return 'Nothing to update' diff --git a/utils/test/testapi/opnfv_testapi/resources/handlers.py b/utils/test/testapi/opnfv_testapi/resources/handlers.py index ed55c7028..8e5dab235 100644 --- a/utils/test/testapi/opnfv_testapi/resources/handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/handlers.py @@ -73,7 +73,10 @@ class GenericApiHandler(web.RequestHandler): cls_data = self.table_cls.from_dict(data) return cls_data.format_http() - @check.authenticate + @web.asynchronous + @gen.coroutine + @check.is_authorized + @check.valid_token @check.no_body @check.miss_fields @check.carriers_exist @@ -172,13 +175,15 @@ class GenericApiHandler(web.RequestHandler): def _get_one(self, data, query=None): self.finish_request(self.format_data(data)) - @check.authenticate + @web.asynchronous + @gen.coroutine @check.not_exist def _delete(self, data, query=None): yield dbapi.db_delete(self.table, query) self.finish_request() - @check.authenticate + @web.asynchronous + @gen.coroutine @check.no_body @check.not_exist @check.updated_one_not_exist @@ -189,7 +194,8 @@ class GenericApiHandler(web.RequestHandler): update_req['_id'] = str(data._id) self.finish_request(update_req) - @check.authenticate + @web.asynchronous + @gen.coroutine @check.no_body @check.not_exist @check.updated_one_not_exist diff --git a/utils/test/testapi/opnfv_testapi/resources/pod_models.py b/utils/test/testapi/opnfv_testapi/resources/pod_models.py index 2c3ea978b..415d3d66b 100644 --- a/utils/test/testapi/opnfv_testapi/resources/pod_models.py +++ b/utils/test/testapi/opnfv_testapi/resources/pod_models.py @@ -29,13 +29,14 @@ class PodCreateRequest(models.ModelBase): class Pod(models.ModelBase): def __init__(self, name='', mode='', details='', - role="", _id='', create_date=''): + role="", _id='', create_date='', owner=''): self.name = name self.mode = mode self.details = details self.role = role self._id = _id self.creation_date = create_date + self.owner = owner @swagger.model() diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py b/utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py index 8cfc513be..ea2297275 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py @@ -1,4 +1,5 @@ import argparse +import pytest def test_config_normal(mocker, config_normal): @@ -13,3 +14,11 @@ def test_config_normal(mocker, config_normal): assert CONF.api_debug is True assert CONF.api_authenticate is False assert CONF.ui_url == 'http://localhost:8000' + + +def test_config_file_not_exist(mocker): + mocker.patch('os.path.exists', return_value=False) + with pytest.raises(Exception) as m_exc: + from opnfv_testapi.common import config + config.Config() + assert 'not found' in str(m_exc.value) diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/executor.py b/utils/test/testapi/opnfv_testapi/tests/unit/executor.py index b8f696caf..aa99b9086 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/executor.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/executor.py @@ -9,6 +9,39 @@ import functools import httplib +from concurrent.futures import ThreadPoolExecutor +import mock + + +O_get_secure_cookie = ( + 'opnfv_testapi.resources.handlers.GenericApiHandler.get_secure_cookie') + + +def thread_execute(method, *args, **kwargs): + with ThreadPoolExecutor(max_workers=2) as executor: + result = executor.submit(method, *args, **kwargs) + return result + + +def mock_invalid_lfid(): + def _mock_invalid_lfid(xstep): + def wrap(self, *args, **kwargs): + with mock.patch(O_get_secure_cookie) as m_cookie: + m_cookie.return_value = 'InvalidUser' + return xstep(self, *args, **kwargs) + return wrap + return _mock_invalid_lfid + + +def mock_valid_lfid(): + def _mock_valid_lfid(xstep): + def wrap(self, *args, **kwargs): + with mock.patch(O_get_secure_cookie) as m_cookie: + m_cookie.return_value = 'ValidUser' + return xstep(self, *args, **kwargs) + return wrap + return _mock_valid_lfid + def upload(excepted_status, excepted_response): def _upload(create_request): 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 3320a866a..c44a92c11 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py @@ -288,3 +288,4 @@ testcases = MemDb('testcases') results = MemDb('results') scenarios = MemDb('scenarios') tokens = MemDb('tokens') +users = MemDb('users') 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 39633e5f5..89cd7e8ed 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 @@ -6,13 +6,16 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from datetime import datetime import json from os import path +from bson.objectid import ObjectId import mock from tornado import testing from opnfv_testapi.resources import models +from opnfv_testapi.resources import pod_models from opnfv_testapi.tests.unit import fake_pymongo @@ -26,10 +29,32 @@ class TestBase(testing.AsyncHTTPTestCase): self.get_res = None self.list_res = None self.update_res = None + self.pod_d = pod_models.Pod(name='zte-pod1', + mode='virtual', + details='zte pod 1', + role='community-ci', + _id=str(ObjectId()), + owner='ValidUser', + create_date=str(datetime.now())) + self.pod_e = pod_models.Pod(name='zte-pod2', + mode='metal', + details='zte pod 2', + role='production-ci', + _id=str(ObjectId()), + owner='ValidUser', + create_date=str(datetime.now())) self.req_d = None self.req_e = None self.addCleanup(self._clear) super(TestBase, self).setUp() + fake_pymongo.users.insert({"user": "ValidUser", + 'email': 'validuser@lf.com', + 'fullname': 'Valid User', + 'groups': [ + 'opnfv-testapi-users', + 'opnfv-gerrit-functest-submitters', + 'opnfv-gerrit-qtip-contributors'] + }) def tearDown(self): self.db_patcher.stop() diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_pod.py b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_pod.py index d1a19f7f0..5d9da3a86 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_pod.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_pod.py @@ -12,24 +12,29 @@ import unittest from opnfv_testapi.common import message from opnfv_testapi.resources import pod_models from opnfv_testapi.tests.unit import executor +from opnfv_testapi.tests.unit import fake_pymongo from opnfv_testapi.tests.unit.resources import test_base as base class TestPodBase(base.TestBase): def setUp(self): super(TestPodBase, self).setUp() - self.req_d = pod_models.PodCreateRequest('zte-1', 'virtual', - 'zte pod 1', 'ci-pod') - self.req_e = pod_models.PodCreateRequest('zte-2', 'metal', 'zte pod 2') - self.req_f = pod_models.PodCreateRequest('Zte-1', 'virtual', - 'zte pod 1', 'ci-pod') self.get_res = pod_models.Pod self.list_res = pod_models.Pods self.basePath = '/api/v1/pods' + self.req_d = pod_models.PodCreateRequest(name=self.pod_d.name, + mode=self.pod_d.mode, + details=self.pod_d.details, + role=self.pod_d.role) + self.req_e = pod_models.PodCreateRequest(name=self.pod_e.name, + mode=self.pod_e.mode, + details=self.pod_e.details, + role=self.pod_e.role) def assert_get_body(self, pod, req=None): if not req: req = self.req_d + self.assertEqual(pod.owner, 'ValidUser') self.assertEqual(pod.name, req.name) self.assertEqual(pod.mode, req.mode) self.assertEqual(pod.details, req.details) @@ -39,38 +44,54 @@ class TestPodBase(base.TestBase): class TestPodCreate(TestPodBase): + @executor.create(httplib.BAD_REQUEST, message.not_login()) + def test_notlogin(self): + return self.req_d + + @executor.mock_invalid_lfid() + @executor.create(httplib.BAD_REQUEST, message.not_lfid()) + def test_invalidLfid(self): + return self.req_d + + @executor.mock_valid_lfid() @executor.create(httplib.BAD_REQUEST, message.no_body()) def test_withoutBody(self): return None + @executor.mock_valid_lfid() @executor.create(httplib.BAD_REQUEST, message.missing('name')) def test_emptyName(self): return pod_models.PodCreateRequest('') + @executor.mock_valid_lfid() @executor.create(httplib.BAD_REQUEST, message.missing('name')) def test_noneName(self): return pod_models.PodCreateRequest(None) + @executor.mock_valid_lfid() @executor.create(httplib.OK, 'assert_create_body') def test_success(self): return self.req_d + @executor.mock_valid_lfid() @executor.create(httplib.FORBIDDEN, message.exist_base) def test_alreadyExist(self): - self.create_d() + fake_pymongo.pods.insert(self.pod_d.format()) return self.req_d + @executor.mock_valid_lfid() @executor.create(httplib.FORBIDDEN, message.exist_base) def test_alreadyExistCaseInsensitive(self): - self.create(self.req_f) + fake_pymongo.pods.insert(self.pod_d.format()) + self.req_d.name = self.req_d.name.upper() return self.req_d class TestPodGet(TestPodBase): def setUp(self): super(TestPodGet, self).setUp() - self.create_d() - self.create_e() + fake_pymongo.pods.insert(self.pod_d.format()) + fake_pymongo.pods.insert(self.pod_e.format()) @executor.get(httplib.NOT_FOUND, message.not_found_base) def test_notExist(self): @@ -78,7 +99,7 @@ class TestPodGet(TestPodBase): @executor.get(httplib.OK, 'assert_get_body') def test_getOne(self): - return self.req_d.name + return self.pod_d.name @executor.get(httplib.OK, '_assert_list') def test_list(self): @@ -87,10 +108,10 @@ class TestPodGet(TestPodBase): def _assert_list(self, body): self.assertEqual(len(body.pods), 2) for pod in body.pods: - if self.req_d.name == pod.name: + if self.pod_d.name == pod.name: self.assert_get_body(pod) else: - self.assert_get_body(pod, self.req_e) + self.assert_get_body(pod, self.pod_e) if __name__ == '__main__': diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py index 1e83ed308..f5026c957 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py @@ -7,17 +7,18 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import copy +from datetime import datetime +from datetime import timedelta import httplib -import unittest -from datetime import datetime, timedelta import json +import unittest from opnfv_testapi.common import message -from opnfv_testapi.resources import pod_models from opnfv_testapi.resources import project_models from opnfv_testapi.resources import result_models from opnfv_testapi.resources import testcase_models from opnfv_testapi.tests.unit import executor +from opnfv_testapi.tests.unit import fake_pymongo from opnfv_testapi.tests.unit.resources import test_base as base @@ -52,7 +53,8 @@ class Details(object): class TestResultBase(base.TestBase): def setUp(self): - self.pod = 'zte-pod1' + super(TestResultBase, self).setUp() + self.pod = self.pod_d.name self.project = 'functest' self.case = 'vPing' self.installer = 'fuel' @@ -65,7 +67,6 @@ class TestResultBase(base.TestBase): self.stop_date = str(datetime.now() + timedelta(minutes=1)) self.update_date = str(datetime.now() + timedelta(days=1)) self.update_step = -0.05 - super(TestResultBase, self).setUp() self.details = Details(timestart='0', duration='9s', status='OK') self.req_d = result_models.ResultCreateRequest( pod_name=self.pod, @@ -84,10 +85,6 @@ class TestResultBase(base.TestBase): self.list_res = result_models.TestResults self.update_res = result_models.TestResult self.basePath = '/api/v1/results' - self.req_pod = pod_models.PodCreateRequest( - self.pod, - 'metal', - 'zte pod 1') self.req_project = project_models.ProjectCreateRequest( self.project, 'vping test') @@ -95,7 +92,7 @@ class TestResultBase(base.TestBase): self.case, '/cases/vping', 'vping-ssh test') - self.create_help('/api/v1/pods', self.req_pod) + fake_pymongo.pods.insert(self.pod_d.format()) self.create_help('/api/v1/projects', self.req_project) self.create_help('/api/v1/projects/%s/cases', self.req_testcase, diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_token.py b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_token.py index 940e256c6..bd64723be 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_token.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_token.py @@ -9,13 +9,12 @@ import unittest from tornado import web from opnfv_testapi.common import message -from opnfv_testapi.resources import project_models from opnfv_testapi.tests.unit import executor from opnfv_testapi.tests.unit import fake_pymongo -from opnfv_testapi.tests.unit.resources import test_base as base +from opnfv_testapi.tests.unit.resources import test_result -class TestToken(base.TestBase): +class TestTokenCreateResult(test_result.TestResultBase): def get_app(self): from opnfv_testapi.router import url_mappings return web.Application( @@ -25,27 +24,23 @@ class TestToken(base.TestBase): auth=True ) - -class TestTokenCreateProject(TestToken): def setUp(self): - super(TestTokenCreateProject, self).setUp() - self.req_d = project_models.ProjectCreateRequest('vping') + super(TestTokenCreateResult, self).setUp() fake_pymongo.tokens.insert({"access_token": "12345"}) - self.basePath = '/api/v1/projects' @executor.create(httplib.FORBIDDEN, message.invalid_token()) - def test_projectCreateTokenInvalid(self): + def test_resultCreateTokenInvalid(self): self.headers['X-Auth-Token'] = '1234' return self.req_d @executor.create(httplib.UNAUTHORIZED, message.unauthorized()) - def test_projectCreateTokenUnauthorized(self): + def test_resultCreateTokenUnauthorized(self): if 'X-Auth-Token' in self.headers: self.headers.pop('X-Auth-Token') return self.req_d @executor.create(httplib.OK, '_create_success') - def test_projectCreateTokenSuccess(self): + def test_resultCreateTokenSuccess(self): self.headers['X-Auth-Token'] = '12345' return self.req_d @@ -53,62 +48,5 @@ class TestTokenCreateProject(TestToken): self.assertIn('CreateResponse', str(type(body))) -class TestTokenDeleteProject(TestToken): - def setUp(self): - super(TestTokenDeleteProject, self).setUp() - self.req_d = project_models.ProjectCreateRequest('vping') - fake_pymongo.tokens.insert({"access_token": "12345"}) - self.basePath = '/api/v1/projects' - self.headers['X-Auth-Token'] = '12345' - self.create_d() - - @executor.delete(httplib.FORBIDDEN, message.invalid_token()) - def test_projectDeleteTokenIvalid(self): - self.headers['X-Auth-Token'] = '1234' - return self.req_d.name - - @executor.delete(httplib.UNAUTHORIZED, message.unauthorized()) - def test_projectDeleteTokenUnauthorized(self): - self.headers.pop('X-Auth-Token') - return self.req_d.name - - @executor.delete(httplib.OK, '_delete_success') - def test_projectDeleteTokenSuccess(self): - return self.req_d.name - - def _delete_success(self, body): - self.assertEqual('', body) - - -class TestTokenUpdateProject(TestToken): - def setUp(self): - super(TestTokenUpdateProject, self).setUp() - self.req_d = project_models.ProjectCreateRequest('vping') - fake_pymongo.tokens.insert({"access_token": "12345"}) - self.basePath = '/api/v1/projects' - self.headers['X-Auth-Token'] = '12345' - self.create_d() - - @executor.update(httplib.FORBIDDEN, message.invalid_token()) - def test_projectUpdateTokenIvalid(self): - self.headers['X-Auth-Token'] = '1234' - req = project_models.ProjectUpdateRequest('newName', 'new description') - return req, self.req_d.name - - @executor.update(httplib.UNAUTHORIZED, message.unauthorized()) - def test_projectUpdateTokenUnauthorized(self): - self.headers.pop('X-Auth-Token') - req = project_models.ProjectUpdateRequest('newName', 'new description') - return req, self.req_d.name - - @executor.update(httplib.OK, '_update_success') - def test_projectUpdateTokenSuccess(self): - req = project_models.ProjectUpdateRequest('newName', 'new description') - return req, self.req_d.name - - def _update_success(self, request, body): - self.assertIn(request.name, body) - - if __name__ == '__main__': unittest.main() |