corotests.py 54 KB

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