Exemplo n.º 1
0
 def testSubscriptionForwarding6(self):
     Info("---- testSubscriptionForwarding6 ----", "TestEventRouterHTTP")
     evmatch = makeEvent(evtype="R1Events/ev1", source="R1Source/src1")
     evdrop = makeEvent(evtype="R1Events/ev2", source="R1Source/src2")
     self.doSubscriptionForwardingR2R1(None, "R1Source/src1", evmatch,
                                       evdrop)
     return
Exemplo n.º 2
0
 def testSubscriptionForwarding11(self):
     Info("---- testSubscriptionForwarding11 ----", "TestEventRouterHTTP")
     evmatch = makeEvent(evtype="R3Events1/ev1", source="R3Source1/src1")
     evdrop = makeEvent(evtype="R3Events1/ev2", source="R3Source1/src2")
     self.doSubscriptionForwardingR2R3("R3Events1/ev1", "R3Source1/src1",
                                       evmatch, evdrop)
     return
Exemplo n.º 3
0
 def testSubscriptionForwarding3(self):
     Info("---- testSubscriptionForwarding3 ----",
          "EventLib.TestEventHTTPClient")
     evmatch = makeEvent(evtype="R3Events1/ev1", source="R3Source1/src1")
     evdrop = makeEvent(evtype="R3Events1/ev2", source="R3Source1/src2")
     self.doSubscriptionForwardingR2R3("R3Events1/ev1", "R3Source1/src1",
                                       evmatch, evdrop)
     return
Exemplo n.º 4
0
 def testSubscriptionForwarding2(self):
     Info("---- testSubscriptionForwarding2 ----",
          "TestEventHTTPClientServer")
     evmatch = makeEvent(evtype="R3Events/ev1", source="R3Source/src1")
     evdrop = makeEvent(evtype="R3Events/ev2", source="R3Source/src2")
     self.doSubscriptionForwardingR2R3(None, "R3Source/src1", evmatch,
                                       evdrop)
     return
Exemplo n.º 5
0
 def testSubscriptionForwarding1(self):
     Info("---- testSubscriptionForwarding1 ----------",
          "TestEventRouterHTTP")
     evmatch = makeEvent(evtype="R2Events/ev1", source="R2Source/src1")
     evdrop = makeEvent(evtype="R2Events/ev2", source="R2Source/src2")
     self.doSubscriptionForwardingR1R2("R2Events/ev1", None, evmatch,
                                       evdrop)
     return
Exemplo n.º 6
0
 def testSubscriptionForwarding12(self):
     Info("---- testSubscriptionForwarding12 ----", "TestEventRouterHTTP")
     evmatch = makeEvent(evtype="RREvents3/ev1", source="RRSource3/src1")
     evdrop = makeEvent(evtype="RREvents3/ev2", source="RRSource3/src2")
     self.doSubscriptionForwardingR2R3("RREvents3/ev1",
                                       "RRSource3/src1",
                                       evmatch,
                                       evdrop,
                                       r1fwd=1)
     return
Exemplo n.º 7
0
 def testSubscriptionForwarding4(self):
     Info("---- testSubscriptionForwarding4 ----",
          "EventLib.TestEventHTTPClient")
     evmatch = makeEvent(evtype="RREvents3/ev1", source="RRSource3/src1")
     evdrop = makeEvent(evtype="RREvents3/ev2", source="RRSource3/src2")
     self.doSubscriptionForwardingR2R3("RREvents3/ev1",
                                       "RRSource3/src1",
                                       evmatch,
                                       evdrop,
                                       r1fwd=1)
     return
Exemplo n.º 8
0
    def testWriteTCPAndLocal(self):        
        """
        Test what happens when we start a write event  to a TCP serial port and a Local one at the same time
        """
        self._log.debug( "\n\n-------------------------------testWriteTCPAndLocal-------------------------------" )
        self._log.debug( "\nInitializng TCP server" )
        TCPServ = TestTCPServer(4747)
        TCPServ.start() 
        try:
            self._log.debug( "\nInitializing serial eventhandler" )
            testCfg = getDictFromXmlString(testConfigLocalAndTCP)
            self._log.debug( "\ntestCfg  : %s" %testCfg )
            eh=Serial(self._router)
            self.assertNotEqual( eh, None )
            
            self._log.debug( "\n Configuring serial eventhandler" )
            eh.configure(testCfg['eventInterface'])
            eh.start()         
            
            self._log.debug( "\nCreating test events :" )   
            TCPSerialevent = makeEvent( 'internal/test/serial', 'serial/test/1', {} )  
            localSerialevent = makeEvent( 'internal/test/serial', 'serial/test/2', {} ) 
               
            self._log.debug( "%s and %s" %(localSerialevent,TCPSerialevent) )      
                        
            self._log.debug( "\nSending TCP event..." )
            eh.handleEvent( TCPSerialevent )            
            self._log.debug( "\nSending local event..." )
            eh.handleEvent( localSerialevent )
            
            time.sleep(1)
            
            portlist = eh.getSerialPorts()
            self._log.debug( "\nList of active ports : %s" %portlist )
            TCPData = TCPServ.data
            self._log.debug( "\nTCP server recieved : ##%s##" %TCPData ) 
            assert TCPData == 'ABC'
            self.assertEqual( len(self._router._pubs), 1 )
            self.assertEqual( self._router._pubs[0][1].getType(), "http://id.webbrick.co.uk/events/serial/receive" )
            self.assertEqual( self._router._pubs[0][1].getSource(), "serial-2/receive" )
            self.assertEqual( self._router._pubs[0][1].getPayload()['data'], "66;67;68:" )   

            self._log.debug( "\nLocal serial recieved local data ") 



            eh.stop()
        finally :  
            
            TCPServ.stop()
            time.sleep(1)        
