From e36ab859d275c9c1b863bbb6564a1da56cabe2dd Mon Sep 17 00:00:00 2001 From: Felipe Vicens Date: Fri, 23 Nov 2018 14:12:09 +0100 Subject: [PATCH] Adding NetSlice Tests Change-Id: If540af6df84f7ba6321f1740524bbaedf6115d9f Signed-off-by: Felipe Vicens --- osm_nbi/descriptor_topics.py | 15 ++--- osm_nbi/instance_topics.py | 2 +- osm_nbi/nbi.py | 2 +- osm_nbi/tests/cirros_slice/cirros_slice.yaml | 49 ++++++++++----- .../tests/cirros_slice/cirros_slice_vld.yaml | 43 +++++++++++++ osm_nbi/tests/test.py | 63 ++++++++++++++++++- 6 files changed, 147 insertions(+), 27 deletions(-) create mode 100644 osm_nbi/tests/cirros_slice/cirros_slice_vld.yaml diff --git a/osm_nbi/descriptor_topics.py b/osm_nbi/descriptor_topics.py index 3a65c0b..5612fdf 100644 --- a/osm_nbi/descriptor_topics.py +++ b/osm_nbi/descriptor_topics.py @@ -739,10 +739,6 @@ class NstTopic(DescriptorTopic): return {} clean_indata = indata - if clean_indata.get('nst:nst'): - clean_indata = clean_indata['nst:nst'] - elif clean_indata.get('nst'): - clean_indata = clean_indata['nst'] if clean_indata.get('nst'): if not isinstance(clean_indata['nst'], list) or len(clean_indata['nst']) != 1: raise EngineException("'nst' must be a list only one element") @@ -753,6 +749,9 @@ class NstTopic(DescriptorTopic): # TODO validate with pyangbind, serialize return indata + def _validate_input_new(self, indata, force=False): + return indata.copy() + def _check_descriptor_dependencies(self, session, descriptor): """ Check that the dependent descriptors exist on a new descriptor or edition @@ -790,13 +789,15 @@ class NstTopic(DescriptorTopic): # Get Network Slice Template from Database _filter = self._get_project_filter(session, write=False, show_all=False) _filter["_id"] = _id - nst = self.db.get_one("nst", _filter) + nst = self.db.get_one("nsts", _filter) # Search NSIs using NST via nst-ref _filter = self._get_project_filter(session, write=False, show_all=False) _filter["nst-ref"] = nst["id"] - if self.db.get_list("nsis", _filter): - raise EngineException("There is some NSIS that depends on this NST", http_code=HTTPStatus.CONFLICT) + nsis_list = self.db.get_list("nsis", _filter) + for nsi_item in nsis_list: + if nsi_item["_admin"].get("nsiState") != "TERMINATED": + raise EngineException("There is some NSIS that depends on this NST", http_code=HTTPStatus.CONFLICT) class PduTopic(BaseTopic): diff --git a/osm_nbi/instance_topics.py b/osm_nbi/instance_topics.py index d9f76a3..e53f28e 100644 --- a/osm_nbi/instance_topics.py +++ b/osm_nbi/instance_topics.py @@ -836,7 +836,7 @@ class NsiTopic(BaseTopic): for service in services: indata_ns = {} indata_ns["nsdId"] = service["_id"] - indata_ns["nsName"] = service["name"] + indata_ns["nsName"] = service["id"] indata_ns["vimAccountId"] = indata.get("vimAccountId") indata_ns["nsDescription"] = service["description"] indata_ns["key-pair-ref"] = None diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index c6a06fd..caf4c2d 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -850,7 +850,7 @@ class Server(object): cherrypy.log("Exception {}".format(e)) else: http_code_value = cherrypy.response.status = HTTPStatus.BAD_REQUEST.value # INTERNAL_SERVER_ERROR - cherrypy.log("CRITICAL: Exception {}".format(e)) + cherrypy.log("CRITICAL: Exception {}".format(e), traceback=True) http_code_name = HTTPStatus.BAD_REQUEST.name if hasattr(outdata, "close"): # is an open file outdata.close() diff --git a/osm_nbi/tests/cirros_slice/cirros_slice.yaml b/osm_nbi/tests/cirros_slice/cirros_slice.yaml index 6f66c27..4f510ce 100644 --- a/osm_nbi/tests/cirros_slice/cirros_slice.yaml +++ b/osm_nbi/tests/cirros_slice/cirros_slice.yaml @@ -1,17 +1,34 @@ +# Copyright [2018] [Felipe Vicens, Pol Alemany, Ricard Vilalta] +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + nst: - nst: - - id: cirros_nst - name: cirros_netslice_template - SNSSAI-identifier: - - slice-service-type: eMBB - quality-of-service: - - id: 1 - netslice-subnet: - - id: cirros_nsd - is-shared-nss: 'false' - description: Slice example for osm-5.0 - nsd-ref: cirros_nsd - instantiation-parameters: - - nsName: cirros_nsd - nsdId: cirros_nsd - vimAccountId: openstack_18 \ No newline at end of file +- id: 'cirros_nst' + name: cirros_netslice_template + SNSSAI-identifier: + - slice-service-type: eMBB + quality-of-service: + - id: 1 + netslice-subnet: + - id: cirros_nsd_1 + is-shared-nss: 'false' + description: Slice example for osm-5.0 + nsd-ref: 'cirros_2vnf_nsd' + instantiation-parameters: + vimAccountId: Openstack_7.18 + - id: cirros_nsd_2 + is-shared-nss: 'false' + description: Slice example for osm-5.0 + nsd-ref: 'cirros_2vnf_nsd' + instantiation-parameters: + vimAccountId: Openstack_7.18 diff --git a/osm_nbi/tests/cirros_slice/cirros_slice_vld.yaml b/osm_nbi/tests/cirros_slice/cirros_slice_vld.yaml new file mode 100644 index 0000000..0cb21bb --- /dev/null +++ b/osm_nbi/tests/cirros_slice/cirros_slice_vld.yaml @@ -0,0 +1,43 @@ +# Copyright [2018] [Felipe Vicens, Pol Alemany, Ricard Vilalta] +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +nst: +- id: cirros_nst + name: cirros_netslice_template + SNSSAI-identifier: + - slice-service-type: eMBB + quality-of-service: + - id: 1 + netslice-subnet: + - id: cirros_nsd_1 + is-shared-nss: 'false' + description: Slice example for osm-5.0 + nsd-ref: cirros_nsd + instantiation-parameters: + - nsName: cirros_nsd + nsdId: cirros_nsd + vimAccountId: openstack_18 + - id: cirros_nsd_2 + is-shared-nss: 'false' + description: Slice example for osm-5.0 + nsd-ref: cirros_nsd + instantiation-parameters: + - nsName: cirros_nsd + nsdId: cirros_nsd + vimAccountId: openstack_18 + netslice-vld: + - id: slice_cirros_vld1 + name: slice_cirros_vld1 + nsd-connection-point-ref: + - nsd-ref: cirros_nsd + nsd-connection-point-ref: cirros_nsd_vld1 \ No newline at end of file diff --git a/osm_nbi/tests/test.py b/osm_nbi/tests/test.py index 73c96c1..a084095 100755 --- a/osm_nbi/tests/test.py +++ b/osm_nbi/tests/test.py @@ -1599,7 +1599,7 @@ class TestDescriptors: self.step += 1 -class TestNstTemplates: +class TestNetSliceTemplates: description = "Upload a NST to OSM" def __init__(self): @@ -1626,6 +1626,64 @@ class TestNstTemplates: 204, None, 0) +class TestNetSliceInstances: + description = "Upload a NST to OSM" + + def __init__(self): + self.nst_filenames = ("@./cirros_slice/cirros_slice.yaml") + + def run(self, engine, test_osm, manual_check, test_params=None): + # nst CREATE + engine.get_autorization() + r = engine.test("NST1", "Onboard NST", "POST", "/nst/v1/netslice_templates_content", headers_yaml, + self.nst_filenames, 201, + {"Location": "/nst/v1/netslice_templates_content", "Content-Type": "application/yaml"}, "yaml") + location = r.headers["Location"] + nst_id = location[location.rfind("/")+1:] + + # nsi CREATE + if test_osm: + self.vim_id = engine.get_create_vim(test_osm) + else: + r = engine.test("VIM1", "Get available VIM", "GET", "/admin/v1/vim_accounts", + headers_json, None, None, r_header_json, "json") + r_json = json.loads(r.text) + vim = r_json[0] + self.vim_id = vim["_id"] + + ns_data = {"nsiDescription": "default description", "nsiName": "my_slice", "nstdId": "cirros_nst", + "vimAccountId": self.vim_id} + ns_data_text = yaml.safe_dump(ns_data, default_flow_style=True, width=256) + + r = engine.test("NSI1", "Onboard NSI", "POST", "/nsilcm/v1/netslice_instances_content", headers_yaml, + ns_data_text, 201, + {"Location": "/nsilcm/v1/netslice_instances_content", "Content-Type": + "application/yaml"}, "yaml") + location = r.headers["Location"] + nsi_id = location[location.rfind("/")+1:] + + # TODO: Improve the wait with a polling if NSI was deployed + wait = 120 + sleep(wait) + + # Check deployment + r = engine.test("NSI2", "Wait until NSI is deployed", "GET", + "/nsilcm/v1/netslice_instances_content/{}".format(nsi_id), headers_json, None, + 200, r_header_json, "json") + + # nsi DELETE + r = engine.test("NSI3", "Delete NSI", "DELETE", + "/nsilcm/v1/netslice_instances_content/{}".format(nsi_id), headers_json, None, + 202, r_header_json, "json") + + sleep(60) + + # nstd DELETE + r = engine.test("NST2", "Delete NSTD", "DELETE", + "/nst/v1/netslice_templates/{}".format(nst_id), headers_json, None, + 204, None, 0) + + if __name__ == "__main__": global logger test = "" @@ -1662,7 +1720,8 @@ if __name__ == "__main__": # "Deploy-MultiVIM": TestDeployMultiVIM, "DeploySingleVdu": TestDeploySingleVdu, "DeployHnfd": TestDeployHnfd, - "Upload-Slice-Template": TestNstTemplates, + "Upload-Slice-Template": TestNetSliceTemplates, + "Deploy-Slice-Instance": TestNetSliceInstances, } test_to_do = [] test_params = {} -- 2.17.1