class NsLcm(LcmBase):
+ timeout_vca_on_error = 5 * 60 # Time for charm from first time at blocked,error status to mark as failed
+ total_deploy_timeout = 2 * 3600 # global timeout for deployment
def __init__(self, db, msg, fs, lcm_tasks, ro_config, vca_config, loop):
"""
vnfd_RO.pop("_admin", None)
if new_id:
vnfd_RO["id"] = new_id
- for vdu in vnfd_RO["vdu"]:
+ for vdu in vnfd_RO.get("vdu", ()):
if "cloud-init-file" in vdu:
base_folder = vnfd["_admin"]["storage"]
clout_init_file = "{}/{}/cloud_init/{}".format(
elif vnfd["mgmt-interface"].get("cp"):
mgmt_cp = vnfd["mgmt-interface"]["cp"]
- for vdu in vnfd.get("vdu"):
+ for vdu in vnfd.get("vdu", ()):
if vdu.get("vdu-configuration"):
vdu_needed_access.append(vdu["id"])
elif mgmt_cp:
if ns_params.get("vduImage"):
RO_ns_params["vduImage"] = ns_params["vduImage"]
- if ns_params.get("ssh-authorized-key"):
- RO_ns_params["cloud-config"] = {"key-pairs": ns_params["ssh-authorized-key"]}
+ if ns_params.get("ssh_keys"):
+ RO_ns_params["cloud-config"] = {"key-pairs": ns_params["ssh_keys"]}
for vnf_params in get_iterable(ns_params, "vnf"):
for constituent_vnfd in nsd["constituent-vnfd"]:
if constituent_vnfd["member-vnf-index"] == vnf_params["member-vnf-index"]:
logging_text = "Task ns={} instantiate={} ".format(nsr_id, nslcmop_id)
self.logger.debug(logging_text + "Enter")
# get all needed from database
+ start_deploy = time()
db_nsr = None
db_nslcmop = None
db_nsr_update = {"_admin.nslcmop": nslcmop_id}
nsd_RO["id"] = RO_osm_nsd_id
nsd_RO.pop("_id", None)
nsd_RO.pop("_admin", None)
- for c_vnf in nsd_RO["constituent-vnfd"]:
+ for c_vnf in nsd_RO.get("constituent-vnfd", ()):
vnfd_id = c_vnf["vnfd-id-ref"]
c_vnf["vnfd-id-ref"] = descriptor_id_2_RO[vnfd_id]
desc = await RO.create("nsd", descriptor=nsd_RO)
detailed_status_old = None
self.logger.debug(logging_text + step)
- deployment_timeout = 2 * 3600 # Two hours
- while deployment_timeout > 0:
+ while time() <= start_deploy + self.total_deploy_timeout:
desc = await RO.show("ns", RO_nsr_id)
ns_status, ns_status_info = RO.check_ns_status(desc)
db_nsr_update["admin.deployed.RO.nsr_status"] = ns_status
detailed_status_old = db_nsr_update["detailed-status"] = detailed_status
self.update_db_2("nsrs", nsr_id, db_nsr_update)
await asyncio.sleep(5, loop=self.loop)
- deployment_timeout -= 5
- if deployment_timeout <= 0:
+ else: # total_deploy_timeout
raise ROclient.ROClientException("Timeout waiting ns to be ready")
step = "Updating VNFRs"
step = "Looking for needed vnfd to configure"
self.logger.debug(logging_text + step)
- for c_vnf in nsd["constituent-vnfd"]:
+ for c_vnf in nsd.get("constituent-vnfd", ()):
vnfd_id = c_vnf["vnfd-id-ref"]
vnf_index = str(c_vnf["member-vnf-index"])
vnfd = db_vnfds_ref[vnfd_id]
# Deploy charms for each VDU that supports one.
vdu_index = 0
- for vdu in vnfd['vdu']:
+ for vdu in vnfd.get('vdu', ()):
vdu_config = vdu.get('vdu-configuration')
proxy_charm = None
config_primitive = None
db_nslcmop_update["detailed-status"] = old_status
# wait until all are configured.
- while True:
+ while time() <= start_deploy + self.total_deploy_timeout:
if db_nsr_update:
self.update_db_2("nsrs", nsr_id, db_nsr_update)
if db_nslcmop_update:
self.update_db_2("nslcmops", nslcmop_id, db_nslcmop_update)
+ # TODO add a fake tast that set n2vc_event after some time
await n2vc_info["n2vc_event"].wait()
n2vc_info["n2vc_event"].clear()
all_active = True
status_map = {}
n2vc_error_text = [] # contain text error list. If empty no one is in error status
+ now = time()
for _, vca_info in nsr_lcm["VCA"].items():
vca_status = vca_info["operational-status"]
if vca_status not in status_map:
status_map[vca_status] = 0
status_map[vca_status] += 1
- if vca_status != "active":
- all_active = False
+ if vca_status == "active":
+ vca_info.pop("time_first_error", None)
+ vca_info.pop("status_first_error", None)
+ continue
+
+ all_active = False
if vca_status in ("error", "blocked"):
- n2vc_error_text.append(
- "member_vnf_index={} vdu_id={} {}: {}".format(vca_info["member-vnf-index"],
- vca_info["vdu_id"], vca_status,
- vca_info["detailed-status"]))
+ vca_info["detailed-status-error"] = vca_info["detailed-status"]
+ # if not first time in this status error
+ if not vca_info.get("time_first_error"):
+ vca_info["time_first_error"] = now
+ continue
+ if vca_info.get("time_first_error") and \
+ now <= vca_info["time_first_error"] + self.timeout_vca_on_error:
+ n2vc_error_text.append("member_vnf_index={} vdu_id={} {}: {}"
+ .format(vca_info["member-vnf-index"],
+ vca_info["vdu_id"], vca_status,
+ vca_info["detailed-status-error"]))
if all_active:
break
db_nsr_update["detailed-status"] = cs
db_nslcmop_update["detailed-status"] = cs
old_status = cs
+ else: # total_deploy_timeout
+ raise LcmException("Timeout waiting ns to be configured")
if not configuration_failed:
# all is done