# See the License for the specific language governing permissions and
# limitations under the License.
-import asynctest
-from asynctest.mock import patch
+import uuid
from copy import deepcopy
from datetime import timedelta
-from unittest.mock import Mock
-import uuid
-from osm_common.temporal_task_queues.task_queues_mappings import LCM_TASK_QUEUE
+import asynctest
+from asynctest import CoroutineMock, Mock, patch
from osm_common.temporal.activities.vnf import (
- ChangeVnfState,
ChangeVnfInstantiationState,
+ ChangeVnfState,
GetTaskQueue,
GetVimCloud,
GetVnfDescriptor,
SetVnfModel,
)
from osm_common.temporal.dataclasses_common import CharmInfo, VduComputeConstraints
-from osm_common.temporal.workflows.vnf import VnfPrepareWorkflow
+from osm_common.temporal.states import VnfInstantiationState, VnfState
from osm_common.temporal.workflows.vdu import VduInstantiateWorkflow
-from osm_common.temporal.states import VnfState, VnfInstantiationState
+from osm_common.temporal.workflows.vnf import VnfPrepareWorkflow
+from osm_common.temporal_task_queues.task_queues_mappings import LCM_TASK_QUEUE
+from temporalio import activity, workflow
+from temporalio.client import WorkflowFailureError
+from temporalio.exceptions import ActivityError, ChildWorkflowError, RetryState
+from temporalio.testing import WorkflowEnvironment
+from temporalio.worker import Worker
+
from osm_lcm.temporal.vnf_workflows import (
VnfInstantiateWorkflowImpl,
VnfPrepareWorkflowImpl,
)
-from temporalio import activity
-from temporalio import workflow
-from temporalio.client import WorkflowFailureError
-from temporalio.exceptions import (
- ActivityError,
- ChildWorkflowError,
- RetryState,
-)
-from temporalio.testing import WorkflowEnvironment
-from temporalio.worker import Worker
+SANDBOXED = False
+DEBUG_MODE = True
+TASK_TIMEOUT = timedelta(seconds=5)
+EXECUTION_TIMEOUT = timedelta(seconds=10)
# The variables used in the tests
model_name = "my-model-name"
config=app_config,
)
-SANDBOXED = False
-DEBUG_MODE = True
-TASK_TIMEOUT = timedelta(seconds=0.5)
-EXECUTION_TIMEOUT = timedelta(seconds=1)
-
class TestException(Exception):
pass
execution_timeout=EXECUTION_TIMEOUT,
)
- def vnf_instantiation_state_is_updated(self, state):
+ def validate_vnf_instantiation_state_is_updated(self, state):
call_mock_change_vnf_instantiation_state_tracker = (
self.mock_change_vnf_instantiation_state_tracker.call_args_list
)
self.task_queue, workflows, activities
), self.get_worker(self.task_queue, workflows, activities):
await self.execute_workflow()
- self.vnf_instantiation_state_is_updated(VnfInstantiationState.INSTANTIATED)
+ self.validate_vnf_instantiation_state_is_updated(
+ VnfInstantiationState.INSTANTIATED
+ )
@patch(
"osm_lcm.temporal.vnf_workflows.VnfInstantiateWorkflowImpl._get_vdu_instantiate_input"
self.task_queue, workflows, activities
), self.get_worker(self.task_queue, workflows, activities):
await self.execute_workflow()
- self.vnf_instantiation_state_is_updated(VnfState.STARTED)
+ self.validate_vnf_instantiation_state_is_updated(VnfState.STARTED)
+
+ @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_workflow(
+ self,
+ mock_execute_child_workflow: CoroutineMock,
+ mock_get_vdu_instantiate_input,
+ ):
+ workflows = [
+ VnfInstantiateWorkflowImpl,
+ MockPrepareVnfWorkflow,
+ MockVduInstantiateWorkflow,
+ ]
+ 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,
+ mock_get_vnf_descriptor,
+ mock_get_vnf_record,
+ mock_get_vim_cloud,
+ ]
+ mock_get_vdu_instantiate_input.return_value = (
+ sample_vdu_instantiate_input_with_config,
+ sample_vdu_instantiate_wf_id_1,
+ )
+ async with self.env, self.get_worker(self.task_queue, workflows, activities):
+ await self.execute_workflow()
+ self.assertTrue(mock_execute_child_workflow.called)
+ self.assertEquals(mock_execute_child_workflow.call_count, 2)
+ # 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
+ call_args = mock_execute_child_workflow.call_args_list[1].kwargs["workflow"]
+ self.assertEquals(call_args, VduInstantiateWorkflow.__name__)
async def test_vnf_instantiate_workflow__activity_change_vnf_instantiation_state_failed__raise_activity_error(
self,
@patch(
"osm_lcm.temporal.vnf_workflows.VnfInstantiateWorkflowImpl._get_vdu_instantiate_input"
)
- @patch("temporalio.workflow.execute_child_workflow")
+ @patch(
+ "temporalio.workflow.execute_child_workflow",
+ )
async def test_instantiate_vdus__empty_vnf_instantiation_config__child_wf_executed_with_expected_vdu_instantiate_input(
self,
mock_execute_child_workflow,
class TestGetVduInstantiateInfo(asynctest.TestCase):
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config"
- )
- @asynctest.mock.patch(
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config")
+ @patch(
"osm_lcm.temporal.vnf_activities.VnfSpecifications.get_vdu_instantiation_params"
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info"
- )
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints"
- )
+ @patch("osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info")
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints")
async def test_get_vdu_instantiate_input__empty_vnf_instantiation_config__get_expected_vdu_inst_input_and_wf_id(
self,
mock_get_compute_constraints,
(sample_vdu_instantiate_input, "my-model-name-my-app"),
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config"
- )
- @asynctest.mock.patch(
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config")
+ @patch(
"osm_lcm.temporal.vnf_activities.VnfSpecifications.get_vdu_instantiation_params"
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info"
- )
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints"
- )
+ @patch("osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info")
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints")
async def test_get_vdu_instantiate_input__with_vnf_instantiation_config__get_expected_vdu_inst_input_and_wf_id(
self,
mock_get_compute_constraints,
(sample_vdu_instantiate_input_with_config, "my-model-name-my-app"),
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config"
- )
- @asynctest.mock.patch(
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config")
+ @patch(
"osm_lcm.temporal.vnf_activities.VnfSpecifications.get_vdu_instantiation_params"
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info"
- )
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints"
- )
+ @patch("osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info")
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints")
async def test_get_vdu_instantiate_input__vnfr_without_namespace__raise_type_error(
self,
mock_get_compute_constraints,
vnf_instantiation_config={},
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config"
- )
- @asynctest.mock.patch(
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config")
+ @patch(
"osm_lcm.temporal.vnf_activities.VnfSpecifications.get_vdu_instantiation_params"
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info"
- )
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints"
- )
+ @patch("osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info")
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints")
async def test_get_vdu_instantiate_input__app_name_is_empty__expected_wf_id(
self,
mock_get_compute_constraints,
)
self.assertEqual(vdu_instantiate_workflow_id, "my-model-name-")
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config"
- )
- @asynctest.mock.patch(
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config")
+ @patch(
"osm_lcm.temporal.vnf_activities.VnfSpecifications.get_vdu_instantiation_params"
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info"
- )
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints"
- )
+ @patch("osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info")
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints")
async def test_get_vdu_instantiate_input__get_compute_constraints_failed__no_vdu_inst_wf_input_and_vdu_wf_id(
self,
mock_get_compute_constraints,
(vdu_instantiate_input, vdu_instantiate_workflow_id), (None, None)
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config"
- )
- @asynctest.mock.patch(
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config")
+ @patch(
"osm_lcm.temporal.vnf_activities.VnfSpecifications.get_vdu_instantiation_params"
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info"
- )
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints"
- )
+ @patch("osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info")
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints")
async def test_get_vdu_instantiate_input__get_compute_constraints_failed__raise_compute_constraints_exception(
self,
mock_get_compute_constraints,
vnf_instantiation_config={},
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config"
- )
- @asynctest.mock.patch(
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config")
+ @patch(
"osm_lcm.temporal.vnf_activities.VnfSpecifications.get_vdu_instantiation_params"
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info"
- )
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints"
- )
+ @patch("osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info")
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints")
async def test_get_vdu_instantiate_input__get_charm_info_failed__raise_get_charm_info_exception(
self,
mock_get_compute_constraints,
vnf_instantiation_config={},
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config"
- )
- @asynctest.mock.patch(
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config")
+ @patch(
"osm_lcm.temporal.vnf_activities.VnfSpecifications.get_vdu_instantiation_params"
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info"
- )
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints"
- )
+ @patch("osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info")
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints")
async def test_get_vdu_instantiate_input__get_charm_info_failed__no_vdu_inst_wf_input_and_vdu_wf_id(
self,
mock_get_compute_constraints,
(vdu_instantiate_input, vdu_instantiate_workflow_id), (None, None)
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config"
- )
- @asynctest.mock.patch(
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config")
+ @patch(
"osm_lcm.temporal.vnf_activities.VnfSpecifications.get_vdu_instantiation_params"
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info"
- )
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints"
- )
+ @patch("osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info")
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints")
async def test_get_vdu_instantiate_input__get_vdu_instantiation_params_failed__raise_get_vdu_instantiation_params_exception(
self,
mock_get_compute_constraints,
vnf_instantiation_config={},
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config"
- )
- @asynctest.mock.patch(
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config")
+ @patch(
"osm_lcm.temporal.vnf_activities.VnfSpecifications.get_vdu_instantiation_params"
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info"
- )
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints"
- )
+ @patch("osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info")
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints")
async def test_get_vdu_instantiate_input__get_vdu_instantiation_params_failed__no_vdu_inst_wf_input_and_vdu_wf_id(
self,
mock_get_compute_constraints,
(vdu_instantiate_input, vdu_instantiate_workflow_id), (None, None)
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config"
- )
- @asynctest.mock.patch(
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config")
+ @patch(
"osm_lcm.temporal.vnf_activities.VnfSpecifications.get_vdu_instantiation_params"
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info"
- )
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints"
- )
+ @patch("osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info")
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints")
async def test_get_vdu_instantiate_input__get_application_config_failed__raise_get_application_config_exception(
self,
mock_get_compute_constraints,
vnf_instantiation_config={},
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config"
- )
- @asynctest.mock.patch(
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_application_config")
+ @patch(
"osm_lcm.temporal.vnf_activities.VnfSpecifications.get_vdu_instantiation_params"
)
- @asynctest.mock.patch(
- "osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info"
- )
- @asynctest.mock.patch(
- "osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints"
- )
+ @patch("osm_lcm.temporal.juju_paas_activities.CharmInfoUtils.get_charm_info")
+ @patch("osm_lcm.temporal.vnf_activities.VnfSpecifications.get_compute_constraints")
async def test_get_vdu_instantiate_input__get_application_config_failed__no_vdu_inst_wf_input_and_vdu_wf_id(
self,
mock_get_compute_constraints,