corotests.py 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561
  1. __copyright__='''
  2. Copyright (c) 2010 Red Hat, Inc.
  3. '''
  4. # All rights reserved.
  5. #
  6. # Author: Angus Salkeld <asalkeld@redhat.com>
  7. #
  8. # This software licensed under BSD license, the text of which follows:
  9. #
  10. # Redistribution and use in source and binary forms, with or without
  11. # modification, are permitted provided that the following conditions are met:
  12. #
  13. # - Redistributions of source code must retain the above copyright notice,
  14. # this list of conditions and the following disclaimer.
  15. # - Redistributions in binary form must reproduce the above copyright notice,
  16. # this list of conditions and the following disclaimer in the documentation
  17. # and/or other materials provided with the distribution.
  18. # - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. # contributors may be used to endorse or promote products derived from this
  20. # software without specific prior written permission.
  21. #
  22. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. # THE POSSIBILITY OF SUCH DAMAGE.
  33. import random
  34. import socket
  35. from UserDict import UserDict
  36. from cts.CTStests import *
  37. from corosync import CpgTestAgent
  38. ###################################################################
  39. class CoroTest(CTSTest):
  40. '''
  41. basic class to make sure that new configuration is applied
  42. and old configuration is removed.
  43. '''
  44. def __init__(self, cm):
  45. CTSTest.__init__(self,cm)
  46. self.start = StartTest(cm)
  47. self.stop = StopTest(cm)
  48. self.config = {}
  49. self.config['logging/logger_subsys[1]/subsys'] = 'MAIN'
  50. self.config['logging/logger_subsys[1]/debug'] = 'on'
  51. self.need_all_up = True
  52. self.CM.start_cpg = True
  53. def setup(self, node):
  54. ret = CTSTest.setup(self, node)
  55. # setup the authkey
  56. localauthkey = '/tmp/authkey'
  57. if not os.path.exists(localauthkey):
  58. self.CM.rsh(node, 'corosync-keygen -l')
  59. self.CM.rsh.cp("%s:%s" % (node, "/etc/corosync/authkey"), localauthkey)
  60. for n in self.CM.Env["nodes"]:
  61. if n is not node:
  62. #copy key onto other nodes
  63. self.CM.rsh.cp(localauthkey, "%s:%s" % (n, "/etc/corosync/authkey"))
  64. # copy over any new config
  65. for c in self.config:
  66. self.CM.new_config[c] = self.config[c]
  67. # apply the config
  68. self.CM.apply_new_config()
  69. # start/stop all corosyncs'
  70. for n in self.CM.Env["nodes"]:
  71. if self.need_all_up and not self.CM.StataCM(n):
  72. self.incr("started")
  73. self.start(n)
  74. if self.need_all_up and self.CM.start_cpg:
  75. self.CM.cpg_agent[n].clean_start()
  76. self.CM.cpg_agent[n].cpg_join(self.name)
  77. self.CM.cpg_agent[n].cfg_initialize()
  78. if not self.need_all_up and self.CM.StataCM(n):
  79. self.incr("stopped")
  80. self.stop(n)
  81. return ret
  82. def config_valid(self, config):
  83. return True
  84. def teardown(self, node):
  85. self.CM.apply_default_config()
  86. return CTSTest.teardown(self, node)
  87. ###################################################################
  88. class CpgContextTest(CoroTest):
  89. def __init__(self, cm):
  90. CoroTest.__init__(self, cm)
  91. self.name="CpgContextTest"
  92. self.CM.start_cpg = True
  93. def __call__(self, node):
  94. self.incr("calls")
  95. res = self.CM.cpg_agent[node].context_test()
  96. if 'OK' in res:
  97. return self.success()
  98. else:
  99. return self.failure('context_test failed')
  100. ###################################################################
  101. class CpgConfigChangeBase(CoroTest):
  102. '''
  103. join a cpg group on each node, and test that the following
  104. causes a leave event:
  105. - a call to cpg_leave()
  106. - app exit
  107. - node leave
  108. - node leave (with large token timeout)
  109. '''
  110. def setup(self, node):
  111. ret = CoroTest.setup(self, node)
  112. self.listener = None
  113. self.wobbly = None
  114. for n in self.CM.Env["nodes"]:
  115. if self.wobbly is None:
  116. self.wobbly = n
  117. elif self.listener is None:
  118. self.listener = n
  119. if self.CM.cpg_agent.has_key(self.wobbly):
  120. self.wobbly_id = self.CM.cpg_agent[self.wobbly].cpg_local_get()
  121. if self.CM.cpg_agent.has_key(self.listener):
  122. self.CM.cpg_agent[self.listener].record_config_events(truncate=True)
  123. return ret
  124. def wait_for_config_change(self):
  125. found = False
  126. max_timeout = 60 * 15
  127. waited = 0
  128. printit = 0
  129. self.CM.log("Waiting for config change on " + self.listener)
  130. while not found:
  131. try:
  132. event = self.CM.cpg_agent[self.listener].read_config_event()
  133. except:
  134. return self.failure('connection to test cpg_agent failed.')
  135. if not event == None:
  136. self.CM.debug("RECEIVED: " + str(event))
  137. if event == None:
  138. if waited >= max_timeout:
  139. return self.failure("timedout(" + str(waited) + " sec) == no event!")
  140. else:
  141. time.sleep(1)
  142. waited = waited + 1
  143. printit = printit + 1
  144. if printit is 60:
  145. print 'waited ' + str(waited) + ' seconds'
  146. printit = 0
  147. elif str(event.node_id) in str(self.wobbly_id) and not event.is_member:
  148. self.CM.log("Got the config change in " + str(waited) + " seconds")
  149. found = True
  150. else:
  151. self.CM.debug("No match")
  152. self.CM.debug("wobbly nodeid:" + str(self.wobbly_id))
  153. self.CM.debug("event nodeid:" + str(event.node_id))
  154. self.CM.debug("event.is_member:" + str(event.is_member))
  155. if found:
  156. return self.success()
  157. ###################################################################
  158. class CpgCfgChgOnGroupLeave(CpgConfigChangeBase):
  159. def __init__(self, cm):
  160. CpgConfigChangeBase.__init__(self,cm)
  161. self.name="CpgCfgChgOnGroupLeave"
  162. def failure_action(self):
  163. self.CM.log("calling cpg_leave() on " + self.wobbly)
  164. self.CM.cpg_agent[self.wobbly].cpg_leave(self.name)
  165. def __call__(self, node):
  166. self.incr("calls")
  167. self.failure_action()
  168. return self.wait_for_config_change()
  169. ###################################################################
  170. class CpgCfgChgOnNodeLeave(CpgConfigChangeBase):
  171. def __init__(self, cm):
  172. CpgConfigChangeBase.__init__(self,cm)
  173. self.name="CpgCfgChgOnNodeLeave"
  174. def failure_action(self):
  175. self.CM.log("stopping corosync on " + self.wobbly)
  176. self.stop(self.wobbly)
  177. def __call__(self, node):
  178. self.incr("calls")
  179. self.failure_action()
  180. return self.wait_for_config_change()
  181. ###################################################################
  182. class CpgCfgChgOnLowestNodeJoin(CTSTest):
  183. '''
  184. 1) stop all nodes
  185. 2) start all but the node with the smallest ip address
  186. 3) start recording events
  187. 4) start the last node
  188. '''
  189. def __init__(self, cm):
  190. CTSTest.__init__(self, cm)
  191. self.name="CpgCfgChgOnLowestNodeJoin"
  192. self.start = StartTest(cm)
  193. self.stop = StopTest(cm)
  194. self.config = {}
  195. self.need_all_up = False
  196. self.config['compatibility'] = 'none'
  197. def config_valid(self, config):
  198. return True
  199. def lowest_ip_set(self):
  200. self.lowest = None
  201. for n in self.CM.Env["nodes"]:
  202. if self.lowest is None:
  203. self.lowest = n
  204. self.CM.log("lowest node is " + self.lowest)
  205. def setup(self, node):
  206. # stop all nodes
  207. for n in self.CM.Env["nodes"]:
  208. self.CM.StopaCM(n)
  209. self.lowest_ip_set()
  210. # copy over any new config
  211. for c in self.config:
  212. self.CM.new_config[c] = self.config[c]
  213. # install the config
  214. self.CM.install_all_config()
  215. # start all but lowest
  216. self.listener = None
  217. for n in self.CM.Env["nodes"]:
  218. if n is not self.lowest:
  219. if self.listener is None:
  220. self.listener = n
  221. self.incr("started")
  222. self.CM.log("starting " + n)
  223. self.start(n)
  224. self.CM.cpg_agent[n].clean_start()
  225. self.CM.cpg_agent[n].cpg_join(self.name)
  226. # start recording events
  227. pats = []
  228. pats.append("%s .*sync: node joined.*" % self.listener)
  229. pats.append("%s .*sync: activate correctly.*" % self.listener)
  230. self.sync_log = self.create_watch(pats, 60)
  231. self.sync_log.setwatch()
  232. self.CM.log("setup done")
  233. return CTSTest.setup(self, node)
  234. def __call__(self, node):
  235. self.incr("calls")
  236. self.start(self.lowest)
  237. self.CM.cpg_agent[self.lowest].clean_start()
  238. self.CM.cpg_agent[self.lowest].cpg_join(self.name)
  239. self.wobbly_id = self.CM.cpg_agent[self.lowest].cpg_local_get()
  240. self.CM.log("waiting for sync events")
  241. if not self.sync_log.lookforall():
  242. return self.failure("Patterns not found: " + repr(self.sync_log.unmatched))
  243. else:
  244. return self.success()
  245. ###################################################################
  246. class CpgCfgChgOnExecCrash(CpgConfigChangeBase):
  247. def __init__(self, cm):
  248. CpgConfigChangeBase.__init__(self,cm)
  249. self.name="CpgCfgChgOnExecCrash"
  250. def failure_action(self):
  251. self.CM.log("sending KILL to corosync on " + self.wobbly)
  252. self.CM.rsh(self.wobbly, "killall -9 corosync")
  253. self.CM.rsh(self.wobbly, "rm -f /var/run/corosync.pid")
  254. self.CM.ShouldBeStatus[self.wobbly] = "down"
  255. def __call__(self, node):
  256. self.incr("calls")
  257. self.failure_action()
  258. return self.wait_for_config_change()
  259. ###################################################################
  260. class CpgCfgChgOnNodeIsolate(CpgConfigChangeBase):
  261. def __init__(self, cm):
  262. CpgConfigChangeBase.__init__(self,cm)
  263. self.name="CpgCfgChgOnNodeIsolate"
  264. def config_valid(self, config):
  265. if config.has_key('totem/rrp_mode'):
  266. return False
  267. else:
  268. return True
  269. def failure_action(self):
  270. self.CM.log("isolating node " + self.wobbly)
  271. self.CM.isolate_node(self.wobbly)
  272. def __call__(self, node):
  273. self.incr("calls")
  274. self.failure_action()
  275. return self.wait_for_config_change()
  276. def teardown(self, node):
  277. self.CM.unisolate_node (self.wobbly)
  278. return CpgConfigChangeBase.teardown(self, node)
  279. ###################################################################
  280. class CpgCfgChgOnNodeRestart(CpgConfigChangeBase):
  281. def __init__(self, cm):
  282. CpgConfigChangeBase.__init__(self,cm)
  283. self.name="CpgCfgChgOnNodeRestart"
  284. self.CM.start_cpg = False
  285. def config_valid(self, config):
  286. if config.has_key('totem/secauth'):
  287. if config['totem/secauth'] is 'on':
  288. return False
  289. else:
  290. return True
  291. if config.has_key('totem/rrp_mode'):
  292. return False
  293. else:
  294. return True
  295. def failure_action(self):
  296. self.CM.log("2: isolating node " + self.wobbly)
  297. self.CM.isolate_node(self.wobbly)
  298. self.CM.log("3: Killing corosync on " + self.wobbly)
  299. self.CM.rsh(self.wobbly, "killall -9 corosync")
  300. self.CM.rsh(self.wobbly, "rm -f /var/run/corosync.pid")
  301. self.CM.ShouldBeStatus[self.wobbly] = "down"
  302. self.CM.log("4: unisolating node " + self.wobbly)
  303. self.CM.unisolate_node (self.wobbly)
  304. self.CM.log("5: starting corosync on " + self.wobbly)
  305. self.CM.StartaCM(self.wobbly)
  306. time.sleep(5)
  307. self.CM.log("6: starting cpg on all nodes")
  308. self.CM.start_cpg = True
  309. for node in self.CM.Env["nodes"]:
  310. self.CM.cpg_agent[node] = CpgTestAgent(node, self.CM.Env)
  311. self.CM.cpg_agent[node].start()
  312. self.CM.cpg_agent[node].cpg_join(self.name)
  313. self.wobbly_id = self.CM.cpg_agent[self.wobbly].cpg_local_get()
  314. self.CM.cpg_agent[self.listener].record_config_events(truncate=True)
  315. self.CM.log("7: isolating node " + self.wobbly)
  316. self.CM.isolate_node(self.wobbly)
  317. self.CM.log("8: Killing corosync on " + self.wobbly)
  318. self.CM.rsh(self.wobbly, "killall -9 corosync")
  319. self.CM.rsh(self.wobbly, "rm -f /var/run/corosync.pid")
  320. self.CM.ShouldBeStatus[self.wobbly] = "down"
  321. self.CM.log("9: unisolating node " + self.wobbly)
  322. self.CM.unisolate_node (self.wobbly)
  323. self.CM.log("10: starting corosync on " + self.wobbly)
  324. self.CM.StartaCM(self.wobbly)
  325. def __call__(self, node):
  326. self.incr("calls")
  327. self.failure_action()
  328. return self.wait_for_config_change()
  329. def teardown(self, node):
  330. self.CM.unisolate_node (self.wobbly)
  331. return CpgConfigChangeBase.teardown(self, node)
  332. ###################################################################
  333. class CpgMsgOrderBase(CoroTest):
  334. def __init__(self, cm):
  335. CoroTest.__init__(self,cm)
  336. self.num_msgs_per_node = 0
  337. self.total_num_msgs = 0
  338. def setup(self, node):
  339. ret = CoroTest.setup(self, node)
  340. for n in self.CM.Env["nodes"]:
  341. self.CM.cpg_agent[n].clean_start()
  342. self.CM.cpg_agent[n].cpg_join(self.name)
  343. self.CM.cpg_agent[n].record_messages()
  344. time.sleep(1)
  345. return ret
  346. def cpg_msg_blaster(self):
  347. for n in self.CM.Env["nodes"]:
  348. self.CM.cpg_agent[n].msg_blaster(self.num_msgs_per_node)
  349. def wait_and_validate_order(self):
  350. msgs = {}
  351. self.total_num_msgs = 0
  352. for n in self.CM.Env["nodes"]:
  353. self.total_num_msgs = self.total_num_msgs + self.num_msgs_per_node
  354. for n in self.CM.Env["nodes"]:
  355. msgs[n] = []
  356. stopped = False
  357. waited = 0
  358. while len(msgs[n]) < self.total_num_msgs and waited < 360:
  359. try:
  360. msg = self.CM.cpg_agent[n].read_messages(50)
  361. except:
  362. return self.failure('connection to test cpg_agent failed.')
  363. if not msg == None:
  364. msgl = msg.split(";")
  365. # remove empty entries
  366. not_done=True
  367. while not_done:
  368. try:
  369. msgl.remove('')
  370. except:
  371. not_done = False
  372. msgs[n].extend(msgl)
  373. elif msg == None:
  374. time.sleep(2)
  375. waited = waited + 2
  376. if len(msgs[n]) < self.total_num_msgs:
  377. return self.failure("expected %d messages from %s got %d" % (self.total_num_msgs, n, len(msgs[n])))
  378. fail = False
  379. error_message = ''
  380. for i in range(0, self.total_num_msgs):
  381. first = None
  382. for n in self.CM.Env["nodes"]:
  383. # first test for errors
  384. params = msgs[n][i].split(":")
  385. if not 'OK' in params[3]:
  386. fail = True
  387. error_message = 'error: ' + params[3] + ' in received message'
  388. self.CM.log(str(params))
  389. # then look for out of order messages
  390. if first == None:
  391. first = n
  392. else:
  393. if not msgs[first][i] == msgs[n][i]:
  394. # message order not the same!
  395. fail = True
  396. error_message = 'message out of order'
  397. self.CM.log(msgs[first][i] + " != " + msgs[n][i])
  398. if fail:
  399. return self.failure(error_message)
  400. else:
  401. return self.success()
  402. ###################################################################
  403. class CpgMsgOrderBasic(CpgMsgOrderBase):
  404. '''
  405. each sends & logs lots of messages
  406. '''
  407. def __init__(self, cm):
  408. CpgMsgOrderBase.__init__(self,cm)
  409. self.name="CpgMsgOrderBasic"
  410. self.num_msgs_per_node = 9000
  411. def __call__(self, node):
  412. self.incr("calls")
  413. for n in self.CM.Env["nodes"]:
  414. self.CM.cpg_agent[n].msg_blaster(self.num_msgs_per_node)
  415. return self.wait_and_validate_order()
  416. ###################################################################
  417. class CpgMsgOrderZcb(CpgMsgOrderBase):
  418. '''
  419. each sends & logs lots of messages
  420. '''
  421. def __init__(self, cm):
  422. CpgMsgOrderBase.__init__(self,cm)
  423. self.name="CpgMsgOrderZcb"
  424. self.num_msgs_per_node = 9000
  425. def __call__(self, node):
  426. self.incr("calls")
  427. for n in self.CM.Env["nodes"]:
  428. self.CM.cpg_agent[n].msg_blaster_zcb(self.num_msgs_per_node)
  429. return self.wait_and_validate_order()
  430. ###################################################################
  431. class MemLeakObject(CoroTest):
  432. '''
  433. run mem_leak_test.sh -1
  434. '''
  435. def __init__(self, cm):
  436. CoroTest.__init__(self,cm)
  437. self.name="MemLeakObject"
  438. def __call__(self, node):
  439. self.incr("calls")
  440. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -1")
  441. if mem_leaked is 0:
  442. return self.success()
  443. else:
  444. return self.failure(str(mem_leaked) + 'kB memory leaked.')
  445. ###################################################################
  446. class MemLeakSession(CoroTest):
  447. '''
  448. run mem_leak_test.sh -2
  449. '''
  450. def __init__(self, cm):
  451. CoroTest.__init__(self,cm)
  452. self.name="MemLeakSession"
  453. def __call__(self, node):
  454. self.incr("calls")
  455. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -2")
  456. if mem_leaked is 0:
  457. return self.success()
  458. else:
  459. return self.failure(str(mem_leaked) + 'kB memory leaked.')
  460. ###################################################################
  461. class CMapDispatchDeadlock(CoroTest):
  462. '''
  463. run cmap-dispatch-deadlock.sh
  464. '''
  465. def __init__(self, cm):
  466. CoroTest.__init__(self,cm)
  467. self.name="CMapDispatchDeadlock"
  468. def __call__(self, node):
  469. self.incr("calls")
  470. result = self.CM.rsh(node, "/usr/share/corosync/tests/cmap-dispatch-deadlock.sh")
  471. if result is 0:
  472. return self.success()
  473. else:
  474. return self.failure('Deadlock detected')
  475. ###################################################################
  476. class SamTest1(CoroTest):
  477. def __init__(self, cm):
  478. CoroTest.__init__(self, cm)
  479. self.name="SamTest1"
  480. def __call__(self, node):
  481. self.incr("calls")
  482. res = self.CM.sam_agent[node].test1()
  483. if 'OK' in res:
  484. return self.success()
  485. else:
  486. return self.failure(self.name + ' failed')
  487. ###################################################################
  488. class SamTest2(CoroTest):
  489. def __init__(self, cm):
  490. CoroTest.__init__(self, cm)
  491. self.name="SamTest2"
  492. def __call__(self, node):
  493. self.incr("calls")
  494. res = self.CM.sam_agent[node].test2()
  495. if 'OK' in res:
  496. return self.success()
  497. else:
  498. return self.failure(self.name + ' failed')
  499. ###################################################################
  500. class SamTest4(CoroTest):
  501. def __init__(self, cm):
  502. CoroTest.__init__(self, cm)
  503. self.name="SamTest4"
  504. def __call__(self, node):
  505. self.incr("calls")
  506. res = self.CM.sam_agent[node].test4()
  507. if 'OK' in res:
  508. return self.success()
  509. else:
  510. return self.failure(self.name + ' failed')
  511. ###################################################################
  512. class SamTest5(CoroTest):
  513. def __init__(self, cm):
  514. CoroTest.__init__(self, cm)
  515. self.name="SamTest5"
  516. def __call__(self, node):
  517. self.incr("calls")
  518. res = self.CM.sam_agent[node].test5()
  519. if 'OK' in res:
  520. return self.success()
  521. else:
  522. return self.failure(self.name + ' failed')
  523. ###################################################################
  524. class SamTest6(CoroTest):
  525. def __init__(self, cm):
  526. CoroTest.__init__(self, cm)
  527. self.name="SamTest6"
  528. def __call__(self, node):
  529. self.incr("calls")
  530. res = self.CM.sam_agent[node].test6()
  531. if 'OK' in res:
  532. return self.success()
  533. else:
  534. return self.failure(self.name + ' failed')
  535. ###################################################################
  536. class SamTest8(CoroTest):
  537. def __init__(self, cm):
  538. CoroTest.__init__(self, cm)
  539. self.name="SamTest8"
  540. def __call__(self, node):
  541. self.incr("calls")
  542. res = self.CM.sam_agent[node].test8()
  543. if 'OK' in res:
  544. return self.success()
  545. else:
  546. return self.failure(self.name + ' failed')
  547. ###################################################################
  548. class SamTest9(CoroTest):
  549. def __init__(self, cm):
  550. CoroTest.__init__(self, cm)
  551. self.name="SamTest9"
  552. def __call__(self, node):
  553. self.incr("calls")
  554. res = self.CM.sam_agent[node].test9()
  555. if 'OK' in res:
  556. return self.success()
  557. else:
  558. return self.failure(self.name + ' failed')
  559. class QuorumState(object):
  560. def __init__(self, cm, node):
  561. self.node = node
  562. self.CM = cm
  563. self.CM.votequorum_agent[self.node].init()
  564. def refresh(self):
  565. info = self.CM.votequorum_agent[self.node].votequorum_getinfo()
  566. assert(info != 'FAIL')
  567. assert(info != 'NOT_SUPPORTED')
  568. #self.CM.log('refresh: ' + info)
  569. params = info.split(':')
  570. self.node_votes = int(params[0])
  571. self.expected_votes = int(params[1])
  572. self.highest_expected = int(params[2])
  573. self.total_votes = int(params[3])
  574. self.quorum = int(params[4])
  575. self.quorate = self.CM.votequorum_agent[self.node].quorum_getquorate()
  576. assert(self.quorate != 'FAIL')
  577. assert(self.quorate != 'NOT_SUPPORTED')
  578. #self.CM.log('quorate: ' + str(self.quorate))
  579. ###################################################################
  580. class VoteQuorumBase(CoroTest):
  581. def setup(self, node):
  582. ret = CoroTest.setup(self, node)
  583. self.id_map = {}
  584. self.listener = None
  585. for n in self.CM.Env["nodes"]:
  586. if self.listener is None:
  587. self.listener = n
  588. if self.need_all_up:
  589. self.CM.cpg_agent[n].clean_start()
  590. self.CM.cpg_agent[n].cpg_join(self.name)
  591. self.id_map[n] = self.CM.cpg_agent[n].cpg_local_get()
  592. return ret
  593. def config_valid(self, config):
  594. if config.has_key('totem/rrp_mode'):
  595. return False
  596. if config.has_key('quorum/provider'):
  597. return False
  598. return True
  599. ###################################################################
  600. class VoteQuorumGoDown(VoteQuorumBase):
  601. # all up
  602. # calc min expected votes to get Q
  603. # bring nodes down one-by-one
  604. # confirm cluster looses Q when V < EV
  605. #
  606. def __init__(self, cm):
  607. VoteQuorumBase.__init__(self, cm)
  608. self.name="VoteQuorumGoDown"
  609. self.victims = []
  610. self.expected = len(self.CM.Env["nodes"])
  611. self.config['quorum/provider'] = 'corosync_votequorum'
  612. self.config['quorum/expected_votes'] = self.expected
  613. #self.CM.log('set expected to %d' % (self.expected))
  614. def __call__(self, node):
  615. self.incr("calls")
  616. self.victims = []
  617. pats = []
  618. pats.append("%s .*VQ notification quorate: 0" % self.listener)
  619. pats.append("%s .*NQ notification quorate: 0" % self.listener)
  620. quorum = self.create_watch(pats, 30)
  621. quorum.setwatch()
  622. state = QuorumState(self.CM, self.listener)
  623. state.refresh()
  624. for n in self.CM.Env["nodes"]:
  625. if n is self.listener:
  626. continue
  627. self.victims.append(n)
  628. self.CM.StopaCM(n)
  629. #if not self.wait_for_quorum_change():
  630. # return self.failure(self.error_message)
  631. nodes_alive = len(self.CM.Env["nodes"]) - len(self.victims)
  632. state.refresh()
  633. #self.expected = self.expected - 1
  634. if state.node_votes != 1:
  635. self.failure('unexpected number of node_votes')
  636. if state.expected_votes != self.expected:
  637. self.CM.log('nev: %d != exp %d' % (state.expected_votes, self.expected))
  638. self.failure('unexpected number of expected_votes')
  639. if state.total_votes != nodes_alive:
  640. self.failure('unexpected number of total votes:%d, nodes_alive:%d' % (state.total_votes, nodes_alive))
  641. min = ((len(self.CM.Env["nodes"]) + 2) / 2)
  642. if min != state.quorum:
  643. self.failure('we should have %d (not %d) as quorum' % (min, state.quorum))
  644. if nodes_alive < state.quorum:
  645. if state.quorate == 1:
  646. self.failure('we should NOT have quorum(%d) %d > %d' % (state.quorate, state.quorum, nodes_alive))
  647. else:
  648. if state.quorate == 0:
  649. self.failure('we should have quorum(%d) %d <= %d' % (state.quorate, state.quorum, nodes_alive))
  650. if not quorum.lookforall():
  651. self.CM.log("Patterns not found: " + repr(quorum.unmatched))
  652. return self.failure('quorm event not found')
  653. return self.success()
  654. # all down
  655. # calc min expected votes to get Q
  656. # bring nodes up one-by-one
  657. # confirm cluster gains Q when V >= EV
  658. #
  659. ###################################################################
  660. class VoteQuorumGoUp(VoteQuorumBase):
  661. # all up
  662. # calc min expected votes to get Q
  663. # bring nodes down one-by-one
  664. # confirm cluster looses Q when V < EV
  665. #
  666. def __init__(self, cm):
  667. VoteQuorumBase.__init__(self, cm)
  668. self.name="VoteQuorumGoUp"
  669. self.need_all_up = False
  670. self.expected = len(self.CM.Env["nodes"])
  671. self.config['quorum/provider'] = 'corosync_votequorum'
  672. self.config['quorum/expected_votes'] = self.expected
  673. #self.CM.log('set expected to %d' % (self.expected))
  674. def __call__(self, node):
  675. self.incr("calls")
  676. pats = []
  677. pats.append("%s .*VQ notification quorate: 1" % self.listener)
  678. pats.append("%s .*NQ notification quorate: 1" % self.listener)
  679. quorum = self.create_watch(pats, 30)
  680. quorum.setwatch()
  681. self.CM.StartaCM(self.listener)
  682. nodes_alive = 1
  683. state = QuorumState(self.CM, self.listener)
  684. state.refresh()
  685. for n in self.CM.Env["nodes"]:
  686. if n is self.listener:
  687. continue
  688. #if not self.wait_for_quorum_change():
  689. # return self.failure(self.error_message)
  690. if state.node_votes != 1:
  691. self.failure('unexpected number of node_votes')
  692. if state.expected_votes != self.expected:
  693. self.CM.log('nev: %d != exp %d' % (state.expected_votes, self.expected))
  694. self.failure('unexpected number of expected_votes')
  695. if state.total_votes != nodes_alive:
  696. self.failure('unexpected number of total votes')
  697. min = ((len(self.CM.Env["nodes"]) + 2) / 2)
  698. if min != state.quorum:
  699. self.failure('we should have %d (not %d) as quorum' % (min, state.quorum))
  700. if nodes_alive < state.quorum:
  701. if state.quorate == 1:
  702. self.failure('we should NOT have quorum(%d) %d > %d' % (state.quorate, state.quorum, nodes_alive))
  703. else:
  704. if state.quorate == 0:
  705. self.failure('we should have quorum(%d) %d <= %d' % (state.quorate, state.quorum, nodes_alive))
  706. self.CM.StartaCM(n)
  707. nodes_alive = nodes_alive + 1
  708. state.refresh()
  709. if not quorum.lookforall():
  710. self.CM.log("Patterns not found: " + repr(quorum.unmatched))
  711. return self.failure('quorm event not found')
  712. return self.success()
  713. ###################################################################
  714. class VoteQuorumContextTest(CoroTest):
  715. def __init__(self, cm):
  716. CoroTest.__init__(self, cm)
  717. self.name="VoteQuorumContextTest"
  718. self.expected = len(self.CM.Env["nodes"])
  719. self.config['quorum/provider'] = 'corosync_votequorum'
  720. self.config['quorum/expected_votes'] = self.expected
  721. def __call__(self, node):
  722. self.incr("calls")
  723. res = self.CM.votequorum_agent[node].context_test()
  724. if 'OK' in res:
  725. return self.success()
  726. else:
  727. return self.failure('context_test failed')
  728. ###################################################################
  729. class GenSimulStart(CoroTest):
  730. '''Start all the nodes ~ simultaneously'''
  731. def __init__(self, cm):
  732. CoroTest.__init__(self,cm)
  733. self.name="GenSimulStart"
  734. self.need_all_up = False
  735. self.stopall = SimulStopLite(cm)
  736. self.startall = SimulStartLite(cm)
  737. def __call__(self, dummy):
  738. '''Perform the 'SimulStart' test. '''
  739. self.incr("calls")
  740. # We ignore the "node" parameter...
  741. # Shut down all the nodes...
  742. ret = self.stopall(None)
  743. if not ret:
  744. return self.failure("Setup failed")
  745. self.CM.clear_all_caches()
  746. if not self.startall(None):
  747. return self.failure("Startall failed")
  748. return self.success()
  749. ###################################################################
  750. class GenSimulStop(CoroTest):
  751. '''Stop all the nodes ~ simultaneously'''
  752. def __init__(self, cm):
  753. CoroTest.__init__(self,cm)
  754. self.name="GenSimulStop"
  755. self.startall = SimulStartLite(cm)
  756. self.stopall = SimulStopLite(cm)
  757. self.need_all_up = True
  758. def __call__(self, dummy):
  759. '''Perform the 'GenSimulStop' test. '''
  760. self.incr("calls")
  761. # We ignore the "node" parameter...
  762. # Start up all the nodes...
  763. ret = self.startall(None)
  764. if not ret:
  765. return self.failure("Setup failed")
  766. if not self.stopall(None):
  767. return self.failure("Stopall failed")
  768. return self.success()
  769. class GenFlipTest(CoroTest):
  770. def __init__(self, cm):
  771. CoroTest.__init__(self,cm)
  772. self.name="GenFlipTest"
  773. self.test = FlipTest(cm)
  774. def __call__(self, dummy):
  775. '''Perform the test. '''
  776. self.incr("calls")
  777. return self.test.__call__(dummy)
  778. class GenRestartTest(CoroTest):
  779. def __init__(self, cm):
  780. CoroTest.__init__(self,cm)
  781. self.name="GenRestartTest"
  782. self.test = RestartTest(cm)
  783. def __call__(self, dummy):
  784. '''Perform the test. '''
  785. self.incr("calls")
  786. return self.test.__call__(dummy)
  787. class GenStartOnebyOne(CoroTest):
  788. def __init__(self, cm):
  789. CoroTest.__init__(self,cm)
  790. self.name="GenStartOnebyOne"
  791. self.test = RestartOnebyOne(cm)
  792. def __call__(self, dummy):
  793. '''Perform the test. '''
  794. self.incr("calls")
  795. return self.test.__call__(dummy)
  796. class GenStopOnebyOne(CoroTest):
  797. def __init__(self, cm):
  798. CoroTest.__init__(self,cm)
  799. self.name="GenStopOnebyOne"
  800. self.test = StopOnebyOne(cm)
  801. def __call__(self, dummy):
  802. '''Perform the test. '''
  803. self.incr("calls")
  804. return self.test.__call__(dummy)
  805. class GenRestartOnebyOne(CoroTest):
  806. def __init__(self, cm):
  807. CoroTest.__init__(self,cm)
  808. self.name="GenRestartOnebyOne"
  809. self.test = RestartOnebyOne(cm)
  810. def __call__(self, dummy):
  811. '''Perform the test. '''
  812. self.incr("calls")
  813. return self.test.__call__(dummy)
  814. ###################################################################
  815. class GenStopAllBeekhof(CoroTest):
  816. '''Stop all the nodes ~ simultaneously'''
  817. def __init__(self, cm):
  818. CoroTest.__init__(self,cm)
  819. self.name="GenStopAllBeekhof"
  820. self.need_all_up = True
  821. self.config['logging/logger_subsys[2]/subsys'] = 'CFG'
  822. self.config['logging/logger_subsys[2]/debug'] = 'on'
  823. def __call__(self, node):
  824. '''Perform the 'GenStopAllBeekhof' test. '''
  825. self.incr("calls")
  826. stopping = int(time.time())
  827. for n in self.CM.Env["nodes"]:
  828. self.CM.cpg_agent[n].pcmk_test()
  829. for n in self.CM.Env["nodes"]:
  830. self.CM.cpg_agent[n].msg_blaster(1000)
  831. for n in self.CM.Env["nodes"]:
  832. self.CM.cpg_agent[n].cfg_shutdown()
  833. self.CM.ShouldBeStatus[n] = "down"
  834. waited = 0
  835. max_wait = 60 * 15
  836. still_up = list(self.CM.Env["nodes"])
  837. while len(still_up) > 0:
  838. waited = int(time.time()) - stopping
  839. self.CM.log("%s still up %s; waited %d secs" % (self.name, str(still_up), waited))
  840. if waited > max_wait:
  841. break
  842. time.sleep(3)
  843. for v in self.CM.Env["nodes"]:
  844. if v in still_up:
  845. self.CM.ShouldBeStatus[n] = "down"
  846. if not self.CM.StataCM(v):
  847. still_up.remove(v)
  848. waited = int(time.time()) - stopping
  849. if waited > max_wait:
  850. return self.failure("Waited %d secs for nodes: %s to stop" % (waited, str(still_up)))
  851. self.CM.log("%s ALL good (waited %d secs)" % (self.name, waited))
  852. return self.success()
  853. ###################################################################
  854. class NoWDConfig(CoroTest):
  855. '''Assertion: no config == no watchdog
  856. Setup: no config, kmod inserted
  857. 1] make sure watchdog is not enabled
  858. '''
  859. def __init__(self, cm):
  860. CoroTest.__init__(self,cm)
  861. self.name="NoWDConfig"
  862. self.need_all_up = False
  863. def config_valid(self, config):
  864. return not config.has_key('resources')
  865. def __call__(self, node):
  866. '''Perform the 'NoWDConfig' test. '''
  867. self.incr("calls")
  868. self.CM.StopaCM(node)
  869. pats = []
  870. pats.append("%s .*no resources configured." % node)
  871. w = self.create_watch(pats, 60)
  872. w.setwatch()
  873. self.CM.StartaCM(node)
  874. if not w.lookforall():
  875. return self.failure("Patterns not found: " + repr(w.unmatched))
  876. else:
  877. return self.success()
  878. ###################################################################
  879. class WDConfigNoWd(CoroTest):
  880. '''Assertion: watchdog config but no watchdog kmod will emit a log
  881. Setup: config watchdog, but no kmod
  882. 1] look in the log for warning that there is no kmod
  883. '''
  884. def __init__(self, cm):
  885. CoroTest.__init__(self,cm)
  886. self.name="WDConfigNoWd"
  887. self.need_all_up = False
  888. def __call__(self, node):
  889. '''Perform the 'WDConfigNoWd' test. '''
  890. self.incr("calls")
  891. self.CM.StopaCM(node)
  892. self.CM.rsh(node, 'rmmod softdog')
  893. pats = []
  894. pats.append("%s .*No Watchdog, try modprobe.*" % node)
  895. w = self.create_watch(pats, 60)
  896. w.setwatch()
  897. self.CM.StartaCM(node)
  898. if not w.lookforall():
  899. return self.failure("Patterns not found: " + repr(w.unmatched))
  900. else:
  901. return self.success()
  902. ###################################################################
  903. class NoWDOnCorosyncStop(CoroTest):
  904. '''Configure WD then /etc/init.d/corosync stop
  905. must stay up for > 60 secs
  906. '''
  907. def __init__(self, cm):
  908. CoroTest.__init__(self,cm)
  909. self.name="NoWDOnCorosyncStop"
  910. self.need_all_up = False
  911. def __call__(self, node):
  912. '''Perform the test. '''
  913. self.incr("calls")
  914. self.CM.StopaCM(node)
  915. self.CM.rsh(node, 'modprobe softdog')
  916. self.CM.StartaCM(node)
  917. pats = []
  918. pats.append("%s .*Unexpected close, not stopping watchdog.*" % node)
  919. w = self.create_watch(pats, 60)
  920. w.setwatch()
  921. self.CM.StopaCM(node)
  922. if w.lookforall():
  923. return self.failure("Should have closed the WD better: " + repr(w.matched))
  924. else:
  925. return self.success()
  926. ###################################################################
  927. class WDOnForkBomb(CoroTest):
  928. '''Configure memory resource
  929. run memory leaker / forkbomb
  930. confirm watchdog action
  931. '''
  932. def __init__(self, cm):
  933. CoroTest.__init__(self,cm)
  934. self.name="WDOnForkBomb"
  935. self.need_all_up = False
  936. self.config['logging/logger_subsys[2]/subsys'] = 'WD'
  937. self.config['logging/logger_subsys[2]/debug'] = 'on'
  938. self.config['resources/system/memory_used/recovery'] = 'watchdog'
  939. self.config['resources/system/memory_used/max'] = '80'
  940. self.config['resources/system/memory_used/poll_period'] = '800'
  941. def __call__(self, node):
  942. '''Perform the test. '''
  943. self.incr("calls")
  944. # get the uptime
  945. up_before = self.CM.rsh(node, 'cut -d. -f1 /proc/uptime', 1).rstrip()
  946. self.CM.StopaCM(node)
  947. self.CM.rsh(node, 'modprobe softdog')
  948. self.CM.StartaCM(node)
  949. self.CM.rsh(node, ':(){ :|:& };:', synchronous=0)
  950. self.CM.log("wait for it to watchdog")
  951. time.sleep(60 * 5)
  952. ping_able = False
  953. while not ping_able:
  954. if self.CM.rsh("localhost", "ping -nq -c10 -w10 %s" % node) == 0:
  955. ping_able = True
  956. self.CM.log("can ping 10 in 10secs.")
  957. else:
  958. self.CM.log("not yet responding to pings.")
  959. self.CM.ShouldBeStatus[node] = "down"
  960. # wait for the node to come back up
  961. self.CM.log("waiting for node to come back up.")
  962. if self.CM.ns.WaitForNodeToComeUp(node):
  963. up_after = self.CM.rsh(node, 'cut -d. -f1 /proc/uptime', 1).rstrip()
  964. if int(up_after) < int(up_before):
  965. return self.success()
  966. else:
  967. return self.failure("node didn't seem to watchdog uptime 1 %s; 2 %s" %(up_before, up_after))
  968. else:
  969. return self.failure("node didn't seem to come back up")
  970. ###################################################################
  971. class SamWdIntegration1(CoroTest):
  972. '''start sam hc
  973. kill agent
  974. confirm action
  975. '''
  976. def __init__(self, cm):
  977. CoroTest.__init__(self,cm)
  978. self.name="SamWdIntegration1"
  979. self.need_all_up = True
  980. self.config['logging/logger_subsys[2]/subsys'] = 'WD'
  981. self.config['logging/logger_subsys[2]/debug'] = 'on'
  982. def __call__(self, node):
  983. '''Perform the test. '''
  984. self.incr("calls")
  985. self.CM.sam_agent[node].setup_hc()
  986. pids = self.CM.sam_agent[node].getpid().rstrip().split(" ")
  987. pats = []
  988. for pid in pids:
  989. pats.append('%s .*resource "%s" failed!' % (node, pid))
  990. w = self.create_watch(pats, 60)
  991. w.setwatch()
  992. self.CM.sam_agent[node].kill()
  993. look_result = w.look()
  994. if not look_result:
  995. return self.failure("Patterns not found: " + repr(w.regexes))
  996. else:
  997. return self.success()
  998. ###################################################################
  999. class SamWdIntegration2(CoroTest):
  1000. '''start sam hc
  1001. call sam_stop()
  1002. confirm resource "stopped" and no watchdog action.
  1003. '''
  1004. def __init__(self, cm):
  1005. CoroTest.__init__(self,cm)
  1006. self.name="SamWdIntegration2"
  1007. self.need_all_up = True
  1008. self.config['logging/logger_subsys[2]/subsys'] = 'WD'
  1009. self.config['logging/logger_subsys[2]/debug'] = 'on'
  1010. def __call__(self, node):
  1011. '''Perform the test. '''
  1012. self.incr("calls")
  1013. self.CM.sam_agent[node].setup_hc()
  1014. pids = self.CM.sam_agent[node].getpid().rstrip().split(" ")
  1015. no_pats = []
  1016. yes_pats = []
  1017. for pid in pids:
  1018. no_pats.append('%s .*resource "%s" failed!' % (node, pid))
  1019. yes_pats.append('%s .*Fsm:%s event "config_changed", state "running" --> "stopped"' % (node, pid))
  1020. yes_w = self.create_watch(yes_pats, 10)
  1021. no_w = self.create_watch(no_pats, 10)
  1022. yes_w.setwatch()
  1023. no_w.setwatch()
  1024. time.sleep(2)
  1025. self.CM.sam_agent[node].sam_stop()
  1026. yes_matched = yes_w.look()
  1027. no_matched = no_w.look()
  1028. if no_matched:
  1029. return self.failure("Patterns found: " + repr(no_matched))
  1030. else:
  1031. if not yes_matched:
  1032. return self.failure("Patterns NOT found: " + repr(yes_w.regexes))
  1033. return self.success()
  1034. ###################################################################
  1035. class WdDeleteResource(CoroTest):
  1036. '''config resource & start corosync
  1037. check that it is getting checked
  1038. delete the object resource object
  1039. check that we do NOT get watchdog'ed
  1040. '''
  1041. def __init__(self, cm):
  1042. CoroTest.__init__(self,cm)
  1043. self.name="WdDeleteResource"
  1044. self.need_all_up = True
  1045. self.config['logging/logger_subsys[2]/subsys'] = 'MON'
  1046. self.config['logging/logger_subsys[2]/debug'] = 'on'
  1047. self.config['logging/logger_subsys[3]/subsys'] = 'WD'
  1048. self.config['logging/logger_subsys[3]/debug'] = 'on'
  1049. self.config['resources/system/memory_used/recovery'] = 'watchdog'
  1050. self.config['resources/system/memory_used/max'] = '80'
  1051. self.config['resources/system/memory_used/poll_period'] = '800'
  1052. def __call__(self, node):
  1053. '''Perform the test. '''
  1054. self.incr("calls")
  1055. no_pats = []
  1056. yes_pats = []
  1057. no_pats.append('%s .*resource "memory_used" failed!' % node)
  1058. yes_pats.append('%s .*resource "memory_used" deleted from cmap!' % node)
  1059. yes_w = self.create_watch(yes_pats, 10)
  1060. no_w = self.create_watch(no_pats, 10)
  1061. yes_w.setwatch()
  1062. no_w.setwatch()
  1063. time.sleep(2)
  1064. self.CM.rsh(node, 'corosync-cmapctl -D resources.system.memory_used')
  1065. yes_matched = yes_w.look()
  1066. no_matched = no_w.look()
  1067. if no_matched:
  1068. return self.failure("Patterns found: " + repr(no_matched))
  1069. else:
  1070. if not yes_matched:
  1071. return self.failure("Patterns NOT found: " + repr(yes_w.regexes))
  1072. return self.success()
  1073. ###################################################################
  1074. class ResourcePollAdjust(CoroTest):
  1075. '''config resource & start corosync
  1076. change the poll_period
  1077. check that we do NOT get watchdog'ed
  1078. '''
  1079. def __init__(self, cm):
  1080. CoroTest.__init__(self,cm)
  1081. self.name="ResourcePollAdjust"
  1082. self.need_all_up = True
  1083. self.config['logging/logger_subsys[2]/subsys'] = 'MON'
  1084. self.config['logging/logger_subsys[2]/debug'] = 'on'
  1085. self.config['logging/logger_subsys[3]/subsys'] = 'WD'
  1086. self.config['logging/logger_subsys[3]/debug'] = 'on'
  1087. self.config['resources/system/memory_used/recovery'] = 'none'
  1088. self.config['resources/system/memory_used/max'] = '80'
  1089. self.config['resources/system/memory_used/poll_period'] = '800'
  1090. def __call__(self, node):
  1091. '''Perform the test. '''
  1092. self.incr("calls")
  1093. no_pats = []
  1094. no_pats.append('%s .*resource "memory_used" failed!' % node)
  1095. no_pats.append('%s .*Could NOT use poll_period.*' % node)
  1096. no_w = self.create_watch(no_pats, 10)
  1097. no_w.setwatch()
  1098. changes = 0
  1099. while changes < 50:
  1100. changes = changes + 1
  1101. poll_period = int(random.random() * 5000)
  1102. if poll_period < 500:
  1103. poll_period = 500
  1104. self.CM.log("setting poll_period to: %d" % poll_period)
  1105. self.CM.rsh(node, 'corosync-cmapctl -s resources.system.memory_used.poll_period str %d' % poll_period)
  1106. sleep_time = poll_period * 2 / 1000
  1107. if sleep_time < 1:
  1108. sleep_time = 1
  1109. time.sleep(sleep_time)
  1110. no_matched = no_w.look()
  1111. if no_matched:
  1112. return self.failure("Patterns found: " + repr(no_matched))
  1113. return self.success()
  1114. ###################################################################
  1115. class RebootOnHighMem(CoroTest):
  1116. '''Configure memory resource
  1117. run memory leaker / forkbomb
  1118. confirm reboot action
  1119. '''
  1120. def __init__(self, cm):
  1121. CoroTest.__init__(self,cm)
  1122. self.name="RebootOnHighMem"
  1123. self.need_all_up = True
  1124. self.config['logging/logger_subsys[2]/subsys'] = 'WD'
  1125. self.config['logging/logger_subsys[2]/debug'] = 'on'
  1126. self.config['resources/system/memory_used/recovery'] = 'reboot'
  1127. self.config['resources/system/memory_used/max'] = '80'
  1128. self.config['resources/system/memory_used/poll_period'] = '800'
  1129. def __call__(self, node):
  1130. '''Perform the test. '''
  1131. self.incr("calls")
  1132. # get the uptime
  1133. up_before = self.CM.rsh(node, 'cut -d. -f1 /proc/uptime', 1).rstrip()
  1134. cmd = 'corosync-cmapctl resources.system.memory_used. | grep current | cut -d= -f2'
  1135. mem_current_str = self.CM.rsh(node, cmd, 1).rstrip()
  1136. mem_new_max = int(mem_current_str) + 5
  1137. self.CM.log("current mem usage: %s, new max:%d" % (mem_current_str, mem_new_max))
  1138. cmd = 'corosync-cmapctl -s resources.system.memory_used.max str ' + str(mem_new_max)
  1139. self.CM.rsh(node, cmd)
  1140. self.CM.rsh(node, 'memhog -r10000 200m', synchronous=0)
  1141. self.CM.log("wait for it to reboot")
  1142. time.sleep(60 * 3)
  1143. cmd = 'corosync-cmapctl resources.system.memory_used. | grep current | cut -d= -f2'
  1144. mem_current_str = self.CM.rsh(node, cmd, 1).rstrip()
  1145. self.CM.log("current mem usage: %s" % (mem_current_str))
  1146. ping_able = False
  1147. while not ping_able:
  1148. if self.CM.rsh("localhost", "ping -nq -c10 -w10 %s" % node) == 0:
  1149. ping_able = True
  1150. self.CM.log("can ping 10 in 10secs.")
  1151. else:
  1152. self.CM.log("not yet responding to pings.")
  1153. self.CM.ShouldBeStatus[node] = "down"
  1154. # wait for the node to come back up
  1155. self.CM.log("waiting for node to come back up.")
  1156. if self.CM.ns.WaitForNodeToComeUp(node):
  1157. up_after = self.CM.rsh(node, 'cut -d. -f1 /proc/uptime', 1).rstrip()
  1158. if int(up_after) < int(up_before):
  1159. return self.success()
  1160. else:
  1161. return self.failure("node didn't seem to watchdog uptime 1 %s; 2 %s" %(up_before, up_after))
  1162. else:
  1163. return self.failure("node didn't seem to come back up")
  1164. GenTestClasses = []
  1165. GenTestClasses.append(GenSimulStart)
  1166. GenTestClasses.append(GenSimulStop)
  1167. GenTestClasses.append(GenFlipTest)
  1168. GenTestClasses.append(GenRestartTest)
  1169. GenTestClasses.append(GenStartOnebyOne)
  1170. GenTestClasses.append(GenStopOnebyOne)
  1171. GenTestClasses.append(GenRestartOnebyOne)
  1172. GenTestClasses.append(GenStopAllBeekhof)
  1173. GenTestClasses.append(CpgMsgOrderBasic)
  1174. GenTestClasses.append(CpgMsgOrderZcb)
  1175. GenTestClasses.append(CpgCfgChgOnExecCrash)
  1176. GenTestClasses.append(CpgCfgChgOnGroupLeave)
  1177. GenTestClasses.append(CpgCfgChgOnNodeLeave)
  1178. GenTestClasses.append(CpgCfgChgOnNodeIsolate)
  1179. #GenTestClasses.append(CpgCfgChgOnNodeRestart)
  1180. AllTestClasses = []
  1181. AllTestClasses.append(CpgContextTest)
  1182. AllTestClasses.append(VoteQuorumContextTest)
  1183. AllTestClasses.append(SamTest1)
  1184. AllTestClasses.append(SamTest2)
  1185. AllTestClasses.append(SamTest4)
  1186. AllTestClasses.append(SamTest5)
  1187. AllTestClasses.append(SamTest6)
  1188. AllTestClasses.append(SamTest8)
  1189. AllTestClasses.append(SamTest9)
  1190. AllTestClasses.append(SamWdIntegration1)
  1191. AllTestClasses.append(SamWdIntegration2)
  1192. AllTestClasses.append(NoWDConfig)
  1193. AllTestClasses.append(WDConfigNoWd)
  1194. AllTestClasses.append(NoWDOnCorosyncStop)
  1195. #AllTestClasses.append(WDOnForkBomb)
  1196. AllTestClasses.append(WdDeleteResource)
  1197. #AllTestClasses.append(RebootOnHighMem)
  1198. AllTestClasses.append(ResourcePollAdjust)
  1199. AllTestClasses.append(MemLeakObject)
  1200. AllTestClasses.append(MemLeakSession)
  1201. #AllTestClasses.append(CMapDispatchDeadlock)
  1202. # FIXME quorum tests
  1203. #GenTestClasses.append(VoteQuorumGoDown)
  1204. #GenTestClasses.append(VoteQuorumGoUp)
  1205. # FIXME need log messages in sync
  1206. #GenTestClasses.append(CpgCfgChgOnLowestNodeJoin)
  1207. class ConfigContainer(UserDict):
  1208. def __init__ (self, name):
  1209. self.name = name
  1210. UserDict.__init__(self)
  1211. def CoroTestList(cm, audits):
  1212. result = []
  1213. configs = []
  1214. for testclass in AllTestClasses:
  1215. bound_test = testclass(cm)
  1216. if bound_test.is_applicable():
  1217. bound_test.Audits = audits
  1218. result.append(bound_test)
  1219. default = ConfigContainer('default')
  1220. default['logging/fileline'] = 'on'
  1221. default['logging/function_name'] = 'off'
  1222. default['logging/logfile_priority'] = 'info'
  1223. default['logging/syslog_priority'] = 'info'
  1224. default['logging/syslog_facility'] = 'daemon'
  1225. default['uidgid/uid'] = '0'
  1226. default['uidgid/gid'] = '0'
  1227. configs.append(default)
  1228. a = ConfigContainer('none_5min')
  1229. a['compatibility'] = 'none'
  1230. a['totem/token'] = (5 * 60 * 1000)
  1231. a['totem/consensus'] = int(5 * 60 * 1000 * 1.2) + 1
  1232. configs.append(a)
  1233. b = ConfigContainer('pcmk_basic')
  1234. b['compatibility'] = 'whitetank'
  1235. b['totem/token'] = 5000
  1236. b['totem/token_retransmits_before_loss_const'] = 10
  1237. b['totem/join'] = 1000
  1238. b['totem/consensus'] = 7500
  1239. configs.append(b)
  1240. c = ConfigContainer('pcmk_sec_nss')
  1241. c['totem/secauth'] = 'on'
  1242. c['totem/crypto_accept'] = 'new'
  1243. c['totem/crypto_type'] = 'nss'
  1244. c['totem/token'] = 5000
  1245. c['totem/token_retransmits_before_loss_const'] = 10
  1246. c['totem/join'] = 1000
  1247. c['totem/consensus'] = 7500
  1248. configs.append(c)
  1249. #
  1250. # s = ConfigContainer('pcmk_vq')
  1251. # s['quorum/provider'] = 'corosync_votequorum'
  1252. # s['quorum/expected_votes'] = len(cm.Env["nodes"])
  1253. # s['totem/token'] = 5000
  1254. # s['totem/token_retransmits_before_loss_const'] = 10
  1255. # s['totem/join'] = 1000
  1256. # s['totem/vsftype'] = 'none'
  1257. # s['totem/consensus'] = 7500
  1258. # s['totem/max_messages'] = 20
  1259. # configs.append(s)
  1260. #
  1261. d = ConfigContainer('sec_sober')
  1262. d['totem/secauth'] = 'on'
  1263. d['totem/crypto_type'] = 'sober'
  1264. configs.append(d)
  1265. if not cm.Env["RrpBindAddr"] is None:
  1266. g = ConfigContainer('rrp_passive')
  1267. g['totem/rrp_mode'] = 'passive'
  1268. g['totem/interface[2]/ringnumber'] = '1'
  1269. g['totem/interface[2]/bindnetaddr'] = cm.Env["RrpBindAddr"]
  1270. g['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  1271. g['totem/interface[2]/mcastport'] = '5405'
  1272. configs.append(g)
  1273. h = ConfigContainer('rrp_active')
  1274. h['totem/rrp_mode'] = 'active'
  1275. h['totem/interface[2]/ringnumber'] = '1'
  1276. h['totem/interface[2]/bindnetaddr'] = cm.Env["RrpBindAddr"]
  1277. h['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  1278. h['totem/interface[2]/mcastport'] = '5405'
  1279. configs.append(h)
  1280. else:
  1281. print 'Not including rrp tests. Use --rrp-binaddr to enable them.'
  1282. num=1
  1283. for cfg in configs:
  1284. for testclass in GenTestClasses:
  1285. bound_test = testclass(cm)
  1286. if bound_test.is_applicable() and bound_test.config_valid(cfg):
  1287. bound_test.Audits = audits
  1288. for c in cfg.keys():
  1289. bound_test.config[c] = cfg[c]
  1290. bound_test.name = bound_test.name + '_' + cfg.name
  1291. result.append(bound_test)
  1292. num = num + 1
  1293. return result