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,
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()
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"))
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',
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')