Exemplo n.º 9
0
 def testWriteTCP(self):
     """
     Test what happens when we start a write event to a TCP serial port
     """
     self._log.debug( "\n\n-------------------------------testWriteTCP-------------------------------" )
     self._log.debug( "\nInitializng TCP server" )
     TCPServ = TestTCPServer(4747)
     TCPServ.start() 
     try:
         self._log.debug( "\nInitializing serial eventhandler" )
         testCfg = getDictFromXmlString(testConfigTCP)
         self._log.debug( "\ntestCfg  : %s" %testCfg )
         eh=Serial(self._router)
         self.assertNotEqual( eh, None )
         eh.configure(testCfg['eventInterface'])
         eh.start()
         
         
         self._log.debug( "\nCreating test event :" )
         testEvent = makeEvent( 'internal/test/serial', 'serial/test/1', {} )
         self._log.debug( testEvent )
         
         self._log.debug( "\nTesting eventhandler..." )
         eh.handleEvent( testEvent )
         time.sleep(1)
         portlist = eh.getSerialPorts()
         self._log.debug( "\nList of active ports : %s" %portlist )
         data = TCPServ.data
         self._log.debug( "\nTCP server recieved : ##%s##" %data ) 
         assert data == "turn lights onsuccess!"
         eh.stop()
     finally:
         
         TCPServ.stop()
Exemplo n.º 10
0
 def doActions( self, actions, inEvent ):
     for de in actions[0]:
         # update from event
         de.update(inEvent)
         
     for ae in actions[1]:
         # perform action
         if ae._action == ACTION_CSV:
             # write an event log entry
             ntry = ",".join( [de.get() for de in self._columns] )
             ls = logging.getLogger(ae._streamname)
             ls.info( ntry )
             
         elif ae._action == ACTION_XML:
             atts = "".join( [" %s='%s' " % (de._name, de._value) for de in self._columns] )
             elms = "".join( ["<%s>%s</%s>" % (de._name, de._value, de._name) for de in self._columns] )
             ntry = "<%s %s>%s</%s>" % (ae._element, atts, elms, ae._element)
             ls = logging.getLogger(ae._streamname)
             ls.info( ntry )
                 
         elif ae._action == ACTION_EVENT:
             # create an event
             od = dict()
             for de in self._columns:
                 od[de._name] = de._value
             self.sendEvent( makeEvent( ae._type, ae._source, od ) )
             
         elif ae._action == ACTION_CLEAR:
             # clear current data values
             for de in self._columns:
                 de.clear()
Exemplo n.º 11
0
 def doTestPublish(self,typid,srcid,expectTriggered):
     src = makeEventAgent(typid+srcid)
     evt = makeEvent(evtype=typid,source=srcid)
     sts = self.router.publish(src, evt)
     self.assertEqual( sts.syncValue(), StatusVal.OK, str(sts.syncValue())+" is not StatusVal.OK" )
     mapAssert(evTriggerEq, self.handlers, expectTriggered, "Trigger "+typid+srcid)
     return
Exemplo n.º 12
0
 def testMakeEvent2(self):
     e = makeEvent(evtype="EventTypeUri",
                   source="EventSourceUri",
                   payload="payload")
     assert e.getType() == "EventTypeUri", "testMakeEvent2, getType"
     assert e.getSource() == "EventSourceUri", "testMakeEvent2, getSource"
     assert e.getPayload() == "payload", "testMakeEvent2, getPayload"
 def testBlockingEventDelivery(self):
     es = makeEventAgent(uri="es")
     eh = makeEventHandler(uri="eh",
                           handler=eventHandlerBlocking,
                           initSubscription=subHandler,
                           endSubscription=unsubHandler)
     eh.subcount = 0
     eh.evcount = 0
     evtyp = "R3Events1/ev1"  # Select event routed R3 -> R1 -> R2 ..
     evsrc = "R3Source1/src1"  # .. (see setUp)
     ev = makeEvent(evtype=evtyp, source=evsrc)
     sts = self.R2.subscribe(60, eh, evtype=evtyp, source=evsrc)
     Trace("Subscribe returned", "EventLib.TestEventRouterThreaded")
     time.sleep(0.1)  # Allow subscribe time to propagate
     Trace("Subscribed", "EventLib.TestEventRouterThreaded")
     self.assertEqual(eh.evcount, 0)
     sts = self.R3.publish(es, ev)
     self.assertEqual(eh.evcount, 0)  # Not delivered immediately ...
     Trace("Before sleep", "EventLib.TestEventRouterThreaded")
     time.sleep(1.5)  # Note: evcent handler blocks for 1 sec
     Trace("After sleep: eh.evcount %d" % (eh.evcount),
           "EventLib.TestEventRouterThreaded")
     self.assertEqual(eh.evcount, 1)  # ... but  sometime after a second
     self.assertEqual(eh.event.getType(), evtyp)
     self.assertEqual(eh.event.getSource(), evsrc)
     Trace("testBlockingEventDelivery OK",
           "EventLib.TestEventRouterThreaded")
     return
    def sendTestEvent(self):
        print ("sendTestEvent start")
        self.setUpRouter()

        # Listen for incoming events using a custom handler.
        eventType = "to/router/original"
        eventSource = "source/router2"
        router1EventAgentIncoming = makeEventAgent(uri="router1EventAgentIncoming")
        router1EventHandlerIncoming = makeEventHandler(
            uri="router1EventAgentIncoming",
            handler=eventHandlerIncoming,
            initSubscription=subHandlerIncoming,
            endSubscription=unsubHandlerIncoming,
        )
        router1EventHandlerIncoming.subcount = 0
        router1EventHandlerIncoming.evcount = 0
        status = self.R1.subscribe(
            60, router1EventHandlerIncoming, evtype=eventType, source=eventSource
        )  # R1 subscribes to eventType to send a response back

        # Set the counter to 1, make our first event.
        self.inC()

        eventType = "to/router/2"
        eventSource = "source/router1"
        event = makeEvent(evtype=eventType, source=eventSource, payload=router.getCount())
        self.sendTestEventDo(self.R3C, self.R1, event, eventType, eventSource)  # Send the event
        print ("sendTestEvent end")
