Fix FT vnf package functional tests

test_upload_from_file_and_delete functional test is failing
as the vnf package 'operationalState' is not DISABLED
before deletion.

To fix this issue, I have merged two existing FTs into new one
which will test the flow - create, upload, update, show and delete.

* Deleted existing FT
  test_upload_from_file_and_delete
  test_patch_in_onboarded_state
* Added new FT
  test_upload_from_file_update_show_and_delete.
* Fixed get vnfd related functional tests by setting package
  operational state to DISABLED before deleting
* assert_resp_contents method now uses assertCountEqual to compare
  list of string as it ignores order of items in the list.

Closes-bug: #1866776
Change-Id: I310f4206527cfe215116f8d85acdb1f519d67a97
This commit is contained in:
tpatil 2020-04-21 03:06:40 +00:00
parent c45c877f36
commit 31beaa32b8

View File

@ -71,6 +71,16 @@ class VnfPackageTest(base.BaseTackerTest):
self.assertEqual(201, resp.status_code)
return response_body
def _disable_operational_state(self, package_uuid):
update_req_body = jsonutils.dumps({
"operationalState": "DISABLED"})
resp, resp_body = self.http_client.do_request(
'{base_path}/{id}'.format(id=package_uuid,
base_path=self.base_url),
"PATCH", content_type='application/json', body=update_req_body)
self.assertEqual(200, resp.status_code)
def _delete_vnf_package(self, package_uuid):
url = self.base_url + "/" + package_uuid
resp, body = self.http_client.do_request(url, "DELETE")
@ -123,49 +133,38 @@ class VnfPackageTest(base.BaseTackerTest):
'../../etc/samples/' + file_name))
return file_path
def test_upload_from_file_and_delete(self):
body = jsonutils.dumps({"userDefinedData": {"foo": "bar"}})
vnf_package = self._create_vnf_package(body)
file_path = self._get_csar_file_path("sample_vnf_package_csar.zip")
with open(file_path, 'rb') as file_object:
resp, resp_body = self.http_client.do_request(
'{base_path}/{id}/package_content'.format(
id=vnf_package['id'],
base_path=self.base_url),
"PUT", body=file_object, content_type='application/zip')
def test_upload_from_file_update_show_and_delete(self):
"""This method tests multiple operations on vnf package.
self.assertEqual(202, resp.status_code)
self._wait_for_onboard(vnf_package['id'])
self._delete_vnf_package(vnf_package['id'])
self._wait_for_delete(vnf_package['id'])
def test_patch_in_onboarded_state(self):
- upload package from file
- update the package state to DISABLED.
- show the package
- delete the package
"""
user_data = jsonutils.dumps(
{"userDefinedData": {"key1": "val1", "key2": "val2",
"key3": "val3"}})
vnf_package = self._create_vnf_package(user_data)
file_path = self._get_csar_file_path("sample_vnf_package_csar.zip")
upload_url = "{base_path}/{id}/package_content".format(
base_path=self.base_url, id=vnf_package['id'])
with open(file_path, 'rb') as file_object:
resp, resp_body = self.http_client.do_request(upload_url,
"PUT", body=file_object, content_type='application/zip')
self.assertEqual(202, resp.status_code)
self._wait_for_onboard(vnf_package['id'])
update_req_body = jsonutils.dumps(
{"operationalState": "DISABLED",
"userDefinedData": {"key1": "changed_val1",
"key2": "val2", "new_key": "new_val"}})
expected_result = {"operationalState": "DISABLED",
"userDefinedData": {
"key1": "changed_val1", "new_key": "new_val"}}
file_path = self._get_csar_file_path("sample_vnf_package_csar.zip")
with open(file_path, 'rb') as file_object:
resp, resp_body = self.http_client.do_request(
'{base_path}/{id}/package_content'.format(
id=vnf_package['id'],
base_path=self.base_url),
"PUT", body=file_object, content_type='application/zip')
self.assertEqual(202, resp.status_code)
self._wait_for_onboard(vnf_package['id'])
operational_state = "DISABLED"
user_defined_data = {"key1": "changed_val1", "new_key": "new_val"}
expected_result = {"operationalState": operational_state,
"userDefinedData": user_defined_data}
# Update vnf package which is onboarded
resp, resp_body = self.http_client.do_request(
@ -175,6 +174,17 @@ class VnfPackageTest(base.BaseTackerTest):
self.assertEqual(200, resp.status_code)
self.assertEqual(expected_result, resp_body)
# Show vnf package and verify whether the userDefinedData
# and operationalState parameters are updated correctly.
show_url = self.base_url + "/" + vnf_package['id']
resp, body = self.http_client.do_request(show_url, "GET")
self.assertEqual(200, resp.status_code)
self.assertEqual(operational_state, body['operationalState'])
expected_user_defined_data = {'key1': 'changed_val1', 'key2': 'val2',
'key3': 'val3', 'new_key': 'new_val'}
self.assertEqual(expected_user_defined_data, body['userDefinedData'])
self._delete_vnf_package(vnf_package['id'])
self._wait_for_delete(vnf_package['id'])
@ -198,6 +208,7 @@ class VnfPackageTest(base.BaseTackerTest):
def test_get_vnfd_from_onboarded_vnf_package_for_content_type_zip(self):
vnf_package_id = self._create_and_onboard_vnf_package()
self.addCleanup(self._delete_vnf_package, vnf_package_id)
self.addCleanup(self._disable_operational_state, vnf_package_id)
resp, resp_body = self.http_client.do_request(
'{base_path}/{id}/vnfd'.format(id=vnf_package_id,
base_path=self.base_url),
@ -223,7 +234,7 @@ class VnfPackageTest(base.BaseTackerTest):
with zipfile.ZipFile(tmp, 'r') as zipObj:
# Get list of files names in zip
actual_file_list = zipObj.namelist()
self.assertEqual(expected_file_list, actual_file_list)
self.assertCountEqual(expected_file_list, actual_file_list)
tmp.close()
@ -235,6 +246,7 @@ class VnfPackageTest(base.BaseTackerTest):
vnf_package_id = self._create_and_onboard_vnf_package(
single_yaml_csar)
self.addCleanup(self._delete_vnf_package, vnf_package_id)
self.addCleanup(self._disable_operational_state, vnf_package_id)
resp, resp_body = self.http_client.do_request(
'{base_path}/{id}/vnfd'.format(id=vnf_package_id,
base_path=self.base_url),