Fix black and cover errors
[osm/POL.git] / osm_policy_module / autoscaling / service.py
index 41731b4..33472fd 100644 (file)
@@ -59,7 +59,7 @@ class AutoscalingService:
         self.mon_client = MonClient(config, loop=self.loop)
         self.lcm_client = LcmClient(config, loop=self.loop)
 
-    async def configure_scaling_groups(self, nsr_id: str):
+    async def configure_scaling_groups(self, nsr_id: str, vnf_member_index=None):
         """
         Configures scaling groups for a network service. Creates records in DB. Creates alarms in MON.
         :param nsr_id: Network service record id
@@ -73,7 +73,13 @@ class AutoscalingService:
         try:
             with database.db.atomic() as tx:
                 try:
-                    vnfrs = self.db_client.get_vnfrs(nsr_id)
+                    if vnf_member_index is None:
+                        vnfrs = self.db_client.get_vnfrs(nsr_id)
+                    else:
+                        vnfrs = []
+                        vnfr = self.db_client.get_vnfr(nsr_id, vnf_member_index)
+                        vnfrs.append(vnfr)
+                    # vnfrs = self.db_client.get_vnfrs(nsr_id)
                     for vnfr in vnfrs:
                         log.debug("Processing vnfr: %s", vnfr)
                         vnfd = self.db_client.get_vnfd(vnfr["vnfd-id"])
@@ -192,7 +198,7 @@ class AutoscalingService:
                                                     operation=scaling_criteria[
                                                         "scale-in-relational-operation"
                                                     ],
-                                                    action="scale_in"
+                                                    action="scale_in",
                                                 )
                                             )
                                             alarm = ScalingAlarmRepository.create(
@@ -256,8 +262,10 @@ class AutoscalingService:
                     if vnf_member_index is None:
                         scale_conditions = ScalingGroup.nsr_id == nsr_id
                     else:
-                        query_list = [ScalingGroup.nsr_id == nsr_id,
-                                      ScalingGroup.vnf_member_index == vnf_member_index]
+                        query_list = [
+                            ScalingGroup.nsr_id == nsr_id,
+                            ScalingGroup.vnf_member_index == vnf_member_index,
+                        ]
                         scale_conditions = functools.reduce(operator.and_, query_list)
                     for scaling_group in ScalingGroupRepository.list(scale_conditions):
                         for scaling_policy in scaling_group.scaling_policies: