本文整理汇总了Python中assimevent.AssimEvent.enable_all_observers方法的典型用法代码示例。如果您正苦于以下问题:Python AssimEvent.enable_all_observers方法的具体用法?Python AssimEvent.enable_all_observers怎么用?Python AssimEvent.enable_all_observers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类assimevent.AssimEvent
的用法示例。
在下文中一共展示了AssimEvent.enable_all_observers方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_simple_init_bad
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import enable_all_observers [as 别名]
def test_simple_init_bad(self):
'Perform a few simple AssimEvent bad initializations'
AssimEvent.enable_all_observers()
AssimEvent.observers = []
observer=DummyObserver()
badobserver=BadObserver()
AssimEvent.registerobserver(observer)
self.assertRaises(ValueError, AssimEvent, 'first', 999)
self.assertRaises(AttributeError, AssimEvent.registerobserver, badobserver)
示例2: test_fork_exec_event
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import enable_all_observers [as 别名]
def test_fork_exec_event(self):
'''This test will create a fork/exec event observer script
and then test to see if its getting invoked properly...
'''
AssimEvent.enable_all_observers()
tmpdir = tempfile.mkdtemp('.d', 'testexec_')
(fd, pathname) = tempfile.mkstemp('.out.txt')
execscript = os.path.join(tmpdir, 'observer.sh')
makescript(execscript, pathname)
AssimEvent.observers = []
observer=ForkExecObserver(scriptdir=tmpdir)
dummyclient = ClientClass()
dummyclient.fred='fred'
dummyclient.sevenofnine='Annika'
dummyclient.foo = {'foo': 'bar'}
self.assertEqual(observer.listscripts(), [execscript,])
AssimEvent.registerobserver(observer)
AssimEvent(dummyclient, AssimEvent.CREATEOBJ)
AssimEvent(dummyclient, AssimEvent.OBJUP, extrainfo={'origaddr': '10.10.10.254'})
os.close(fd)
expectedcontent=\
'''====START====
ARG1=create
ARG2=ClientClass
ASSIM_fred=fred
ASSIM_nodetype=ClientClass
ASSIM_sevenofnine=Annika
==== JSON START ====
{"associatedobject":{"foo":{"foo":"bar"},"fred":"fred","nodetype":"ClientClass","sevenofnine":"Annika"},"eventtype":0,"extrainfo":null}
==== JSON END ====
====END====
====START====
ARG1=up
ARG2=ClientClass
ASSIM_fred=fred
ASSIM_nodetype=ClientClass
ASSIM_origaddr=10.10.10.254
ASSIM_sevenofnine=Annika
==== JSON START ====
{"associatedobject":{"foo":{"foo":"bar"},"fred":"fred","nodetype":"ClientClass","sevenofnine":"Annika"},"eventtype":1,"extrainfo":{"origaddr":"10.10.10.254"}}
==== JSON END ====
====END====
'''
TestAssimEvent.waitfor(pathname, expectedcontent)
f=open(pathname, 'r')
content=f.read()
f.close()
self.assertEqual(content, expectedcontent)
os.unlink(execscript)
os.unlink(pathname)
os.rmdir(tmpdir)
示例3: test_fork_exec_killchild
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import enable_all_observers [as 别名]
def test_fork_exec_killchild(self):
'''This test will create a fork/exec event observer script
and then kill the child listener and verify that it is handled
correctly.
'''
AssimEvent.enable_all_observers()
tmpdir = tempfile.mkdtemp('.d', 'testexec_')
(fd, pathname) = tempfile.mkstemp('.out.txt')
execscript = os.path.join(tmpdir, 'observer.sh')
makescript(execscript, pathname)
AssimEvent.observers = []
observer=ForkExecObserver(scriptdir=tmpdir)
dummyclient = ClientClass()
dummyclient.fred='fred'
dummyclient.sevenofnine='Annika'
dummyclient.foo = {'foo': 'bar'}
AssimEvent.registerobserver(observer)
try:
os.kill(observer.childpid, signal.SIGKILL)
except OSError:
# "docker build" doesn't let us kill processes...
# so we give up on this test and call it good...
os.unlink(execscript)
os.unlink(pathname)
os.rmdir(tmpdir)
return
time.sleep(0.1)
AssimEvent(dummyclient, AssimEvent.CREATEOBJ)
# Death of our FIFO child will cause it to get respawned, and
# message sent to new child. No messages should be lost.
expectedcontent=\
'''====START====
ARG1=create
ARG2=ClientClass
ASSIM_fred=fred
ASSIM_nodetype=ClientClass
ASSIM_sevenofnine=Annika
==== JSON START ====
{"associatedobject":{"foo":{"foo":"bar"},"fred":"fred","nodetype":"ClientClass","sevenofnine":"Annika"},"eventtype":0,"extrainfo":null}
==== JSON END ====
====END====
'''
TestAssimEvent.waitfor(pathname, expectedcontent)
f=open(pathname, 'r')
content=f.read()
f.close()
self.assertEqual(content, expectedcontent)
os.close(fd)
os.unlink(execscript)
os.unlink(pathname)
os.rmdir(tmpdir)
示例4: test_simple_init_good
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import enable_all_observers [as 别名]
def test_simple_init_good(self):
'Perform a few simple AssimEvent good initializations'
AssimEvent.enable_all_observers()
AssimEvent.observers = []
observer=DummyObserver()
AssimEvent.registerobserver(observer)
event1 = AssimEvent('first', AssimEvent.CREATEOBJ)
self.assertEqual(len(observer.events), 1)
self.assertTrue(observer.events[0], event1)
self.assertEqual(AssimEvent.unregisterobserver(observer), True)
event2 = AssimEvent('second', AssimEvent.CREATEOBJ)
self.assertEqual(len(observer.events), 1)
self.assertTrue(observer.events[0], event1)
AssimEvent.registerobserver(observer)
event3 = AssimEvent('third', AssimEvent.CREATEOBJ)
self.assertEqual(len(observer.events), 2)
self.assertTrue(observer.events[0], event3)
示例5: makescript
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import enable_all_observers [as 别名]
# You should have received a copy of the GNU General Public License
# along with the Assimilation Project software. If not, see http://www.gnu.org/licenses/
#
#
_suites = ['all', 'events']
import sys
sys.path.append("../cma")
sys.path.append("/usr/local/lib/python2.7/dist-packages")
from testify import *
import os, sys, tempfile, time, signal
from assimevent import AssimEvent
from assimeventobserver import ForkExecObserver
DEBUG=False
AssimEvent.enable_all_observers()
def makescript(createdscriptname, outfile):
'Create the requested script - outputting to requested file'
script='''#!/bin/sh
# Simple script to test external event interfaces
( echo "====START===="
j=1
for arg
do
echo "ARG${j}=$arg"
j=$(expr $j + 1)
done
env | grep '^ASSIM_' | LC_ALL=C sort
echo "==== JSON START ===="
cat