def test_get_ns_instances_nsinstanceid( test_get_ns_instances_nsinstanceid_keys): """Tests API call to read an individual NS instance resource""" sonata_nslcm = SONATAClient.Nslcm(HOST_URL) sonata_auth = SONATAClient.Auth(HOST_URL) sonata_nsd = SONATAClient.Nsd(HOST_URL) _token = json.loads(sonata_auth.auth(username=USERNAME, password=PASSWORD)) _token = json.loads(_token["data"]) _nsd_list = json.loads( sonata_nsd.get_ns_descriptors(token=_token["token"]["access_token"])) _nsd_list = json.loads(_nsd_list["data"]) _ns_list = json.loads( sonata_nslcm.get_ns_instances(token=_token["token"]["access_token"])) _ns_list = json.loads(_ns_list["data"]) _ns = None for _n in _nsd_list: if "A dummy Example." == _n['nsd']['description']: for _n2 in _ns_list: if _n['uuid'] == _n2['descriptor_reference']: _ns = _n2['uuid'] response = json.loads( sonata_nslcm.get_ns_instances_nsinstanceid( token=_token["token"]["access_token"], nsInstanceId=_ns)) print(response) assert response['error'] == False response = json.loads(response["data"]) assert isinstance(response, dict) assert set(test_get_ns_instances_nsinstanceid_keys).issubset( response.keys()), "All keys should be in the response"
def sonata_cleanup(): sonata_nsd = SONATAClient.Nsd(HOST_URL) sonata_pishahang = SONATAClient.Pishahang(HOST_URL) sonata_nslcm = SONATAClient.Nslcm(HOST_URL) sonata_auth = SONATAClient.Auth(HOST_URL) sonata_vnfpkgm = SONATAClient.VnfPkgm(HOST_URL) print("Sonata NSD/VNFD Cleanup") _token = json.loads(sonata_auth.auth(username=USERNAME, password=PASSWORD)) _token = json.loads(_token["data"]) _csd_list = json.loads( sonata_pishahang.get_csd_descriptors( token=_token, limit=1000, )) _csd_list = json.loads(_csd_list["data"]) print(len(_csd_list)) for _csd in _csd_list: sonata_pishahang.delete_csd_descriptors_csdpkgid(token=_token, csdpkgid=_csd['uuid']) _cosd_list = json.loads( sonata_pishahang.get_cosd_descriptors(token=_token, limit=1000)) _cosd_list = json.loads(_cosd_list["data"]) print(len(_cosd_list)) for _cosd in _cosd_list: sonata_pishahang.delete_cosd_descriptors_cosdpkgid( token=_token, cosdpkgid=_cosd['uuid'])
def test_post_ns_instances_nsinstanceid_instantiate( post_ns_instances_nsinstanceid_instantiate_keys): """Tests API call to instantiate an NS""" sonata_nslcm = SONATAClient.Nslcm(HOST_URL) sonata_auth = SONATAClient.Auth(HOST_URL) sonata_nsd = SONATAClient.Nsd(HOST_URL) _token = json.loads(sonata_auth.auth(username=USERNAME, password=PASSWORD)) _token = json.loads(_token["data"]) _nsd_list = json.loads( sonata_nsd.get_ns_descriptors(token=_token["token"]["access_token"])) _nsd_list = json.loads(_nsd_list["data"]) _ns = None for _n in _nsd_list: if "A dummy Example." == _n['nsd']['description']: _ns = _n['uuid'] if _ns: response = json.loads( sonata_nslcm.post_ns_instances_nsinstanceid_instantiate( token=_token["token"]["access_token"], nsInstanceId=_ns)) assert response['error'] == False response = json.loads(response["data"]) assert isinstance(response, dict) assert set(post_ns_instances_nsinstanceid_instantiate_keys).issubset( response.keys()), "All keys should be in the response" else: return False
def test_put_ns_descriptors_nsdinfoid(): sonata_nsd = SONATAClient.Nsd(HOST_URL) sonata_auth = SONATAClient.Auth(HOST_URL) _token = json.loads(sonata_auth.auth(username=USERNAME, password=PASSWORD)) _token = json.loads(_token["data"]) Helpers._upload_test_nsd(_token=_token["token"]["access_token"]) _nsd_list = json.loads( sonata_nsd.get_ns_descriptors(token=_token["token"]["access_token"])) _nsd_list = json.loads(_nsd_list["data"]) _nsd = None for _n in _nsd_list: if "sonata-demo" == _n['nsd']['name']: _nsd = _n['uuid'] response = json.loads( sonata_nsd.put_ns_descriptors_nsdinfoid( token=_token["token"]["access_token"], data_path="tests/samples/Sonata/sonata_simple_nsd.json", nsdinfoid=_nsd)) Helpers._delete_test_nsd("sonata-demo") if response["error"]: return True else: return False
def test_get_ns_descriptors(get_ns_descriptors_keys): """Tests API call to fetch multiple NS descriptor resources""" sonata_nsd = SONATAClient.Nsd(HOST_URL) sonata_auth = SONATAClient.Auth(HOST_URL) _token = json.loads(sonata_auth.auth(username=USERNAME, password=PASSWORD)) _token = json.loads(_token["data"]) response = json.loads( sonata_nsd.get_ns_descriptors(token=_token["token"]["access_token"], limit=1000)) response = json.loads(response["data"]) assert isinstance(response, list) if len(response) > 0: assert set(get_ns_descriptors_keys).issubset( response[0].keys()), "All keys should be in the response"
def test_delete_ns_descriptors_nsdinfoid(delete_ns_descriptors_nsdinfoid_keys): """Tests API call to delete NS descriptor resources""" sonata_vnfpkgm = SONATAClient.VnfPkgm(HOST_URL) sonata_nsd = SONATAClient.Nsd(HOST_URL) sonata_auth = SONATAClient.Auth(HOST_URL) _token = json.loads(sonata_auth.auth(username=USERNAME, password=PASSWORD)) _token = json.loads(_token["data"]) _nsd_list = json.loads( sonata_nsd.get_ns_descriptors(token=_token["token"]["access_token"])) _nsd_list = json.loads(_nsd_list["data"]) _nsd = None for _n in _nsd_list: if "sonata-demo" == _n['nsd']['name']: _nsd = _n['uuid'] time.sleep(10) # Wait for NSD onboarding response = json.loads( sonata_nsd.delete_ns_descriptors_nsdinfoid( token=_token["token"]["access_token"], nsdinfoid=_nsd)) assert isinstance(response, dict) assert response["data"] == "{\"error\":\"The NSD ID None does not exist\"}" time.sleep(2) #Wait for NSD onboarding _vnfd_list = json.loads( sonata_vnfpkgm.get_vnf_packages(token=_token["token"]["access_token"])) _vnfd_list = json.loads(_vnfd_list["data"]) _vnfd = None for _v in _vnfd_list: if "vnfd_example" == _v['uuid']: _vnfd = _v['uuid'] response = None if _vnfd: response = json.loads( sonata_vnfpkgm.delete_vnf_packages_vnfpkgid( token=_token["token"]["access_token"], vnfPkgId=_vnfd)) assert isinstance(response, dict) assert response["data"] == ""
def test_post_ns_descriptors(post_ns_descriptors_keys): """Tests API call to onboard NS descriptor resources""" sonata_vnfpkgm = SONATAClient.VnfPkgm(HOST_URL) sonata_nsd = SONATAClient.Nsd(HOST_URL) sonata_auth = SONATAClient.Auth(HOST_URL) _token = json.loads(sonata_auth.auth(username=USERNAME, password=PASSWORD)) _token = json.loads(_token["data"]) Helpers._delete_test_nsd(_token=_token["token"]["access_token"]) sonata_vnfpkgm.post_vnf_packages( token=_token["token"]["access_token"], package_path="tests/samples/vnfd_example.yml") response = json.loads( sonata_nsd.post_ns_descriptors( token=_token["token"]["access_token"], package_path="tests/samples/nsd_example.yml")) assert response['error'] == False assert response['data'] != ''
def test_get_ns_descriptors_nsdinfoid(): """Tests API call to read information about an NS descriptor resources""" sonata_nsd = SONATAClient.Nsd(HOST_URL) sonata_auth = SONATAClient.Auth(HOST_URL) _token = json.loads(sonata_auth.auth(username=USERNAME, password=PASSWORD)) _token = json.loads(_token["data"]) _nsd_list = json.loads( sonata_nsd.get_ns_descriptors(token=_token["token"]["access_token"])) _nsd_list = json.loads(_nsd_list["data"]) Helpers._upload_test_nsd(_token=_token["token"]["access_token"]) for _n in _nsd_list: if "sonata-demo" == _n['nsd']['name']: _nsd = _n['uuid'] response = json.loads( sonata_nsd.get_ns_descriptors_nsdinfoid( token=_token["token"]["access_token"], nsdinfoid=_nsd)) Helpers._delete_test_nsd(_token=_token["token"]["access_token"]) if response["error"]: return True else: return False
image=_image, case=_case, instances=_instances, rpm=_rpm, run=_run) NSD_PATH = "/app/SONATA/Descriptors/CASE{case}/{image}_case{case}_nsd_sonata.yml".format( image=_image, case=_case) # VNFD_PATHS = ["/app/SONATA/Descriptors/CASE{case}/{image}_vnfd.1.yml".format(image=_image, case=_case), "/app/SONATA/Descriptors/CASE{case}/{image}_vnfd.2.yml".format(image=_image, case=_case), "/app/SONATA/Descriptors/CASE{case}/{image}_vnfd.3.yml".format(image=_image, case=_case), "/app/SONATA/Descriptors/CASE{case}/{image}_vnfd.4.yml".format(image=_image, case=_case), "/app/SONATA/Descriptors/CASE{case}/{image}_vnfd.5.yml".format(image=_image, case=_case)] with open(NSD_PATH, 'r') as file: nsd_data = file.read() # with open(VNFD_PATH, 'r') as file: # vnfd_data = file.read() sonata_nsd = SONATAClient.Nsd(HOST_URL) sonata_nslcm = SONATAClient.Nslcm(HOST_URL) sonata_auth = SONATAClient.Auth(HOST_URL) sonata_vnfpkgm = SONATAClient.VnfPkgm(HOST_URL) experiment_timestamps = {} sonata_cleanup() _token = json.loads( sonata_auth.auth(username=USERNAME, password=PASSWORD)) _token = json.loads(_token["data"]) for _c in range(1, 6): # for _vnfd in VNFD_PATHS: VNFD_PATH = "/app/SONATA/Descriptors/CASE{case}/{image}_vnfd_{vnfid}.yml".format(