本文整理汇总了Python中assimevent.AssimEvent类的典型用法代码示例。如果您正苦于以下问题:Python AssimEvent类的具体用法?Python AssimEvent怎么用?Python AssimEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AssimEvent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: ioerror
def ioerror(self, unusedevent):
'''This function gets called when we get an I/O error writing to the FIFO.
This is likely an EPIPE (broken pipe) error.
'''
unusedevent = unusedevent # Make pylint happy...
if self.maxerrcount is not None and self.errcount > self.maxerrcount:
AssimEvent.unregisterobserver(self)
开发者ID:borgified,项目名称:assimilation,代码行数:7,代码来源:assimeventobserver.py
示例2: test_automonitor_LSB_failures
def test_automonitor_LSB_failures(self):
AssimEvent.disable_all_observers()
self.assertRaises(ValueError, LSBMonitoringRule, "neo4j-service", [])
self.assertRaises(ValueError, LSBMonitoringRule, "neo4j-service", (("a.b.c", ")"),))
self.assertRaises(ValueError, LSBMonitoringRule, "neo4j-service", ((1, 2, 3, 4, 5),))
self.assertRaises(ValueError, LSBMonitoringRule, "neo4j-service", ((1,),))
self.assertRaises(ValueError, LSBMonitoringRule, "neo4j-service", ((),))
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:7,代码来源:cma_test.py
示例3: test_automonitor_strings_basic
def test_automonitor_strings_basic(self):
# Clean things out so we only see what we want to see...
AssimEvent.disable_all_observers()
ocf_string = '''{
# comment
"class": "ocf",
"type": "neo4j",
"provider": "assimilation",
"classconfig": [
[null, "@basename()", "java$"],
[null, "$argv[-1]", "org\\.neo4j\\.server\\.Bootstrapper$"],
["PORT", "serviceport", "[0-9]+$"],
["NEOHOME", "@argequals(-Dneo4j.home)", "/.*"]
]
}'''
ocf = MonitoringRule.ConstructFromString(ocf_string)
self.assertTrue(isinstance(ocf, OCFMonitoringRule))
lsb_string = '''{
# comment
"class": "lsb",
"type": "neo4j",
"classconfig": [
["@basename()", "java$"],
["$argv[-1]", "org\\.neo4j\\.server\\.Bootstrapper$"],
]
}'''
lsb = MonitoringRule.ConstructFromString(lsb_string)
self.assertTrue(isinstance(lsb, LSBMonitoringRule))
开发者ID:carrieao,项目名称:assimilation-official,代码行数:28,代码来源:cma_test.py
示例4: __init__
def __init__(self, constraints):
'''Initializer for AssimEventObserver class.
Parameters:
-----------
constraints: dict-like *or* callable() returning bool
A dict describing our desired events. The constraints in the dict are
effectively ANDed together. Each key is an attribute name in either
the event itself or its associated object. The value associated with
each attribute is either a list or a scalar value or something
implementing __contains__. A scalar value implies that it *must* have exactly
that value, otherwise it must be *in* the associated list/tuple/etc.
This should be able to constrain the type of event we're looking at, the
type of event-object we're looking at, and the domain of the event-object -
and lots of other potentially useful things.
See the "is_interesting" method below for implementation details...
If 'constraints' is a callable (that is, callable(constraints) is True), then
we will just call constraints(event) to see if the event is interesting to
this observer. Whatever 'constraints' returns will be interpreted in a
boolean context - so returning a bool would be a good idea...
'''
self.constraints = constraints
AssimEvent.registerobserver(self)
开发者ID:JJediny,项目名称:assimilation-official,代码行数:26,代码来源:assimeventobserver.py
示例5: test_simple_init_bad
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)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:9,代码来源:assimevent_test.py
示例6: test_fork_exec_event
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)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:52,代码来源:assimevent_test.py
示例7: test_fork_exec_killchild
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)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:51,代码来源:assimevent_test.py
示例8: test_eof
def test_eof(self):
'Get EOF with empty input'
if BuildListOnly: return
if DEBUG:
print >> sys.stderr, 'Running test_test_eof()'
AssimEvent.disable_all_observers()
framesets=[]
io = TestIO(framesets, 0)
CMAinit(io, cleanoutdb=True, debug=DEBUG)
# just make sure it seems to do the right thing
(foo, bar) = io.recvframesets()
assert foo is None
del io
assert_no_dangling_Cclasses()
开发者ID:carrieao,项目名称:assimilation-official,代码行数:14,代码来源:cma_test.py
示例9: test_get1pkt
def test_get1pkt(self):
'Read a single packet'
if BuildListOnly: return
if DEBUG:
print >> sys.stderr, 'Running test_test_eof()'
AssimEvent.disable_all_observers()
otherguy = pyNetAddr([1,2,3,4],)
strframe1=pyCstringFrame(FrameTypes.CSTRINGVAL, "Hello, world.")
fs = pyFrameSet(42)
fs.append(strframe1)
framesets=((otherguy, (strframe1,)),)
io = TestIO(framesets, 0)
CMAinit(io, cleanoutdb=True, debug=DEBUG)
gottenfs = io.recvframesets()
self.assertEqual(len(gottenfs), 2)
self.assertEqual(gottenfs, framesets[0])
gottenfs = io.recvframesets()
self.assertEqual(len(gottenfs), 2)
assert gottenfs[0] is None
io.cleanio()
del io
开发者ID:carrieao,项目名称:assimilation-official,代码行数:21,代码来源:cma_test.py
示例10: __init__
def __init__(self, constraints):
'''Initializer for AssimEventObserver class.
Parameters:
-----------
constraints: dict
A dict describing our desired events. The constraints in the dict are
effectively ANDed together. Each key is an attribute name in either
the event itself or its associated object. The value associated with
each attribute is either a list or a scalar value. A list implies that
any one of those values is acceptable. A scalar value implies that it
*must* have that value.
This should be able to constrain the type of event we're looking at, the
type of event-object we're looking at, and the domain of the event-object -
and lots of other potentially useful things.
See the "is_interesting" method below for implementation details...
'''
self.constraints = constraints
AssimEvent.registerobserver(self)
开发者ID:borgified,项目名称:assimilation,代码行数:21,代码来源:assimeventobserver.py
示例11: test_echo1pkt
def test_echo1pkt(self):
'Read a packet and write it back out'
if BuildListOnly: return
if DEBUG:
print >> sys.stderr, 'Running test_echo1pkt()'
AssimEvent.disable_all_observers()
strframe1=pyCstringFrame(FrameTypes.CSTRINGVAL, "Hello, world.")
fs = pyFrameSet(42)
fs.append(strframe1)
otherguy = pyNetAddr([1,2,3,4],)
framesets=((otherguy, (strframe1,)),)
io = TestIO(framesets, 0)
CMAinit(io, cleanoutdb=True, debug=DEBUG)
fslist = io.recvframesets() # read in a packet
self.assertEqual(len(fslist), 2)
self.assertEqual(fslist, framesets[0])
io.sendframesets(fslist[0], fslist[1]) # echo it back out
self.assertEqual(len(io.packetswritten), len(framesets))
gottenfs = io.recvframesets()
self.assertEqual(len(gottenfs), 2)
assert gottenfs[0] is None
io.cleanio()
del io
开发者ID:carrieao,项目名称:assimilation-official,代码行数:23,代码来源:cma_test.py
示例12: test_simple_init_good
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)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:17,代码来源:assimevent_test.py
示例13: disabled
if t2 < 10: t2 = 10
t3 = t2
if not DoAudit:
print >> sys.stderr, 'WARNING: Audits suppressed.'
if not doHBDEAD:
print >> sys.stderr, 'WARNING: Server death tests disabled.'
if not CheckForDanglingClasses:
print >> sys.stderr, 'WARNING: Memory Leak Detection disabled.'
elif not AssertOnDanglingClasses:
print >> sys.stderr, 'WARNING: Memory Leak assertions disabled (detection still enabled).'
#gc.set_threshold(t1, t2, t3)
AssimEvent.disable_all_observers()
def assert_no_dangling_Cclasses(doassert=None):
global CheckForDanglingClasses
global WorstDanglingCount
sys._clear_type_cache()
if doassert is None:
doassert = AssertOnDanglingClasses
CMAinit.uninit()
gc.collect() # For good measure...
count = proj_class_live_object_count()
#print >>sys.stderr, "CHECKING FOR DANGLING CLASSES (%d)..." % count
# Avoid cluttering the output up with redundant messages...
if count > WorstDanglingCount and CheckForDanglingClasses:
WorstDanglingCount = count
if doassert:
开发者ID:carrieao,项目名称:assimilation-official,代码行数:31,代码来源:cma_test.py
示例14: test_startup
def test_startup(self):
'''A semi-interesting test: We send a STARTUP message and get back a
SETCONFIG message with lots of good stuff in it.
and for good measure, we also send along some discovery packets.
'''
if BuildListOnly: return
if DEBUG:
print >> sys.stderr, 'Running test_startup()'
AssimEvent.disable_all_observers()
from dispatchtarget import DispatchTarget
droneid = 1
droneip = droneipaddress(droneid)
designation = dronedesignation(droneid)
designationframe=pyCstringFrame(FrameTypes.HOSTNAME, designation)
dronediscovery=hostdiscoveryinfo(droneid)
discoveryframe=pyCstringFrame(FrameTypes.JSDISCOVER, dronediscovery)
fs = pyFrameSet(FrameSetTypes.STARTUP)
fs.append(designationframe)
fs.append(discoveryframe)
fs2 = pyFrameSet(FrameSetTypes.JSDISCOVERY)
osdiscovery=pyCstringFrame(FrameTypes.JSDISCOVER, self.OS_DISCOVERY)
fs2.append(osdiscovery)
fs3 = pyFrameSet(FrameSetTypes.JSDISCOVERY)
ulimitdiscovery=pyCstringFrame(FrameTypes.JSDISCOVER, self.ULIMIT_DISCOVERY)
fs3.append(ulimitdiscovery)
fsin = ((droneip, (fs,)), (droneip, (fs2,)), (droneip, (fs3,)))
io = TestIO(fsin,0)
#print >> sys.stderr, 'CMAinit: %s' % str(CMAinit)
#print >> sys.stderr, 'CMAinit.__init__: %s' % str(CMAinit.__init__)
OurAddr = pyNetAddr((127,0,0,1),1984)
configinit = geninitconfig(OurAddr)
config = pyConfigContext(init=configinit)
io.config = config
CMAinit(io, cleanoutdb=True, debug=DEBUG)
CMAdb.io.config = config
assimcli_check('loadqueries')
disp = MessageDispatcher(DispatchTarget.dispatchtable, encryption_required=False)
listener = PacketListener(config, disp, io=io, encryption_required=False)
io.mainloop = listener.mainloop
TestIO.mainloop = listener.mainloop
# We send the CMA an intial STARTUP packet
listener.listen()
# Let's see what happened...
#print >> sys.stderr, ('READ: %s' % io.packetsread)
#print >> sys.stderr, ('WRITTEN: %s' % len(io.packetswritten))
#print >> sys.stderr, ('PACKETS WRITTEN: %s' % str(io.packetswritten))
self.assertEqual(len(io.packetswritten), 2) # Did we send out four packets?
# Note that this change over time
# As we change discovery...
self.assertEqual(io.packetsread, 3) # Did we read 3 packets?
AUDITS().auditSETCONFIG(io.packetswritten[0], droneid, configinit)
assimcli_check("query allips", 1)
assimcli_check("query allservers", 1)
assimcli_check("query findip %s" % str(droneip), 1)
assimcli_check("query shutdown", 0)
assimcli_check("query crashed", 0)
assimcli_check("query unknownips", 0)
CMAdb.io.config = config
Drones = CMAdb.store.load_cypher_nodes("START n=node:Drone('*:*') RETURN n", Drone)
Drones = [drone for drone in Drones]
for drone in Drones:
self.check_discovery(drone, (dronediscovery, self.OS_DISCOVERY, self.ULIMIT_DISCOVERY))
self.assertEqual(len(Drones), 1) # Should only be one drone
io.config = None
io.cleanio()
del io
del ulimitdiscovery, osdiscovery, Drones
DispatchTarget.dispatchtable = {}
del DispatchTarget
开发者ID:carrieao,项目名称:assimilation-official,代码行数:71,代码来源:cma_test.py
示例15: test_automonitor_functions
def test_automonitor_functions(self):
AssimEvent.disable_all_observers()
MonitoringRule.monitor_objects = {'service': {}, 'host':{}}
drone = FakeDrone({
'data': {
'ocf': {
'assimilation/neo4j',
},
'lsb': {
'bacula',
},
}
})
ocf_string = '''{
"class": "ocf", "type": "neo4j", "provider": "assimilation",
"classconfig": [
["classpath", "@flagvalue(-cp)"],
["ipaddr", "@serviceip($procinfo.listenaddrs)"],
["port", "@serviceport()", "[0-9]+$"]
]
}'''
ssh_json = '''{
"exe": "/usr/sbin/sshd",
"argv": [ "/usr/sbin/sshd", "-D" ],
"uid": "root",
"gid": "root",
"cwd": "/",
"listenaddrs": {
"0.0.0.0:22": {
"proto": "tcp",
"addr": "0.0.0.0",
"port": 22
},
":::22": {
"proto": "tcp6",
"addr": "::",
"port": 22
}
}
}'''
neo4j_json = '''{
"exe": "/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java",
"argv": [ "/usr/bin/java", "-cp", "/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar: ...", "-server", "-XX:+DisableExplicitGC", "-Dorg.neo4j.server.properties=conf/neo4
j-server.properties", "-Djava.util.logging.config.file=conf/logging.properties", "-Dlog4j.configuration=file:conf/log4j.properties", "-XX:
+UseConcMarkSweepGC", "-XX:+CMSClassUnloadingEnabled", "-Dneo4j.home=/var/lib/neo4j", "-Dneo4j.instance=/var/lib/neo4j", "-Dfile.encoding=
UTF-8", "org.neo4j.server.Bootstrapper" ],
"uid": "neo4j",
"gid": "neo4j",
"cwd": "/var/lib/neo4j",
"listenaddrs": {
":::1337": {
"proto": "tcp6",
"addr": "::",
"port": 1337
},
":::39185": {
"proto": "tcp6",
"addr": "::",
"port": 39185
}
}
}'''
bacula_json = '''{
"exe": "/usr/sbin/bacula-dir",
"argv": [ "/usr/sbin/bacula-dir", "-c", "/etc/bacula/bacula-dir.conf", "-u", "bacula", "-g", "bacula" ],
"uid": "bacula",
"gid": "bacula",
"cwd": "/",
"listenaddrs": {
"10.10.10.5:9101": {
"proto": "tcp",
"addr": "10.10.10.5",
"port": 9101
}
}
}'''
MonitoringRule.ConstructFromString(ocf_string)
neoargs = pyConfigContext(neo4j_json)['argv']
testnode = ProcessNode('global', 'foofred', 'fred', '/usr/bin/java', neoargs
, 'root', 'root', '/', roles=(CMAconsts.ROLE_server,))
testnode.procinfo = neo4j_json
context = ExpressionContext((testnode, drone))
(prio, match) = MonitoringRule.findbestmatch(context)
self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
self.assertEqual(match['arglist']['ipaddr'], '::1')
self.assertEqual(match['arglist']['port'], '1337')
testnode.procinfo = ssh_json
context = ExpressionContext((testnode, drone))
(prio, match) = MonitoringRule.findbestmatch(context)
self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
self.assertEqual(match['arglist']['port'], '22')
self.assertEqual(match['arglist']['ipaddr'], '127.0.0.1')
testnode.procinfo = bacula_json
context = ExpressionContext((testnode, drone))
(prio, match) = MonitoringRule.findbestmatch(context)
self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
self.assertEqual(match['arglist']['port'], '9101')
#.........这里部分代码省略.........
开发者ID:carrieao,项目名称:assimilation-official,代码行数:101,代码来源:cma_test.py
示例16: test_automonitor_search_basic
def test_automonitor_search_basic(self):
AssimEvent.disable_all_observers()
drone = FakeDrone({
'data': {
'ocf': {
'assimilation/neo4j',
},
'lsb': {
'neo4j-service',
}
}
})
MonitoringRule.monitor_objects = {'service': {}, 'host':{}}
ocf_string = '''{
"class": "ocf", "type": "neo4j", "provider": "assimilation",
"classconfig": [
[null, "@basename()", "java$"],
[null, "$argv[-1]", "org\\.neo4j\\.server\\.Bootstrapper$"],
["PORT", "$serviceport"],
["NEOHOME", "@argequals(-Dneo4j.home)", "/.*"]
]
}'''
MonitoringRule.ConstructFromString(ocf_string)
lsb_string = '''{
"class": "lsb", "type": "neo4j-service",
"classconfig": [
["@basename()", "java$"],
["$argv[-1]", "org\\.neo4j\\.server\\.Bootstrapper$"],
]
}'''
MonitoringRule.ConstructFromString(lsb_string)
neoprocargs = ("/usr/bin/java", "-cp"
, "/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:"
"AND SO ON:"
"/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:"
"/var/lib/neo4j/conf/", "-server", "-XX:"
"+DisableExplicitGC"
, "-Dneo4j.home=/var/lib/neo4j"
, "-Dneo4j.instance=/var/lib/neo4j"
, "-Dfile.encoding=UTF-8"
, "org.neo4j.server.Bootstrapper")
neonode = ProcessNode('global', 'foofred', 'fred', '/usr/bin/java', neoprocargs
, 'root', 'root', '/', roles=(CMAconsts.ROLE_server,))
#neonode.serviceport=7474
context = ExpressionContext((neonode, drone))
first = MonitoringRule.findbestmatch(context)
second = MonitoringRule.findbestmatch(context, False)
list1 = MonitoringRule.findallmatches(context)
neonode.serviceport=7474
third = MonitoringRule.findbestmatch(context)
list2 = MonitoringRule.findallmatches(context)
# first should be the LSB instance
self.assertEqual(first[1]['monitorclass'], 'lsb')
self.assertEqual(first[0], MonitoringRule.LOWPRIOMATCH)
# second should be the incomplete OCF instance
self.assertEqual(second[1]['monitorclass'], 'ocf')
self.assertEqual(second[0], MonitoringRule.PARTMATCH)
# third should be the high priority OCF instance
self.assertEqual(third[1]['monitorclass'], 'ocf')
self.assertEqual(third[0], MonitoringRule.HIGHPRIOMATCH)
# list1 should be the incomplete OCF and the complete LSB - in that order
self.assertEqual(len(list1), 2)
# They should come out sorted by monitorclass
self.assertEqual(list1[0][0], MonitoringRule.LOWPRIOMATCH)
self.assertEqual(list1[0][1]['monitorclass'], 'lsb')
self.assertEqual(list1[1][0], MonitoringRule.PARTMATCH)
self.assertEqual(list1[1][1]['monitorclass'], 'ocf')
# third should be a complete OCF match
# list2 should be the complete OCF and the complete OCF - in that order
self.assertEqual(len(list2), 2)
self.assertEqual(list2[0][0], MonitoringRule.LOWPRIOMATCH)
self.assertEqual(list2[0][1]['monitorclass'], 'lsb')
self.assertEqual(list2[1][0], MonitoringRule.HIGHPRIOMATCH)
self.assertEqual(list2[1][1]['monitorclass'], 'ocf')
开发者ID:carrieao,项目名称:assimilation-official,代码行数:76,代码来源:cma_test.py
示例17: test_automonitor_LSB_basic
def test_automonitor_LSB_basic(self):
AssimEvent.disable_all_observers()
drone = FakeDrone({"data": {"lsb": {"ssh", "neo4j-service"}}})
neoargs = (
("$argv[0]", r".*/[^/]*java[^/]*$"), # Might be overkill
("$argv[3]", r"-server$"), # Probably overkill
("$argv[-1]", r"org\.neo4j\.server\.Bootstrapper$"),
)
neorule = LSBMonitoringRule("neo4j-service", neoargs)
sshnode = ProcessNode(
"global",
"foofred",
"fred",
"/usr/bin/sshd",
["/usr/bin/sshd", "-D"]
# ProcessNode:
# (domain, host, nodename, pathname, argv, uid, gid, cwd, roles=None):
,
"root",
"root",
"/",
roles=(CMAconsts.ROLE_server,),
)
sshargs = (
# This means one of our nodes should have a value called
# pathname, and it should end in '/sshd'
("@basename()", "sshd$"),
)
sshrule = LSBMonitoringRule("ssh", sshargs)
udevnode = ProcessNode(
"global",
"foofred",
"fred",
"/usr/bin/udevd",
["/usr/bin/udevd"],
"root",
"root",
"/",
roles=(CMAconsts.ROLE_server,),
)
neoprocargs = (
"/usr/bin/java",
"-cp",
"/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:"
"AND SO ON:"
"/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:"
"/var/lib/neo4j/conf/",
"-server",
"-XX:" "+DisableExplicitGC",
"-Dorg.neo4j.server.properties=conf/neo4j-server.properties",
"-Djava.util.logging.config.file=conf/logging.properties",
"-Dlog4j.configuration=file:conf/log4j.properties",
"-XX:+UseConcMarkSweepGC",
"-XX:+CMSClassUnloadingEnabled",
"-Dneo4j.home=/var/lib/neo4j",
"-Dneo4j.instance=/var/lib/neo4j",
"-Dfile.encoding=UTF-8",
"org.neo4j.server.Bootstrapper",
)
neonode = ProcessNode(
"global",
"foofred",
"fred",
"/usr/bin/java",
neoprocargs,
"root",
"root",
"/",
roles=(CMAconsts.ROLE_server,),
)
for tup in (
sshrule.specmatch(ExpressionContext((udevnode, drone))),
sshrule.specmatch(ExpressionContext((neonode, drone))),
neorule.specmatch(ExpressionContext((sshnode, drone))),
):
(prio, table) = tup
self.assertEqual(prio, MonitoringRule.NOMATCH)
self.assertTrue(table is None)
(prio, table) = sshrule.specmatch(ExpressionContext((sshnode, drone)))
self.assertEqual(prio, MonitoringRule.LOWPRIOMATCH)
self.assertEqual(table["monitorclass"], "lsb")
self.assertEqual(table["monitortype"], "ssh")
(prio, table) = neorule.specmatch(ExpressionContext((neonode, drone)))
self.assertEqual(prio, MonitoringRule.LOWPRIOMATCH)
self.assertEqual(table["monitorclass"], "lsb")
self.assertEqual(table["monitortype"], "neo4j-service")
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:94,代码来源:cma_test.py
示例18: makescript
# 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
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:31,代码来源:assimevent_test.py
示例19: test_automonitor_OCF_basic
def test_automonitor_OCF_basic(self):
AssimEvent.disable_all_observers()
drone = FakeDrone({
'data': {
'ocf': {
'assimilation/neo4j',
}
}
})
kitchensink = OCFMonitoringRule('assimilation', 'neo4j',
( ('cantguess',) # length 1 - name
, ('port', '$port') # length 2 - name, expression
, (None, '$port') # length 2 - name, expression
, ('-', '$pathname') # length 2 - name, expression
, ('port', '$port', '[0-9]+$') # length 3 - name, expression, regex
, (None, '$pathname', '.*/java$') # length 3 - name, expression, regex
, (None, '@basename()', 'java$') # length 3 - name, expression, regex
, ('-', '$argv[-1]', r'org\.neo4j\.server\.Bootstrapper$')
# length 3 - name, expression, regex
, ('port', '@serviceport()', '[0-9]+$', re.I) # length 4 - name, expression, regex, flags
))
keys = kitchensink.nvpairs.keys()
keys.sort()
self.assertEqual(str(keys), "['cantguess', 'port']")
values = []
for key in keys:
values.append(kitchensink.nvpairs[key])
self.assertEqual(str(values), "[None, '@serviceport()']")
regex = re.compile('xxx')
regextype = type(regex)
exprlist = []
for tup in kitchensink._tuplespec:
self.assertEqual(type(tup[1]), regextype)
exprlist.append(tup[0])
self.assertEqual(str(exprlist)
, "['$port', '$pathname', '@basename()', '$argv[-1]', '@serviceport()']")
#
# That was a pain...
#
# Now, let's test the basics in a little more depth by creating what should be a working
# set of arguments to a (hypothetical) OCF resource agent
#
neo4j = OCFMonitoringRule('assimilation', 'neo4j',
( ('port', '$port')
, (None, '$pathname', '.*/java$')
, ('-', '$argv[-1]', r'org\.neo4j\.server\.Bootstrapper$')
, ('home', '@argequals(-Dneo4j.home)', '/.*')
, ('neo4j', '@basename(@argequals(-Dneo4j.home))', '.')
)
)
neoprocargs = ("/usr/bin/java", "-cp"
, "/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:"
"AND SO ON:"
"/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:"
"/var/lib/neo4j/conf/", "-server", "-XX:"
"+DisableExplicitGC"
, "-Dorg.neo4j.server.properties=conf/neo4j-server.properties"
, "-Djava.util.logging.config.file=conf/logging.properties"
, "-Dlog4j.configuration=file:conf/log4j.properties"
, "-XX:+UseConcMarkSweepGC"
, "-XX:+CMSClassUnloadingEnabled"
, "-Dneo4j.home=/var/lib/neo4j"
, "-Dneo4j.instance=/var/lib/neo4j"
, "-Dfile.encoding=UTF-8"
, "org.neo4j.server.Bootstrapper")
neonode = ProcessNode('global', 'foofred', 'fred', '/usr/bin/java', neoprocargs
, 'root', 'root', '/', roles=(CMAconsts.ROLE_server,))
# We'll be missing the value of 'port'
neocontext = ExpressionContext((neonode, drone))
match = neo4j.specmatch(neocontext)
(prio, table, missing) = neo4j.specmatch(neocontext)
self.assertEqual(prio, MonitoringRule.PARTMATCH)
self.assertEqual(missing, ['port'])
# Now fill in the port value
neonode.port=7474
(prio, table) = neo4j.specmatch(neocontext)
self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
self.assertEqual(table['monitortype'], 'neo4j')
self.assertEqual(table['monitorclass'], 'ocf')
self.assertEqual(table['provider'], 'assimilation')
keys = table.keys()
keys.sort()
self.assertEqual(str(keys), "['arglist', 'monitorclass', 'monitortype', 'provider']")
arglist = table['arglist']
keys = arglist.keys()
keys.sort()
self.assertEqual(keys, ['home', 'neo4j', 'port'])
self.assertEqual(arglist['port'], '7474')
self.assertEqual(arglist['home'], '/var/lib/neo4j')
self.assertEqual(arglist['neo4j'], 'neo4j')
开发者ID:carrieao,项目名称:assimilation-official,代码行数:91,代码来源:cma_test.py
示例20: test_automonitor_OCF_failures
def test_automonitor_OCF_failures(self):
AssimEvent.disable_all_observers()
self.assertRaises(ValueError, OCFMonitoringRule, 'assimilation', 'neo4j',
((1,2,3,4,5),))
self.assertRaises(ValueError, OCFMonitoringRule, 'assimilation', 'neo4j',
((),))
开发者ID:carrieao,项目名称:assimilation-official,代码行数:6,代码来源:cma_test.py
注:本文中的assimevent.AssimEvent类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论