From 8262942ce6bc595c61e68f101f04128594a5231a Mon Sep 17 00:00:00 2001 From: Mark Beierl Date: Thu, 29 Jun 2023 20:22:36 +0000 Subject: [PATCH] Post refactor cleanup Activity was on wrong level (__call__) instead of class Change-Id: I1dba820b9764824d742e6531dd3156386b2d054d Signed-off-by: Mark Beierl --- osm_lcm/nglcm.py | 40 ++++++++++++------------ osm_lcm/temporal/juju_paas_activities.py | 8 ++--- osm_lcm/temporal/lcm_activities.py | 4 +-- osm_lcm/temporal/ns_activities.py | 6 ++-- osm_lcm/temporal/ns_workflows.py | 4 ++- osm_lcm/temporal/vim_activities.py | 6 ++-- osm_lcm/temporal/vnf_activities.py | 16 +++++----- osm_lcm/tests/test_vim_workflows.py | 4 +-- 8 files changed, 45 insertions(+), 43 deletions(-) diff --git a/osm_lcm/nglcm.py b/osm_lcm/nglcm.py index 7feb866..38015bf 100644 --- a/osm_lcm/nglcm.py +++ b/osm_lcm/nglcm.py @@ -175,26 +175,26 @@ class NGLcm: VnfPrepareWorkflowImpl, ] activities = [ - UpdateNsStateImpl(self.db).__call__, - GetVnfDetailsImpl(self.db).__call__, - GetNsRecordImpl(self.db).__call__, - UpdateNsLcmOperationStateImpl(self.db).__call__, - NsLcmNoOpImpl().__call__, - CreateModelImpl(self.db, paas_connector_instance).__call__, - DeployCharmImpl(paas_connector_instance).__call__, - CheckCharmStatusImpl(paas_connector_instance).__call__, - TestVimConnectivityImpl(paas_connector_instance).__call__, - UpdateVimOperationStateImpl(self.db).__call__, - UpdateVimStateImpl(self.db).__call__, - DeleteVimRecordImpl(self.db).__call__, - ChangeVnfStateImpl(self.db).__call__, - ChangeVnfInstantiationStateImpl(self.db).__call__, - GetTaskQueueImpl(self.db).__call__, - GetVimCloudImpl(self.db).__call__, - GetVnfDescriptorImpl(self.db).__call__, - GetVnfRecordImpl(self.db).__call__, - SendNotificationForVnfImpl().__call__, - SetVnfModelImpl(self.db).__call__, + UpdateNsStateImpl(self.db), + GetVnfDetailsImpl(self.db), + GetNsRecordImpl(self.db), + UpdateNsLcmOperationStateImpl(self.db), + NsLcmNoOpImpl(), + CreateModelImpl(self.db, paas_connector_instance), + DeployCharmImpl(paas_connector_instance), + CheckCharmStatusImpl(paas_connector_instance), + TestVimConnectivityImpl(paas_connector_instance), + UpdateVimOperationStateImpl(self.db), + UpdateVimStateImpl(self.db), + DeleteVimRecordImpl(self.db), + ChangeVnfStateImpl(self.db), + ChangeVnfInstantiationStateImpl(self.db), + GetTaskQueueImpl(self.db), + GetVimCloudImpl(self.db), + GetVnfDescriptorImpl(self.db), + GetVnfRecordImpl(self.db), + SendNotificationForVnfImpl(), + SetVnfModelImpl(self.db), ] # Check if we are running under a debugger diff --git a/osm_lcm/temporal/juju_paas_activities.py b/osm_lcm/temporal/juju_paas_activities.py index 2915ee9..8b51f24 100644 --- a/osm_lcm/temporal/juju_paas_activities.py +++ b/osm_lcm/temporal/juju_paas_activities.py @@ -134,8 +134,8 @@ class JujuPaasConnector: return True +@activity.defn(name=TestVimConnectivity.__name__) class TestVimConnectivityImpl(TestVimConnectivity): - @activity.defn(name=TestVimConnectivity.__name__) async def __call__(self, activity_input: TestVimConnectivity.Input) -> None: vim_id = activity_input.vim_uuid await self.juju_controller._get_controller(vim_id) @@ -143,8 +143,8 @@ class TestVimConnectivityImpl(TestVimConnectivity): self.logger.info(message) +@activity.defn(name=CreateModel.__name__) class CreateModelImpl(CreateModel): - @activity.defn(name=CreateModel.__name__) async def __call__(self, activity_input: CreateModel.Input) -> None: controller = await self.juju_controller._get_controller(activity_input.vim_uuid) if activity_input.model_name in await controller.list_models(): @@ -174,8 +174,8 @@ class CreateModelImpl(CreateModel): self.logger.debug(f"Model {activity_input.model_name} created") +@activity.defn(name=DeployCharm.__name__) class DeployCharmImpl(DeployCharm): - @activity.defn(name=DeployCharm.__name__) async def __call__(self, activity_input: DeployCharm.Input) -> None: model_name = activity_input.model_name charm_info = activity_input.charm_info @@ -196,8 +196,8 @@ class DeployCharmImpl(DeployCharm): ) +@activity.defn(name=CheckCharmStatus.__name__) class CheckCharmStatusImpl(CheckCharmStatus): - @activity.defn(name=CheckCharmStatus.__name__) async def __call__(self, activity_input: CheckCharmStatus.Input) -> None: controller = await self.juju_controller._get_controller(activity_input.vim_uuid) model = await controller.get_model(activity_input.model_name) diff --git a/osm_lcm/temporal/lcm_activities.py b/osm_lcm/temporal/lcm_activities.py index 3400e94..de42b20 100644 --- a/osm_lcm/temporal/lcm_activities.py +++ b/osm_lcm/temporal/lcm_activities.py @@ -23,14 +23,14 @@ from osm_common.temporal.activities.lcm import ( ) +@activity.defn(name=NsLcmNoOp.__name__) class NsLcmNoOpImpl(NsLcmNoOp): - @activity.defn(name=NsLcmNoOp.__name__) async def __call__(self, activity_input: NsLcmNoOp.Input) -> None: self.logger.debug(f"Called with: {activity_input.nslcmop}") +@activity.defn(name=UpdateNsLcmOperationState.__name__) class UpdateNsLcmOperationStateImpl(UpdateNsLcmOperationState): - @activity.defn(name=UpdateNsLcmOperationState.__name__) async def __call__(self, activity_input: UpdateNsLcmOperationState.Input): now = time.time() diff --git a/osm_lcm/temporal/ns_activities.py b/osm_lcm/temporal/ns_activities.py index f25f78a..69cf7df 100644 --- a/osm_lcm/temporal/ns_activities.py +++ b/osm_lcm/temporal/ns_activities.py @@ -24,8 +24,8 @@ from osm_common.temporal.activities.ns import ( ) +@activity.defn(name=GetVnfDetails.__name__) class GetVnfDetailsImpl(GetVnfDetails): - @activity.defn(name=GetVnfDetails.__name__) async def __call__( self, activity_input: GetVnfDetails.Input ) -> GetVnfDetails.Output: @@ -35,16 +35,16 @@ class GetVnfDetailsImpl(GetVnfDetails): ) +@activity.defn(name=GetNsRecord.__name__) class GetNsRecordImpl(GetNsRecord): - @activity.defn(name=GetNsRecord.__name__) async def __call__(self, activity_input: GetNsRecord.Input) -> GetNsRecord.Output: nsr = self.db.get_one("nsrs", {"_id": activity_input.nsr_uuid}) self.logger.debug("Got the nsr from Database for VNF operations.") return GetNsRecord.Output(nsr=nsr) +@activity.defn(name=UpdateNsState.__name__) class UpdateNsStateImpl(UpdateNsState): - @activity.defn(name=UpdateNsState.__name__) async def __call__(self, activity_input: UpdateNsState.Input) -> None: update_ns_state = { "nsState": activity_input.state.name, diff --git a/osm_lcm/temporal/ns_workflows.py b/osm_lcm/temporal/ns_workflows.py index 58bb40e..ea08f9d 100644 --- a/osm_lcm/temporal/ns_workflows.py +++ b/osm_lcm/temporal/ns_workflows.py @@ -39,7 +39,9 @@ class NsInstantiateWorkflowImpl(LcmOperationWorkflow): await super().wrap_nslcmop(workflow_input=workflow_input) async def run(self, workflow_input: NsInstantiateWorkflow.Input) -> None: - self.logger.info(f"Executing {NsInstantiateWorkflow.__name__} with {input}") + self.logger.info( + f"Executing {NsInstantiateWorkflow.__name__} with {workflow_input}" + ) # TODO: Can we clean up the input? Perhaps this workflow could receive NsInstantiateInput directly. ns_uuid = workflow_input.nslcmop["nsInstanceId"] diff --git a/osm_lcm/temporal/vim_activities.py b/osm_lcm/temporal/vim_activities.py index 708c423..54e002e 100644 --- a/osm_lcm/temporal/vim_activities.py +++ b/osm_lcm/temporal/vim_activities.py @@ -23,8 +23,8 @@ from osm_common.temporal.activities.vim import ( ) +@activity.defn(name=UpdateVimState.__name__) class UpdateVimStateImpl(UpdateVimState): - @activity.defn(name=UpdateVimState.__name__) async def __call__(self, activity_input: UpdateVimState.Input) -> None: update_vim_state = { "_admin.operationalState": activity_input.operational_state.name, @@ -40,8 +40,8 @@ class UpdateVimStateImpl(UpdateVimState): ) +@activity.defn(name=UpdateVimOperationState.__name__) class UpdateVimOperationStateImpl(UpdateVimOperationState): - @activity.defn(name=UpdateVimOperationState.__name__) async def __call__(self, activity_input: UpdateVimOperationState.Input) -> None: update_operation_state = { f"_admin.operations.{format(activity_input.op_id)}.operationState": activity_input.op_state.name, @@ -57,8 +57,8 @@ class UpdateVimOperationStateImpl(UpdateVimOperationState): ) +@activity.defn(name=DeleteVimRecord.__name__) class DeleteVimRecordImpl(DeleteVimRecord): - @activity.defn(name=DeleteVimRecord.__name__) async def __call__(self, activity_input: DeleteVimRecord.Input) -> None: self.db.del_one("vim_accounts", {"_id": activity_input.vim_uuid}) self.logger.debug(f"Removed VIM {activity_input.vim_uuid}") diff --git a/osm_lcm/temporal/vnf_activities.py b/osm_lcm/temporal/vnf_activities.py index 156bc59..d47318f 100644 --- a/osm_lcm/temporal/vnf_activities.py +++ b/osm_lcm/temporal/vnf_activities.py @@ -34,8 +34,8 @@ from osm_common.temporal_task_queues.task_queues_mappings import ( CONFIG_IDENTIFIER = "config::" +@activity.defn(name=GetTaskQueue.__name__) class GetTaskQueueImpl(GetTaskQueue): - @activity.defn(name=GetTaskQueue.__name__) async def __call__(self, activity_input: GetTaskQueue.Input) -> GetTaskQueue.Output: vnfr = self.db.get_one("vnfrs", {"_id": activity_input.vnfr_uuid}) vim_record = self.db.get_one("vim_accounts", {"_id": vnfr["vim-account-id"]}) @@ -44,8 +44,8 @@ class GetTaskQueueImpl(GetTaskQueue): return GetTaskQueue.Output(task_queue) +@activity.defn(name=GetVimCloud.__name__) class GetVimCloudImpl(GetVimCloud): - @activity.defn(name=GetVimCloud.__name__) async def __call__(self, activity_input: GetVimCloud.Input) -> GetVimCloud.Output: vnfr = self.db.get_one("vnfrs", {"_id": activity_input.vnfr_uuid}) vim_record = self.db.get_one("vim_accounts", {"_id": vnfr["vim-account-id"]}) @@ -54,16 +54,16 @@ class GetVimCloudImpl(GetVimCloud): return GetVimCloud.Output(cloud=cloud) +@activity.defn(name=GetVnfRecord.__name__) class GetVnfRecordImpl(GetVnfRecord): - @activity.defn(name=GetVnfRecord.__name__) async def __call__(self, activity_input: GetVnfRecord.Input) -> GetVnfRecord.Output: vnfr = self.db.get_one("vnfrs", {"_id": activity_input.vnfr_uuid}) self.logger.debug("Got the vnfr from Database for VNF operations.") return GetVnfRecord.Output(vnfr=vnfr) +@activity.defn(name=GetVnfDescriptor.__name__) class GetVnfDescriptorImpl(GetVnfDescriptor): - @activity.defn(name=GetVnfDescriptor.__name__) async def __call__( self, activity_input: GetVnfDescriptor.Input ) -> GetVnfDescriptor.Output: @@ -131,8 +131,8 @@ class VnfSpecifications: } +@activity.defn(name=ChangeVnfState.__name__) class ChangeVnfStateImpl(ChangeVnfState): - @activity.defn(name=ChangeVnfState.__name__) async def __call__(self, activity_input: ChangeVnfState.Input) -> None: update_vnf_state = {"vnfState": activity_input.state.name} self.db.set_one("vnfrs", {"_id": activity_input.vnfr_uuid}, update_vnf_state) @@ -141,8 +141,8 @@ class ChangeVnfStateImpl(ChangeVnfState): ) +@activity.defn(name=ChangeVnfInstantiationState.__name__) class ChangeVnfInstantiationStateImpl(ChangeVnfInstantiationState): - @activity.defn(name=ChangeVnfInstantiationState.__name__) async def __call__(self, activity_input: ChangeVnfInstantiationState.Input) -> None: update_vnf_instantiation_state = { "instantiationState": activity_input.state.name @@ -157,8 +157,8 @@ class ChangeVnfInstantiationStateImpl(ChangeVnfInstantiationState): ) +@activity.defn(name=SetVnfModel.__name__) class SetVnfModelImpl(SetVnfModel): - @activity.defn(name=SetVnfModel.__name__) async def __call__(self, activity_input: SetVnfModel.Input) -> None: update_namespace = {"namespace": activity_input.model_name} self.db.set_one("vnfrs", {"_id": activity_input.vnfr_uuid}, update_namespace) @@ -167,7 +167,7 @@ class SetVnfModelImpl(SetVnfModel): ) +@activity.defn(name=SendNotificationForVnf.__name__) class SendNotificationForVnfImpl(SendNotificationForVnf): - @activity.defn(name=SendNotificationForVnf.__name__) async def __call__(self, activity_input: SendNotificationForVnf.Input) -> None: self.logger.debug("Send notification for VNF not implemented.") diff --git a/osm_lcm/tests/test_vim_workflows.py b/osm_lcm/tests/test_vim_workflows.py index 8be573e..7ec5d18 100644 --- a/osm_lcm/tests/test_vim_workflows.py +++ b/osm_lcm/tests/test_vim_workflows.py @@ -178,7 +178,7 @@ class TestVimWorkflow(TestVimWorkflowsBase): self.mock_update_vim_state_raises, self.mock_update_vim_operation_state, ] - retry_policy = 3 + retry_policy = 1 # TODO: Figure out what this should be anchored to expected_vim_state = [VimState.ENABLED] * retry_policy expected_vim_op_state = [VimOperationState.COMPLETED] async with self.env, self.get_worker(activities): @@ -201,7 +201,7 @@ class TestVimWorkflow(TestVimWorkflowsBase): self.mock_update_vim_operation_state_raises, ] expected_vim_state = [VimState.ENABLED] - retry_policy = 3 + retry_policy = 1 # TODO: Figure out what this should be anchored to expected_vim_op_state = [VimOperationState.COMPLETED] * retry_policy async with self.env, self.get_worker(activities): with self.assertRaises(WorkflowFailureError): -- 2.25.1