@activity.defn(name=GetVnfDescriptor.__name__)
-async def mock_get_vnf_descriptor(
- get_vnf_descriptor_input: GetVnfDescriptor.Input,
-) -> GetVnfDescriptor.Output:
- return GetVnfDescriptor.Output(vnfd=sample_vnfd)
+class MockGetVnfDescriptor:
+ def __init__(self, vnfd=sample_vnfd) -> None:
+ self.vnfd = vnfd
+
+ async def __call__(
+ self, get_vnf_descriptor_input: GetVnfDescriptor.Input
+ ) -> GetVnfDescriptor.Output:
+ return GetVnfDescriptor.Output(vnfd=self.vnfd)
@activity.defn(name=GetVnfDescriptor.__name__)
pass
+@workflow.defn(name=VduInstantiateWorkflow.__name__, sandboxed=SANDBOXED)
+class MockVduInstantiateWorkflowSlow:
+ @workflow.run
+ async def run(self, workflow_input: VduInstantiateWorkflow.Input) -> None:
+ await asyncio.sleep(0.5)
+
+
@workflow.defn(name=VduInstantiateWorkflow.__name__, sandboxed=SANDBOXED)
class MockVduInstantiateWorkflowFailed:
@workflow.run
self.mock_change_vnf_state,
self.mock_send_notification_for_vnf,
mock_set_vnf_model,
- mock_get_vnf_descriptor,
+ MockGetVnfDescriptor(),
mock_get_vnf_record,
mock_get_vim_cloud,
]
self.mock_change_vnf_state,
self.mock_send_notification_for_vnf,
mock_set_vnf_model,
- mock_get_vnf_descriptor,
+ MockGetVnfDescriptor(),
mock_get_vnf_record,
mock_get_vim_cloud,
]
self.mock_change_vnf_state,
self.mock_send_notification_for_vnf,
mock_set_vnf_model,
- mock_get_vnf_descriptor,
+ MockGetVnfDescriptor(),
mock_get_vnf_record,
mock_get_vim_cloud,
]
call_args = mock_execute_child_workflow.call_args_list[1].kwargs["workflow"]
self.assertEquals(call_args, VduInstantiateWorkflow.__name__)
+ @patch(
+ "osm_lcm.temporal.vnf_workflows.VnfInstantiateWorkflowImpl._get_vdu_instantiate_input"
+ )
+ @patch(
+ "temporalio.workflow.execute_child_workflow",
+ wraps=workflow.execute_child_workflow,
+ )
+ async def test_vnf_instantiate_workflow__successful__executes_child_workflows_concurrently(
+ self,
+ mock_execute_child_workflow: CoroutineMock,
+ mock_get_vdu_instantiate_input,
+ ):
+ # Choose a number of child workflows that would take longer to execute than the execution timeout
+ num_child_workflows = EXECUTION_TIMEOUT.seconds * 2 + 1
+ workflows = [
+ VnfInstantiateWorkflowImpl,
+ MockPrepareVnfWorkflow,
+ MockVduInstantiateWorkflowSlow,
+ ]
+ vnfd = {
+ "vdu": [vdu] * num_child_workflows,
+ }
+ activities = [
+ mock_get_task_queue,
+ self.mock_change_vnf_instantiation_state,
+ self.mock_change_vnf_state,
+ self.mock_send_notification_for_vnf,
+ mock_set_vnf_model,
+ MockGetVnfDescriptor(vnfd),
+ mock_get_vnf_record,
+ mock_get_vim_cloud,
+ ]
+
+ # Set up the return values with a unique workflow ID for each child workflow
+ mock_get_vdu_instantiate_input.side_effect = [
+ (
+ sample_vdu_instantiate_input_with_config,
+ uuid.uuid4().hex,
+ )
+ for _ in range(num_child_workflows)
+ ]
+ async with self.env, self.get_worker(self.task_queue, workflows, activities):
+ await self.execute_workflow()
+
+ self.assertEquals(
+ mock_execute_child_workflow.call_count, num_child_workflows + 1
+ )
+ # Check that PrepareVnfWorkflow is executed
+ call_args = mock_execute_child_workflow.call_args_list[0].kwargs["workflow"]
+ self.assertEquals(call_args, VnfPrepareWorkflow.__name__)
+ # Check that VduInstantiateWorkflow is executed
+ for i in range(1, num_child_workflows + 1):
+ call_args = mock_execute_child_workflow.call_args_list[i].kwargs["workflow"]
+ self.assertEquals(call_args, VduInstantiateWorkflow.__name__)
+
async def test_vnf_instantiate_workflow__activity_change_vnf_instantiation_state_failed__raise_activity_error(
self,
):
self.mock_change_vnf_state,
self.mock_send_notification_for_vnf,
mock_set_vnf_model,
- mock_get_vnf_descriptor,
+ MockGetVnfDescriptor(),
mock_get_vnf_record,
mock_get_vim_cloud,
]
self.mock_change_vnf_state,
self.mock_send_notification_for_vnf,
mock_set_vnf_model,
- mock_get_vnf_descriptor,
+ MockGetVnfDescriptor(),
mock_get_vnf_record,
mock_get_vim_cloud,
]
self.mock_change_vnf_state_exception,
self.mock_send_notification_for_vnf,
mock_set_vnf_model,
- mock_get_vnf_descriptor,
+ MockGetVnfDescriptor(),
mock_get_vnf_record,
mock_get_vim_cloud,
]
self.mock_change_vnf_state,
self.mock_send_notification_for_vnf,
mock_set_vnf_model,
- mock_get_vnf_descriptor,
+ MockGetVnfDescriptor(),
mock_get_vnf_record,
mock_get_vim_cloud,
]
self.mock_change_vnf_state,
self.mock_send_notification_for_vnf,
mock_set_vnf_model,
- mock_get_vnf_descriptor,
+ MockGetVnfDescriptor(),
mock_get_vnf_record,
mock_get_vim_cloud,
]
self.mock_change_vnf_state,
self.mock_send_notification_for_vnf,
mock_set_vnf_model,
- mock_get_vnf_descriptor,
+ MockGetVnfDescriptor(),
mock_get_vnf_record,
mock_get_vim_cloud,
]
self.mock_change_vnf_state,
self.mock_send_notification_for_vnf,
mock_set_vnf_model,
- mock_get_vnf_descriptor,
+ MockGetVnfDescriptor(),
mock_get_vnf_record_raise_exception,
mock_get_vim_cloud,
]
self.mock_change_vnf_state,
self.mock_send_notification_for_vnf,
mock_set_vnf_model,
- mock_get_vnf_descriptor,
+ MockGetVnfDescriptor(),
mock_get_vnf_record,
mock_get_vim_cloud_raise_exception,
]
self.mock_change_vnf_state,
self.mock_send_notification_for_vnf,
mock_set_vnf_model,
- mock_get_vnf_descriptor,
+ MockGetVnfDescriptor(),
mock_get_vnf_record,
mock_get_vim_cloud,
]