diff options
-rwxr-xr-x | jjb/3rd_party_ci/download-netvirt-artifact.sh | 7 | ||||
-rw-r--r-- | jjb/3rd_party_ci/odl-netvirt.yml | 2 | ||||
-rw-r--r-- | jjb/apex/apex-snapshot-deploy.sh | 1 | ||||
-rwxr-xr-x | jjb/daisy4nfv/daisy4nfv-download-artifact.sh | 10 | ||||
-rw-r--r-- | jjb/dovetail/dovetail-ci-jobs.yml | 25 | ||||
-rw-r--r-- | jjb/fuel/fuel-daily-jobs.yml | 102 | ||||
-rwxr-xr-x | jjb/securedlab/check-jinja2.sh | 4 | ||||
-rwxr-xr-x | jjb/xci/bifrost-verify.sh | 4 | ||||
-rw-r--r-- | prototypes/bifrost/playbooks/opnfv-virtual.yaml | 15 | ||||
-rwxr-xr-x | prototypes/bifrost/scripts/bifrost-provision.sh | 4 | ||||
-rwxr-xr-x | prototypes/bifrost/scripts/destroy-env.sh | 2 | ||||
-rw-r--r-- | utils/create_pod_file.py | 26 | ||||
-rwxr-xr-x | utils/fetch_os_creds.sh | 2 | ||||
-rw-r--r-- | utils/test/testapi/opnfv_testapi/tests/unit/test_project.py | 116 | ||||
-rw-r--r-- | utils/test/testapi/opnfv_testapi/tests/unit/test_result.py | 208 | ||||
-rw-r--r-- | utils/test/testapi/opnfv_testapi/tests/unit/test_testcase.py | 123 |
16 files changed, 405 insertions, 246 deletions
diff --git a/jjb/3rd_party_ci/download-netvirt-artifact.sh b/jjb/3rd_party_ci/download-netvirt-artifact.sh index 6aea01d2a..70e307028 100755 --- a/jjb/3rd_party_ci/download-netvirt-artifact.sh +++ b/jjb/3rd_party_ci/download-netvirt-artifact.sh @@ -8,9 +8,10 @@ ODL_ZIP=distribution-karaf-0.6.0-SNAPSHOT.zip echo "Attempting to fetch the artifact location from ODL Jenkins" CHANGE_DETAILS_URL="https://git.opendaylight.org/gerrit/changes/netvirt~master~$GERRIT_CHANGE_ID/detail" # due to limitation with the Jenkins Gerrit Trigger, we need to use Gerrit REST API to get the change details -ODL_BUILD_JOB_NUM=$(curl -s $CHANGE_DETAILS_URL | grep -Eo 'netvirt-distribution-check-carbon/[0-9]+' | tail -1 | grep -Eo [0-9]+) +ODL_BUILD_JOB_NUM=$(curl -s $CHANGE_DETAILS_URL | grep -Eo 'netvirt-distribution-check-nitrogen/[0-9]+' | tail -1 | grep -Eo [0-9]+) +DISTRO_CHECK_CONSOLE_LOG="https://logs.opendaylight.org/releng/jenkins092/netvirt-distribution-check-nitrogen/${ODL_BUILD_JOB_NUM}/console.log.gz" +NETVIRT_ARTIFACT_URL=$(curl -s --compressed $DISTRO_CHECK_CONSOLE_LOG | grep 'BUNDLE_URL' | cut -d = -f 2) -NETVIRT_ARTIFACT_URL="https://jenkins.opendaylight.org/releng/job/netvirt-distribution-check-carbon/${ODL_BUILD_JOB_NUM}/artifact/${ODL_ZIP}" echo -e "URL to artifact is\n\t$NETVIRT_ARTIFACT_URL" echo "Downloading the artifact. This could take time..." @@ -27,4 +28,4 @@ unzip $ODL_ZIP tar czf /tmp/${NETVIRT_ARTIFACT} $(echo $ODL_ZIP | sed -n 's/\.zip//p') echo "Download complete" -ls -al /tmp/${NETVIRT_ARTIFACT} +ls -al /tmp/${NETVIRT_ARTIFACT}
\ No newline at end of file diff --git a/jjb/3rd_party_ci/odl-netvirt.yml b/jjb/3rd_party_ci/odl-netvirt.yml index 470e4335e..ac15fe707 100644 --- a/jjb/3rd_party_ci/odl-netvirt.yml +++ b/jjb/3rd_party_ci/odl-netvirt.yml @@ -128,7 +128,7 @@ - name: 'functest-netvirt-virtual-suite-{stream}' predefined-parameters: | DEPLOY_SCENARIO=os-odl_l3-nofeature-ha - FUNCTEST_SUITE_NAME=tempest_smoke_serial + FUNCTEST_SUITE_NAME=odl_netvirt RC_FILE_PATH=$HOME/cloner-info/overcloudrc node-parameters: true kill-phase-on: FAILURE diff --git a/jjb/apex/apex-snapshot-deploy.sh b/jjb/apex/apex-snapshot-deploy.sh index 06c002319..3eb3cf23a 100644 --- a/jjb/apex/apex-snapshot-deploy.sh +++ b/jjb/apex/apex-snapshot-deploy.sh @@ -129,6 +129,7 @@ if [ -z "$virsh_vm_defs" ]; then fi for node_def in ${virsh_vm_defs}; do + sed -ri "s/machine='[^\s]+'/machine='pc'/" ${node_def} sudo virsh define ${node_def} node=$(echo ${node_def} | awk -F '.' '{print $1}') sudo cp -f ${node}.qcow2 /var/lib/libvirt/images/ diff --git a/jjb/daisy4nfv/daisy4nfv-download-artifact.sh b/jjb/daisy4nfv/daisy4nfv-download-artifact.sh index 1cc0443ad..a64c80e5c 100755 --- a/jjb/daisy4nfv/daisy4nfv-download-artifact.sh +++ b/jjb/daisy4nfv/daisy4nfv-download-artifact.sh @@ -57,12 +57,18 @@ fi # log info to console echo "Downloading the $INSTALLER_TYPE artifact using URL http://$OPNFV_ARTIFACT_URL" -echo "This could take some time..." +echo "This could take some time... Now the time is $(date -u)" echo "--------------------------------------------------------" echo # download the file -curl -L -s -o $WORKSPACE/opnfv.bin http://$OPNFV_ARTIFACT_URL > gsutil.bin.log 2>&1 +if [[ "$NODE_NAME" =~ (zte) ]] && [ -x "$(command -v aria2c)" ]; then + DOWNLOAD_CMD="aria2c -x 3 --allow-overwrite=true -d $WORKSPACE -o opnfv.bin" +else + DOWNLOAD_CMD="curl -L -s -o $WORKSPACE/opnfv.bin" +fi + +$DOWNLOAD_CMD http://$OPNFV_ARTIFACT_URL > gsutil.bin.log 2>&1 # list the file ls -al $WORKSPACE/opnfv.bin diff --git a/jjb/dovetail/dovetail-ci-jobs.yml b/jjb/dovetail/dovetail-ci-jobs.yml index 4998278c8..682948d8b 100644 --- a/jjb/dovetail/dovetail-ci-jobs.yml +++ b/jjb/dovetail/dovetail-ci-jobs.yml @@ -142,6 +142,31 @@ SUT: fuel auto-trigger-name: 'daily-trigger-disabled' <<: *master + - zte-pod1: + slave-label: zte-pod1 + SUT: fuel + auto-trigger-name: 'daily-trigger-disabled' + <<: *master + - zte-pod2: + slave-label: zte-pod2 + SUT: fuel + auto-trigger-name: 'daily-trigger-disabled' + <<: *master + - zte-pod3: + slave-label: zte-pod3 + SUT: fuel + auto-trigger-name: 'daily-trigger-disabled' + <<: *master + - zte-pod1: + slave-label: zte-pod1 + SUT: fuel + auto-trigger-name: 'daily-trigger-disabled' + <<: *danube + - zte-pod3: + slave-label: zte-pod3 + SUT: fuel + auto-trigger-name: 'daily-trigger-disabled' + <<: *danube #-------------------------------- testsuite: - 'debug' diff --git a/jjb/fuel/fuel-daily-jobs.yml b/jjb/fuel/fuel-daily-jobs.yml index 32abad624..2fa868779 100644 --- a/jjb/fuel/fuel-daily-jobs.yml +++ b/jjb/fuel/fuel-daily-jobs.yml @@ -73,8 +73,8 @@ auto-trigger-name: 'fuel-{scenario}-{pod}-daily-{stream}-trigger' - 'os-odl_l2-sfc-ha': auto-trigger-name: 'fuel-{scenario}-{pod}-daily-{stream}-trigger' - - 'os-odl_l2-bgpvpn-ha': - auto-trigger-name: 'fuel-{scenario}-{pod}-daily-{stream}-trigger' + # - 'os-odl_l2-bgpvpn-ha': + # auto-trigger-name: 'fuel-{scenario}-{pod}-daily-{stream}-trigger' - 'os-nosdn-kvm-ha': auto-trigger-name: 'fuel-{scenario}-{pod}-daily-{stream}-trigger' - 'os-nosdn-ovs-ha': @@ -112,6 +112,7 @@ jobs: - 'fuel-{scenario}-{pod}-daily-{stream}' - 'fuel-deploy-{pod}-daily-{stream}' + - 'fuel-os-odl_l2-bgpvpn-ha-{pod}-daily-{stream}' ######################## # job templates @@ -195,6 +196,103 @@ recipients: peter.barabas@ericsson.com fzhadaev@mirantis.com - job-template: + name: 'fuel-os-odl_l2-bgpvpn-ha-{pod}-daily-{stream}' + + disabled: '{obj:disabled}' + + concurrent: false + + properties: + - logrotate-default + - throttle: + enabled: true + max-total: 4 + max-per-node: 1 + option: 'project' + - build-blocker: + use-build-blocker: true + blocking-jobs: + - 'fuel-os-.*?-{pod}-daily-.*' + - 'fuel-os-.*?-{pod}-weekly-.*' + block-level: 'NODE' + + wrappers: + - build-name: + name: '$BUILD_NUMBER - Scenario: os-odl_l2-bgpvpn-ha' + + triggers: + - 'fuel-os-odl_l2-bgpvpn-ha-{pod}-daily-{stream}-trigger' + + parameters: + - project-parameter: + project: '{project}' + branch: '{branch}' + - '{installer}-defaults' + - '{slave-label}-defaults': + installer: '{installer}' + - string: + name: DEPLOY_SCENARIO + default: "os-odl_l2-bgpvpn-ha" + - fuel-ci-parameter: + gs-pathname: '{gs-pathname}' + + builders: + - description-setter: + description: "Built on $NODE_NAME" + - trigger-builds: + - project: 'fuel-deploy-{pod}-daily-{stream}' + current-parameters: false + predefined-parameters: + DEPLOY_SCENARIO=os-odl_l2-bgpvpn-ha + same-node: true + block: true + - trigger-builds: + - project: 'functest-fuel-{pod}-daily-{stream}' + current-parameters: false + predefined-parameters: + DEPLOY_SCENARIO=os-odl_l2-bgpvpn-ha + same-node: true + block: true + block-thresholds: + build-step-failure-threshold: 'never' + failure-threshold: 'never' + unstable-threshold: 'FAILURE' + - trigger-builds: + - project: 'yardstick-fuel-{pod}-daily-{stream}' + current-parameters: false + predefined-parameters: + DEPLOY_SCENARIO=os-odl_l2-bgpvpn-ha + block: true + same-node: true + block-thresholds: + build-step-failure-threshold: 'never' + failure-threshold: 'never' + unstable-threshold: 'FAILURE' + # 1.dovetail only master by now, not sync with A/B/C branches + # 2.here the stream means the SUT stream, dovetail stream is defined in its own job + # 3.only debug testsuite here(includes basic testcase, + # i.e. refstack ipv6 vpn test cases from functest, HA test case + # from yardstick) + # 4.not used for release criteria or compliance, + # only to debug the dovetail tool bugs with fuel bgpvpn scenario + - trigger-builds: + - project: 'dovetail-fuel-{pod}-proposed_tests-{stream}' + current-parameters: false + predefined-parameters: + DEPLOY_SCENARIO=os-odl_l2-bgpvpn-ha + block: true + same-node: true + block-thresholds: + build-step-failure-threshold: 'never' + failure-threshold: 'never' + unstable-threshold: 'FAILURE' + + publishers: + - email: + recipients: peter.barabas@ericsson.com fzhadaev@mirantis.com matthew.lijun@huawei.com + + +- job-template: name: 'fuel-deploy-{pod}-daily-{stream}' disabled: '{obj:disabled}' diff --git a/jjb/securedlab/check-jinja2.sh b/jjb/securedlab/check-jinja2.sh index be4d951ed..84907e5eb 100755 --- a/jjb/securedlab/check-jinja2.sh +++ b/jjb/securedlab/check-jinja2.sh @@ -1,9 +1,9 @@ #!/bin/bash set +x set -o errexit -for lab_configs in $(find labs/ -name 'pod.yaml' | grep -v zte); do +for lab_configs in $(find labs/ -name 'pod.yaml'); do while IFS= read -r jinja_templates; do echo "./utils/generate_config.py -y $lab_configs -j $jinja_templates" ./utils/generate_config.py -y $lab_configs -j $jinja_templates - done < <(find installers/ -name '*.jinja2') + done < <(find installers/ -name 'pod_config.yaml.j2') done diff --git a/jjb/xci/bifrost-verify.sh b/jjb/xci/bifrost-verify.sh index f596d7527..29af7ca3b 100755 --- a/jjb/xci/bifrost-verify.sh +++ b/jjb/xci/bifrost-verify.sh @@ -113,11 +113,11 @@ sudo /bin/cp -rf /opt/releng/prototypes/bifrost/* /opt/bifrost/ # cleanup remnants of previous deployment cd /opt/bifrost -sudo -E ./scripts/destroy-env.sh +sudo -H -E ./scripts/destroy-env.sh # provision 3 VMs; xcimaster, controller, and compute cd /opt/bifrost -sudo -E ./scripts/bifrost-provision.sh +sudo -H -E ./scripts/bifrost-provision.sh # list the provisioned VMs cd /opt/bifrost diff --git a/prototypes/bifrost/playbooks/opnfv-virtual.yaml b/prototypes/bifrost/playbooks/opnfv-virtual.yaml index 310eca864..699c96698 100644 --- a/prototypes/bifrost/playbooks/opnfv-virtual.yaml +++ b/prototypes/bifrost/playbooks/opnfv-virtual.yaml @@ -35,6 +35,7 @@ become: yes gather_facts: yes roles: + - role: bifrost-keystone-install - role: bifrost-ironic-install cleaning: false testing: true @@ -57,6 +58,20 @@ dib_elements: "vm enable-serial-console simple-init devuser growroot {{ extra_dib_elements }}" dib_packages: "{{ lookup('env', 'DIB_OS_PACKAGES') }}" when: create_image_via_dib | bool == true and transform_boot_image | bool == false + - role: bifrost-keystone-client-config + # NOTE(hwoarang): This should be ansible_env.SUDO_USER like in the + # upstream playbook. However, we run ansible as root (ie with sudo) + # so clouds.yaml will be placed in the user's home directory (see + # the bifrost-keystone-client-config role) and then ansible will look + # for one in /root and fail. As such we hardcode the user to be 'root'. + user: "root" + clouds: + bifrost: + config_username: "{{ ironic.keystone.default_username }}" + config_password: "{{ ironic.keystone.default_password }}" + config_project_name: "baremetal" + config_region_name: "{{ keystone.bootstrap.region_name }}" + config_auth_url: "{{ keystone.bootstrap.public_url }}" environment: http_proxy: "{{ lookup('env','http_proxy') }}" https_proxy: "{{ lookup('env','https_proxy') }}" diff --git a/prototypes/bifrost/scripts/bifrost-provision.sh b/prototypes/bifrost/scripts/bifrost-provision.sh index d3b28ee10..056196254 100755 --- a/prototypes/bifrost/scripts/bifrost-provision.sh +++ b/prototypes/bifrost/scripts/bifrost-provision.sh @@ -70,7 +70,6 @@ export EXTRA_DIB_ELEMENTS=${EXTRA_DIB_ELEMENTS:-"openssh-server"} # Source Ansible set +x +o nounset $SCRIPT_HOME/env-setup.sh -source ${ANSIBLE_INSTALL_ROOT}/ansible/hacking/env-setup ANSIBLE=$(which ansible-playbook) set -x -o nounset @@ -121,7 +120,8 @@ ${ANSIBLE} ${ANSIBLE_VERBOSITY} \ -e create_ipa_image=${CREATE_IPA_IMAGE} \ -e write_interfaces_file=${WRITE_INTERFACES_FILE} \ -e ipv4_gateway=192.168.122.1 \ - -e wait_timeout=${PROVISION_WAIT_TIMEOUT} + -e wait_timeout=${PROVISION_WAIT_TIMEOUT} \ + -e enable_keystone=false EXITCODE=$? if [ $EXITCODE != 0 ]; then diff --git a/prototypes/bifrost/scripts/destroy-env.sh b/prototypes/bifrost/scripts/destroy-env.sh index d570f10ad..c75e814b7 100755 --- a/prototypes/bifrost/scripts/destroy-env.sh +++ b/prototypes/bifrost/scripts/destroy-env.sh @@ -16,6 +16,8 @@ fi # Start fresh rm -rf /opt/stack +# HOME is normally set by sudo -H +rm -rf ${HOME}/.config/openstack # Delete all libvirt VMs and hosts from vbmc (look for a port number) for vm in $(vbmc list | awk '/[0-9]/{{ print $2 }}'); do diff --git a/utils/create_pod_file.py b/utils/create_pod_file.py index 22943fc97..7e30cc639 100644 --- a/utils/create_pod_file.py +++ b/utils/create_pod_file.py @@ -63,17 +63,27 @@ def create_file(handler): node_list = [] index = 1 for node in nodes: - if node.roles[0].lower() == "controller": - node_info = {'name': "node%s" % index, 'role': node.roles[0], - 'ip': node.ip, 'user': 'root'} + try: + if node.roles[0].lower() == "controller": + node_info = {'name': "node%s" % index, 'role': node.roles[0], + 'ip': node.ip, 'user': 'root'} + node_list.append(node_info) + index += 1 + except Exception: + node_info = {'name': node.name, 'role': 'unknown', 'ip': node.ip, + 'user': 'root'} node_list.append(node_info) - index += 1 for node in nodes: - if node.roles[0].lower() == "compute": - node_info = {'name': "node%s" % index, 'role': node.roles[0], - 'ip': node.ip, 'user': 'root'} + try: + if node.roles[0].lower() == "compute": + node_info = {'name': "node%s" % index, 'role': node.roles[0], + 'ip': node.ip, 'user': 'root'} + node_list.append(node_info) + index += 1 + except Exception: + node_info = {'name': node.name, 'role': 'unknown', 'ip': node.ip, + 'user': 'root'} node_list.append(node_info) - index += 1 if args.INSTALLER_TYPE == 'compass': for item in node_list: item['password'] = 'root' diff --git a/utils/fetch_os_creds.sh b/utils/fetch_os_creds.sh index c99afaca8..6a382a56c 100755 --- a/utils/fetch_os_creds.sh +++ b/utils/fetch_os_creds.sh @@ -138,7 +138,7 @@ elif [ "$installer_type" == "apex" ]; then if [ -f /root/.ssh/id_rsa ]; then chmod 600 /root/.ssh/id_rsa fi - sudo scp $ssh_options root@$installer_ip:/home/stack/overcloudrc $dest_path + sudo scp $ssh_options root@$installer_ip:/home/stack/overcloudrc.v3 $dest_path elif [ "$installer_type" == "compass" ]; then verify_connectivity $installer_ip diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/test_project.py b/utils/test/testapi/opnfv_testapi/tests/unit/test_project.py index 9143f8a8a..323a1168f 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/test_project.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/test_project.py @@ -1,16 +1,9 @@ -############################################################################## -# Copyright (c) 2016 ZTE Corporation -# feng.xiaowei@zte.com.cn -# 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 -############################################################################## import httplib import unittest 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 test_base as base @@ -36,49 +29,47 @@ class TestProjectBase(base.TestBase): class TestProjectCreate(TestProjectBase): + @executor.create(httplib.BAD_REQUEST, message.no_body()) def test_withoutBody(self): - (code, body) = self.create() - self.assertEqual(code, httplib.BAD_REQUEST) + return None + @executor.create(httplib.BAD_REQUEST, message.missing('name')) def test_emptyName(self): - req_empty = project_models.ProjectCreateRequest('') - (code, body) = self.create(req_empty) - self.assertEqual(code, httplib.BAD_REQUEST) - self.assertIn(message.missing('name'), body) + return project_models.ProjectCreateRequest('') + @executor.create(httplib.BAD_REQUEST, message.missing('name')) def test_noneName(self): - req_none = project_models.ProjectCreateRequest(None) - (code, body) = self.create(req_none) - self.assertEqual(code, httplib.BAD_REQUEST) - self.assertIn(message.missing('name'), body) + return project_models.ProjectCreateRequest(None) + @executor.create(httplib.OK, 'assert_create_body') def test_success(self): - (code, body) = self.create_d() - self.assertEqual(code, httplib.OK) - self.assert_create_body(body) + return self.req_d + @executor.create(httplib.FORBIDDEN, message.exist_base) def test_alreadyExist(self): self.create_d() - (code, body) = self.create_d() - self.assertEqual(code, httplib.FORBIDDEN) - self.assertIn(message.exist_base, body) + return self.req_d class TestProjectGet(TestProjectBase): + def setUp(self): + super(TestProjectGet, self).setUp() + self.create_d() + self.create_e() + + @executor.get(httplib.NOT_FOUND, message.not_found_base) def test_notExist(self): - code, body = self.get('notExist') - self.assertEqual(code, httplib.NOT_FOUND) + return 'notExist' + @executor.get(httplib.OK, 'assert_body') def test_getOne(self): - self.create_d() - code, body = self.get(self.req_d.name) - self.assertEqual(code, httplib.OK) - self.assert_body(body) + return self.req_d.name + @executor.get(httplib.OK, '_assert_list') def test_list(self): - self.create_d() - self.create_e() - code, body = self.get() + return None + + def _assert_list(self, body): for project in body.projects: if self.req_d.name == project.name: self.assert_body(project) @@ -87,54 +78,57 @@ class TestProjectGet(TestProjectBase): class TestProjectUpdate(TestProjectBase): + def setUp(self): + super(TestProjectUpdate, self).setUp() + _, d_body = self.create_d() + _, get_res = self.get(self.req_d.name) + self.index_d = get_res._id + self.create_e() + + @executor.update(httplib.BAD_REQUEST, message.no_body()) def test_withoutBody(self): - code, _ = self.update(None, 'noBody') - self.assertEqual(code, httplib.BAD_REQUEST) + return None, 'noBody' + @executor.update(httplib.NOT_FOUND, message.not_found_base) def test_notFound(self): - code, _ = self.update(self.req_e, 'notFound') - self.assertEqual(code, httplib.NOT_FOUND) + return self.req_e, 'notFound' + @executor.update(httplib.FORBIDDEN, message.exist_base) def test_newNameExist(self): - self.create_d() - self.create_e() - code, body = self.update(self.req_e, self.req_d.name) - self.assertEqual(code, httplib.FORBIDDEN) - self.assertIn(message.exist_base, body) + return self.req_e, self.req_d.name + @executor.update(httplib.FORBIDDEN, message.no_update()) def test_noUpdate(self): - self.create_d() - code, body = self.update(self.req_d, self.req_d.name) - self.assertEqual(code, httplib.FORBIDDEN) - self.assertIn(message.no_update(), body) + return self.req_d, self.req_d.name + @executor.update(httplib.OK, '_assert_update') def test_success(self): - self.create_d() - code, body = self.get(self.req_d.name) - _id = body._id - req = project_models.ProjectUpdateRequest('newName', 'new description') - code, body = self.update(req, self.req_d.name) - self.assertEqual(code, httplib.OK) - self.assertEqual(_id, body._id) - self.assert_body(body, req) + return req, self.req_d.name + def _assert_update(self, req, body): + self.assertEqual(self.index_d, body._id) + self.assert_body(body, req) _, new_body = self.get(req.name) - self.assertEqual(_id, new_body._id) + self.assertEqual(self.index_d, new_body._id) self.assert_body(new_body, req) class TestProjectDelete(TestProjectBase): + def setUp(self): + super(TestProjectDelete, self).setUp() + self.create_d() + + @executor.delete(httplib.NOT_FOUND, message.not_found_base) def test_notFound(self): - code, body = self.delete('notFound') - self.assertEqual(code, httplib.NOT_FOUND) + return 'notFound' + @executor.delete(httplib.OK, '_assert_delete') def test_success(self): - self.create_d() - code, body = self.delete(self.req_d.name) - self.assertEqual(code, httplib.OK) - self.assertEqual(body, '') + return self.req_d.name + def _assert_delete(self, body): + self.assertEqual(body, '') code, body = self.get(self.req_d.name) self.assertEqual(code, httplib.NOT_FOUND) diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/test_result.py b/utils/test/testapi/opnfv_testapi/tests/unit/test_result.py index 940279cd4..ef2ce307e 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/test_result.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/test_result.py @@ -17,6 +17,7 @@ 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 test_base as base +from opnfv_testapi.tests.unit import executor class Details(object): @@ -99,8 +100,7 @@ class TestResultBase(base.TestBase): self.req_testcase, self.project) - def assert_res(self, code, result, req=None): - self.assertEqual(code, httplib.OK) + def assert_res(self, result, req=None): if req is None: req = self.req_d self.assertEqual(result.pod_name, req.pod_name) @@ -133,65 +133,57 @@ class TestResultBase(base.TestBase): class TestResultCreate(TestResultBase): + @executor.create(httplib.BAD_REQUEST, message.no_body()) def test_nobody(self): - (code, body) = self.create(None) - self.assertEqual(code, httplib.BAD_REQUEST) - self.assertIn(message.no_body(), body) + return None + @executor.create(httplib.BAD_REQUEST, message.missing('pod_name')) def test_podNotProvided(self): req = self.req_d req.pod_name = None - (code, body) = self.create(req) - self.assertEqual(code, httplib.BAD_REQUEST) - self.assertIn(message.missing('pod_name'), body) + return req + @executor.create(httplib.BAD_REQUEST, message.missing('project_name')) def test_projectNotProvided(self): req = self.req_d req.project_name = None - (code, body) = self.create(req) - self.assertEqual(code, httplib.BAD_REQUEST) - self.assertIn(message.missing('project_name'), body) + return req + @executor.create(httplib.BAD_REQUEST, message.missing('case_name')) def test_testcaseNotProvided(self): req = self.req_d req.case_name = None - (code, body) = self.create(req) - self.assertEqual(code, httplib.BAD_REQUEST) - self.assertIn(message.missing('case_name'), body) + return req + @executor.create(httplib.FORBIDDEN, message.not_found_base) def test_noPod(self): req = self.req_d req.pod_name = 'notExistPod' - (code, body) = self.create(req) - self.assertEqual(code, httplib.FORBIDDEN) - self.assertIn(message.not_found_base, body) + return req + @executor.create(httplib.FORBIDDEN, message.not_found_base) def test_noProject(self): req = self.req_d req.project_name = 'notExistProject' - (code, body) = self.create(req) - self.assertEqual(code, httplib.FORBIDDEN) - self.assertIn(message.not_found_base, body) + return req + @executor.create(httplib.FORBIDDEN, message.not_found_base) def test_noTestcase(self): req = self.req_d req.case_name = 'notExistTestcase' - (code, body) = self.create(req) - self.assertEqual(code, httplib.FORBIDDEN) - self.assertIn(message.not_found_base, body) + return req + @executor.create(httplib.OK, 'assert_href') def test_success(self): - (code, body) = self.create_d() - self.assertEqual(code, httplib.OK) - self.assert_href(body) + return self.req_d + @executor.create(httplib.OK, 'assert_href') def test_key_with_doc(self): req = copy.deepcopy(self.req_d) req.details = {'1.name': 'dot_name'} - (code, body) = self.create(req) - self.assertEqual(code, httplib.OK) - self.assert_href(body) + return req + @executor.create(httplib.OK, '_assert_no_ti') def test_no_ti(self): req = result_models.ResultCreateRequest(pod_name=self.pod, project_name=self.project, @@ -204,106 +196,110 @@ class TestResultCreate(TestResultBase): build_tag=self.build_tag, scenario=self.scenario, criteria=self.criteria) - (code, res) = self.create(req) - _id = res.href.split('/')[-1] - self.assertEqual(code, httplib.OK) + self.actual_req = req + return req + + def _assert_no_ti(self, body): + _id = body.href.split('/')[-1] code, body = self.get(_id) - self.assert_res(code, body, req) + self.assert_res(body, self.actual_req) class TestResultGet(TestResultBase): + def setUp(self): + super(TestResultGet, self).setUp() + self.req_d_id = self._create_d() + self.req_10d_later = self._create_changed_date(days=10) + self.req_10d_before = self._create_changed_date(days=-10) + + @executor.get(httplib.OK, 'assert_res') def test_getOne(self): - _id = self._create_d() - code, body = self.get(_id) - self.assert_res(code, body) + return self.req_d_id + @executor.query(httplib.OK, '_query_success', 3) def test_queryPod(self): - self._query_and_assert(self._set_query('pod')) + return self._set_query('pod') + @executor.query(httplib.OK, '_query_success', 3) def test_queryProject(self): - self._query_and_assert(self._set_query('project')) + return self._set_query('project') + @executor.query(httplib.OK, '_query_success', 3) def test_queryTestcase(self): - self._query_and_assert(self._set_query('case')) + return self._set_query('case') + @executor.query(httplib.OK, '_query_success', 3) def test_queryVersion(self): - self._query_and_assert(self._set_query('version')) + return self._set_query('version') + @executor.query(httplib.OK, '_query_success', 3) def test_queryInstaller(self): - self._query_and_assert(self._set_query('installer')) + return self._set_query('installer') + @executor.query(httplib.OK, '_query_success', 3) def test_queryBuildTag(self): - self._query_and_assert(self._set_query('build_tag')) + return self._set_query('build_tag') + @executor.query(httplib.OK, '_query_success', 3) def test_queryScenario(self): - self._query_and_assert(self._set_query('scenario')) + return self._set_query('scenario') + @executor.query(httplib.OK, '_query_success', 3) def test_queryTrustIndicator(self): - self._query_and_assert(self._set_query('trust_indicator')) + return self._set_query('trust_indicator') + @executor.query(httplib.OK, '_query_success', 3) def test_queryCriteria(self): - self._query_and_assert(self._set_query('criteria')) + return self._set_query('criteria') + @executor.query(httplib.BAD_REQUEST, message.must_int('period')) def test_queryPeriodNotInt(self): - code, body = self.query(self._set_query('period=a')) - self.assertEqual(code, httplib.BAD_REQUEST) - self.assertIn('period must be int', body) - - def test_queryPeriodFail(self): - self._query_and_assert(self._set_query('period=1'), - found=False, days=-10) + return self._set_query('period=a') + @executor.query(httplib.OK, '_query_last_one', 1) def test_queryPeriodSuccess(self): - self._query_and_assert(self._set_query('period=1'), - found=True) + return self._set_query('period=1') + @executor.query(httplib.BAD_REQUEST, message.must_int('last')) def test_queryLastNotInt(self): - code, body = self.query(self._set_query('last=a')) - self.assertEqual(code, httplib.BAD_REQUEST) - self.assertIn('last must be int', body) + return self._set_query('last=a') + @executor.query(httplib.OK, '_query_last_one', 1) def test_queryLast(self): - self._create_changed_date() - req = self._create_changed_date(minutes=20) - self._create_changed_date(minutes=-20) - self._query_and_assert(self._set_query('last=1'), req=req) + return self._set_query('last=1') + @executor.query(httplib.OK, '_query_last_one', 1) def test_combination(self): - self._query_and_assert(self._set_query('pod', - 'project', - 'case', - 'version', - 'installer', - 'build_tag', - 'scenario', - 'trust_indicator', - 'criteria', - 'period=1')) - + return self._set_query('pod', + 'project', + 'case', + 'version', + 'installer', + 'build_tag', + 'scenario', + 'trust_indicator', + 'criteria', + 'period=1') + + @executor.query(httplib.OK, '_query_success', 0) def test_notFound(self): - self._query_and_assert(self._set_query('pod=notExistPod', - 'project', - 'case', - 'version', - 'installer', - 'build_tag', - 'scenario', - 'trust_indicator', - 'criteria', - 'period=1'), - found=False) - - def _query_and_assert(self, query, found=True, req=None, **kwargs): - if req is None: - req = self._create_changed_date(**kwargs) - code, body = self.query(query) - if not found: - self.assertEqual(code, httplib.OK) - self.assertEqual(0, len(body.results)) - else: - self.assertEqual(1, len(body.results)) - for result in body.results: - self.assert_res(code, result, req) + return self._set_query('pod=notExistPod', + 'project', + 'case', + 'version', + 'installer', + 'build_tag', + 'scenario', + 'trust_indicator', + 'criteria', + 'period=1') + + def _query_success(self, body, number): + self.assertEqual(number, len(body.results)) + + def _query_last_one(self, body, number): + self.assertEqual(number, len(body.results)) + self.assert_res(body.results[0], self.req_10d_later) def _create_changed_date(self, **kwargs): req = copy.deepcopy(self.req_d) @@ -327,9 +323,12 @@ class TestResultGet(TestResultBase): class TestResultUpdate(TestResultBase): - def test_success(self): - _id = self._create_d() + def setUp(self): + super(TestResultUpdate, self).setUp() + self.req_d_id = self._create_d() + @executor.update(httplib.OK, '_assert_update_ti') + def test_success(self): new_ti = copy.deepcopy(self.trust_indicator) new_ti.current += self.update_step new_ti.histories.append( @@ -337,13 +336,16 @@ class TestResultUpdate(TestResultBase): new_data = copy.deepcopy(self.req_d) new_data.trust_indicator = new_ti update = result_models.ResultUpdateRequest(trust_indicator=new_ti) - code, body = self.update(update, _id) - self.assertEqual(_id, body._id) - self.assert_res(code, body, new_data) + self.update_req = new_data + return update, self.req_d_id - code, new_body = self.get(_id) - self.assertEqual(_id, new_body._id) - self.assert_res(code, new_body, new_data) + def _assert_update_ti(self, request, body): + ti = body.trust_indicator + self.assertEqual(ti.current, request.trust_indicator.current) + if ti.histories: + history = ti.histories[0] + self.assertEqual(history.date, self.update_date) + self.assertEqual(history.step, self.update_step) if __name__ == '__main__': diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/test_testcase.py b/utils/test/testapi/opnfv_testapi/tests/unit/test_testcase.py index 73c481986..e28eaf5b8 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/test_testcase.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/test_testcase.py @@ -14,6 +14,7 @@ from opnfv_testapi.common import message from opnfv_testapi.resources import project_models from opnfv_testapi.resources import testcase_models from opnfv_testapi.tests.unit import test_base as base +from opnfv_testapi.tests.unit import executor class TestCaseBase(base.TestBase): @@ -70,6 +71,9 @@ class TestCaseBase(base.TestBase): def get(self, case=None): return super(TestCaseBase, self).get(self.project, case) + def create(self, req=None, *args): + return super(TestCaseBase, self).create(req, self.project) + def update(self, new=None, case=None): return super(TestCaseBase, self).update(new, self.project, case) @@ -78,54 +82,57 @@ class TestCaseBase(base.TestBase): class TestCaseCreate(TestCaseBase): + @executor.create(httplib.BAD_REQUEST, message.no_body()) def test_noBody(self): - (code, body) = self.create(None, 'vping') - self.assertEqual(code, httplib.BAD_REQUEST) + return None + @executor.create(httplib.FORBIDDEN, message.not_found_base) def test_noProject(self): - code, body = self.create(self.req_d, 'noProject') - self.assertEqual(code, httplib.FORBIDDEN) - self.assertIn(message.not_found_base, body) + self.project = 'noProject' + return self.req_d + @executor.create(httplib.BAD_REQUEST, message.missing('name')) def test_emptyName(self): req_empty = testcase_models.TestcaseCreateRequest('') - (code, body) = self.create(req_empty, self.project) - self.assertEqual(code, httplib.BAD_REQUEST) - self.assertIn(message.missing('name'), body) + return req_empty + @executor.create(httplib.BAD_REQUEST, message.missing('name')) def test_noneName(self): req_none = testcase_models.TestcaseCreateRequest(None) - (code, body) = self.create(req_none, self.project) - self.assertEqual(code, httplib.BAD_REQUEST) - self.assertIn(message.missing('name'), body) + return req_none + @executor.create(httplib.OK, '_assert_success') def test_success(self): - code, body = self.create_d() - self.assertEqual(code, httplib.OK) - self.assert_create_body(body, None, self.project) + return self.req_d + + def _assert_success(self, body): + self.assert_create_body(body, self.req_d, self.project) + @executor.create(httplib.FORBIDDEN, message.exist_base) def test_alreadyExist(self): self.create_d() - code, body = self.create_d() - self.assertEqual(code, httplib.FORBIDDEN) - self.assertIn(message.exist_base, body) + return self.req_d class TestCaseGet(TestCaseBase): + def setUp(self): + super(TestCaseGet, self).setUp() + self.create_d() + self.create_e() + + @executor.get(httplib.NOT_FOUND, message.not_found_base) def test_notExist(self): - code, body = self.get('notExist') - self.assertEqual(code, httplib.NOT_FOUND) + return 'notExist' + @executor.get(httplib.OK, 'assert_body') def test_getOne(self): - self.create_d() - code, body = self.get(self.req_d.name) - self.assertEqual(code, httplib.OK) - self.assert_body(body) + return self.req_d.name + @executor.get(httplib.OK, '_list') def test_list(self): - self.create_d() - self.create_e() - code, body = self.get() + return None + + def _list(self, body): for case in body.testcases: if self.req_d.name == case.name: self.assert_body(case) @@ -134,60 +141,58 @@ class TestCaseGet(TestCaseBase): class TestCaseUpdate(TestCaseBase): + def setUp(self): + super(TestCaseUpdate, self).setUp() + self.create_d() + + @executor.update(httplib.BAD_REQUEST, message.no_body()) def test_noBody(self): - code, _ = self.update(case='noBody') - self.assertEqual(code, httplib.BAD_REQUEST) + return None, 'noBody' + @executor.update(httplib.NOT_FOUND, message.not_found_base) def test_notFound(self): - code, _ = self.update(self.update_e, 'notFound') - self.assertEqual(code, httplib.NOT_FOUND) + return self.update_e, 'notFound' + @executor.update(httplib.FORBIDDEN, message.exist_base) def test_newNameExist(self): - self.create_d() self.create_e() - code, body = self.update(self.update_e, self.req_d.name) - self.assertEqual(code, httplib.FORBIDDEN) - self.assertIn(message.exist_base, body) + return self.update_e, self.req_d.name + @executor.update(httplib.FORBIDDEN, message.no_update()) def test_noUpdate(self): - self.create_d() - code, body = self.update(self.update_d, self.req_d.name) - self.assertEqual(code, httplib.FORBIDDEN) - self.assertIn(message.no_update(), body) + return self.update_d, self.req_d.name + @executor.update(httplib.OK, '_update_success') def test_success(self): - self.create_d() - code, body = self.get(self.req_d.name) - _id = body._id - - code, body = self.update(self.update_e, self.req_d.name) - self.assertEqual(code, httplib.OK) - self.assertEqual(_id, body._id) - self.assert_update_body(self.req_d, body, self.update_e) - - _, new_body = self.get(self.req_e.name) - self.assertEqual(_id, new_body._id) - self.assert_update_body(self.req_d, new_body, self.update_e) + return self.update_e, self.req_d.name + @executor.update(httplib.OK, '_update_success') def test_with_dollar(self): - self.create_d() update = copy.deepcopy(self.update_d) update.description = {'2. change': 'dollar change'} - code, body = self.update(update, self.req_d.name) - self.assertEqual(code, httplib.OK) + return update, self.req_d.name + + def _update_success(self, request, body): + self.assert_update_body(self.req_d, body, request) + _, new_body = self.get(request.name) + self.assert_update_body(self.req_d, new_body, request) class TestCaseDelete(TestCaseBase): + def setUp(self): + super(TestCaseDelete, self).setUp() + self.create_d() + + @executor.delete(httplib.NOT_FOUND, message.not_found_base) def test_notFound(self): - code, body = self.delete('notFound') - self.assertEqual(code, httplib.NOT_FOUND) + return 'notFound' + @executor.delete(httplib.OK, '_delete_success') def test_success(self): - self.create_d() - code, body = self.delete(self.req_d.name) - self.assertEqual(code, httplib.OK) - self.assertEqual(body, '') + return self.req_d.name + def _delete_success(self, body): + self.assertEqual(body, '') code, body = self.get(self.req_d.name) self.assertEqual(code, httplib.NOT_FOUND) |