config["database"]["driver"]
)
)
- except (DbException) as e:
+ except DbException as e:
self.logger.critical(str(e), exc_info=True)
raise Exception(str(e))
config["storage"]["driver"]
)
)
- except (FsException) as e:
+ except FsException as e:
self.logger.critical(str(e), exc_info=True)
raise Exception(str(e))
class Lcm:
-
ping_interval_pace = (
120 # how many time ping is send once is confirmed all is running
)
self.logger.debug("Task kafka_read exit")
def start(self):
-
# check RO version
self.loop.run_until_complete(self.check_RO_version())
if __name__ == "__main__":
-
try:
# print("SYS.PATH='{}'".format(sys.path))
# load parameters and configuration
)
try:
-
# Obtain cluster_uuid
system_cluster_uuid = await self._get_system_cluster_id()
channel.close()
def _write_op_detailed_status(self, db_dict, status, detailed_message):
-
# write ee_id to database: _admin.deployed.VCA.x
try:
the_table = db_dict["collection"]
target_charm = self.fs.path + target_charm_path
if os.path.exists(current_charm) and os.path.exists(target_charm):
-
# Compare the hash of .charm files
if current_charm.endswith(".charm"):
return LcmBase.compare_charm_hash(current_charm, target_charm)
# Get the NSD package path
if revision:
-
nsd_package_path = db_nsr["nsd-id"] + ":" + str(revision)
db_nsd = self.db.get_one("nsds_revisions", {"_id": nsd_package_path})
)
async def instantiate(self, nsir_id, nsilcmop_id):
-
# Try to lock HA task here
task_is_locked_by_me = self.lcm_tasks.lock_HA("nsi", "nsilcmops", nsilcmop_id)
if not task_is_locked_by_me:
self.lcm_tasks.remove("nsi", nsir_id, nsilcmop_id, "nsi_instantiate")
async def terminate(self, nsir_id, nsilcmop_id):
-
# Try to lock HA task here
task_is_locked_by_me = self.lcm_tasks.lock_HA("nsi", "nsilcmops", nsilcmop_id)
if not task_is_locked_by_me:
return None
def _on_update_ro_db(self, nsrs_id, ro_descriptor):
-
# self.logger.debug('_on_update_ro_db(nsrs_id={}'.format(nsrs_id))
try:
)
async def _on_update_n2vc_db(self, table, filter, path, updated_data, vca_id=None):
-
# remove last dot from path (if exists)
if path.endswith("."):
path = path[:-1]
# self.logger.debug('_on_update_n2vc_db(table={}, filter={}, path={}, updated_data={}'
# .format(table, filter, path, updated_data))
try:
-
nsr_id = filter.get("_id")
# read ns record from database
return wim_account
def scale_vnfr(self, db_vnfr, vdu_create=None, vdu_delete=None, mark_delete=False):
-
db_vdu_push_list = []
template_vdur = []
db_update = {"_admin.modified": time()}
start_deploy,
timeout_ns_deploy,
):
-
db_vims = {}
def get_vim_account(vim_account_id):
lambda v_vld: v_vld["name"] in (a_vld["name"], a_vld["id"]),
)
if target_vld:
-
if vnf_params.get("vimAccountId") not in a_vld.get(
"vim_info", {}
):
ro_retries = 0
while True:
-
ro_retries += 1
if ro_retries >= 360: # 1 hour
raise LcmException(
}
step = ""
try:
-
element_type = "NS"
element_under_configuration = nsr_id
vca_id = self.get_vca_id(db_vnfr, db_nsr)
# create or register execution environment in VCA
if vca_type in ("lxc_proxy_charm", "k8s_proxy_charm", "helm", "helm-v3"):
-
self._write_configuration_status(
nsr_id=nsr_id,
vca_index=vca_index,
element_type: str = None,
other_update: dict = None,
):
-
# self.logger.debug('_write_configuration_status(): vca_index={}, status={}'
# .format(vca_index, status))
vca_index: int,
timeout: int = 3600,
) -> bool:
-
# steps:
# 1. find all relations for this VCA
# 2. wait for other peers related
timeout: int = 600,
vca_id: str = None,
):
-
try:
k8sclustertype = k8s_instance_info["k8scluster-type"]
# Instantiate kdu
raise
except Exception as e:
-
self.logger.debug("Error upgrading charm {}".format(path))
return "FAILED", "Error upgrading charm {}: {}".format(path, e)
nsr_deployed = db_nsr["_admin"].get("deployed")
if update_type == "CHANGE_VNFPKG":
-
# Get the input parameters given through update request
vnf_instance_id = db_nslcmop["operationParams"][
"changeVnfPackageData"
step = "Checking if revision has changed in VNFD"
if current_vnf_revision != latest_vnfd_revision:
-
change_type = "policy_updated"
# There is new revision of VNFD, update operation is required
step = "Getting descriptor config"
if current_vnfd.get("kdu"):
-
search_key = "kdu_name"
else:
search_key = "vnfd_id"
# There could be several charm used in the same VNF
for ee_item in ee_list:
if ee_item.get("juju"):
-
step = "Getting charm name"
charm_name = ee_item["juju"].get("charm")
if find_software_version(current_vnfd) != find_software_version(
latest_vnfd
):
-
step = "Checking if existing VNF has charm"
for current_charm_path, target_charm_path in list(
charm_artifact_paths
current_charm_path, target_charm_path
)
):
-
step = "Checking whether VNF uses juju bundle"
if check_juju_bundle_existence(current_vnfd):
-
raise LcmException(
"Charm upgrade is not supported for the instance which"
" uses juju-bundle: {}".format(
}
step = ""
try:
-
element_type = "NS"
element_under_configuration = nsr_id
class TestLcmBase(TestCase):
-
test_nsr_id = "f48163a6-c807-47bc-9682-f72caef5af85"
test_nsd_id = "8c2f8b95-bb1b-47ee-8001-36dc090678da"
nsd_package_path = "/" + test_nsd_id
with patch("osm_lcm.lcm_utils.LcmBase._get_charm_path", mock_charm_path), patch(
"osm_lcm.lcm_utils.LcmBase._get_charm_metadata_file", mock_metadata_file
), patch("osm_lcm.lcm_utils.LcmBase.get_charm_name", mock_charm_name):
-
result = instance.find_charm_name(db_nsr, "simple")
self.assertEqual(result, expected_result, "Wrong charm name")
mock_charm_path.assert_called_once()
with patch("osm_lcm.lcm_utils.LcmBase._get_charm_path", mock_charm_path), patch(
"osm_lcm.lcm_utils.LcmBase._get_charm_metadata_file", mock_metadata_file
), patch("osm_lcm.lcm_utils.LcmBase.get_charm_name", mock_charm_name):
-
with self.assertRaises(LcmException):
-
instance.find_charm_name(db_nsr, "simple")
self.assertEqual(mock_charm_path.call_count, 1)
self.assertEqual(mock_metadata_file.call_count, 1)
with patch("osm_lcm.lcm_utils.LcmBase._get_charm_path", mock_charm_path), patch(
"osm_lcm.lcm_utils.LcmBase._get_charm_metadata_file", mock_metadata_file
), patch("osm_lcm.lcm_utils.LcmBase.get_charm_name", mock_charm_name):
-
with self.assertRaises(LcmException):
instance.find_charm_name(db_nsr, "")
mock_charm_path.assert_not_called()
with patch("osm_lcm.lcm_utils.LcmBase._get_charm_path", mock_charm_path), patch(
"osm_lcm.lcm_utils.LcmBase._get_charm_metadata_file", mock_metadata_file
), patch("osm_lcm.lcm_utils.LcmBase.get_charm_name", mock_charm_name):
-
with self.assertRaises(LcmException):
instance.find_charm_name(db_nsr, "simple")
self.assertEqual(mock_charm_path.call_count, 1)
super().__init__(msg, self.logger)
async def create(self, vim_content, order_id):
-
# HA tasks and backward compatibility:
# If 'vim_content' does not include 'op_id', we a running a legacy NBI version.
# In such a case, HA is not supported by NBI, 'op_id' is None, and lock_HA() will do nothing.
self.lcm_tasks.remove("vim_account", vim_id, order_id)
async def edit(self, vim_content, order_id):
-
# HA tasks and backward compatibility:
# If 'vim_content' does not include 'op_id', we a running a legacy NBI version.
# In such a case, HA is not supported by NBI, and the HA check always returns True
self.lcm_tasks.remove("vim_account", vim_id, order_id)
async def delete(self, vim_content, order_id):
-
# HA tasks and backward compatibility:
# If 'vim_content' does not include 'op_id', we a running a legacy NBI version.
# In such a case, HA is not supported by NBI, and the HA check always returns True
super().__init__(msg, self.logger)
async def create(self, wim_content, order_id):
-
# HA tasks and backward compatibility:
# If 'wim_content' does not include 'op_id', we a running a legacy NBI version.
# In such a case, HA is not supported by NBI, 'op_id' is None, and lock_HA() will do nothing.
self.lcm_tasks.remove("wim_account", wim_id, order_id)
async def edit(self, wim_content, order_id):
-
# HA tasks and backward compatibility:
# If 'wim_content' does not include 'op_id', we a running a legacy NBI version.
# In such a case, HA is not supported by NBI, and the HA check always returns True
and db_wim["_admin"].get("deployed")
and db_wim["_admin"]["deployed"].get("RO")
):
-
RO_wim_id = db_wim["_admin"]["deployed"]["RO"]
step = "Editing wim at RO"
RO = ROclient.ROClient(self.loop, **self.ro_config)
self.lcm_tasks.remove("wim_account", wim_id, order_id)
async def delete(self, wim_content, order_id):
-
# HA tasks and backward compatibility:
# If 'vim_content' does not include 'op_id', we a running a legacy NBI version.
# In such a case, HA is not supported by NBI, and the HA check always returns True
super().__init__(msg, self.logger)
async def create(self, sdn_content, order_id):
-
# HA tasks and backward compatibility:
# If 'sdn_content' does not include 'op_id', we a running a legacy NBI version.
# In such a case, HA is not supported by NBI, 'op_id' is None, and lock_HA() will do nothing.
self.lcm_tasks.remove("sdn", sdn_id, order_id)
async def edit(self, sdn_content, order_id):
-
# HA tasks and backward compatibility:
# If 'sdn_content' does not include 'op_id', we a running a legacy NBI version.
# In such a case, HA is not supported by NBI, and the HA check always returns True
self.lcm_tasks.remove("sdn", sdn_id, order_id)
async def delete(self, sdn_content, order_id):
-
# HA tasks and backward compatibility:
# If 'vim_content' does not include 'op_id', we a running a legacy NBI version.
# In such a case, HA is not supported by NBI, and the HA check always returns True
}
async def create(self, k8scluster_content, order_id):
-
op_id = k8scluster_content.pop("op_id", None)
if not self.lcm_tasks.lock_HA("k8scluster", "create", op_id):
return
self.lcm_tasks.remove("k8scluster", k8scluster_id, order_id)
async def edit(self, k8scluster_content, order_id):
-
op_id = k8scluster_content.pop("op_id", None)
if not self.lcm_tasks.lock_HA("k8scluster", "edit", op_id):
return
k8scluster_id = k8scluster_content["_id"]
+
logging_text = "Task k8scluster_edit={} ".format(k8scluster_id)
self.logger.debug(logging_text + "Enter")
self.lcm_tasks.remove("k8scluster", k8scluster_id, order_id)
async def delete(self, k8scluster_content, order_id):
-
# HA tasks and backward compatibility:
# If 'vim_content' does not include 'op_id', we a running a legacy NBI version.
# In such a case, HA is not supported by NBI, 'op_id' is None, and lock_HA() will do nothing.
self.lcm_tasks.remove("vca", vca_id, order_id)
async def delete(self, vca_content, order_id):
-
# HA tasks and backward compatibility:
# If "vim_content" does not include "op_id", we a running a legacy NBI version.
# In such a case, HA is not supported by NBI, "op_id" is None, and lock_HA() will do nothing.
)
async def create(self, k8srepo_content, order_id):
-
# HA tasks and backward compatibility:
# If 'vim_content' does not include 'op_id', we a running a legacy NBI version.
# In such a case, HA is not supported by NBI, 'op_id' is None, and lock_HA() will do nothing.
self.lcm_tasks.remove("k8srepo", k8srepo_id, order_id)
async def delete(self, k8srepo_content, order_id):
-
# HA tasks and backward compatibility:
# If 'vim_content' does not include 'op_id', we a running a legacy NBI version.
# In such a case, HA is not supported by NBI, 'op_id' is None, and lock_HA() will do nothing.