OSMENG-1006 Implement Instantiate VNF Workflow
Change-Id: I12ce8268b949e4f5e901001059a088edb230258b
Signed-off-by: Gulsum Atici <gulsum.atici@canonical.com>
Signed-off-by: Mark Beierl <mark.beierl@canonical.com>
diff --git a/osm_lcm/temporal/ns_activities.py b/osm_lcm/temporal/ns_activities.py
index 3ea7dcf..2e08f91 100644
--- a/osm_lcm/temporal/ns_activities.py
+++ b/osm_lcm/temporal/ns_activities.py
@@ -38,8 +38,8 @@
async def get_vnf_records(
self, get_vnf_records_input: GetVnfRecordIdsInput
) -> GetVnfRecordIdsOutput:
- # TODO: [OSMENG-1043] Implement Get VNF Records
- return GetVnfRecordIdsOutput(vnfr_ids=[""])
+ vnfrs = self.db.get_list("vnfrs", {"nsr-id-ref": get_vnf_records_input.ns_uuid})
+ return GetVnfRecordIdsOutput(vnfr_ids=[vnfr["id"] for vnfr in vnfrs])
class NsDbActivity:
diff --git a/osm_lcm/temporal/ns_workflows.py b/osm_lcm/temporal/ns_workflows.py
index e78392e..7f13810 100644
--- a/osm_lcm/temporal/ns_workflows.py
+++ b/osm_lcm/temporal/ns_workflows.py
@@ -14,8 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import asyncio
-
from osm_common.dataclasses.temporal_dataclasses import (
GetVnfRecordIdsInput,
GetVnfRecordIdsOutput,
@@ -75,14 +73,13 @@
retry_policy=LcmOperationWorkflow.no_retry_policy,
),
)
- asyncio.gather(
- workflow.execute_child_workflow(
+
+ for vnfr_uuid in vnf_record_ids_output.vnfr_ids:
+ await workflow.execute_child_workflow(
workflow=WORKFLOW_VNF_INSTANTIATE,
arg=VnfInstantiateInput(vnfr_uuid=vnfr_uuid, model_name=model_name),
id=f"{WORKFLOW_VNF_INSTANTIATE}-{vnfr_uuid}",
)
- for vnfr_uuid in vnf_record_ids_output.vnfr_ids
- )
except ActivityError as e:
await self.update_ns_state(ns_uuid, NsState.INSTANTIATED, e.cause.message)
diff --git a/osm_lcm/temporal/vnf_activities.py b/osm_lcm/temporal/vnf_activities.py
index 16cc93c..95b4232 100644
--- a/osm_lcm/temporal/vnf_activities.py
+++ b/osm_lcm/temporal/vnf_activities.py
@@ -67,7 +67,7 @@
"""
vnfr = self.db.get_one("vnfrs", {"_id": get_task_queue_input.vnfr_uuid})
vim_record = self.db.get_one("vim_accounts", {"_id": vnfr["vim-account-id"]})
- task_queue = VIM_TYPE_TASK_QUEUE_MAPPINGS[vim_record["vim-type"]]
+ task_queue = VIM_TYPE_TASK_QUEUE_MAPPINGS[vim_record["vim_type"]]
self.logger.debug(f"Got the task queue {task_queue} for VNF operations.")
return GetTaskQueueOutput(task_queue)
@@ -213,7 +213,9 @@
self.logger = logging.getLogger(f"lcm.act.{self.__class__.__name__}")
@activity.defn(name=ACTIVITY_SEND_NOTIFICATION_FOR_VNF)
- async def send_notification_for_vnf(self) -> None:
+ async def send_notification_for_vnf(
+ self, input: ChangeVnfInstantiationStateInput
+ ) -> None:
"""If VNF LCM operation state changes, send notification updates.
This activity does nothing.
diff --git a/osm_lcm/temporal/vnf_workflows.py b/osm_lcm/temporal/vnf_workflows.py
index 4469c46..ed81a8e 100644
--- a/osm_lcm/temporal/vnf_workflows.py
+++ b/osm_lcm/temporal/vnf_workflows.py
@@ -73,11 +73,11 @@
vnf_state = ChangeVnfStateInput(
vnfr_uuid=input.vnfr_uuid, state=VnfState.STOPPED
)
- await self.update_states(
- vnf_instantiation_state=vnf_instantiation_state,
- vnf_state=vnf_state,
- )
try:
+ await self.update_states(
+ vnf_instantiation_state=vnf_instantiation_state,
+ vnf_state=vnf_state,
+ )
vnf_task_queue = value_to_type(
GetTaskQueueOutput,
await workflow.execute_activity(
@@ -154,11 +154,13 @@
)
@staticmethod
- async def send_notification_for_vnf():
+ async def send_notification_for_vnf(
+ vnf_instantiation_state: ChangeVnfInstantiationStateInput,
+ ):
await workflow.execute_activity(
activity=ACTIVITY_SEND_NOTIFICATION_FOR_VNF,
- arg=None,
- activity_id=f"{ACTIVITY_SEND_NOTIFICATION_FOR_VNF}",
+ arg=vnf_instantiation_state,
+ activity_id=f"{ACTIVITY_SEND_NOTIFICATION_FOR_VNF}-{vnf_instantiation_state.vnfr_uuid}",
task_queue=LCM_TASK_QUEUE,
schedule_to_close_timeout=default_schedule_to_close_timeout,
retry_policy=retry_policy,
@@ -187,7 +189,7 @@
vdu_instantiate_input = VduInstantiateInput(vim_id, model_name, vdu_info)
vdu_instantiate_workflow_id = (
vdu_instantiate_input.model_name
- + "_"
+ + "-"
+ vdu_instantiate_input.charm_info.app_name
)
return vdu_instantiate_input, vdu_instantiate_workflow_id
@@ -199,7 +201,7 @@
):
await self.update_vnf_instantiation_state(vnf_instantiation_state)
await self.update_vnf_state(vnf_state)
- await self.send_notification_for_vnf()
+ await self.send_notification_for_vnf(vnf_instantiation_state)
@workflow.defn(name=WORKFLOW_VNF_PREPARE, sandboxed=_SANDBOXED)