Exemplo n.º 15
0
    def testFloatCounterSet(self):
        """
        Set Counter to a fixed value 
        """
        _log.debug( "\ntestFloatCounterSet" )
        self.loader = EventRouterLoader()
        errCount = self.loader.loadHandlers( getDictFromXmlString(testConfigFloatCounterSet) )
        self.assertEqual( errCount, 0)

        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        self.router.publish( EventAgent("testCounters"), makeEvent( 'test/event', 'set/counter', { 'val':'300.45' } ) )

        TestEventLogger.logEvents()
        expectedEvents = { 
                    "test/event" : 
                            [
                                ("set/counter" , 'val', 300.45)
                            ],
                    "test/1" : 
                            [   ("test/entryCount",'val', 300.45)
                            ]
                     }
       
        Utils.expectNevents(self, 2)

        
        haveErr, excessEvents = Utils.verifyEvents2( expectedEvents, TestEventLogger._events )
        _log.debug( "Excess Events %s " % (excessEvents) )

        self.assertEqual( haveErr, False, "Incorrect event set" )
Exemplo n.º 16
0
 def doTestPublish(self,typid,srcid,expectTriggered):
     src = makeEventAgent(typid+srcid)
     evt = makeEvent(evtype=typid,source=srcid)
     sts = self.router.publish(src, evt)
     self.assertEqual( sts.syncValue(), StatusVal.OK, str(sts.syncValue())+" is not StatusVal.OK" )
     mapAssert(evTriggerEq, self.handlers, expectTriggered, "Trigger "+typid+srcid)
     return
def eventHandlerIncoming(h, e):
    h.evcount += 1
    h.event = e
    if h.event.getType() == "to/router/original":
        rootlogger.warn("== Received an incoming event, event number: %s ==", router.getCount())

        # Increment the counter for the incoming events. Sleep so that we don't have a continuous loop of events.
        router.inC()
        time.sleep(0.5)

        # Make and publish an event back to Router2Console
        eventType = "to/router/2"
        eventSource = "source/router1"
        router1EventAgentOutgoing = makeEventAgent(uri="router1EventAgentOutgoing")
        router1EventHandlerOutgoing = makeEventHandler(
            uri="router1EventAgentOutgoing",
            handler=eventHandlerOutgoing,
            initSubscription=subHandlerOutgoing,
            endSubscription=unsubHandlerOutgoing,
        )
        router1EventHandlerOutgoing.subcount = 0
        router1EventHandlerOutgoing.evcount = 0

        event = makeEvent(evtype=eventType, source=eventSource, payload=router.getCount())

        rootlogger.warn("== Sending out event, number: %s ==", router.getCount())
        status2 = router.getR1().publish(
            router1EventHandlerOutgoing, event
        )  ## R1 publishes the main event, R2C picks it up and forwards it to TestEventHTTPRouter1Console.py
        rootlogger.warn("== The event has completed being published ==")

    return makeDeferred(StatusVal.OK)
 def testBlockingEventDelivery(self):
     es = makeEventAgent(uri="es")
     eh = makeEventHandler(
             uri="eh", handler=eventHandlerBlocking, 
             initSubscription=subHandler, endSubscription=unsubHandler)
     eh.subcount = 0
     eh.evcount  = 0
     evtyp = "R3Events1/ev1"             # Select event routed R3 -> R1 -> R2 ..
     evsrc = "R3Source1/src1"            # .. (see setUp)
     ev  = makeEvent(evtype=evtyp, source=evsrc)
     sts = self.R2.subscribe(60, eh, evtype=evtyp, source=evsrc)
     Trace("Subscribe returned", "EventLib.TestEventRouterThreaded")
     time.sleep(0.1)                     # Allow subscribe time to propagate
     Trace("Subscribed", "EventLib.TestEventRouterThreaded")
     self.assertEqual(eh.evcount, 0)
     sts = self.R3.publish(es, ev)
     self.assertEqual(eh.evcount, 0)     # Not delivered immediately ...
     Trace("Before sleep", "EventLib.TestEventRouterThreaded")
     time.sleep(1.5)                     # Note: evcent handler blocks for 1 sec
     Trace("After sleep: eh.evcount %d"%(eh.evcount), "EventLib.TestEventRouterThreaded")
     self.assertEqual(eh.evcount, 1)     # ... but  sometime after a second
     self.assertEqual(eh.event.getType(), evtyp)
     self.assertEqual(eh.event.getSource(), evsrc)
     Trace("testBlockingEventDelivery OK", "EventLib.TestEventRouterThreaded")
     return
