Exemple #1
0
    def test_update_once_on_multiple_records(self, alarm_get_mock,
                                             parent_update_mock, db_api_mock):
        db_api_mock.alarm_track_create = mock.Mock()

        first_record_obj = fake_alarm_object(
            **get_alarm_data(contract_id=22, treshold=33, period=22))
        second_record_obj = fake_alarm_object(
            **get_alarm_data(contract_id=33, treshold=33, period=22))
        unique_db_alarm = get_alarm_data(contract_id=22,
                                         threhold=22,
                                         period=10)

        first_record_obj.type = ceilometer_alarms.HostDownUniqueAlarm.ALARM_TYPE
        second_record_obj.type = ceilometer_alarms.HostDownUniqueAlarm.ALARM_TYPE
        # we should not need to test this here, but instead mock if_something_changed.
        first_alarm = ceilometer_alarms.HostDownUniqueAlarm(
            ctx=None, alarm_object=first_record_obj)

        alarm_get_mock.return_value = fake_alarm_object(**unique_db_alarm)
        first_alarm.update()
        self.assertTrue(parent_update_mock.called)
        self.assertTrue(first_record_obj.save.called)

        # now, the unique_db_alarm should be equal to first_record_obj in db
        parent_update_mock.reset_mock()
        alarm_get_mock.return_value = first_record_obj
        second_alarm = ceilometer_alarms.HostDownUniqueAlarm(
            ctx=None, alarm_object=second_record_obj)
        second_alarm.update()
        self.assertFalse(parent_update_mock.called)
        self.assertTrue(second_record_obj.save.called)
Exemple #2
0
 def test_first_alarm_create_external(self, parent_create_mock,
                                      db_api_mock):
     db_api_mock.alarm_track_create = mock.Mock()
     data = get_alarm_data()
     am = ceilometer_alarms.HostDownUniqueAlarm(**data)
     with mock.patch.object(am, 'get_unique_alarm') as mk:
         mk.return_value = None
         am.alarm_track = fake_alarm_object(**data)
         am.create()
     self.assertTrue(parent_create_mock.called)
Exemple #3
0
 def test_delete_alarm_if_last_record(self, alarm_get_mock,
                                      parent_delete_mock, db_api_mock):
     db_api_mock.alarm_track_create = mock.Mock()
     data = get_alarm_data()
     # in real code we use alarm utils get by type() from alarm object
     # for testing purposes is the same.
     am = ceilometer_alarms.HostDownUniqueAlarm(**data)
     alarm_get_mock.return_value = None
     new_alarm_data = dict(data)
     new_alarm_data['id'] = 0
     new_alarm_data['alarm_id'] = None
     am.alarm_track = fake_alarm_object(**data)
     am.delete()
     self.assertTrue(parent_delete_mock.called)
     self.assertTrue(am.alarm_track.delete.called)
Exemple #4
0
 def test_second_alarm_dont_create_external(self, alarm_get_mock,
                                            parent_create_mock,
                                            db_api_mock):
     db_api_mock.alarm_track_create = mock.Mock()
     data = get_alarm_data()
     am = ceilometer_alarms.HostDownUniqueAlarm(**data)
     alarm_get_mock.return_value = fake_alarm_object(**data)
     new_alarm_data = dict(data)
     new_alarm_data['id'] = 0
     new_alarm_data['alarm_id'] = None
     am.alarm_track = fake_alarm_object(**data)
     am.create()
     self.assertFalse(parent_create_mock.called)
     self.assertTrue(am.alarm_track.create.called)
     self.assertEqual(am.alarm_id, alarm_get_mock.return_value.alarm_id)