From: Atul Agarwal Date: Tue, 9 Jun 2020 14:18:10 +0000 (+0000) Subject: Resolved bug 1087 X-Git-Tag: release-v8.0-start~2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F60%2F9060%2F6;p=osm%2FPOL.git Resolved bug 1087 Change-Id: I2b83e1d731e0459a76f1ecf5ab95357c808999f7 Signed-off-by: Atul Agarwal --- diff --git a/osm_policy_module/autoscaling/service.py b/osm_policy_module/autoscaling/service.py index f6f71c2..b840acb 100644 --- a/osm_policy_module/autoscaling/service.py +++ b/osm_policy_module/autoscaling/service.py @@ -114,23 +114,34 @@ class AutoscalingService: except ScalingAlarm.DoesNotExist: pass metric_name = self._get_metric_name(vnf_monitoring_param, vdur, vnfd) - alarm_uuid = await self.mon_client.create_alarm( - metric_name=metric_name, - ns_id=nsr_id, - vdu_name=vdur['name'], - vnf_member_index=vnfr['member-vnf-index-ref'], - threshold=scaling_criteria['scale-in-threshold'], - operation=scaling_criteria['scale-in-relational-operation'], - statistic=vnf_monitoring_param['aggregation-type'] - ) - alarm = ScalingAlarmRepository.create( - alarm_uuid=alarm_uuid, - action='scale_in', - vnf_member_index=vnfr['member-vnf-index-ref'], - vdu_name=vdur['name'], - scaling_criteria=scaling_criteria_record - ) - alarms_created.append(alarm) + + db_nsr = self.db_client.get_nsr(nsr_id) + nb_scale_op = 0 + if db_nsr["_admin"].get("scaling-group"): + db_nsr_admin = db_nsr["_admin"]["scaling-group"] + for admin_scale_index, admin_scale_info in enumerate(db_nsr_admin): + if admin_scale_info["name"] == scaling_group["name"]: + nb_scale_op = admin_scale_info.get("nb-scale-op", 0) + break + min_instance_count = int(scaling_group["min-instance-count"]) + if nb_scale_op > min_instance_count: + alarm_uuid = await self.mon_client.create_alarm( + metric_name=metric_name, + ns_id=nsr_id, + vdu_name=vdur['name'], + vnf_member_index=vnfr['member-vnf-index-ref'], + threshold=scaling_criteria['scale-in-threshold'], + operation=scaling_criteria['scale-in-relational-operation'], + statistic=vnf_monitoring_param['aggregation-type'] + ) + alarm = ScalingAlarmRepository.create( + alarm_uuid=alarm_uuid, + action='scale_in', + vnf_member_index=vnfr['member-vnf-index-ref'], + vdu_name=vdur['name'], + scaling_criteria=scaling_criteria_record + ) + alarms_created.append(alarm) alarm_uuid = await self.mon_client.create_alarm( metric_name=metric_name, ns_id=nsr_id, diff --git a/osm_policy_module/tests/integration/test_policy_agent.py b/osm_policy_module/tests/integration/test_policy_agent.py index 1470b25..1a9dd68 100644 --- a/osm_policy_module/tests/integration/test_policy_agent.py +++ b/osm_policy_module/tests/integration/test_policy_agent.py @@ -478,6 +478,13 @@ class PolicyModuleAgentTest(unittest.TestCase): if '2' in args[1]: return vnfr_record_mocks[1] + def assert_not_called_with(*args, **kwargs): + try: + create_alarm.assert_called_with(*args, **kwargs) + except AssertionError: + return + raise AssertionError('Expected to not have been called.') + async def _test_configure_scaling_groups_create_alarm(*args, **kwargs): return uuid.uuid4() @@ -486,6 +493,7 @@ class PolicyModuleAgentTest(unittest.TestCase): get_nsr.return_value = nsr_record_mock get_vnfd.return_value = vnfd_record_mock create_alarm.side_effect = _test_configure_scaling_groups_create_alarm + create_alarm.assert_not_called_with = assert_not_called_with config = Config() agent = PolicyModuleAgent(config, self.loop) self.loop.run_until_complete(agent.autoscaling_service.configure_scaling_groups("test_nsr_id")) @@ -496,13 +504,13 @@ class PolicyModuleAgentTest(unittest.TestCase): threshold=80, vdu_name='cirros_ns-1-cirros_vnfd-VM-1', vnf_member_index='1') - create_alarm.assert_any_call(metric_name='average_memory_utilization', - ns_id='test_nsr_id', - operation='LT', - statistic='AVERAGE', - threshold=20, - vdu_name='cirros_ns-1-cirros_vnfd-VM-1', - vnf_member_index='1') + create_alarm.assert_not_called_with(metric_name='average_memory_utilization', + ns_id='test_nsr_id', + operation='LT', + statistic='AVERAGE', + threshold=20, + vdu_name='cirros_ns-1-cirros_vnfd-VM-1', + vnf_member_index='1') create_alarm.assert_any_call(metric_name='average_memory_utilization', ns_id='test_nsr_id', operation='GT', @@ -510,13 +518,13 @@ class PolicyModuleAgentTest(unittest.TestCase): threshold=80, vdu_name='cirros_ns-2-cirros_vnfd-VM-1', vnf_member_index='2') - create_alarm.assert_any_call(metric_name='average_memory_utilization', - ns_id='test_nsr_id', - operation='LT', - statistic='AVERAGE', - threshold=20, - vdu_name='cirros_ns-2-cirros_vnfd-VM-1', - vnf_member_index='2') + create_alarm.assert_not_called_with(metric_name='average_memory_utilization', + ns_id='test_nsr_id', + operation='LT', + statistic='AVERAGE', + threshold=20, + vdu_name='cirros_ns-2-cirros_vnfd-VM-1', + vnf_member_index='2') scaling_record = ScalingGroup.get() self.assertEqual(scaling_record.name, 'scale_cirros_vnfd-VM') self.assertEqual(scaling_record.nsr_id, 'test_nsr_id')