Exemplo n.º 19
0
 def testMakeEnvSubscribeData4(self):
     payload = [44, None, None]
     ev = makeEvent(URI.EventSubscribeType, "agent", payload)
     env = EventEnvelope(ev, "router")
     self.assertEqual(
         es.sub("/", makeEnvelopeData(env)), '["forward", ' +
         '[["router"], ' + '"http://id.webbrick.co.uk/events/subscribe", ' +
         '"agent", ' + '[44, null, null]]]')
Exemplo n.º 20
0
 def testMakeEnvSubscribeData3(self):
     payload = [33, self.ev.getType(), None]
     ev = makeEvent(URI.EventSubscribeType, "agent", payload)
     env = EventEnvelope(ev, "router")
     self.assertEqual(
         es.sub("/", makeEnvelopeData(env)), '["forward", ' +
         '[["router"], ' + '"http://id.webbrick.co.uk/events/subscribe", ' +
         '"agent", ' + '[33, "s://auth.b/path/type/d#frag", null]]]')
Exemplo n.º 21
0
 def testMakeEnvelopeData2(self):
     self.ev2 = makeEvent("s://auth.b/path/type/d#frag",
                          "s://auth.b/path/source/d#frag", None)
     self.env2 = EventEnvelope(self.ev2, "R1").nextHop("R2").nextHop("R3")
     self.assertEqual(
         es.sub("/", makeEnvelopeData(self.env2)), '["forward", ' +
         '[["R1", "R2", "R3"], ' + '"s://auth.b/path/type/d#frag", ' +
         '"s://auth.b/path/source/d#frag", ' + 'null]]')
Exemplo n.º 22
0
 def clickhandler(self, h, e):
     """
     On receiving a button-click, bump the counter and generate some more events
     """
     log.info("clickhandler %s", e)
     buttonstates  = ('up', 'down', 'waiting', 'unknown')
     displaystates = ('normal', 'low', 'high', 'unknown')
     if e.getPayload() == "click":
         self._count += 1
         e1 = makeEvent(SetButtonTextEvent, h.getUri(), "Button:%i"%(self._count))
         self._router.publish(h, e1)
         e2 = makeEvent(SetButtonStateEvent, h.getUri(), buttonstates[self._count%4])
         self._router.publish(h, e2)
         e3 = makeEvent(SetNumericDisplayValueEvent, h.getUri(), str(self._count))
         self._router.publish(h, e3)
         e4 = makeEvent(SetNumericDisplayStateEvent, h.getUri(), displaystates[self._count%4])
         self._router.publish(h, e4)
     return makeDeferred(StatusVal.OK)
Exemplo n.º 23
0
 def testMakeEnvelopeData2(self):
     self.ev2  = makeEvent("s://auth.b/path/type/d#frag", "s://auth.b/path/source/d#frag", None)
     self.env2 = EventEnvelope(self.ev2,"R1").nextHop("R2").nextHop("R3")
     self.assertEqual( es.sub("/", makeEnvelopeData(self.env2)),
         '["forward", '+
         '[["R1", "R2", "R3"], '+
          '"s://auth.b/path/type/d#frag", '+
          '"s://auth.b/path/source/d#frag", '+
          'null]]' )
 def publishFromThread( es, cq, wait0, wait1, evlist):
     n = 0
     for (et,es) in evlist:
         n += 1
         time.sleep(wait0)
         wait0 = wait1
         ev = makeEvent(evtype=et, source=es)
         sts = self.R3.publish(es, ev)
     cq.put(n)
     return
 def publishFromThread(es, cq, wait0, wait1, evlist):
     n = 0
     for (et, es) in evlist:
         n += 1
         time.sleep(wait0)
         wait0 = wait1
         ev = makeEvent(evtype=et, source=es)
         sts = self.R3.publish(es, ev)
     cq.put(n)
     return
Exemplo n.º 26
0
 def testMakeEnvSubscribeData4(self):
     payload = [44, None, None]
     ev      = makeEvent(URI.EventSubscribeType, "agent", payload)
     env     = EventEnvelope(ev, "router")
     self.assertEqual( es.sub("/", makeEnvelopeData(env)),
         '["forward", '+
         '[["router"], '+
          '"http://id.webbrick.co.uk/events/subscribe", '+
          '"agent", '+
          '[44, null, null]]]' )
Exemplo n.º 27
0
 def testMakeEnvSubscribeData3(self):
     payload = [33, self.ev.getType(), None]
     ev      = makeEvent(URI.EventSubscribeType, "agent", payload)
     env     = EventEnvelope(ev, "router")
     self.assertEqual( es.sub("/", makeEnvelopeData(env)),
         '["forward", '+
         '[["router"], '+
          '"http://id.webbrick.co.uk/events/subscribe", '+
          '"agent", '+
          '[33, "s://auth.b/path/type/d#frag", null]]]' )
