from base_topic import BaseTopic, EngineException, get_iterable
from descriptor_topics import DescriptorTopic
from yaml import safe_dump
+from osm_common.dbbase import DbException
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
if dry_run:
return
+ # Deleting the nsrs belonging to nsir
+ nsir = self.db.get_one("nsis", {"_id": _id})
+ for nsrs_detailed_item in nsir["_admin"]["nsrs-detailed-list"]:
+ nsr_id = nsrs_detailed_item["nsrId"]
+ if nsrs_detailed_item.get("shared"):
+ _filter = {"_admin.nsrs-detailed-list.ANYINDEX.shared": True,
+ "_admin.nsrs-detailed-list.ANYINDEX.nsrId": nsr_id,
+ "_id.ne": nsir["_id"]}
+ nsi = self.db.get_one("nsis", _filter, fail_on_empty=False, fail_on_more=False)
+ if nsi: # last one using nsr
+ continue
+ try:
+ self.nsrTopic.delete(session, nsr_id, force=force, dry_run=False)
+ except (DbException, EngineException) as e:
+ if e.http_code == HTTPStatus.NOT_FOUND:
+ pass
+ else:
+ raise
# deletes NetSlice instance object
v = self.db.del_one("nsis", {"_id": _id})
_filter = {"netsliceInstanceId": _id}
self.db.del_list("nsilcmops", _filter)
- _filter = {"operationParams.netsliceInstanceId": _id}
- nslcmops_list = self.db.get_list("nslcmops", _filter)
-
- for id_item in nslcmops_list:
- _filter = {"_id": id_item}
- nslcmop = self.db.get_one("nslcmops", _filter)
- nsr_id = nslcmop["operationParams"]["nsr_id"]
- self.nsrTopic.delete(session, nsr_id, force=False, dry_run=False)
- self._send_msg("deleted", {"_id": _id})
+ # Search if nst is being used by other nsi
+ nsir_admin = nsir.get("_admin")
+ if nsir_admin:
+ if nsir_admin.get("nst-id"):
+ nsis_list = self.db.get_one("nsis", {"nst-id": nsir_admin["nst-id"]},
+ fail_on_empty=False, fail_on_more=False)
+ if not nsis_list:
+ self.db.set_one("nsts", {"_id": nsir_admin["nst-id"]}, {"_admin.usageState": "NOT_IN_USE"})
return v
def new(self, rollback, session, indata=None, kwargs=None, headers=None, force=False, make_public=False):
_filter.update(BaseTopic._get_project_filter(session, write=False, show_all=True))
nstd = self.db.get_one("nsts", _filter)
nstd.pop("_admin", None)
- nstd.pop("_id", None)
+ nstd_id = nstd.pop("_id", None)
nsi_id = str(uuid4())
step = "filling nsi_descriptor with input data"
self.format_on_new(nsi_descriptor, session["project_id"], make_public=make_public)
nsi_descriptor["_admin"]["nsiState"] = "NOT_INSTANTIATED"
nsi_descriptor["_admin"]["netslice-subnet"] = None
-
+ nsi_descriptor["_admin"]["deployed"] = {}
+ nsi_descriptor["_admin"]["deployed"]["RO"] = []
+ nsi_descriptor["_admin"]["nst-id"] = nstd_id
+
# Creating netslice-vld for the RO.
step = "creating netslice-vld at database"
- instantiation_parameters = slice_request
# Building the vlds list to be deployed
# From netslice descriptors, creating the initial list
- nsi_vlds = []
- if nstd.get("netslice-vld"):
- # Building VLDs from NST
- for netslice_vlds in nstd["netslice-vld"]:
- nsi_vld = {}
- # Adding nst vld name and global vimAccountId for netslice vld creation
- nsi_vld["name"] = netslice_vlds["name"]
- nsi_vld["vimAccountId"] = slice_request["vimAccountId"]
- # Getting template Instantiation parameters from NST
- for netslice_vld in netslice_vlds["nss-connection-point-ref"]:
- for netslice_subnet in nstd["netslice-subnet"]:
- nsi_vld["nsd-ref"] = netslice_subnet["nsd-ref"]
- nsi_vld["nsd-connection-point-ref"] = netslice_vld["nsd-connection-point-ref"]
- # Obtaining the vimAccountId from template instantiation parameter
- if netslice_subnet.get("instantiation-parameters"):
- # Taking the vimAccountId from NST netslice-subnet instantiation parameters
- if netslice_subnet["instantiation-parameters"].get("vimAccountId"):
- netsn = netslice_subnet["instantiation-parameters"]["vimAccountId"]
- nsi_vld["vimAccountId"] = netsn
- # Obtaining the vimAccountId from user instantiation parameter
- if instantiation_parameters.get("netslice-subnet"):
- for ins_param in instantiation_parameters["netslice-subnet"]:
- if ins_param.get("id") == netslice_vld["nss-ref"]:
- if ins_param.get("vimAccountId"):
- nsi_vld["vimAccountId"] = ins_param["vimAccountId"]
- # Adding vim-network-name / vim-network-id defined by the user to vld
- if instantiation_parameters.get("netslice-vld"):
- for ins_param in instantiation_parameters["netslice-vld"]:
- if ins_param["name"] == netslice_vlds["name"]:
- if ins_param.get("vim-network-name"):
- nsi_vld["vim-network-name"] = ins_param.get("vim-network-name")
- if ins_param.get("vim-network-id"):
- nsi_vld["vim-network-id"] = ins_param.get("vim-network-id")
- if netslice_vlds.get("mgmt-network"):
- nsi_vld["mgmt-network"] = netslice_vlds.get("mgmt-network")
- nsi_vlds.append(nsi_vld)
+ nsi_vlds = []
+
+ for netslice_vlds in get_iterable(nstd.get("netslice-vld")):
+ # Getting template Instantiation parameters from NST
+ nsi_vld = deepcopy(netslice_vlds)
+ nsi_vld["shared-nsrs-list"] = []
+ nsi_vld["vimAccountId"] = slice_request["vimAccountId"]
+ nsi_vlds.append(nsi_vld)
nsi_descriptor["_admin"]["netslice-vld"] = nsi_vlds
# Creating netslice-subnet_record.
needed_nsds = {}
services = []
+ # Updating the nstd with the nsd["_id"] associated to the nss -> services list
for member_ns in nstd["netslice-subnet"]:
nsd_id = member_ns["nsd-ref"]
step = "getting nstd id='{}' constituent-nsd='{}' from database".format(
nsd = DescriptorTopic.get_one_by_id(self.db, session, "nsds", nsd_id)
nsd.pop("_admin")
needed_nsds[nsd_id] = nsd
- member_ns["_id"] = needed_nsds[nsd_id].get("_id")
- services.append(member_ns)
else:
nsd = needed_nsds[nsd_id]
- member_ns["_id"] = needed_nsds[nsd_id].get("_id")
- services.append(member_ns)
+ member_ns["_id"] = needed_nsds[nsd_id].get("_id")
+ services.append(member_ns)
step = "filling nsir nsd-id='{}' constituent-nsd='{}' from database".format(
member_ns["nsd-ref"], member_ns["id"])
- # check additionalParamsForSubnet contains a valid id
- if slice_request.get("additionalParamsForSubnet"):
- for additional_params_subnet in get_iterable(slice_request.get("additionalParamsForSubnet")):
- for service in services:
- if additional_params_subnet["id"] == service["id"]:
- break
- else:
- raise EngineException("Error at additionalParamsForSubnet:id='{}' not match any "
- "netslice-subnet:id".format(additional_params_subnet["id"]))
-
# creates Network Services records (NSRs)
step = "creating nsrs at database using NsrTopic.new()"
ns_params = slice_request.get("netslice-subnet")
-
nsrs_list = []
nsi_netslice_subnet = []
for service in services:
+ # Check if the netslice-subnet is shared and if it is share if the nss exists
+ _id_nsr = None
indata_ns = {}
- indata_ns["nsdId"] = service["_id"]
- indata_ns["nsName"] = slice_request.get("nsiName") + "." + service["id"]
- indata_ns["vimAccountId"] = slice_request.get("vimAccountId")
- indata_ns["nsDescription"] = service["description"]
- indata_ns["key-pair-ref"] = None
-
- # NsrTopic(rollback, session, indata_ns, kwargs, headers, force)
- # Overwriting ns_params filtering by nsName == netslice-subnet.id
-
- if ns_params:
- for ns_param in ns_params:
- if ns_param.get("id") == service["id"]:
- copy_ns_param = deepcopy(ns_param)
- del copy_ns_param["id"]
- indata_ns.update(copy_ns_param)
- break
+ # Is the nss shared and instantiated?
+ _filter = {"_admin.nsrs-detailed-list.ANYINDEX.shared": True,
+ "_admin.nsrs-detailed-list.ANYINDEX.nsd-id": service["nsd-ref"]}
+ nsi = self.db.get_one("nsis", _filter, fail_on_empty=False, fail_on_more=False)
- # Override the instantiation parameters for netslice-vld provided by user
- if nsi_vlds:
- indata_ns_list = []
- for nsi_vld in nsi_vlds:
- nsd = self.db.get_one("nsds", {"id": nsi_vld["nsd-ref"]})
- if nsd["connection-point"]:
- for cp_item in nsd["connection-point"]:
- if cp_item["name"] == nsi_vld["nsd-connection-point-ref"]:
- vld_id_ref = cp_item["vld-id-ref"]
- # Mapping the vim-network-name or vim-network-id instantiation parameters
- if nsi_vld.get("vim-network-id"):
- vnid = nsi_vld.get("vim-network-id")
- if type(vnid) is not dict:
- vim_network_id = {slice_request.get("vimAccountId"): vnid}
- else: # is string
- vim_network_id = vnid
- indata_ns_list.append({"name": vld_id_ref, "vim-network-id": vim_network_id})
- # Case not vim-network-name instantiation parameter
- elif nsi_vld.get("vim-network-name"):
- vnm = nsi_vld.get("vim-network-name")
- if type(vnm) is not dict:
- vim_network_name = {slice_request.get("vimAccountId"): vnm}
- else: # is string
- vim_network_name = vnm
- indata_ns_list.append({"name": vld_id_ref,
- "vim-network-name": vim_network_name})
- # Case neither vim-network-name nor vim-network-id provided
- else:
- indata_ns_list.append({"name": vld_id_ref})
- if indata_ns_list:
- indata_ns["vld"] = indata_ns_list
-
- # Creates Nsr objects
- _id_nsr = self.nsrTopic.new(rollback, session, indata_ns, kwargs, headers, force)
- nsrs_item = {"nsrId": _id_nsr}
+ if nsi and service.get("is-shared-nss"):
+ nsrs_detailed_list = nsi["_admin"]["nsrs-detailed-list"]
+ for nsrs_detailed_item in nsrs_detailed_list:
+ if nsrs_detailed_item["nsd-id"] == service["nsd-ref"]:
+ _id_nsr = nsrs_detailed_item["nsrId"]
+ break
+ for netslice_subnet in nsi["_admin"]["netslice-subnet"]:
+ if netslice_subnet["nss-id"] == service["id"]:
+ indata_ns = netslice_subnet
+ break
+ else:
+ indata_ns = {}
+ if service.get("instantiation-parameters"):
+ indata_ns = deepcopy(service["instantiation-parameters"])
+ # del service["instantiation-parameters"]
+
+ indata_ns["nsdId"] = service["_id"]
+ indata_ns["nsName"] = slice_request.get("nsiName") + "." + service["id"]
+ indata_ns["vimAccountId"] = slice_request.get("vimAccountId")
+ indata_ns["nsDescription"] = service["description"]
+ indata_ns["key-pair-ref"] = slice_request.get("key-pair-ref")
+
+ if ns_params:
+ for ns_param in ns_params:
+ if ns_param.get("id") == service["id"]:
+ copy_ns_param = deepcopy(ns_param)
+ del copy_ns_param["id"]
+ indata_ns.update(copy_ns_param)
+ break
+
+ # Creates Nsr objects
+ _id_nsr = self.nsrTopic.new(rollback, session, indata_ns, kwargs, headers, force)
+ nsrs_item = {"nsrId": _id_nsr, "shared": service.get("is-shared-nss"), "nsd-id": service["nsd-ref"],
+ "nslcmop_instantiate": None}
+ indata_ns["nss-id"] = service["id"]
nsrs_list.append(nsrs_item)
nsi_netslice_subnet.append(indata_ns)
nsr_ref = {"nsr-ref": _id_nsr}
# Adding the nsrs list to the nsi
nsi_descriptor["_admin"]["nsrs-detailed-list"] = nsrs_list
nsi_descriptor["_admin"]["netslice-subnet"] = nsi_netslice_subnet
+ self.db.set_one("nsts", {"_id": slice_request["nstId"]}, {"_admin.usageState": "IN_USE"})
+
# Creating the entry in the database
self.db.create("nsis", nsi_descriptor)
rollback.append({"topic": "nsis", "_id": nsi_id})
"instantiate": nsi_instantiate,
"terminate": None
}
-
+
def __init__(self, db, fs, msg):
BaseTopic.__init__(self, db, fs, msg)
+ self.nsi_NsLcmOpTopic = NsLcmOpTopic(self.db, self.fs, self.msg)
def _check_nsi_operation(self, session, nsir, operation, indata):
"""
}
return nsilcmop
+ def add_shared_nsr_2vld(self, nsir, nsr_item):
+ for nst_sb_item in nsir["network-slice-template"].get("netslice-subnet"):
+ if nst_sb_item.get("is-shared-nss"):
+ for admin_subnet_item in nsir["_admin"].get("netslice-subnet"):
+ if admin_subnet_item["nss-id"] == nst_sb_item["id"]:
+ for admin_vld_item in nsir["_admin"].get("netslice-vld"):
+ for admin_vld_nss_cp_ref_item in admin_vld_item["nss-connection-point-ref"]:
+ if admin_subnet_item["nss-id"] == admin_vld_nss_cp_ref_item["nss-ref"]:
+ if not nsr_item["nsrId"] in admin_vld_item["shared-nsrs-list"]:
+ admin_vld_item["shared-nsrs-list"].append(nsr_item["nsrId"])
+ break
+ # self.db.set_one("nsis", {"_id": nsir["_id"]}, nsir)
+ self.db.set_one("nsis", {"_id": nsir["_id"]}, {"_admin.netslice-vld": nsir["_admin"].get("netslice-vld")})
+
def new(self, rollback, session, indata=None, kwargs=None, headers=None, force=False, make_public=False):
"""
Performs a new operation over a ns
# Get service list from db
nsrs_list = nsir["_admin"]["nsrs-detailed-list"]
nslcmops = []
- for nsr_item in nsrs_list:
- service = self.db.get_one("nsrs", {"_id": nsr_item["nsrId"]})
- indata_ns = {}
- indata_ns = service["instantiate_params"]
- indata_ns["lcmOperationType"] = operation
- indata_ns["nsInstanceId"] = service["_id"]
- # Including netslice_id in the ns instantiate Operation
- indata_ns["netsliceInstanceId"] = nsiInstanceId
- del indata_ns["key-pair-ref"]
- nsi_NsLcmOpTopic = NsLcmOpTopic(self.db, self.fs, self.msg)
- # Creating NS_LCM_OP with the flag slice_object=True to not trigger the service instantiation
- # message via kafka bus
- nslcmop = nsi_NsLcmOpTopic.new(rollback, session, indata_ns, kwargs, headers, force, slice_object=True)
- nslcmops.append(nslcmop)
+ # nslcmops_item = None
+ for index, nsr_item in enumerate(nsrs_list):
+ nsi = None
+ if nsr_item.get("shared"):
+ _filter = {"_admin.nsrs-detailed-list.ANYINDEX.shared": True,
+ "_admin.nsrs-detailed-list.ANYINDEX.nsrId": nsr_item["nsrId"],
+ "_admin.nsrs-detailed-list.ANYINDEX.nslcmop_instantiate.ne": None,
+ "_id.ne": nsiInstanceId}
+
+ nsi = self.db.get_one("nsis", _filter, fail_on_empty=False, fail_on_more=False)
+ # looks the first nsi fulfilling the conditions but not being the current NSIR
+ if nsi:
+ nsi_admin_shared = nsi["_admin"]["nsrs-detailed-list"]
+ for nsi_nsr_item in nsi_admin_shared:
+ if nsi_nsr_item["nsd-id"] == nsr_item["nsd-id"] and nsi_nsr_item["shared"]:
+ self.add_shared_nsr_2vld(nsir, nsr_item)
+ nslcmops.append(nsi_nsr_item["nslcmop_instantiate"])
+ _update = {"_admin.nsrs-detailed-list.{}".format(index): nsi_nsr_item}
+ self.db.set_one("nsis", {"_id": nsir["_id"]}, _update)
+ break
+ # continue to not create nslcmop since nsrs is shared and nsrs was created
+ continue
+ else:
+ self.add_shared_nsr_2vld(nsir, nsr_item)
+
+ try:
+ service = self.db.get_one("nsrs", {"_id": nsr_item["nsrId"]})
+ indata_ns = {}
+ indata_ns = service["instantiate_params"]
+ indata_ns["lcmOperationType"] = operation
+ indata_ns["nsInstanceId"] = service["_id"]
+ # Including netslice_id in the ns instantiate Operation
+ indata_ns["netsliceInstanceId"] = nsiInstanceId
+ del indata_ns["key-pair-ref"]
+ # Creating NS_LCM_OP with the flag slice_object=True to not trigger the service instantiation
+ # message via kafka bus
+ nslcmop = self.nsi_NsLcmOpTopic.new(rollback, session, indata_ns, kwargs, headers, force,
+ slice_object=True)
+ nslcmops.append(nslcmop)
+ if operation == "terminate":
+ nslcmop = None
+ _update = {"_admin.nsrs-detailed-list.{}.nslcmop_instantiate".format(index): nslcmop}
+ self.db.set_one("nsis", {"_id": nsir["_id"]}, _update)
+ except (DbException, EngineException) as e:
+ if e.http_code == HTTPStatus.NOT_FOUND:
+ self.logger.info("HTTPStatus.NOT_FOUND")
+ pass
+ else:
+ raise
# Creates nsilcmop
indata["nslcmops_ids"] = nslcmops
self._check_nsi_operation(session, nsir, operation, indata)
+
nsilcmop_desc = self._create_nsilcmop(session, nsiInstanceId, operation, indata)
self.format_on_new(nsilcmop_desc, session["project_id"], make_public=make_public)
_id = self.db.create("nsilcmops", nsilcmop_desc)
return _id
except ValidationError as e:
raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
- # except DbException as e:
- # raise EngineException("Cannot get nsi_instance '{}': {}".format(e), HTTPStatus.NOT_FOUND)
def delete(self, session, _id, force=False, dry_run=False):
raise EngineException("Method delete called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
self.logger.debug("Starting")
while True:
try:
- self.aiomain_task = asyncio.ensure_future(self.msg.aioread("ns", loop=self.loop,
+ self.aiomain_task = asyncio.ensure_future(self.msg.aioread(("ns", "nsi"), loop=self.loop,
callback=self._msg_callback),
loop=self.loop)
self.loop.run_until_complete(self.aiomain_task)
"""
try:
if topic == "ns":
- if command == "terminated":
+ if command == "terminated" and params["operationState"] in ("COMPLETED", "PARTIALLY_COMPLETED"):
self.logger.debug("received ns terminated {}".format(params))
if params.get("autoremove"):
self.engine.del_item(self.internal_session, "nsrs", _id=params["nsr_id"])
self.logger.debug("ns={} deleted from database".format(params["nsr_id"]))
return
+ if topic == "nsi":
+ if command == "terminated" and params["operationState"] in ("COMPLETED", "PARTIALLY_COMPLETED"):
+ self.logger.debug("received nsi terminated {}".format(params))
+ if params.get("autoremove"):
+ self.engine.del_item(self.internal_session, "nsis", _id=params["nsir_id"])
+ self.logger.debug("nsis={} deleted from database".format(params["nsir_id"]))
+ return
except (EngineException, DbException, MsgException) as e:
self.logger.error("Error while processing topic={} command={}: {}".format(topic, command, e))
except Exception as e:
--- /dev/null
+# Copyright [2019] [Pol Alemany, Ricard Vilalta (CTTC), Felipe Vicens (ATOS)]
+#
+# 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.
+
+nsd-catalog:
+ nsd:
+ - id: slice_hackfest_middle_nsd
+ name: slice_hackfest_middle_nsd
+ short-name: slice_hackfest_middle_ns
+ description: NSD to be used on Slice Session of the 5th hackfest
+ vendor: OSM
+ version: '1.0'
+ logo: osm_2x.png
+
+ constituent-vnfd:
+ - member-vnf-index: 1
+ vnfd-id-ref: slice_hackfest_middle_vnfd
+
+ connection-point:
+ - name: nsd_cp_mgmt
+ vld-id-ref: nsd_vnfd_vld_mgmt
+ - name: nsd_cp_data_east
+ vld-id-ref: nsd_vnfd_vld_data_east
+ - name: nsd_cp_data_west
+ vld-id-ref: nsd_vnfd_vld_data_west
+
+ vld:
+ - id: nsd_vnfd_vld_mgmt
+ name: nsd_vnfd_vld_mgmt
+ short-name: nsd_vnfd_vld_mgmt
+ type: ELAN
+ mgmt-network: 'true'
+ vnfd-connection-point-ref:
+ - member-vnf-index-ref: 1
+ vnfd-id-ref: slice_hackfest_middle_vnfd
+ vnfd-connection-point-ref: eth0
+ - id: nsd_vnfd_vld_data_east
+ name: nsd_vnfd_vld_data_east
+ short-name: nsd_vnfd_vld_data_east
+ type: ELAN
+ mgmt-network: 'false'
+ vnfd-connection-point-ref:
+ - member-vnf-index-ref: 1
+ vnfd-id-ref: slice_hackfest_middle_vnfd
+ vnfd-connection-point-ref: eth1
+ - id: nsd_vnfd_vld_data_west
+ name: nsd_vnfd_vld_data_west
+ short-name: nsd_vnfd_vld_data_west
+ type: ELAN
+ mgmt-network: 'false'
+ vnfd-connection-point-ref:
+ - member-vnf-index-ref: 1
+ vnfd-id-ref: slice_hackfest_middle_vnfd
+ vnfd-connection-point-ref: eth2
\ No newline at end of file
--- /dev/null
+# Copyright [2019] [Pol Alemany, Ricard Vilalta (CTTC), Felipe Vicens (ATOS)]
+#
+# 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.
+
+nsd-catalog:
+ nsd:
+ - id: slice_hackfest_nsd
+ name: slice_hackfest_nsd
+ short-name: slice_hackfest_ns
+ description: NSD to be used on Slice Session of the 5th hackfest
+ vendor: OSM
+ version: '1.0'
+ logo: osm_2x.png
+
+ constituent-vnfd:
+ - member-vnf-index: 1
+ vnfd-id-ref: slice_hackfest_vnfd
+
+ connection-point:
+ - name: nsd_cp_mgmt
+ vld-id-ref: nsd_vnfd_vld_mgmt
+ - name: nsd_cp_data
+ vld-id-ref: nsd_vnfd_vld_data
+
+ vld:
+ - id: nsd_vnfd_vld_mgmt
+ name: nsd_vnfd_vld_mgmt
+ short-name: nsd_vnfd_vld_mgmt
+ type: ELAN
+ mgmt-network: 'true'
+ vnfd-connection-point-ref:
+ - member-vnf-index-ref: 1
+ vnfd-id-ref: slice_hackfest_vnfd
+ vnfd-connection-point-ref: eth0
+ - id: nsd_vnfd_vld_data
+ name: nsd_vnfd_vld_data
+ short-name: nsd_vnfd_vld_data
+ type: ELAN
+ mgmt-network: 'false'
+ vnfd-connection-point-ref:
+ - member-vnf-index-ref: 1
+ vnfd-id-ref: slice_hackfest_vnfd
+ vnfd-connection-point-ref: eth1
\ No newline at end of file
--- /dev/null
+# Copyright [2019] [Pol Alemany, Ricard Vilalta (CTTC), Felipe Vicens (ATOS)]
+#
+# 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 to test VLD connection between Network Services within the same VIM
+nst:
+- id: slice_hackfest_nstd
+ name: slice_hackfest_nstd
+ SNSSAI-identifier:
+ slice-service-type: eMBB
+ quality-of-service:
+ id: 1
+
+ netslice-subnet:
+ - id: slice_hackfest_nsd_1
+ is-shared-nss: 'false'
+ description: NetSlice Subnet (service) composed by 1 vnf with 2 cp
+ nsd-ref: slice_hackfest_nsd
+ - id: slice_hackfest_nsd_2
+ is-shared-nss: 'true'
+ description: NetSlice Subnet (service) composed by 1 vnf with 3 cp
+ nsd-ref: slice_hackfest_middle_nsd
+ - id: slice_hackfest_nsd_3
+ is-shared-nss: 'false'
+ description: NetSlice Subnet (service) composed by 1 vnf with 2 cp
+ nsd-ref: slice_hackfest_nsd
+
+ netslice-vld:
+ - id: slice_cirros_vld_mgmt
+ name: slice_cirros_vld_mgmt
+ type: ELAN
+ mgmt-network: 'true'
+ nss-connection-point-ref:
+ - nss-ref: slice_hackfest_nsd_1
+ nsd-connection-point-ref: nsd_cp_mgmt
+ - nss-ref: slice_hackfest_nsd_2
+ nsd-connection-point-ref: nsd_cp_mgmt
+ - nss-ref: slice_hackfest_nsd_3
+ nsd-connection-point-ref: nsd_cp_mgmt
+ - id: slice_cirros_vld_data1
+ name: slice_cirros_vld_data1
+ type: ELAN
+ nss-connection-point-ref:
+ - nss-ref: slice_hackfest_nsd_1
+ nsd-connection-point-ref: nsd_cp_data
+ - nss-ref: slice_hackfest_nsd_2
+ nsd-connection-point-ref: nsd_cp_data_east
+ - id: slice_cirros_vld_data2
+ name: slice_cirros_vld_data2
+ type: ELAN
+ nss-connection-point-ref:
+ - nss-ref: slice_hackfest_nsd_2
+ nsd-connection-point-ref: nsd_cp_data_west
+ - nss-ref: slice_hackfest_nsd_3
+ nsd-connection-point-ref: nsd_cp_data
--- /dev/null
+# Copyright [2019] [Pol Alemany, Ricard Vilalta (CTTC), Felipe Vicens (ATOS)]
+#
+# 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.
+
+vnfd-catalog:
+ vnfd:
+ - id: slice_hackfest_middle_vnfd
+ name: slice_hackfest_middle_vnfd
+ short-name: slice_hackfest_middle_vnfd
+ description: VNFD with 3 CPs to be used on Slice Session of the 5th hackfest
+ vendor: OSM
+ version: '1.0'
+
+ # Management interface
+ mgmt-interface:
+ cp: eth0
+
+ # Atleast one VDU need to be specified
+ vdu:
+ - id: ubuntu_slice-VM
+ name: ubuntu_slice-VM
+ description: ubuntu_slice-VM
+ count: 1
+
+ # Flavour of the VM to be instantiated for the VDU
+ # flavor below can fit into m1.micro
+ vm-flavor:
+ vcpu-count: 1
+ memory-mb: 1024
+ storage-gb: 10
+
+ # Image/checksum or image including the full path
+ image: 'cirros034'
+ #checksum:
+
+ interface:
+ # Specify the external interfaces
+ # There can be multiple interfaces defined
+ - name: eth0
+ type: EXTERNAL
+ virtual-interface:
+ type: VIRTIO
+ bandwidth: '0'
+ vpci: 0000:00:0a.0
+ external-connection-point-ref: eth0
+ - name: eth1
+ type: EXTERNAL
+ virtual-interface:
+ type: VIRTIO
+ bandwidth: '0'
+ vpci: 0000:00:0a.0
+ external-connection-point-ref: eth1
+ - name: eth2
+ type: EXTERNAL
+ virtual-interface:
+ type: VIRTIO
+ bandwidth: '0'
+ vpci: 0000:00:0a.0
+ external-connection-point-ref: eth2
+
+ connection-point:
+ - name: eth0
+ type: VPORT
+ - name: eth1
+ type: VPORT
+ - name: eth2
+ type: VPORT
\ No newline at end of file
--- /dev/null
+# Copyright [2019] [Pol Alemany, Ricard Vilalta (CTTC), Felipe Vicens (ATOS)]
+#
+# 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.
+vnfd-catalog:
+ vnfd:
+ - id: slice_hackfest_vnfd
+ name: slice_hackfest_vnfd
+ short-name: slice_hackfest_vnfd
+ description: VNFD with 2 CPs to be used on Slice Session of the 5th hackfest
+ vendor: OSM
+ version: '1.0'
+
+ # Management interface
+ mgmt-interface:
+ cp: eth0
+
+ # Atleast one VDU need to be specified
+ vdu:
+ - id: ubuntu_slice-VM
+ name: ubuntu_slice-VM
+ description: ubuntu_slice-VM
+ count: 1
+
+ # Flavour of the VM to be instantiated for the VDU
+ # flavor below can fit into m1.micro
+ vm-flavor:
+ vcpu-count: 1
+ memory-mb: 1024
+ storage-gb: 10
+
+ # Image/checksum or image including the full path
+ image: 'cirros034'
+ #checksum:
+
+ interface:
+ # Specify the external interfaces
+ # There can be multiple interfaces defined
+ - name: eth0
+ type: EXTERNAL
+ virtual-interface:
+ type: VIRTIO
+ bandwidth: '0'
+ vpci: 0000:00:0a.0
+ external-connection-point-ref: eth0
+ - name: eth1
+ type: EXTERNAL
+ virtual-interface:
+ type: VIRTIO
+ bandwidth: '0'
+ vpci: 0000:00:0a.0
+ external-connection-point-ref: eth1
+
+ connection-point:
+ - name: eth0
+ type: VPORT
+ - name: eth1
+ type: VPORT
\ No newline at end of file
r_headers_yaml_location_nsd = {"Location": "/nsd/v1/ns_descriptors_content/", "Content-Type": "application/yaml"}
r_headers_yaml_location_nst = {"Location": "/nst/v1/netslice_templates_content", "Content-Type": "application/yaml"}
r_headers_yaml_location_nslcmop = {"Location": "nslcm/v1/ns_lcm_op_occs/", "Content-Type": "application/yaml"}
+r_headers_yaml_location_nsilcmop = {"Location": "/osm/nsilcm/v1/nsi_lcm_op_occs/", "Content-Type": "application/yaml"}
# test ones authorized
test_authorized_list = (
description = "Upload a NST to OSM"
def __init__(self):
- self.nst_filenames = ("@./cirros_slice/cirros_slice_vld.yaml")
+ self.vnfd_filename = ("@./slice_shared/vnfd/slice_shared_vnfd.yaml")
+ self.vnfd_filename_middle = ("@./slice_shared/vnfd/slice_shared_middle_vnfd.yaml")
+ self.nsd_filename = ("@./slice_shared/nsd/slice_shared_nsd.yaml")
+ self.nsd_filename_middle = ("@./slice_shared/nsd/slice_shared_middle_nsd.yaml")
+ self.nst_filenames = ("@./slice_shared/slice_shared_nstd.yaml")
def run(self, engine, test_osm, manual_check, test_params=None):
# nst CREATE
- engine.set_test_name("NST")
+ engine.set_test_name("NST step ")
engine.get_autorization()
+ temp_dir = os.path.dirname(os.path.abspath(__file__)) + "/temp/"
+ if not os.path.exists(temp_dir):
+ os.makedirs(temp_dir)
+
+ # Onboard VNFDs
+ engine.test("Onboard edge VNFD", "POST", "/vnfpkgm/v1/vnf_packages_content", headers_yaml,
+ self.vnfd_filename, 201, r_headers_yaml_location_vnfd, "yaml")
+ self.vnfd_edge_id = engine.last_id
+
+ engine.test("Onboard middle VNFD", "POST", "/vnfpkgm/v1/vnf_packages_content", headers_yaml,
+ self.vnfd_filename_middle, 201, r_headers_yaml_location_vnfd, "yaml")
+ self.vnfd_middle_id = engine.last_id
+
+ # Onboard NSDs
+ engine.test("Onboard NSD edge", "POST", "/nsd/v1/ns_descriptors_content", headers_yaml,
+ self.nsd_filename, 201, r_headers_yaml_location_nsd, "yaml")
+ self.nsd_edge_id = engine.last_id
+
+ engine.test("Onboard NSD middle", "POST", "/nsd/v1/ns_descriptors_content", headers_yaml,
+ self.nsd_filename_middle, 201, r_headers_yaml_location_nsd, "yaml")
+ self.nsd_middle_id = engine.last_id
+
+ # Onboard NST
engine.test("Onboard NST", "POST", "/nst/v1/netslice_templates_content", headers_yaml, self.nst_filenames,
201, r_headers_yaml_location_nst, "yaml")
nst_id = engine.last_id
engine.test("Delete NSTD", "DELETE", "/nst/v1/netslice_templates/{}".format(nst_id), headers_json, None,
204, None, 0)
+ # NSDs DELETE
+ test_rest.test("Delete NSD middle", "DELETE", "/nsd/v1/ns_descriptors/{}".format(self.nsd_middle_id),
+ headers_json, None, 204, None, 0)
+
+ test_rest.test("Delete NSD edge", "DELETE", "/nsd/v1/ns_descriptors/{}".format(self.nsd_edge_id), headers_json,
+ None, 204, None, 0)
+
+ # VNFDs DELETE
+ test_rest.test("Delete VNFD edge", "DELETE", "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_edge_id),
+ headers_yaml, None, 204, None, 0)
+
+ test_rest.test("Delete VNFD middle", "DELETE", "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_middle_id),
+ headers_yaml, None, 204, None, 0)
+
class TestNetSliceInstances:
+ '''
+ Test procedure:
+ 1. Populate databases with VNFD, NSD, NST with the following scenario
+ +-----------------management-----------------+
+ | | |
+ +--+---+ +----+----+ +---+--+
+ | | | | | |
+ | edge +---data1----+ middle +---data2-----+ edge |
+ | | | | | |
+ +------+ +---------+ +------+
+ shared-nss
+ 2. Create NSI-1
+ 3. Instantiate NSI-1
+ 4. Create NSI-2
+ 5. Instantiate NSI-2
+ Manual check - Are 2 slices instantiated correctly?
+ NSI-1 3 nss (2 nss-edges + 1 nss-middle)
+ NSI-2 2 nss (2 nss-edge sharing nss-middle)
+ 6. Terminate NSI-1
+ 7. Delete NSI-1
+ Manual check - Is slice NSI-1 deleted correctly?
+ NSI-2 with 2 nss-edge + 1 nss-middle (The one from NSI-1)
+ 8. Create NSI-3
+ 9. Instantiate NSI-3
+ Manual check - Is slice NSI-3 instantiated correctly?
+ NSI-3 reuse nss-middle. NSI-3 only create 2 nss-edge
+ 10. Delete NSI-2
+ 11. Terminate NSI-2
+ 12. Delete NSI-3
+ 13. Terminate NSI-3
+ Manual check - All cleaned correctly?
+ NSI-2 and NSI-3 were terminated and deleted
+ 14. Cleanup database
+ '''
+
description = "Upload a NST to OSM"
def __init__(self):
self.vim_id = None
- self.nst_filenames = ("@./cirros_slice/cirros_slice.yaml")
+ self.vnfd_filename = ("@./slice_shared/vnfd/slice_shared_vnfd.yaml")
+ self.vnfd_filename_middle = ("@./slice_shared/vnfd/slice_shared_middle_vnfd.yaml")
+ self.nsd_filename = ("@./slice_shared/nsd/slice_shared_nsd.yaml")
+ self.nsd_filename_middle = ("@./slice_shared/nsd/slice_shared_middle_nsd.yaml")
+ self.nst_filenames = ("@./slice_shared/slice_shared_nstd.yaml")
+
+ def create_slice(self, engine, nsi_data, name):
+ ns_data_text = yaml.safe_dump(nsi_data, default_flow_style=True, width=256)
+ r = engine.test(name, "POST", "/nsilcm/v1/netslice_instances",
+ headers_yaml, ns_data_text, 201,
+ {"Location": "nsilcm/v1/netslice_instances/", "Content-Type": "application/yaml"}, "yaml")
+ return r
+
+ def instantiate_slice(self, engine, nsi_data, nsi_id, name):
+ ns_data_text = yaml.safe_dump(nsi_data, default_flow_style=True, width=256)
+ engine.test(name, "POST",
+ "/nsilcm/v1/netslice_instances/{}/instantiate".format(nsi_id), headers_yaml, ns_data_text,
+ 201, r_headers_yaml_location_nsilcmop, "yaml")
+
+ def terminate_slice(self, engine, nsi_id, name):
+ engine.test(name, "POST", "/nsilcm/v1/netslice_instances/{}/terminate".format(nsi_id),
+ headers_yaml, None, 201, r_headers_yaml_location_nsilcmop, "yaml")
+
+ def delete_slice(self, engine, nsi_id, name):
+ engine.test(name, "DELETE", "/nsilcm/v1/netslice_instances/{}".format(nsi_id), headers_yaml, None,
+ 204, None, 0)
def run(self, engine, test_osm, manual_check, test_params=None):
# nst CREATE
engine.set_test_name("NSI")
engine.get_autorization()
- engine.test("Onboard NST", "POST", "/nst/v1/netslice_templates_content", headers_yaml, self.nst_filenames, 201,
- r_headers_yaml_location_nst, "yaml")
+
+ # Onboard VNFDs
+ engine.test("Onboard edge VNFD", "POST", "/vnfpkgm/v1/vnf_packages_content", headers_yaml,
+ self.vnfd_filename, 201, r_headers_yaml_location_vnfd, "yaml")
+ self.vnfd_edge_id = engine.last_id
+
+ engine.test("Onboard middle VNFD", "POST", "/vnfpkgm/v1/vnf_packages_content", headers_yaml,
+ self.vnfd_filename_middle, 201, r_headers_yaml_location_vnfd, "yaml")
+ self.vnfd_middle_id = engine.last_id
+
+ # Onboard NSDs
+ engine.test("Onboard NSD edge", "POST", "/nsd/v1/ns_descriptors_content", headers_yaml,
+ self.nsd_filename, 201, r_headers_yaml_location_nsd, "yaml")
+ self.nsd_edge_id = engine.last_id
+
+ engine.test("Onboard NSD middle", "POST", "/nsd/v1/ns_descriptors_content", headers_yaml,
+ self.nsd_filename_middle, 201, r_headers_yaml_location_nsd, "yaml")
+ self.nsd_middle_id = engine.last_id
+
+ # Onboard NST
+ engine.test("Onboard NST", "POST", "/nst/v1/netslice_templates_content", headers_yaml, self.nst_filenames,
+ 201, r_headers_yaml_location_nst, "yaml")
nst_id = engine.last_id
- # nsi CREATE
self.vim_id = engine.get_create_vim(test_osm)
- ns_data = {"nsiDescription": "default description", "nsiName": "my_slice", "nstId": nst_id,
- "vimAccountId": self.vim_id}
- ns_data_text = yaml.safe_dump(ns_data, default_flow_style=True, width=256)
+ # CREATE NSI-1
+ ns_data = {'nsiName': 'Deploy-NSI-1', 'vimAccountId': self.vim_id, 'nstId': nst_id, 'nsiDescription': 'default'}
+ r = self.create_slice(engine, ns_data, "Create NSI-1 step 1")
+ if not r:
+ return
+ self.nsi_id1 = engine.last_id
+
+ # INSTANTIATE NSI-1
+ self.instantiate_slice(engine, ns_data, self.nsi_id1, "Instantiate NSI-1 step 2")
+ nsilcmop_id1 = engine.last_id
- engine.test("Onboard NSI", "POST", "/nsilcm/v1/netslice_instances_content", headers_yaml, ns_data_text, 201,
- r_headers_yaml_location_nst, "yaml")
- nsi_id = engine.last_id
+ # Waiting for NSI-1
+ engine.wait_operation_ready("nsi", nsilcmop_id1, timeout_deploy)
+
+ # CREATE NSI-2
+ ns_data = {'nsiName': 'Deploy-NSI-2', 'vimAccountId': self.vim_id, 'nstId': nst_id, 'nsiDescription': 'default'}
+ r = self.create_slice(engine, ns_data, "Create NSI-2 step 1")
+ if not r:
+ return
+ self.nsi_id2 = engine.last_id
+
+ # INSTANTIATE NSI-2
+ self.instantiate_slice(engine, ns_data, self.nsi_id2, "Instantiate NSI-2 step 2")
+ nsilcmop_id2 = engine.last_id
+
+ # Waiting for NSI-2
+ engine.wait_operation_ready("nsi", nsilcmop_id2, timeout_deploy)
+
+ if manual_check:
+ input('NSI-1 AND NSI-2 has been deployed. Perform manual check and press enter to resume')
+
+ # TERMINATE NSI-1
+ self.terminate_slice(engine, self.nsi_id1, "Terminate NSI-1")
+ nsilcmop1_id = engine.last_id
+
+ # Wait terminate NSI-1
+ engine.wait_operation_ready("nsi", nsilcmop1_id, timeout_deploy)
+
+ # DELETE NSI-1
+ self.delete_slice(engine, self.nsi_id1, "Delete NS")
+
+ if manual_check:
+ input('NSI-1 has been deleted. Perform manual check and press enter to resume')
+
+ # CREATE NSI-3
+ ns_data = {'nsiName': 'Deploy-NSI-3', 'vimAccountId': self.vim_id, 'nstId': nst_id, 'nsiDescription': 'default'}
+ r = self.create_slice(engine, ns_data, "Create NSI-3 step 1")
+
+ if not r:
+ return
+ self.nsi_id3 = engine.last_id
+
+ # INSTANTIATE NSI-3
+ self.instantiate_slice(engine, ns_data, self.nsi_id3, "Instantiate NSI-3 step 2")
+ nsilcmop_id3 = engine.last_id
+
+ # Wait Instantiate NSI-3
+ engine.wait_operation_ready("nsi", nsilcmop_id3, timeout_deploy)
+
+ if manual_check:
+ input('NSI-3 has been deployed. Perform manual check and press enter to resume')
+
+ # TERMINATE NSI-2
+ self.terminate_slice(engine, self.nsi_id2, "Terminate NSI-2")
+ nsilcmop2_id = engine.last_id
+
+ # Wait terminate NSI-2
+ engine.wait_operation_ready("nsi", nsilcmop2_id, timeout_deploy)
- # TODO: Improve the wait with a polling if NSI was deployed
- wait = 120
- sleep(wait)
-
- # Check deployment
- engine.test("Wait until NSI is deployed", "GET", "/nsilcm/v1/netslice_instances_content/{}".format(nsi_id),
- headers_json, None, 200, r_header_json, "json")
-
- # nsi DELETE
- engine.test("Delete NSI", "DELETE", "/nsilcm/v1/netslice_instances_content/{}".format(nsi_id), headers_json,
- None, 202, r_header_json, "json")
+ # DELETE NSI-2
+ self.delete_slice(engine, self.nsi_id2, "DELETE NSI-2")
+
+ # TERMINATE NSI-3
+ self. terminate_slice(engine, self.nsi_id3, "Terminate NSI-3")
+ nsilcmop3_id = engine.last_id
- sleep(60)
+ # Wait terminate NSI-3
+ engine.wait_operation_ready("nsi", nsilcmop3_id, timeout_deploy)
+
+ # DELETE NSI-3
+ self.delete_slice(engine, self.nsi_id3, "DELETE NSI-3")
+
+ if manual_check:
+ input('NSI-2 and NSI-3 has been deleted. Perform manual check and press enter to resume')
# nstd DELETE
engine.test("Delete NSTD", "DELETE", "/nst/v1/netslice_templates/{}".format(nst_id), headers_json, None,
204, None, 0)
+ # NSDs DELETE
+ test_rest.test("Delete NSD middle", "DELETE", "/nsd/v1/ns_descriptors/{}".format(self.nsd_middle_id),
+ headers_json, None, 204, None, 0)
+
+ test_rest.test("Delete NSD edge", "DELETE", "/nsd/v1/ns_descriptors/{}".format(self.nsd_edge_id), headers_json,
+ None, 204, None, 0)
+
+ # VNFDs DELETE
+ test_rest.test("Delete VNFD edge", "DELETE", "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_edge_id),
+ headers_yaml, None, 204, None, 0)
+
+ test_rest.test("Delete VNFD middle", "DELETE", "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_middle_id),
+ headers_yaml, None, 204, None, 0)
+
if __name__ == "__main__":
global logger
# "Deploy-MultiVIM": TestDeployMultiVIM,
"DeploySingleVdu": TestDeploySingleVdu,
"DeployHnfd": TestDeployHnfd,
- # "Upload-Slice-Template": TestNetSliceTemplates,
- # "Deploy-Slice-Instance": TestNetSliceInstances,
+ "Upload-Slice-Template": TestNetSliceTemplates,
+ "Deploy-Slice-Instance": TestNetSliceInstances,
"TestDeploySimpleCharm": TestDeploySimpleCharm,
"TestDeploySimpleCharm2": TestDeploySimpleCharm2,
}
"name": string_schema,
"vim-network-name": {"OneOf": [string_schema, object_schema]},
"vim-network-id": {"OneOf": [string_schema, object_schema]},
+ "ns-net": object_schema,
"wimAccountId": {"OneOf": [id_schema, bool_schema, null_schema]},
"ip-profile": object_schema,
"vnfd-connection-point-ref": {