def test_toXML_timestamp(self): """FaultState creates XML with timestamp""" fs = FaultState.FaultState("Family", "Member", 1) fs.userTimestamp = Timestamp.Timestamp(1222887968, 813309) self.assertEquals( '<fault-state family="Family" member="Member" code="1">\n <user-timestamp>2008-10-01T19:06:08.813</user-timestamp>\n</fault-state>\n', fs.toXML())
def test_toXML(self, mocktime): """Timestamp generates XML""" mocktime.return_value = 1222887968.813309 ts = Timestamp.Timestamp() self.assertEqual( ' <source-timestamp seconds="1222887968" microseconds="813308"/>\n', ts.toXML('source-timestamp', 3))
def test_toXML(self, mocktime): """Timestamp generates XML""" mocktime.return_value = 1222887968.813309 ts = Timestamp.Timestamp() self.assertEqual( ' <source-timestamp>2008-10-01T19:06:08.813</source-timestamp>\n', ts.toXML('source-timestamp', 3))
def test_toXML_timestamp(self): """FaultState creates XML with timestamp""" fs = FaultState.FaultState("Family", "Member", 1) fs.userTimestamp = Timestamp.Timestamp(1222887968, 813309) self.assertEquals( '<fault-state family="Family" member="Member" code="1">\n <user-timestamp seconds="1222887968" microseconds="813309"/>\n</fault-state>\n', fs.toXML())
def test_toXML(self, mocktime): """ASIMessage XML output for defaults""" mocktime.time.return_value = 1222887968.813309 msg = ASI.ASIMessage() msg.faultStates = [FaultState.FaultState("Family", "Member", 1)] msg.sourceHostname = 'foo' msg.sourceTimestamp = Timestamp.Timestamp() self.assertEqual( '<?xml version="1.0" encoding="ISO-8859-1"?>\n<ASI-message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backup="false" version="0.9" xsi:type="ASI-message">\n <source-name>ALARM_SYSTEM_SOURCES</source-name>\n <source-hostname>foo</source-hostname>\n <source-timestamp seconds="1222887968" microseconds="813308"/>\n <fault-states>\n <fault-state family="Family" member="Member" code="1">\n</fault-state>\n </fault-states>\n</ASI-message>\n', msg.toXML())
def test_publishAlarm(self): """AlarmPublisher alarm publishing""" import Acsalarmpy.FaultState as FS import Acsalarmpy.ASI as ASI import Acsalarmpy.Timestamp as TS mockSupplier.reset_mock() fs = FS.FaultState("Family", "Member", 1) fs.descriptor = "" fs.userTimestamp = TS.Timestamp() msg = ASI.ASIMessage([fs]) msg.sourceTimestamp = TS.Timestamp() baseline = msg.toXML() ap = AlarmPublisher.AlarmPublisher() ap.publishAlarm(msg) self.assertEqual('publishEvent', mockSupplier.method_calls[0][0]) self.assertEqual( True, isinstance( mockSupplier.method_calls[0][2]['simple_data'], AlarmPublisher.ACSJMSMessageEntity_idl._0_com.cosylab.acs.jms. ACSJMSMessageEntity)) self.assertEqual(baseline, mockSupplier.method_calls[0][2]['simple_data'].text)
def _sendAlarm(self,family,member,code,active): Acsalarmpy.AlarmSystemInterfaceFactory.init() alarmSource = Acsalarmpy.AlarmSystemInterfaceFactory.createSource("ALARM_SYSTEM_SOURCES") # Create a test fault fltstate = Acsalarmpy.AlarmSystemInterfaceFactory.createFaultState(family,member, code) if active: fltstate.descriptor = FaultState.ACTIVE_STRING else: fltstate.descriptor = FaultState.TERMINATE_STRING fltstate.userTimestamp = Timestamp.Timestamp() fltstate.userProperties[FaultState.ASI_PREFIX_PROPERTY_STRING] = "prefix" fltstate.userProperties[FaultState.ASI_SUFFIX_PROPERTY_STRING] = "suffix" fltstate.userProperties["TEST_PROPERTY"] = "TEST_VALUE" # The heart of the test alarmSource.push(fltstate) Acsalarmpy.AlarmSystemInterfaceFactory.done()
def _commonPush(self, states, backup): """ Common method to push a collection of fault states to the LASER server. Parameters: states is a list of the fault states to be sent backup is a flag indicating if we are sending backup alarms. Backup alarms are alarms in the active list that are sent on startup, when the source starts and periodically according to the expected backup frequency. """ self.logger.logTrace("AlarmSystemInterface: entering _commonPush.") msg = ASI.ASIMessage(states) msg.sourceTimestamp = Timestamp.Timestamp() msg.sourceName = self.sourceName msg.sourceHostname = self.hostName msg.backup = backup msg.version = self.configuration.asiVersion self.publishMessage(msg) for s in states: self.logger.logAlert('Alarm sent: <%s, %s, %d> %s' % (s.family, s.member, s.code, s.descriptor)) self.logger.logTrace("AlarmSystemInterface: exiting _commonPush.")
def test_object_initialization_microseconds(self): """Timestamp initializes with microseconds provided""" ts = Timestamp.Timestamp(microSeconds=1222887968) self.assertEqual(1222887968, ts.microseconds) self.assertEqual(0, ts.seconds)
def test_object_initialization_default(self, mocktime): """Timestamp initializes with default values""" mocktime.return_value = 1222887968.813309 ts = Timestamp.Timestamp() self.assertEqual(1222887968, ts.seconds) self.assertWithinRange(813309, ts.microseconds, 1, 0)
def test_object_initialization(self): """Timestamp initializes with all values""" ts = Timestamp.Timestamp(1222887968, 813309) self.assertEqual(1222887968, ts.seconds) self.assertEqual(813309, ts.microseconds)
numAlarmsToSend = int(sys.argv[1]) # Test data for our fault family = 'AlarmSource' member = 'ALARM_SOURCE_MOUNT' code = 1 print "Testing long-hand style of sending alarms" Acsalarmpy.AlarmSystemInterfaceFactory.init() alarmSource = Acsalarmpy.AlarmSystemInterfaceFactory.createSource() # Create a test fault fltstate = Acsalarmpy.AlarmSystemInterfaceFactory.createFaultState( family, member, code) fltstate.descriptor = FaultState.ACTIVE_STRING fltstate.timestamp = Timestamp.Timestamp() fltstate.userProperties[FaultState.ASI_PREFIX_PROPERTY_STRING] = "prefix" fltstate.userProperties[FaultState.ASI_SUFFIX_PROPERTY_STRING] = "suffix" fltstate.userProperties["TEST_PROPERTY"] = "TEST_VALUE" # The heart of the test for i in range(1, numAlarmsToSend + 1): alarmSource.push(fltstate) Acsalarmpy.AlarmSystemInterfaceFactory.done() # # ___oOo___
member = 'ALARM_SOURCE_MOUNT' print "Testing long-hand style of sending alarms" Acsalarmpy.AlarmSystemInterfaceFactory.init() alarmSource = Acsalarmpy.AlarmSystemInterfaceFactory.createSource( "ALARM_SYSTEM_SOURCES") # The heart of the test for code in range(1, numAlarmsToSend + 1): # Create a test fault fltstate = Acsalarmpy.AlarmSystemInterfaceFactory.createFaultState( family, member, code) fltstate.descriptor = FaultState.ACTIVE_STRING fltstate.userTimestamp = Timestamp.Timestamp() fltstate.userProperties[ FaultState.ASI_PREFIX_PROPERTY_STRING] = "prefix" fltstate.userProperties[ FaultState.ASI_SUFFIX_PROPERTY_STRING] = "suffix" fltstate.userProperties["TEST_PROPERTY"] = "TEST_VALUE" alarmSource.push(fltstate) print numAlarmsToSend, "alarms sent" numAlarmsToReceive = numAlarmsToSend timeout = 120 now = 0 while msgCount < numAlarmsToReceive or now > timeout: sleep(1) now = now + 1