Exemplo n.º 28
0
 def testMakeEventHandler2(self):
     eh = makeEventHandler("EventHandlerUri")
     self.assertEqual(eh.getUri(), "EventHandlerUri")
     ev = makeEvent("EventUri", source=eh.getUri())
     sh = eh.handleEvent(ev).syncValue()
     self.assertEqual(sh, StatusVal.OK)
     ss = eh.initSubscription(StatusVal.OK).syncValue()
     self.assertEqual(sh, StatusVal.OK)
     ss = eh.endSubscription(StatusVal.OK).syncValue()
     self.assertEqual(sh, StatusVal.OK)
     return
Exemplo n.º 29
0
 def testMakeEventHandler2(self):
     eh = makeEventHandler("EventHandlerUri")
     self.assertEqual(eh.getUri(), "EventHandlerUri")
     ev = makeEvent("EventUri", source=eh.getUri())
     sh = eh.handleEvent(ev).syncValue()
     self.assertEqual(sh, StatusVal.OK)
     ss = eh.initSubscription(StatusVal.OK).syncValue()
     self.assertEqual(sh, StatusVal.OK)
     ss = eh.endSubscription(StatusVal.OK).syncValue()
     self.assertEqual(sh, StatusVal.OK)
     return
Exemplo n.º 30
0
    def handleMinute( self, inEvent ):
        """ Look through the schedule and process it """
        od = inEvent.getPayload()
        nowDay = od["day"]
        nowTime = od["timestr"]
        _log.debug( 'handleMinute %s %s', nowTime, nowDay )

        for schKey in self.schedule:
            _log.debug( 'schKey %s', schKey )
            for schEntry in self.schedule[schKey].getEntries(nowDay, nowTime):
                _log.debug( 'schEntry %s', schEntry )

                for devKey,devAction in schEntry.getDevices():

                    if devAction.has_key("onoff"):
                        self.sendEvent( makeEvent( "http://id.webbrick.co.uk/events/schedule/control", 
                                "%s/%s" % (devKey,devAction["onoff"]) ) )
                    if devAction.has_key("val"):
                        self.sendEvent( makeEvent( "http://id.webbrick.co.uk/events/schedule/control", 
                                "%s/set" % (devKey,) , 
                                {'val': devAction["val"] } ) )
Exemplo n.º 31
0
 def testMakeEventHandler5(self):
     # Test response to event handler throwing an exception
     eh = makeEventHandler("EventHandlerUri", handleEventException, initSub, endSub)
     self.assertEqual(eh.getUri(), "EventHandlerUri")
     ev = makeEvent("EventUri", source=eh.getUri())
     sh = eh.handleEvent(ev).syncValue()
     self.assertEqual(sh, Status(URI.Status_OK, ev.getType()))
     # The status message value here depends on the default status value set up by
     # EventHandler.handleEvent, which is currently the default supplied by the
     # Status object constructor.
     self.assertEqual(sh.getMessage(), "")
     return
Exemplo n.º 32
0
def publish_versions(evt_router):
    from EventLib.Event import makeEvent  
    from EventLib.EventAgent import EventAgent

    from socket import gethostname
    
    from WebBrickLibs import __VERSION__ as libVersion
    from WebBrickRes import __VERSION__ as resVersion
    from WebBrickDoc import __VERSION__ as docVersion
    from WebBrickGateway import __VERSION__ as gwyVersion
    from WebBrickConfig import __VERSION__ as cfgVersion
    #
    #  Now publish these as events
    #
    
    sysName = gethostname()
    
    evt_router.publish( EventAgent(""), makeEvent( 'http://id.webbrick.co.uk/events/diagnostics/software/version', 'WebBrickLibs', { 'build':libVersion, 'name':sysName } ) )  
    evt_router.publish( EventAgent(""), makeEvent( 'http://id.webbrick.co.uk/events/diagnostics/software/version', 'WebBrickRes', { 'build':resVersion, 'name':sysName } ) )  
    evt_router.publish( EventAgent(""), makeEvent( 'http://id.webbrick.co.uk/events/diagnostics/software/version', 'WebBrickDoc', { 'build':docVersion, 'name':sysName } ) )  
    evt_router.publish( EventAgent(""), makeEvent( 'http://id.webbrick.co.uk/events/diagnostics/software/version', 'WebBrickGateway', { 'build':gwyVersion, 'name':sysName } ) )  
    evt_router.publish( EventAgent(""), makeEvent( 'http://id.webbrick.co.uk/events/diagnostics/software/version', 'WebBrickConfig', { 'build':cfgVersion, 'name':sysName } ) )  
Exemplo n.º 33
0
 def testMakeEventHandler5(self):
     # Test response to event handler throwing an exception
     eh = makeEventHandler("EventHandlerUri", handleEventException, initSub,
                           endSub)
     self.assertEqual(eh.getUri(), "EventHandlerUri")
     ev = makeEvent("EventUri", source=eh.getUri())
     sh = eh.handleEvent(ev).syncValue()
     self.assertEqual(sh, Status(URI.Status_OK, ev.getType()))
     # The status message value here depends on the default status value set up by
     # EventHandler.handleEvent, which is currently the default supplied by the
     # Status object constructor.
     self.assertEqual(sh.getMessage(), "")
     return
