From: aguilard Date: Tue, 11 Apr 2023 12:36:21 +0000 (+0000) Subject: Fix bug in multivim_vm_status DAG when there are no VMs X-Git-Tag: release-v14.0-start~14 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F84%2F13184%2F4;p=osm%2FNG-SA.git Fix bug in multivim_vm_status DAG when there are no VMs Change-Id: Idd67bb9f59a61edbe15012ca05df8c83d920d04e Signed-off-by: aguilard --- diff --git a/src/osm_ngsa/dags/multivim_vm_status.py b/src/osm_ngsa/dags/multivim_vm_status.py index 454f384..18a02e1 100644 --- a/src/osm_ngsa/dags/multivim_vm_status.py +++ b/src/osm_ngsa/dags/multivim_vm_status.py @@ -104,7 +104,8 @@ def create_dag(dag_id, dag_number, dag_description, vim_id): vm_status_list = collector.collect_servers_status() return vm_status_list else: - return None + logger.error("No collector for VIM") + return [] @task(task_id="get_all_vm_status_and_send_to_prometheus") def get_all_vm_status_and_send_to_prometheus(vim_id: str): @@ -132,19 +133,18 @@ def create_dag(dag_id, dag_number, dag_description, vim_id): # Get status of all VM from VIM all_vm_status = get_all_vm_status(vim_account) logger.info(f"Got {len(all_vm_status)} VMs with their status:") - if all_vm_status: - for vm in all_vm_status: - vm_id = vm["id"] - vm_status = vm["status"] - vm_name = vm.get("name", "") - logger.info(f" {vm_name} ({vm_id}) {vm_status}") - metric.labels(vm_id, vim_id).set(vm_status) - # Push to Prometheus only if there are VM - push_to_gateway( - gateway=PROMETHEUS_PUSHGW, - job=f"{PROMETHEUS_JOB_PREFIX}{vim_id}", - registry=registry, - ) + for vm in all_vm_status: + vm_id = vm["id"] + vm_status = vm["status"] + vm_name = vm.get("name", "") + logger.info(f" {vm_name} ({vm_id}) {vm_status}") + metric.labels(vm_id, vim_id).set(vm_status) + # Push to Prometheus + push_to_gateway( + gateway=PROMETHEUS_PUSHGW, + job=f"{PROMETHEUS_JOB_PREFIX}{vim_id}", + registry=registry, + ) return get_all_vm_status_and_send_to_prometheus(vim_id)