Developer-Guide¶
Testing¶
API conformance test with ETSI NFV-TST¶
ETSI NFV-TST 010 specifies the method of the conformance test for APIs specified by NFV specifications. ETSI NFV-TST provides test suites called ‘api-tests’ based on ETSI NFV-TST 010 specification. The following steps are the procedure of API conformance test according to the specification by using Xtesting.
Xtesting environment setup
Check out code from smo-o2 repository into /tmp/ directory in your local machine.
$ cd /tmp $ git clone https://gerrit.o-ran-sc.org/r/smo/o2
Create a virtual environment for xtesting in ‘~/tacker/tacker/tests/’ directory.
$ cd ~/tacker/tacker/tests $ mkdir xtesting $ cd xtesting $ virtualenv xtesting-py3 -p python3
Activate the virtual environment.
$ . xtesting-py3/bin/activate
Install Xtesting package.
$ pip install xtesting
Copy ‘requirements.txt’ from ‘/tmp/o2/tacker/tacker/tests/xtesting/’ to the current directory and install it.
$ cp /tmp/o2/tacker/tacker/tests/xtesting/requirements.txt . $ pip install -r requirements.txt
Check out ‘api-tests’ repository in ETSI NFV into the current directory.
$ git clone https://forge.etsi.org/rep/nfv/api-tests.git
Copy the directories and file under ‘/tmp/o2/tacker/tacker/tests/xtesting/’ to the location under the current directory.
$ cp -r /tmp/o2/tacker/tacker/tests/xtesting/api-tests/SOL003/CNFDeployment ./api-tests/SOL003 $ cp -r /tmp/o2/tacker/tacker/tests/xtesting/api-tests/SOL003/cnflcm ./api-tests/SOL003 $ cp -r /tmp/o2/tacker/tacker/tests/xtesting/api-tests/SOL005/CNFPrecondition ./api-tests/SOL005 $ mkdir jsons $ cp ./api-tests/SOL003/cnflcm/jsons/inst.json ./jsons/instantiateVnfRequest.json
Copy ‘testcases.yaml’ file from ‘/tmp/o2/tacker/tacker/tests/xtesting/’ directory to the location under the current directory.
$ cp /tmp/o2/tacker/tacker/tests/xtesting/testcases.yaml ./xtesting-py3/lib/python3.8/site-packages/xtesting/ci/
Note
If user is working in other directory than ‘/opt/stack/’, then the path specified in ‘suites’ parameter in ‘testcases.yaml’ needs to be updated to the actual one.
Give permissions to ‘api-tests’ directory.
$ sudo chmod -R 775 api-tests
Update ‘VNFM_SCHEMA’, ‘VNFM_PORT’, ‘VNFM_HOST’, ‘PODS_SCHEMA’, ‘PODS_PORT’ and ‘PODS_HOST’ variables in below files with appropriate Request Type (http or https), Port and Host.
$ vi api-tests/SOL003/CNFDeployment/environment/variables.txt
Copy necessary files under api-tests directory into the designated location.
$ cp ./api-tests/SOL003/VNFLifecycleManagement-API/jsons/createVnfRequest.json ./jsons $ cp ./api-tests/SOL003/VNFLifecycleManagement-API/jsons/healVnfRequest.json ./jsons $ mkdir schemas $ cp ./api-tests/SOL003/VNFLifecycleManagement-API/schemas/vnfInstance.schema.json ./schemas
Modify robot files under api-tests directory as below.
$ vi api-tests/SOL003/VNFLifecycleManagement-API/VnfLcmMntOperationKeywords.robot
E.g: Part of file content
(Omitted) POST Create a new vnfInstance Log Create VNF instance by POST to /vnf_instances Set Headers {"Accept":"${ACCEPT}"} Set Headers {"Content-Type": "${CONTENT_TYPE}"} Run Keyword If ${AUTH_USAGE} == 1 Set Headers {"${AUTHORIZATION_HEADER}":"${AUTHORIZATION_TOKEN}"} Run Keyword If ${check_descriptors} == 1 PARSE the Descriptor File ${template}= Get File jsons/createVnfRequest.json ${body}= Format String ${template} vnfdId=${vnfdId} vnfProvider=${Provider} vnfProductName=${Product_Name} vnfSoftwareVersion=${Software_Version} vnfdVersion= ${Descriptor_Version} Post ${apiRoot}/${apiName}/${apiMajorVersion}/vnf_instances ${body} ${outputResponse}= Output response Set Global Variable ${response} ${outputResponse} ${res_body}= Get From Dictionary ${outputResponse} body # Add this line ${vnfInstanceId}= Get From Dictionary ${res_body} id # Add this line Set Global Variable ${vnfInstanceId} # Add this line Run Process api-tests/SOL003/cnflcm/update_variable.sh ${vnfInstanceId} shell=yes # Add this line GET multiple vnfInstances Log Query VNF The GET method queries information about multiple VNF instances. (Omitted)
Note
This change is for holding variable between test cases.
$ vi api-tests/SOL003/VNFLifecycleManagement-API/VNFInstances.robot
E.g: Part of file content
(Omitted) POST Create a new vnfInstance [Documentation] Test ID: 7.3.1.1.1 ... Test title: POST Create a new vnfInstance ... Test objective: The objective is to create a new VNF instance resource ... Pre-conditions: none ... Reference: Clause 5.4.2.3.1 - ETSI GS NFV-SOL 003 [1] v2.8.1 ... Config ID: Config_prod_VNFM ... Applicability: none ... Post-Conditions: VNF instance created POST Create a new vnfInstance Check HTTP Response Status Code Is 201 Check HTTP Response Body Json Schema Is vnfInstance *** comment *** # Add this line GET information about multiple VNF instances [Documentation] Test ID: 7.3.1.1.2 (Omitted)
Note
This change is for avoiding running unnecessary test cases.
Preconditioning for test execution
If there is no ‘nfv_user’ and ‘nfv’ project, create them in your local environment.
$ source ${devstack_dir}/openrc admin admin $ openstack project create --domain default nfv $ openstack user create --domain default --project nfv --password devstack nfv_user $ openstack role add --project nfv --user nfv_user admin
Register Kubernetes VIM and create an executable environment for Helm CLI from steps mentioned in below link.
Install ‘dos2unix’ and ‘jq’.
$ sudo apt-get install dos2unix $ sudo apt install jq
Execute script ‘packageTest.sh’ for package creation and uploading.
$ cd ~/tacker/tacker/tests/xtesting/api-tests/SOL005/CNFPrecondition $ ./packageTest.sh ../../SOL003/VNFLifecycleManagement-API/environment/variables.txt
Get ‘vimId’ and change it in the file ‘instantiateVnfRequest.json’ as below.
$ openstack vim list -c "ID"
E.g: Output of command
+--------------------------------------+ | ID | +--------------------------------------+ | 08260b52-c3f6-47a9-bb1f-cec1f0d3956a | +--------------------------------------+
$ vi ~/tacker/tacker/tests/xtesting/jsons/instantiateVnfRequest.json
E.g: Content of file
{ "flavourId": "helmchart", "additionalParams": { "namespace": "default", "use_helm": "true", "using_helm_install_param": [ { "exthelmchart": "false", "helmchartfile_path": "Files/kubernetes/localhelm-0.1.0.tgz", "helmreleasename": "tacker-test-vdu" } ], "helm_replica_values": { "vdu1_aspect": "replicaCount" }, "vdu_mapping": { "VDU1": { "kind": "Deployment", "name": "tacker-test-vdu-localhelm", "helmreleasename": "tacker-test-vdu" } } }, "vimConnectionInfo": [ { "id": "742f1fc7-7f00-417d-85a6-d4e788353181", "vimId": "d7a811a3-e3fb-41a1-a4e2-4dce2209bcfe", # Update value here "vimType": "kubernetes" } ] }
Start kubectl proxy.
$ kubectl proxy --port=8080 &
Testing steps
Verify Vnflcm Create and Instantiate.
$ cd ~/tacker/tacker/tests/xtesting/ $ . xtesting-py3/bin/activate $ sudo xtesting-py3/bin/run_tests -t cnf-instantiate
Verify Heal
$ cd ~/tacker/tacker/tests/xtesting/ $ . xtesting-py3/bin/activate $ sudo xtesting-py3/bin/run_tests -t cnf-heal-validation
Verify getting all pods and getting specific pod.
$ cd ~/tacker/tacker/tests/xtesting/ $ . xtesting-py3/bin/activate $ sudo xtesting-py3/bin/run_tests -t cnf-deployments-validation
E.g: Output of command
2022-12-05 05:10:13,908 - xtesting.core.robotframework - INFO - ============================================================================== IndividualCnfLcmOperationOccurrence ============================================================================== Get All Pods :: Test ID: 7.3.1.12.7 Test title: Get All Pods Test ... | PASS | ------------------------------------------------------------------------------ Get Specific Pod :: Test ID: 7.3.1.12.8 Test title: Get Specific P... | PASS | ------------------------------------------------------------------------------ IndividualCnfLcmOperationOccurrence | PASS | 2 tests, 2 passed, 0 failed ============================================================================== Output: /var/lib/xtesting/results/cnf-deployments-validation/output.xml 2022-12-05 05:10:13,913 - xtesting.core.robotframework - INFO - Results were successfully parsed 2022-12-05 05:10:13,968 - xtesting.core.robotframework - INFO - Results were successfully generated 2022-12-05 05:10:13,969 - xtesting.ci.run_tests - INFO - Test result: +-------------------------------+-----------------+------------------+----------------+ | TEST CASE | PROJECT | DURATION | RESULT | +-------------------------------+-----------------+------------------+----------------+ | cnf-deployments-validation | smo | 00:01 | PASS | +-------------------------------+-----------------+------------------+----------------+
For Re-testing, user must delete all the VNF instances and packages created in the above test. An example of steps is below.
$ grep -nu "vnfInstanceId" ~/tacker/tacker/tests/xtesting/api-tests/SOL003/VNFLifecycleManagement-API/environment/variables.txt | awk '{print $2}' 6fc3539c-e602-4afa-8e13-962fb5a7d81f $ openstack vnflcm terminate 6fc3539c-e602-4afa-8e13-962fb5a7d81f $ openstack vnflcm delete 6fc3539c-e602-4afa-8e13-962fb5a7d81f $ grep -nu "{vnfPkgId}" ~/tacker/tacker/tests/xtesting/api-tests/SOL003/VNFLifecycleManagement-API/environment/variables.txt | awk '{print $2}' 718b9054-2a7a-4489-a893-f2b2b1794825 $ openstack vnf package update --operational-state DISABLED 718b9054-2a7a-4489-a893-f2b2b1794825 $ openstack vnf package delete 718b9054-2a7a-4489-a893-f2b2b1794825
Note
In current test, the package name and namespace mentioned in deployment file for “Get Specific Pod” test are “vdu2” and “default”. If any update in the package with respect to name and namespace, then the name and namespace variables in the file ‘~/tacker/tacker/tests/xtesting/api-tests/SOL003/CNFDeployment/environment/variables.txt’ need to be updated accordingly.