4
0

corotests.py 53 KB

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