Exemplo n.º 34
0
 def testMakeEventHandler1(self):
     eh = makeEventHandler("EventHandlerUri", handleEvent, initSub, endSub)
     self.assertEqual(eh.getUri(), "EventHandlerUri")
     ev = makeEvent("EventUri", source=eh.getUri())
     sh = eh.handleEvent(ev).syncValue()
     self.assertEqual(sh, Status(URI.Status_TRIGGERED, ev.getType()))
     self.assertEqual(sh.getMessage(), ev.getType())
     ss = eh.initSubscription(StatusVal.OK).syncValue()
     self.assertEqual(ss, Status(URI.Status_SUBSCRIBED, str(StatusVal.OK)))
     self.assertEqual(ss.getMessage(), str(StatusVal.OK))
     su = eh.endSubscription(StatusVal.OK).syncValue()
     self.assertEqual(su, Status(URI.Status_UNSUBSCRIBED, str(StatusVal.OK)))
     self.assertEqual(su.getMessage(), str(StatusVal.OK))
     return
Exemplo n.º 35
0
 def testMakeEventHandler1(self):
     eh = makeEventHandler("EventHandlerUri", handleEvent, initSub, endSub)
     self.assertEqual(eh.getUri(), "EventHandlerUri")
     ev = makeEvent("EventUri", source=eh.getUri())
     sh = eh.handleEvent(ev).syncValue()
     self.assertEqual(sh, Status(URI.Status_TRIGGERED, ev.getType()))
     self.assertEqual(sh.getMessage(), ev.getType())
     ss = eh.initSubscription(StatusVal.OK).syncValue()
     self.assertEqual(ss, Status(URI.Status_SUBSCRIBED, str(StatusVal.OK)))
     self.assertEqual(ss.getMessage(), str(StatusVal.OK))
     su = eh.endSubscription(StatusVal.OK).syncValue()
     self.assertEqual(su, Status(URI.Status_UNSUBSCRIBED,
                                 str(StatusVal.OK)))
     self.assertEqual(su.getMessage(), str(StatusVal.OK))
     return
Exemplo n.º 36
0
 def checkVacationStatus( self, dt_str ):
     if self._currentStatus is None:
         self._log.debug(dt_str)
         self._currentStatus = 1
         for entry in self._entries:
             if entry.onVacation(dt_str):
                 self._currentStatus = 0
         self.sendEvent( makeEvent( 'http://id.webbrick.co.uk/events/config/set', 'occupants/home', {'val': self._currentStatus}) )
         
     else:
         pass
     #if first call
     #   if ical loaded
     #       locate current time and see whether between VacationStart/VacationEnd i.e. onVacation or not
     # send relevant event
     # else
     # if current time matches an entry send relevant event.
     pass
Exemplo n.º 37
0
 def testDisconnectRecover(self):
     """
     Test recieve callback is working correctly for serial ports
     """
     self._log.debug( "\n\n-------------------------------testReadTCP-------------------------------" )
     TCPServ = TestTCPServer(4747)
     TCPServ.start()
     self._log.debug( "\nInitializing serial eventhandler with tcp connection configured" )
     testCfg = getDictFromXmlString(testConfigTCP)
     eh = Serial(self._router)
     self.assertNotEqual( eh, None )
         
     eh.configure(testCfg['eventInterface'])
     eh.start()
         
     self._log.debug ( "Sending test data" )
     TCPServ.send("hello\r")
     
         
     time.sleep(0.5)
     self.assertEqual( len(self._router._pubs), 1 ) 
     self.assertEqual( self._router._pubs[0][1].getType(), "lighting/update" )
     self.assertEqual( self._router._pubs[0][1].getSource(), "light1/on" )
     self.assertEqual( self._router._pubs[0][1].getPayload()['lightval'], "1")     
     TCPServ.stop()
     time.sleep(0.5)
     TCPServ = TestTCPServer(4747)
     TCPServ.start()
     testEvent = makeEvent( 'internal/test/serial', 'serial/test/1', {} )
     self._log.debug( testEvent )            
     self._log.debug( "\nTesting eventhandler..." )
     eh.handleEvent( testEvent )
     eh.handleEvent( testEvent )
     eh.handleEvent( testEvent )
     eh.handleEvent( testEvent ) 
     TCPServ.send("hello\r")
     time.sleep(1)
     assert TCPServ.read() == "turn lights onsuccess!turn lights onsuccess!"
     self.assertEqual( len(self._router._pubs), 2 )
     
     self.assertEqual( self._router._pubs[1][1].getType(), "lighting/update" )
     self.assertEqual( self._router._pubs[1][1].getSource(), "light1/on" )
     self.assertEqual( self._router._pubs[1][1].getPayload()['lightval'], "1")  
     time.sleep(0.5)
def sendBackResponse(count):
    # Send back an event that the Router1Console's INCOMING handler will pickup.
    eventType = "to/router/original"
    eventSource = "source/router2"
    router2EventAgentOutgoing = makeEventAgent(uri="router2EventAgentOutgoing")
    router2EventHandlerOutgoing = makeEventHandler(
        uri="router2EventAgentOutgoing", handler=eventHandlerOutgoing,
        initSubscription=subHandlerOutgoing, endSubscription=unsubHandlerOutgoing)
    router2EventHandlerOutgoing.subcount = 0
    router2EventHandlerOutgoing.evcount = 0
    
    event = makeEvent(evtype=eventType, source=eventSource)
    
    # Only subscribe the first time around.
    if count == 1: 
        status = router.getR2C().subscribe(60, router2EventHandlerOutgoing, evtype=eventType, source=eventSource)    ## R2C subscribes to all interested events (e.g. eventType)
    # Publish the event to Router1Console
    status2 = router.getR1().publish(router2EventHandlerOutgoing, event) ## R1 publishes the main event, R2C picks it up and forwards it to TestEventHTTPRouter1Console.py
    rootlogger.warn("== Router 2 sent out event ==")
