def test_delete_alarm(self): # Test setup alarm_data1 = self._extract_alarm_data(value='1') alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2') alarm_data3 = self._extract_alarm_data(z_resource_name='compute-2', triggerid='2') # Step 1 - delete inactive alarm # Step setup zabbix_driver = MockZabbixDriver(self.conf) zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2]) # Step action alarms = zabbix_driver._get_all_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) # Step 2 - delete active alarm # Step setup zabbix_driver.set_alarm_datas([alarm_data2]) # Step action alarms = zabbix_driver._get_all_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) self.assertEqual(GraphAction.DELETE_ENTITY, alarms[0][DSProps.EVENT_TYPE]) # Step 3 - get changes after get all should not return deleted alarm # Step action alarms = zabbix_driver._get_changed_alarms() # Step assertions self.assertIsNotNone(alarms, 'alarms is None') self.assertThat(alarms, IsEmpty()) # Step 4 - # Step setup zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2]) zabbix_driver._get_all_alarms() zabbix_driver.set_alarm_datas([alarm_data2]) # Step action alarms = zabbix_driver._get_changed_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) self.assertEqual(GraphAction.DELETE_ENTITY, alarms[0][DSProps.EVENT_TYPE])
def test_delete_alarm(self): # Test setup alarm_data1 = self._extract_alarm_data(value='1') alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2') alarm_data3 = self._extract_alarm_data(z_resource_name='compute-2', triggerid='2') # Step 1 - delete inactive alarm # Step setup zabbix_driver = MockZabbixDriver(self.conf) zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2]) # Step action alarms = zabbix_driver._get_all_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertEqual(1, len(alarms)) self._assert_contains(alarm_data1, alarms) # Step 2 - delete active alarm # Step setup zabbix_driver.set_alarm_datas([alarm_data2]) # Step action alarms = zabbix_driver._get_all_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertEqual(1, len(alarms)) self._assert_contains(alarm_data1, alarms) self.assertEqual(GraphAction.DELETE_ENTITY, alarms[0][DSProps.EVENT_TYPE]) # Step 3 - get changes after get all should not return deleted alarm # Step action alarms = zabbix_driver._get_changed_alarms() # Step assertions self.assertIsNotNone(alarms, 'alarms is None') self.assertEqual(0, len(alarms)) # Step 4 - # Step setup zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2]) zabbix_driver._get_all_alarms() zabbix_driver.set_alarm_datas([alarm_data2]) # Step action alarms = zabbix_driver._get_changed_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertEqual(1, len(alarms)) self._assert_contains(alarm_data1, alarms) self.assertEqual(GraphAction.DELETE_ENTITY, alarms[0][DSProps.EVENT_TYPE])
def test_get_all(self): # Test Setup zabbix_driver = MockZabbixDriver(self.conf) alarm_data1 = self._extract_alarm_data(triggerid='1', status='1') alarm_data2 = self._extract_alarm_data(triggerid='2', status='1', value='1') alarm_data3 = self._extract_alarm_data(triggerid='3', value='1') alarm_data4 = self._extract_alarm_data(triggerid='4') zabbix_driver.set_alarm_datas( [alarm_data1, alarm_data2, alarm_data3, alarm_data4]) # Test Action alarms = zabbix_driver._get_all_alarms() # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data3, alarms)
def test_get_all(self): # Test Setup zabbix_driver = MockZabbixDriver(self.conf) alarm_data1 = self._extract_alarm_data(triggerid='1', status='1') alarm_data2 = self._extract_alarm_data(triggerid='2', status='1', value='1') alarm_data3 = self._extract_alarm_data(triggerid='3', value='1') alarm_data4 = self._extract_alarm_data(triggerid='4') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3, alarm_data4]) # Test Action alarms = zabbix_driver._get_all_alarms() # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertEqual(1, len(alarms)) self._assert_contains(alarm_data3, alarms)
def test_get_all_functionality(self): # Step 1 - Services with status OK should not be returned # Test setup scenario zabbix_driver = MockZabbixDriver(self.conf) alarm_data1 = self._extract_alarm_data() alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2') alarm_data3 = self._extract_alarm_data(z_resource_name='compute-2', triggerid='2') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) # Test action alarms = zabbix_driver._get_all_alarms() # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertThat(alarms, IsEmpty()) # Step 2 - one raised alarm # Test setup alarm_data1 = self._extract_alarm_data(value='1') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) # Test action alarms = zabbix_driver._get_all_alarms() # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) # Step 3 - two raised alarms # Test setup alarm_data1 = self._extract_alarm_data(value='1', priority='4') alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2', value='1') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) expected_alarm1 = alarm_data1 expected_alarm2 = copy.copy(alarm_data2) expected_alarm2[ZProps.RESOURCE_NAME] = 'host2' # Test action alarms = zabbix_driver._get_all_alarms() # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertThat(alarms, matchers.HasLength(2)) self._assert_contains(expected_alarm1, alarms) self._assert_contains(expected_alarm2, alarms) # Step 4 - Check inactive alarms. Get all function should return # inactive alarm (alarm that its status has changed to OK) # Test setup alarm_data1 = self._extract_alarm_data() alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) expected_alarm1 = alarm_data1 expected_alarm2 = copy.copy(alarm_data2) expected_alarm2[ZProps.RESOURCE_NAME] = 'host2' # Test action alarms = zabbix_driver._get_all_alarms() # Test assertions # The alarms of alarm_data1/2 should be returned although their # status is OK, because they were not OK earlier self.assertIsNotNone(alarms, 'No alarms returned') self.assertThat(alarms, matchers.HasLength(2)) self._assert_contains(expected_alarm1, alarms) self._assert_contains(expected_alarm2, alarms) # Step 4 - get all when all alarms are inactivated and their status # was not changed # Test action alarms = zabbix_driver._get_all_alarms() # Test assertions self.assertIsNotNone(alarms, 'alarms is None') self.assertThat(alarms, IsEmpty())
def test_get_changes_and_get_all(self): # Step 1 - get changes # Step setup zabbix_driver = MockZabbixDriver(self.conf) alarm_data1 = self._extract_alarm_data(priority='2', value='1') alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2', priority='2') alarm_data3 = self._extract_alarm_data(z_resource_name='compute-2', triggerid='2') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) # Step action alarms = zabbix_driver._get_changed_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) # Step 2 - get changes when no change occurred (returns nothing) # Step action alarms = zabbix_driver._get_changed_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertThat(alarms, IsEmpty()) # Step 3 - get all # Step action alarms = zabbix_driver._get_all_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) # Step 4 - get all for second time # (when no change has occurred it returns the same) # Step action alarms = zabbix_driver._get_all_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) # Step 5 - calling get changes right after get all (returns nothing) # Step setup alarm_data1 = self._extract_alarm_data(priority='4', value='1') alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2', priority='1', value='1') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) expected_alarm1 = alarm_data1 expected_alarm2 = copy.copy(alarm_data2) expected_alarm2[ZProps.RESOURCE_NAME] = 'host2' # Step action get_all_alarms = zabbix_driver._get_all_alarms() changed_alarms = zabbix_driver._get_changed_alarms() # Step assertions self.assertIsNotNone(get_all_alarms, 'No alarms returned') self.assertThat(get_all_alarms, matchers.HasLength(2)) self._assert_contains(expected_alarm1, get_all_alarms) self._assert_contains(expected_alarm2, get_all_alarms) self.assertIsNotNone(changed_alarms, 'No alarms returned') self.assertThat(changed_alarms, IsEmpty()) # Step 6 - get changes # Step setup alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2', priority='4', value='1') alarm_data3 = self._extract_alarm_data(z_resource_name='compute-2', triggerid='2', priority='4', value='1') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) expected_alarm1 = copy.copy(alarm_data2) expected_alarm1[ZProps.RESOURCE_NAME] = 'host2' expected_alarm2 = copy.copy(expected_alarm1) expected_alarm2[ZProps.TRIGGER_ID] = '2' # Step action alarms = zabbix_driver._get_changed_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertThat(alarms, matchers.HasLength(2)) self._assert_contains(expected_alarm1, alarms) self._assert_contains(expected_alarm2, alarms)
def test_get_all_functionality(self): # Step 1 - Services with status OK should not be returned # Test setup scenario zabbix_driver = MockZabbixDriver(self.conf) alarm_data1 = self._extract_alarm_data() alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2') alarm_data3 = self._extract_alarm_data(z_resource_name='compute-2', triggerid='2') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) # Test action alarms = zabbix_driver._get_all_alarms() # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertEqual(0, len(alarms)) # Step 2 - one raised alarm # Test setup alarm_data1 = self._extract_alarm_data(value='1') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) # Test action alarms = zabbix_driver._get_all_alarms() # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertEqual(1, len(alarms)) self._assert_contains(alarm_data1, alarms) # Step 3 - two raised alarms # Test setup alarm_data1 = self._extract_alarm_data(value='1', priority='4') alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2', value='1') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) expected_alarm1 = alarm_data1 expected_alarm2 = copy.copy(alarm_data2) expected_alarm2[ZProps.RESOURCE_NAME] = 'host2' # Test action alarms = zabbix_driver._get_all_alarms() # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertEqual(2, len(alarms)) self._assert_contains(expected_alarm1, alarms) self._assert_contains(expected_alarm2, alarms) # Step 4 - Check inactive alarms. Get all function should return # inactive alarm (alarm that teir status has changed to OK) # Test setup alarm_data1 = self._extract_alarm_data() alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) expected_alarm1 = alarm_data1 expected_alarm2 = copy.copy(alarm_data2) expected_alarm2[ZProps.RESOURCE_NAME] = 'host2' # Test action alarms = zabbix_driver._get_all_alarms() # Test assertions # The alarms of alarm_data1/2 should be returned although their # status is OK, because they were not OK earlier self.assertIsNotNone(alarms, 'No alarms returned') self.assertEqual(2, len(alarms)) self._assert_contains(expected_alarm1, alarms) self._assert_contains(expected_alarm2, alarms) for alarm in alarms: self.assertEqual(GraphAction.DELETE_ENTITY, alarm[DSProps.EVENT_TYPE]) # Step 4 - get all when all alarms are inactivated and their status # was not changed # Test action alarms = zabbix_driver._get_all_alarms() # Test assertions self.assertIsNotNone(alarms, 'alarms is None') self.assertEqual(0, len(alarms))
def test_get_changes_and_get_all(self): # Step 1 - get changes # Step setup zabbix_driver = MockZabbixDriver(self.conf) alarm_data1 = self._extract_alarm_data(priority='2', value='1') alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2', priority='2') alarm_data3 = self._extract_alarm_data(z_resource_name='compute-2', triggerid='2') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) # Step action alarms = zabbix_driver._get_changed_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertEqual(1, len(alarms)) self._assert_contains(alarm_data1, alarms) # Step 2 - get changes when no change occurred (returns nothing) # Step action alarms = zabbix_driver._get_changed_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertEqual(0, len(alarms)) # Step 3 - get all # Step action alarms = zabbix_driver._get_all_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertEqual(1, len(alarms)) self._assert_contains(alarm_data1, alarms) # Step 4 - get all for second time # (when no change has occurred it returns the same) # Step action alarms = zabbix_driver._get_all_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertEqual(1, len(alarms)) self._assert_contains(alarm_data1, alarms) # Step 5 - calling get changes right after get all (returns nothing) # Step setup alarm_data1 = self._extract_alarm_data(priority='4', value='1') alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2', priority='1', value='1') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) expected_alarm1 = alarm_data1 expected_alarm2 = copy.copy(alarm_data2) expected_alarm2[ZProps.RESOURCE_NAME] = 'host2' # Step action get_all_alarms = zabbix_driver._get_all_alarms() changed_alarms = zabbix_driver._get_changed_alarms() # Step assertions self.assertIsNotNone(get_all_alarms, 'No alarms returned') self.assertEqual(2, len(get_all_alarms)) self._assert_contains(expected_alarm1, get_all_alarms) self._assert_contains(expected_alarm2, get_all_alarms) self.assertIsNotNone(changed_alarms, 'No alarms returned') self.assertEqual(0, len(changed_alarms)) # Step 6 - get changes # Step setup alarm_data2 = self._extract_alarm_data(z_resource_name='compute-2', priority='4', value='1') alarm_data3 = self._extract_alarm_data(z_resource_name='compute-2', triggerid='2', priority='4', value='1') zabbix_driver.set_alarm_datas([alarm_data1, alarm_data2, alarm_data3]) expected_alarm1 = copy.copy(alarm_data2) expected_alarm1[ZProps.RESOURCE_NAME] = 'host2' expected_alarm2 = copy.copy(expected_alarm1) expected_alarm2[ZProps.TRIGGER_ID] = '2' # Step action alarms = zabbix_driver._get_changed_alarms() # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') self.assertEqual(2, len(alarms)) self._assert_contains(expected_alarm1, alarms) self._assert_contains(expected_alarm2, alarms)