corotests.py 54 KB

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