Exemplo n.º 39
0
    def testMakeEvent(self):
        self._log.debug("\ntestMakeEvent")

        newEvent = makeNewEvent(
            {
                "type": "newtype",
                "source": "newsource",
                "other_data": {"data": "data", "data1": "data1", "data2": "data2"},
                "copy_other_data": {"data1": "data1", "data2": "data2"},
            },
            makeEvent("oldType", "oldSource", {"data1": "olddata1"}),
            {"data2": "xtradata2"},
        )

        self.assertNotEqual(newEvent, None)
        self.assertEqual(newEvent.getType(), "newtype")
        self.assertEqual(newEvent.getSource(), "newsource")
        od = newEvent.getPayload()
        self.assertEqual(od["data"], "data")
        self.assertEqual(od["data1"], "olddata1")
        self.assertEqual(od["data2"], "xtradata2")
Exemplo n.º 40
0
    def testWriteLocalCustomPayload(self):
        """
        Test what happens when we start a write event with a custom payload to a Local serial port.
        """
        self._log.debug( "\n\n-------------------------------testWriteLocalCustomPayLoad-------------------------------" )
        testCfg = getDictFromXmlString(testConfigLocal)
        self._log.debug( "testCfg %s" % testCfg )

        eh = Serial(self._router)
        self.assertNotEqual( eh, None)
        eh.configure(testCfg['eventInterface'])
        eh.start()
        testEvent = makeEvent( 'internal/test/serial', 'serial/test/2', {'cmd':'write','data':'66;67;68:','address':'serial-2'} )
        eh.handleEvent( testEvent )
        time.sleep(2)
        portlist = eh.getSerialPorts()      
        self._log.debug(portlist)
        self.assertEqual( len(self._router._pubs), 1 )
        self.assertEqual( self._router._pubs[0][1].getType(), "http://id.webbrick.co.uk/events/serial/receive" )
        self.assertEqual( self._router._pubs[0][1].getSource(), "serial-2/receive" )
        self.assertEqual( self._router._pubs[0][1].getPayload()['data'], "66;67;68:" )
        eh.stop()     
Exemplo n.º 41
0
    def testMakeEventSubsitution(self):
        self._log.debug("\ntestMakeEventSubsitution")

        newEvent = makeNewEvent(
            {
                "type": "%(Newtype)s",
                "source": "%(Newsource)s",
                "other_data": {"data": "data", "data1": "TEST%(Subdata)sTEST", "data2": "data2"},
            },
            makeEvent(
                "oldType",
                "oldSource",
                {"data1": "olddata1", "Newtype": "SubType", "Newsource": "SubSource", "Subdata": "SUBBEDDATA"},
            ),
            {"data2": "xtradata2"},
        )
        print newEvent
        self.assertNotEqual(newEvent, None)
        self.assertEqual(newEvent.getType(), "SubType")
        self.assertEqual(newEvent.getSource(), "SubSource")
        od = newEvent.getPayload()
        self.assertEqual(od["data"], "data")
        self.assertEqual(od["data1"], "TESTSUBBEDDATATEST")
Exemplo n.º 42
0
 def setUp(self):
     self.ev = makeEvent("s://auth.b/path/type/d#frag",
                         "s://auth.b/path/source/d#frag", "--- payload ---")
     self.env = EventEnvelope(self.ev, "R1").nextHop("R2").nextHop("R3")
     return
Exemplo n.º 43
0
 def setUp(self):
     self.evt = makeEvent("evtype", "evsource", "payload")
     self.env1 = EventEnvelope(self.evt, "R1")
     self.env2 = self.env1.nextHop("R2")
     self.env3 = self.env2.nextHop("R3")
     return
Exemplo n.º 44
0
 def testSubscriptionForwarding2(self):
     evmatch = makeEvent(evtype="R2Events/ev1",source="R2Source/src1")
     evdrop  = makeEvent(evtype="R2Events/ev2",source="R2Source/src2")
     self.doSubscriptionForwardingR1R2(None, "R2Source/src1", evmatch, evdrop)
     return
Exemplo n.º 45
0
 def setUp(self):
     self.evt = makeEvent("evtype", "evsource", "payload")
     self.env1 = EventEnvelope(self.evt, "R1")
     self.env2 = self.env1.nextHop("R2")
     self.env3 = self.env2.nextHop("R3")
     return
Exemplo n.º 46
0
 def testSubscriptionForwarding3(self):
     Info("---- testSubscriptionForwarding3 ----","EventLib.TestEventHTTPClient")
     evmatch = makeEvent(evtype="R3Events1/ev1",source="R3Source1/src1")
     evdrop  = makeEvent(evtype="R3Events1/ev2",source="R3Source1/src2")
     self.doSubscriptionForwardingR2R3("R3Events1/ev1", "R3Source1/src1", evmatch, evdrop)
     return
Exemplo n.º 47
0
 def testSubscriptionForwarding4(self):
     Info("---- testSubscriptionForwarding4 ----","EventLib.TestEventHTTPClient")
     evmatch = makeEvent(evtype="RREvents3/ev1",source="RRSource3/src1")
     evdrop  = makeEvent(evtype="RREvents3/ev2",source="RRSource3/src2")
     self.doSubscriptionForwardingR2R3("RREvents3/ev1", "RRSource3/src1", evmatch, evdrop, r1fwd=1)
     return
