本文整理汇总了Python中assimevent.AssimEvent.disable_all_observers方法的典型用法代码示例。如果您正苦于以下问题:Python AssimEvent.disable_all_observers方法的具体用法?Python AssimEvent.disable_all_observers怎么用?Python AssimEvent.disable_all_observers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类assimevent.AssimEvent
的用法示例。
在下文中一共展示了AssimEvent.disable_all_observers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_automonitor_LSB_failures
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
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", ((),))
示例2: test_automonitor_strings_basic
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
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))
示例3: test_eof
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
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()
示例4: test_get1pkt
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
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
示例5: test_echo1pkt
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
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
示例6: test_automonitor_OCF_basic
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
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')
示例7: test_automonitor_OCF_failures
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
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',
((),))
示例8: test_automonitor_LSB_basic
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
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')
示例9: test_activate
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
def test_activate(self):
AssimEvent.disable_all_observers()
io = TestIO([],0)
CMAinit(io, cleanoutdb=True, debug=DEBUG)
dummy = CMAdb.store.load_or_create(MonitorAction, domain='global', monitorname='DummyName'
, monitorclass='OCF', monitortype='Dummy', interval=1, timeout=120, provider='heartbeat')
self.assertEqual(len(CMAdb.transaction.tree['packets']), 0)
CMAdb.store.commit()
CMAdb.transaction.commit_trans(io)
self.assertEqual(len(io.packetswritten), 0) # Shouldn't have sent out any pkts yet...
CMAdb.transaction = Transaction(encryption_required=False)
droneid = 1
droneip = droneipaddress(droneid)
designation = dronedesignation(droneid)
droneAddr = pyNetAddr((127,0,0,1),1984)
droneone = CMAdb.store.load_or_create(Drone, designation=designation, port=1984
, startaddr=droneip, primary_ip_addr=droneip)
self.assertTrue(not dummy.isactive)
dummy.activate(droneone)
CMAdb.store.commit()
count=0
for obj in CMAdb.store.load_related(droneone, CMAconsts.REL_hosting, MonitorAction):
self.assertTrue(obj is dummy)
count += 1
self.assertEqual(count, 1)
self.assertTrue(dummy.isactive)
count=0
for obj in CMAdb.store.load_related(dummy, CMAconsts.REL_monitoring, Drone):
self.assertTrue(obj is droneone)
count += 1
self.assertEqual(count, 1)
#worked if we returned at or before here
CMAdb.transaction.commit_trans(io)
#failed if we return here or later
self.assertEqual(len(io.packetswritten), 1) # Did we send out exactly one packet?
if SavePackets:
#io.dumppackets()
for fstuple in io.packetswritten:
(dest, frameset) = fstuple
self.assertEqual(frameset.get_framesettype(), FrameSetTypes.DORSCOP)
for frame in frameset.iter():
self.assertEqual(frame.frametype(), FrameTypes.RSCJSON)
table = pyConfigContext(init=frame.getstr())
for field in ('class', 'type', 'instance', 'repeat'):
self.assertTrue(field in table)
if field == 'monitorclass' and table['monitorclass'] == 'OCF':
self.assertTrue('provider' in table)
for tup in (('class', str), ('type', str), ('resourcename', str)
, ('monitorclass', str), ('provider', str)
, ('repeat_interval', (int, long))
, ('timeout', (int,long))):
(n, t) = tup
if n in table:
self.assertTrue(isinstance(table[n], t))
# TODO: Add test for deactivating the resource(s)
io.cleanio()
del io
示例10: test_several_startups
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
def test_several_startups(self):
'''A very interesting test: We send a STARTUP message and get back a
SETCONFIG message and then send back a bunch of discovery requests.'''
if Store.debug:
raise ValueError('Debug enabled')
if DEBUG:
print >> sys.stderr, 'Running test_several_startups()'
AssimEvent.disable_all_observers()
OurAddr = pyNetAddr((10,10,10,5), 1984)
configinit = geninitconfig(OurAddr)
# Create the STARTUP FrameSets that our fake Drones should appear to send
fsin = []
droneid=0
for droneid in range(1,MaxDrone+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)
fsin.append((droneip, (fs,)))
addrone = droneipaddress(1)
maxdrones = droneid
if doHBDEAD:
# Create the HBDEAD FrameSets that our first fake Drone should appear to send
# concerning the death of its dearly departed peers
#print >> sys.stderr, 'KILLING THEM ALL!!!'
for droneid in range(2,maxdrones+1):
droneip = droneipaddress(droneid)
designation = dronedesignation(droneid)
#deadframe=pyIpPortFrame(FrameTypes.IPPORT, addrstring=droneip)
fs = pyFrameSet(FrameSetTypes.HBSHUTDOWN)
#fs.append(deadframe)
hostframe=pyCstringFrame(FrameTypes.HOSTNAME, designation)
fs.append(hostframe)
fsin.append((droneip, (fs,)))
io = TestIO(fsin)
CMAinit(io, cleanoutdb=True, debug=DEBUG)
assert CMAdb.io.config is not None
assimcli_check('loadqueries')
disp = MessageDispatcher( {
FrameSetTypes.STARTUP: DispatchSTARTUP(),
FrameSetTypes.HBDEAD: DispatchHBDEAD(),
FrameSetTypes.HBSHUTDOWN: DispatchHBSHUTDOWN(),
}, encryption_required=False)
config = pyConfigContext(init=configinit)
listener = PacketListener(config, disp, io=io, encryption_required=False)
io.mainloop = listener.mainloop
TestIO.mainloop = listener.mainloop
# We send the CMA a BUNCH of intial STARTUP packets
# and (optionally) a bunch of HBDEAD packets
assert CMAdb.io.config is not None
listener.listen()
# We audit after each packet is processed
# The auditing code will make sure all is well...
# But it doesn't know how many drones we just registered
Drones = CMAdb.store.load_cypher_nodes("START n=node:Drone('*:*') RETURN n", Drone)
Drones = [drone for drone in Drones]
#print >> sys.stderr, 'WE NOW HAVE THESE DRONES:', Drones
self.assertEqual(len(Drones), maxdrones)
if doHBDEAD:
# Verify that all drones except one are dead
#livecount, partnercount, ringmemberships
#self.check_live_counts(1, 0, 1)
assimcli_check("query allservers", maxdrones)
assimcli_check("query down", maxdrones-1)
assimcli_check("query crashed", 0)
assimcli_check("query shutdown", maxdrones-1)
else:
if maxdrones == 1:
partnercount=0
elif maxdrones == 2:
partnercount = 2
else:
partnercount=2*maxdrones
# livecount partnercount ringmemberships
#self.check_live_counts(maxdrones, partnercount, maxdrones)
assimcli_check("query allservers", maxdrones)
assimcli_check("query down", 0)
assimcli_check("query shutdown", 0)
assimcli_check("query unknownips", 0)
for droneid in range(1,MaxDrone+1):
droneip = droneipaddress(droneid)
assimcli_check("query findip %s" % str(droneip), 1)
if DoAudit:
auditalldrones()
auditallrings()
if DEBUG:
print "The CMA read %d packets." % io.packetsread
print "The CMA wrote %d packets." % io.writecount
#io.dumppackets()
io.config = None
io.cleanio()
del io
示例11: test_startup
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
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
示例12: test_automonitor_functions
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
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')
#.........这里部分代码省略.........
示例13: test_automonitor_search_basic
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
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')
示例14: disabled
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
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:
示例15: test_automonitor_LSB_basic
# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import disable_all_observers [as 别名]
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")