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_object_initialization(self, mocktime): """ASIMessage default initializer""" mocktime.time.return_value = 1222887968.813309 msg = ASI.ASIMessage() self.assertEquals(True, msg.faultStates is None) self.assertEquals(False, msg.backup) self.assertEquals(ASI.ASI_VERSION, msg.version) self.assertEquals(ASI.ALARM_SOURCE_NAME, msg.sourceName) self.assertEquals(True, msg.sourceHostname is None) self.assertEquals(True, msg.sourceTimestamp is None)
def __init__(self, sourceName=None, hostName=None): """ Create an instance of the AlarmSystemInterface. Parameters: sourceName is the name of this source hostName is the name of the computer where the source is running. """ self.logger = Log.getLogger() self.sourceName = sourceName self.hostName = hostName self.configuration = ASI.ASIConfiguration()
def test_object_initialization(self): """ASIConfiguration default initializer""" asiconfig = ASI.ASIConfiguration() self.assertEquals(ASI.ASI_VERSION, asiconfig.asiVersion) self.assertEquals(ASI.ALARMS_TOPIC, asiconfig.alarmsTopic) self.assertEquals(ASI.BACKUP_DELIVERY_MODE, asiconfig.backupDeliveryMode) self.assertEquals(ASI.BACKUP_PRIORITY, asiconfig.backupPriority) self.assertEquals(ASI.BACKUP_TIME_TO_LIVE, asiconfig.backupTimeToLive) self.assertEquals(ASI.CHANGES_DELIVERY_MODE, asiconfig.changesDeliveryMode) self.assertEquals(ASI.CHANGES_PRIORITY, asiconfig.changesPriority) self.assertEquals(ASI.CHANGES_TIME_TO_LIVE, asiconfig.changesTimeToLive)
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_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)