Exemplo n.º 48
0
 def testSubscriptionForwarding7(self):
     evmatch = makeEvent(evtype="R3Events1/ev1",source="R3Source1/src1")
     evdrop  = makeEvent(evtype="R3Events1/ev2",source="R3Source1/src2")
     self.doSubscriptionForwardingR2R3("R3Events1/ev1", "R3Source1/src1", evmatch, evdrop)
     return
Exemplo n.º 49
0
# Copyright L.P.Klyne 2013 
# Licenced under 3 clause BSD licence 

# $Id: Events.py 3738 2010-10-01 15:04:17Z andy.harris $
#
# Some test Events
# 
import threading, sys, time

from EventLib.Event import Event, makeEvent

# Some test events that can be sent.

evtTD0 = makeEvent( 'http://id.webbrick.co.uk/events/webbrick/TD', 'webbrick/100/TD/0', {'tgtChannel': 0, 'srcChannel': 0, 'val': 1, 'setPoint': 0, 'fromNode': 100, 'udpType': 'G', 'version': 6, 'action': 1, 'dwell': 0, 'pktType': 'TD', 'ipAdr': '10.100.100.100'} )
evtTD1 = makeEvent( 'http://id.webbrick.co.uk/events/webbrick/TD', 'webbrick/100/TD/1', {'tgtChannel': 0, 'srcChannel': 0, 'val': 1, 'setPoint': 0, 'fromNode': 100, 'udpType': 'G', 'version': 6, 'action': 1, 'dwell': 0, 'pktType': 'TD', 'ipAdr': '10.100.100.100'} )
evtDO_0_off = makeEvent( 'http://id.webbrick.co.uk/events/webbrick/DO', 'webbrick/100/DO/0', { 'state':'0' } )
evtDO_1_off = makeEvent( 'http://id.webbrick.co.uk/events/webbrick/DO', 'webbrick/100/DO/1', { 'state':'0' } )
evtDO_2_off = makeEvent( 'http://id.webbrick.co.uk/events/webbrick/DO', 'webbrick/100/DO/2', { 'state':'0' } )
evtDO_0_on = makeEvent( 'http://id.webbrick.co.uk/events/webbrick/DO', 'webbrick/100/DO/0', { 'state':'1' } )
evtDO_1_on = makeEvent( 'http://id.webbrick.co.uk/events/webbrick/DO', 'webbrick/100/DO/1', { 'state':'1' } )
evtDO_2_on = makeEvent( 'http://id.webbrick.co.uk/events/webbrick/DO', 'webbrick/100/DO/2', { 'state':'1' } )
evtDI_0_off = makeEvent( 'http://id.webbrick.co.uk/events/webbrick/DI', 'webbrick/100/DI/0', { 'state':'0' } )
evtDI_1_off = makeEvent( 'http://id.webbrick.co.uk/events/webbrick/DI', 'webbrick/100/DI/1', { 'state':'0' } )
evtDI_0_on = makeEvent( 'http://id.webbrick.co.uk/events/webbrick/DI', 'webbrick/100/DI/0', { 'state':'1' } )
evtDI_1_on = makeEvent( 'http://id.webbrick.co.uk/events/webbrick/DI', 'webbrick/100/DI/1', { 'state':'1' } )

#
#  AnalogueIn events
#

evtAI_0_10 = makeEvent( 'http://id.webbrick.co.uk/events/webbrick/AI', 'webbrick/100/AI/0', { 'srcChannel': 0, 'curhi': 99.0, 'val': 10.0, 'fromNode': 100, 'curlo': 98.0, 'defhi': 99, 'deflo': 98} )
Exemplo n.º 50
0
 def testMakeEvent1(self):
     e = makeEvent("EventTypeUri", "EventSourceUri", "payload")
     assert e.getType() == "EventTypeUri", "testMakeEvent1, getType"
     assert e.getSource() == "EventSourceUri", "testMakeEvent1, getSource"
     assert e.getPayload() == "payload", "testMakeEvent1, getPayload"
Exemplo n.º 51
0
 def testEventEqual6(self):
     e2 = makeEvent(evtype="EventTypeUri",
                    source="EventSourceUri2",
                    payload="payload")
     self.assertNotEqual(None, e2, "testEventEqual6")
Exemplo n.º 52
0
 def testSubscriptionForwarding8(self):
     evmatch = makeEvent(evtype="RREvents3/ev1",source="RRSource3/src1")
     evdrop  = makeEvent(evtype="RREvents3/ev2",source="RRSource3/src2")
     self.doSubscriptionForwardingR2R3("RREvents3/ev1", "RRSource3/src1", evmatch, evdrop, r1fwd=1)
     return
Exemplo n.º 53
0
 def testEventEqual2(self):
     e1 = Event("EventTypeUri", "", None)
     e2 = makeEvent(evtype="EventTypeUri")
     self.assertEqual(e1, e2, "testEventEqual2")
Exemplo n.º 54
0
 def testEventEqual5(self):
     e1 = Event("EventTypeUri", "EventSourceUri", "payload1")
     e2 = makeEvent(evtype="EventTypeUri", source="EventSourceUri", payload="payload2")
     self.assertNotEqual(e1, e2, "testEventEqual5")