corotests.py 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655
  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. ###################################################################
  519. class ConfdbReplaceTest(CoroTest):
  520. def __init__(self, cm):
  521. CoroTest.__init__(self, cm)
  522. self.name="ConfdbReplaceTest"
  523. def __call__(self, node):
  524. self.incr("calls")
  525. res = self.CM.confdb_agent[node].set_get_test()
  526. if 'OK' in res:
  527. return self.success()
  528. else:
  529. return self.failure('set_get_test failed')
  530. ###################################################################
  531. class ConfdbContextTest(CoroTest):
  532. def __init__(self, cm):
  533. CoroTest.__init__(self, cm)
  534. self.name="ConfdbContextTest"
  535. def __call__(self, node):
  536. self.incr("calls")
  537. res = self.CM.confdb_agent[node].context_test()
  538. if 'OK' in res:
  539. return self.success()
  540. else:
  541. return self.failure('context_test failed')
  542. ###################################################################
  543. class ConfdbIncrementTest(CoroTest):
  544. def __init__(self, cm):
  545. CoroTest.__init__(self, cm)
  546. self.name="ConfdbIncrementTest"
  547. def __call__(self, node):
  548. self.incr("calls")
  549. res = self.CM.confdb_agent[node].increment_decrement_test()
  550. if 'OK' in res:
  551. return self.success()
  552. else:
  553. return self.failure('increment_decrement_test failed')
  554. ###################################################################
  555. class ConfdbObjectFindTest(CoroTest):
  556. def __init__(self, cm):
  557. CoroTest.__init__(self, cm)
  558. self.name="ConfdbObjectFindTest"
  559. def __call__(self, node):
  560. self.incr("calls")
  561. res = self.CM.confdb_agent[node].object_find_test()
  562. if 'OK' in res:
  563. return self.success()
  564. else:
  565. return self.failure('object_find_test failed')
  566. ###################################################################
  567. class ConfdbNotificationTest(CoroTest):
  568. def __init__(self, cm):
  569. CoroTest.__init__(self, cm)
  570. self.name="ConfdbNotificationTest"
  571. def __call__(self, node):
  572. self.incr("calls")
  573. res = self.CM.confdb_agent[node].notification_test()
  574. if 'OK' in res:
  575. return self.success()
  576. else:
  577. return self.failure('notification_test failed')
  578. ###################################################################
  579. class SamTest1(CoroTest):
  580. def __init__(self, cm):
  581. CoroTest.__init__(self, cm)
  582. self.name="SamTest1"
  583. def __call__(self, node):
  584. self.incr("calls")
  585. res = self.CM.sam_agent[node].test1()
  586. if 'OK' in res:
  587. return self.success()
  588. else:
  589. return self.failure(self.name + ' failed')
  590. ###################################################################
  591. class SamTest2(CoroTest):
  592. def __init__(self, cm):
  593. CoroTest.__init__(self, cm)
  594. self.name="SamTest2"
  595. def __call__(self, node):
  596. self.incr("calls")
  597. res = self.CM.sam_agent[node].test2()
  598. if 'OK' in res:
  599. return self.success()
  600. else:
  601. return self.failure(self.name + ' failed')
  602. ###################################################################
  603. class SamTest4(CoroTest):
  604. def __init__(self, cm):
  605. CoroTest.__init__(self, cm)
  606. self.name="SamTest4"
  607. def __call__(self, node):
  608. self.incr("calls")
  609. res = self.CM.sam_agent[node].test4()
  610. if 'OK' in res:
  611. return self.success()
  612. else:
  613. return self.failure(self.name + ' failed')
  614. ###################################################################
  615. class SamTest5(CoroTest):
  616. def __init__(self, cm):
  617. CoroTest.__init__(self, cm)
  618. self.name="SamTest5"
  619. def __call__(self, node):
  620. self.incr("calls")
  621. res = self.CM.sam_agent[node].test5()
  622. if 'OK' in res:
  623. return self.success()
  624. else:
  625. return self.failure(self.name + ' failed')
  626. ###################################################################
  627. class SamTest6(CoroTest):
  628. def __init__(self, cm):
  629. CoroTest.__init__(self, cm)
  630. self.name="SamTest6"
  631. def __call__(self, node):
  632. self.incr("calls")
  633. res = self.CM.sam_agent[node].test6()
  634. if 'OK' in res:
  635. return self.success()
  636. else:
  637. return self.failure(self.name + ' failed')
  638. ###################################################################
  639. class SamTestQuorum(CoroTest):
  640. def __init__(self, cm):
  641. CoroTest.__init__(self, cm)
  642. self.name="SamTestQuorum"
  643. self.config['quorum/provider'] = 'testquorum'
  644. self.config['quorum/quorate'] = '1'
  645. def __call__(self, node):
  646. self.incr("calls")
  647. res = self.CM.sam_agent[node].test_quorum()
  648. if 'OK' in res:
  649. return self.success()
  650. else:
  651. return self.failure(self.name + ' failed')
  652. ###################################################################
  653. class SamTest8(CoroTest):
  654. def __init__(self, cm):
  655. CoroTest.__init__(self, cm)
  656. self.name="SamTest8"
  657. def __call__(self, node):
  658. self.incr("calls")
  659. res = self.CM.sam_agent[node].test8()
  660. if 'OK' in res:
  661. return self.success()
  662. else:
  663. return self.failure(self.name + ' failed')
  664. ###################################################################
  665. class SamTest9(CoroTest):
  666. def __init__(self, cm):
  667. CoroTest.__init__(self, cm)
  668. self.name="SamTest9"
  669. def __call__(self, node):
  670. self.incr("calls")
  671. res = self.CM.sam_agent[node].test9()
  672. if 'OK' in res:
  673. return self.success()
  674. else:
  675. return self.failure(self.name + ' failed')
  676. class QuorumState(object):
  677. def __init__(self, cm, node):
  678. self.node = node
  679. self.CM = cm
  680. self.CM.votequorum_agent[self.node].init()
  681. def refresh(self):
  682. info = self.CM.votequorum_agent[self.node].votequorum_getinfo()
  683. assert(info != 'FAIL')
  684. assert(info != 'NOT_SUPPORTED')
  685. #self.CM.log('refresh: ' + info)
  686. params = info.split(':')
  687. self.node_votes = int(params[0])
  688. self.expected_votes = int(params[1])
  689. self.highest_expected = int(params[2])
  690. self.total_votes = int(params[3])
  691. self.quorum = int(params[4])
  692. self.quorate = self.CM.votequorum_agent[self.node].quorum_getquorate()
  693. assert(self.quorate != 'FAIL')
  694. assert(self.quorate != 'NOT_SUPPORTED')
  695. #self.CM.log('quorate: ' + str(self.quorate))
  696. ###################################################################
  697. class VoteQuorumBase(CoroTest):
  698. def setup(self, node):
  699. ret = CoroTest.setup(self, node)
  700. self.id_map = {}
  701. self.listener = None
  702. for n in self.CM.Env["nodes"]:
  703. if self.listener is None:
  704. self.listener = n
  705. if self.need_all_up:
  706. self.CM.cpg_agent[n].clean_start()
  707. self.CM.cpg_agent[n].cpg_join(self.name)
  708. self.id_map[n] = self.CM.cpg_agent[n].cpg_local_get()
  709. return ret
  710. def config_valid(self, config):
  711. if config.has_key('totem/rrp_mode'):
  712. return False
  713. if config.has_key('quorum/provider'):
  714. return False
  715. return True
  716. ###################################################################
  717. class VoteQuorumGoDown(VoteQuorumBase):
  718. # all up
  719. # calc min expected votes to get Q
  720. # bring nodes down one-by-one
  721. # confirm cluster looses Q when V < EV
  722. #
  723. def __init__(self, cm):
  724. VoteQuorumBase.__init__(self, cm)
  725. self.name="VoteQuorumGoDown"
  726. self.victims = []
  727. self.expected = len(self.CM.Env["nodes"])
  728. self.config['quorum/provider'] = 'corosync_votequorum'
  729. self.config['quorum/expected_votes'] = self.expected
  730. #self.CM.log('set expected to %d' % (self.expected))
  731. def __call__(self, node):
  732. self.incr("calls")
  733. self.victims = []
  734. pats = []
  735. pats.append("%s .*VQ notification quorate: 0" % self.listener)
  736. pats.append("%s .*NQ notification quorate: 0" % self.listener)
  737. quorum = self.create_watch(pats, 30)
  738. quorum.setwatch()
  739. state = QuorumState(self.CM, self.listener)
  740. state.refresh()
  741. for n in self.CM.Env["nodes"]:
  742. if n is self.listener:
  743. continue
  744. self.victims.append(n)
  745. self.CM.StopaCM(n)
  746. #if not self.wait_for_quorum_change():
  747. # return self.failure(self.error_message)
  748. nodes_alive = len(self.CM.Env["nodes"]) - len(self.victims)
  749. state.refresh()
  750. #self.expected = self.expected - 1
  751. if state.node_votes != 1:
  752. self.failure('unexpected number of node_votes')
  753. if state.expected_votes != self.expected:
  754. self.CM.log('nev: %d != exp %d' % (state.expected_votes, self.expected))
  755. self.failure('unexpected number of expected_votes')
  756. if state.total_votes != nodes_alive:
  757. self.failure('unexpected number of total votes:%d, nodes_alive:%d' % (state.total_votes, nodes_alive))
  758. min = ((len(self.CM.Env["nodes"]) + 2) / 2)
  759. if min != state.quorum:
  760. self.failure('we should have %d (not %d) as quorum' % (min, state.quorum))
  761. if nodes_alive < state.quorum:
  762. if state.quorate == 1:
  763. self.failure('we should NOT have quorum(%d) %d > %d' % (state.quorate, state.quorum, nodes_alive))
  764. else:
  765. if state.quorate == 0:
  766. self.failure('we should have quorum(%d) %d <= %d' % (state.quorate, state.quorum, nodes_alive))
  767. if not quorum.lookforall():
  768. self.CM.log("Patterns not found: " + repr(quorum.unmatched))
  769. return self.failure('quorm event not found')
  770. return self.success()
  771. # all down
  772. # calc min expected votes to get Q
  773. # bring nodes up one-by-one
  774. # confirm cluster gains Q when V >= EV
  775. #
  776. ###################################################################
  777. class VoteQuorumGoUp(VoteQuorumBase):
  778. # all up
  779. # calc min expected votes to get Q
  780. # bring nodes down one-by-one
  781. # confirm cluster looses Q when V < EV
  782. #
  783. def __init__(self, cm):
  784. VoteQuorumBase.__init__(self, cm)
  785. self.name="VoteQuorumGoUp"
  786. self.need_all_up = False
  787. self.expected = len(self.CM.Env["nodes"])
  788. self.config['quorum/provider'] = 'corosync_votequorum'
  789. self.config['quorum/expected_votes'] = self.expected
  790. #self.CM.log('set expected to %d' % (self.expected))
  791. def __call__(self, node):
  792. self.incr("calls")
  793. pats = []
  794. pats.append("%s .*VQ notification quorate: 1" % self.listener)
  795. pats.append("%s .*NQ notification quorate: 1" % self.listener)
  796. quorum = self.create_watch(pats, 30)
  797. quorum.setwatch()
  798. self.CM.StartaCM(self.listener)
  799. nodes_alive = 1
  800. state = QuorumState(self.CM, self.listener)
  801. state.refresh()
  802. for n in self.CM.Env["nodes"]:
  803. if n is self.listener:
  804. continue
  805. #if not self.wait_for_quorum_change():
  806. # return self.failure(self.error_message)
  807. if state.node_votes != 1:
  808. self.failure('unexpected number of node_votes')
  809. if state.expected_votes != self.expected:
  810. self.CM.log('nev: %d != exp %d' % (state.expected_votes, self.expected))
  811. self.failure('unexpected number of expected_votes')
  812. if state.total_votes != nodes_alive:
  813. self.failure('unexpected number of total votes')
  814. min = ((len(self.CM.Env["nodes"]) + 2) / 2)
  815. if min != state.quorum:
  816. self.failure('we should have %d (not %d) as quorum' % (min, state.quorum))
  817. if nodes_alive < state.quorum:
  818. if state.quorate == 1:
  819. self.failure('we should NOT have quorum(%d) %d > %d' % (state.quorate, state.quorum, nodes_alive))
  820. else:
  821. if state.quorate == 0:
  822. self.failure('we should have quorum(%d) %d <= %d' % (state.quorate, state.quorum, nodes_alive))
  823. self.CM.StartaCM(n)
  824. nodes_alive = nodes_alive + 1
  825. state.refresh()
  826. if not quorum.lookforall():
  827. self.CM.log("Patterns not found: " + repr(quorum.unmatched))
  828. return self.failure('quorm event not found')
  829. return self.success()
  830. ###################################################################
  831. class VoteQuorumContextTest(CoroTest):
  832. def __init__(self, cm):
  833. CoroTest.__init__(self, cm)
  834. self.name="VoteQuorumContextTest"
  835. self.expected = len(self.CM.Env["nodes"])
  836. self.config['quorum/provider'] = 'corosync_votequorum'
  837. self.config['quorum/expected_votes'] = self.expected
  838. def __call__(self, node):
  839. self.incr("calls")
  840. res = self.CM.votequorum_agent[node].context_test()
  841. if 'OK' in res:
  842. return self.success()
  843. else:
  844. return self.failure('context_test failed')
  845. ###################################################################
  846. class GenSimulStart(CoroTest):
  847. '''Start all the nodes ~ simultaneously'''
  848. def __init__(self, cm):
  849. CoroTest.__init__(self,cm)
  850. self.name="GenSimulStart"
  851. self.need_all_up = False
  852. self.stopall = SimulStopLite(cm)
  853. self.startall = SimulStartLite(cm)
  854. def __call__(self, dummy):
  855. '''Perform the 'SimulStart' test. '''
  856. self.incr("calls")
  857. # We ignore the "node" parameter...
  858. # Shut down all the nodes...
  859. ret = self.stopall(None)
  860. if not ret:
  861. return self.failure("Setup failed")
  862. self.CM.clear_all_caches()
  863. if not self.startall(None):
  864. return self.failure("Startall failed")
  865. return self.success()
  866. ###################################################################
  867. class GenSimulStop(CoroTest):
  868. '''Stop all the nodes ~ simultaneously'''
  869. def __init__(self, cm):
  870. CoroTest.__init__(self,cm)
  871. self.name="GenSimulStop"
  872. self.startall = SimulStartLite(cm)
  873. self.stopall = SimulStopLite(cm)
  874. self.need_all_up = True
  875. def __call__(self, dummy):
  876. '''Perform the 'GenSimulStop' test. '''
  877. self.incr("calls")
  878. # We ignore the "node" parameter...
  879. # Start up all the nodes...
  880. ret = self.startall(None)
  881. if not ret:
  882. return self.failure("Setup failed")
  883. if not self.stopall(None):
  884. return self.failure("Stopall failed")
  885. return self.success()
  886. ###################################################################
  887. class GenStopAllBeekhof(CoroTest):
  888. '''Stop all the nodes ~ simultaneously'''
  889. def __init__(self, cm):
  890. CoroTest.__init__(self,cm)
  891. self.name="GenStopAllBeekhof"
  892. self.need_all_up = True
  893. def __call__(self, node):
  894. '''Perform the 'GenStopAllBeekhof' test. '''
  895. self.incr("calls")
  896. stopping = int(time.time())
  897. for n in self.CM.Env["nodes"]:
  898. self.CM.cpg_agent[n].pcmk_test()
  899. self.CM.cpg_agent[n].msg_blaster(10000)
  900. self.CM.cpg_agent[n].cfg_shutdown()
  901. self.CM.ShouldBeStatus[n] = "down"
  902. waited = 0
  903. max_wait = 60 * 15
  904. still_up = list(self.CM.Env["nodes"])
  905. while len(still_up) > 0:
  906. waited = int(time.time()) - stopping
  907. self.CM.log("%s still up %s; waited %d secs" % (self.name, str(still_up), waited))
  908. if waited > max_wait:
  909. break
  910. time.sleep(3)
  911. for v in self.CM.Env["nodes"]:
  912. if v in still_up:
  913. self.CM.ShouldBeStatus[n] = "down"
  914. if not self.CM.StataCM(v):
  915. still_up.remove(v)
  916. waited = int(time.time()) - stopping
  917. if waited > max_wait:
  918. for v in still_up:
  919. self.CM.log("%s killing corosync on %s" % (self.name, v))
  920. self.CM.rsh(v, 'killall -SIGSEGV corosync cpg_test_agent')
  921. return self.failure("Waited %d secs for nodes: %s to stop" % (waited, str(still_up)))
  922. self.CM.log("%s ALL good (waited %d secs)" % (self.name, waited))
  923. return self.success()
  924. ###################################################################
  925. class NoWDConfig(CoroTest):
  926. '''Assertion: no config == no watchdog
  927. Setup: no config, kmod inserted
  928. 1] make sure watchdog is not enabled
  929. '''
  930. def __init__(self, cm):
  931. CoroTest.__init__(self,cm)
  932. self.name="NoWDConfig"
  933. self.need_all_up = False
  934. def config_valid(self, config):
  935. return not config.has_key('resources')
  936. def __call__(self, node):
  937. '''Perform the 'NoWDConfig' test. '''
  938. self.incr("calls")
  939. self.CM.StopaCM(node)
  940. pats = []
  941. pats.append("%s .*no resources configured." % node)
  942. w = self.create_watch(pats, 60)
  943. w.setwatch()
  944. self.CM.StartaCM(node)
  945. if not w.lookforall():
  946. return self.failure("Patterns not found: " + repr(w.unmatched))
  947. else:
  948. return self.success()
  949. ###################################################################
  950. class WDConfigNoWd(CoroTest):
  951. '''Assertion: watchdog config but no watchdog kmod will emit a log
  952. Setup: config watchdog, but no kmod
  953. 1] look in the log for warning that there is no kmod
  954. '''
  955. def __init__(self, cm):
  956. CoroTest.__init__(self,cm)
  957. self.name="WDConfigNoWd"
  958. self.need_all_up = False
  959. def __call__(self, node):
  960. '''Perform the 'WDConfigNoWd' test. '''
  961. self.incr("calls")
  962. self.CM.StopaCM(node)
  963. self.CM.rsh(node, 'rmmod softdog')
  964. pats = []
  965. pats.append("%s .*No Watchdog, try modprobe.*" % node)
  966. w = self.create_watch(pats, 60)
  967. w.setwatch()
  968. self.CM.StartaCM(node)
  969. if not w.lookforall():
  970. return self.failure("Patterns not found: " + repr(w.unmatched))
  971. else:
  972. return self.success()
  973. ###################################################################
  974. class NoWDOnCorosyncStop(CoroTest):
  975. '''Configure WD then /etc/init.d/corosync stop
  976. must stay up for > 60 secs
  977. '''
  978. def __init__(self, cm):
  979. CoroTest.__init__(self,cm)
  980. self.name="NoWDOnCorosyncStop"
  981. self.need_all_up = False
  982. def __call__(self, node):
  983. '''Perform the test. '''
  984. self.incr("calls")
  985. self.CM.StopaCM(node)
  986. self.CM.rsh(node, 'modprobe softdog')
  987. self.CM.StartaCM(node)
  988. pats = []
  989. pats.append("%s .*Unexpected close, not stopping watchdog.*" % node)
  990. w = self.create_watch(pats, 60)
  991. w.setwatch()
  992. self.CM.StopaCM(node)
  993. if w.lookforall():
  994. return self.failure("Should have closed the WD better: " + repr(w.matched))
  995. else:
  996. return self.success()
  997. ###################################################################
  998. class WDOnForkBomb(CoroTest):
  999. '''Configure memory resource
  1000. run memory leaker / forkbomb
  1001. confirm watchdog action
  1002. '''
  1003. def __init__(self, cm):
  1004. CoroTest.__init__(self,cm)
  1005. self.name="WDOnForkBomb"
  1006. self.need_all_up = False
  1007. self.config['logging/logger_subsys[1]/subsys'] = 'WD'
  1008. self.config['logging/logger_subsys[1]/debug'] = 'on'
  1009. self.config['resources/system/memory_used/recovery'] = 'watchdog'
  1010. self.config['resources/system/memory_used/max'] = '80'
  1011. self.config['resources/system/memory_used/poll_period'] = '800'
  1012. def __call__(self, node):
  1013. '''Perform the test. '''
  1014. self.incr("calls")
  1015. # get the uptime
  1016. up_before = self.CM.rsh(node, 'cut -d. -f1 /proc/uptime', 1).rstrip()
  1017. self.CM.StopaCM(node)
  1018. self.CM.rsh(node, 'modprobe softdog')
  1019. self.CM.StartaCM(node)
  1020. self.CM.rsh(node, ':(){ :|:& };:', blocking=0)
  1021. self.CM.log("wait for it to watchdog")
  1022. time.sleep(60 * 3)
  1023. ping_able = False
  1024. while not ping_able:
  1025. if self.CM.rsh("localhost", "ping -nq -c10 -w10 %s" % node) == 0:
  1026. ping_able = True
  1027. self.CM.log("can ping 10 in 10secs.")
  1028. else:
  1029. self.CM.log("not yet responding to pings.")
  1030. self.CM.ShouldBeStatus[node] = "down"
  1031. # wait for the node to come back up
  1032. self.CM.log("waiting for node to come back up.")
  1033. if self.CM.ns.WaitForNodeToComeUp(node):
  1034. up_after = self.CM.rsh(node, 'cut -d. -f1 /proc/uptime', 1).rstrip()
  1035. if int(up_after) < int(up_before):
  1036. return self.success()
  1037. else:
  1038. return self.failure("node didn't seem to watchdog uptime 1 %s; 2 %s" %(up_before, up_after))
  1039. else:
  1040. return self.failure("node didn't seem to come back up")
  1041. ###################################################################
  1042. class SamWdIntegration1(CoroTest):
  1043. '''start sam hc
  1044. kill agent
  1045. confirm action
  1046. '''
  1047. def __init__(self, cm):
  1048. CoroTest.__init__(self,cm)
  1049. self.name="SamWdIntegration1"
  1050. self.need_all_up = True
  1051. self.config['logging/logger_subsys[1]/subsys'] = 'WD'
  1052. self.config['logging/logger_subsys[1]/debug'] = 'on'
  1053. def __call__(self, node):
  1054. '''Perform the test. '''
  1055. self.incr("calls")
  1056. self.CM.sam_agent[node].setup_hc()
  1057. pids = self.CM.sam_agent[node].getpid().rstrip().split(" ")
  1058. pats = []
  1059. for pid in pids:
  1060. pats.append('%s .*resource "sam_test_agent:%s" failed!' % (node, pid))
  1061. w = self.create_watch(pats, 60)
  1062. w.setwatch()
  1063. self.CM.sam_agent[node].kill()
  1064. look_result = w.look()
  1065. if not look_result:
  1066. return self.failure("Patterns not found: " + repr(w.regexes))
  1067. else:
  1068. return self.success()
  1069. ###################################################################
  1070. class SamWdIntegration2(CoroTest):
  1071. '''start sam hc
  1072. call sam_stop()
  1073. confirm resource "stopped" and no watchdog action.
  1074. '''
  1075. def __init__(self, cm):
  1076. CoroTest.__init__(self,cm)
  1077. self.name="SamWdIntegration2"
  1078. self.need_all_up = True
  1079. self.config['logging/logger_subsys[1]/subsys'] = 'WD'
  1080. self.config['logging/logger_subsys[1]/debug'] = 'on'
  1081. def __call__(self, node):
  1082. '''Perform the test. '''
  1083. self.incr("calls")
  1084. self.CM.sam_agent[node].setup_hc()
  1085. pids = self.CM.sam_agent[node].getpid().rstrip().split(" ")
  1086. no_pats = []
  1087. yes_pats = []
  1088. for pid in pids:
  1089. no_pats.append('%s .*resource "sam_test_agent:%s" failed!' % (node, pid))
  1090. yes_pats.append('%s .*Fsm:sam_test_agent:%s event "config_changed", state "running" --> "stopped"' % (node, pid))
  1091. yes_w = self.create_watch(yes_pats, 10)
  1092. no_w = self.create_watch(no_pats, 10)
  1093. yes_w.setwatch()
  1094. no_w.setwatch()
  1095. time.sleep(2)
  1096. self.CM.sam_agent[node].sam_stop()
  1097. yes_matched = yes_w.look()
  1098. no_matched = no_w.look()
  1099. if no_matched:
  1100. return self.failure("Patterns found: " + repr(no_matched))
  1101. else:
  1102. if not yes_matched:
  1103. return self.failure("Patterns NOT found: " + repr(yes_w.regexes))
  1104. return self.success()
  1105. ###################################################################
  1106. class WdDeleteResource(CoroTest):
  1107. '''config resource & start corosync
  1108. check that it is getting checked
  1109. delete the object resource object
  1110. check that we do NOT get watchdog'ed
  1111. '''
  1112. def __init__(self, cm):
  1113. CoroTest.__init__(self,cm)
  1114. self.name="WdDeleteResource"
  1115. self.need_all_up = True
  1116. self.config['logging/logger_subsys[1]/subsys'] = 'WD'
  1117. self.config['logging/logger_subsys[1]/debug'] = 'on'
  1118. self.config['logging/logger_subsys[2]/subsys'] = 'MON'
  1119. self.config['logging/logger_subsys[2]/debug'] = 'on'
  1120. self.config['resources/system/memory_used/recovery'] = 'watchdog'
  1121. self.config['resources/system/memory_used/max'] = '80'
  1122. self.config['resources/system/memory_used/poll_period'] = '800'
  1123. def __call__(self, node):
  1124. '''Perform the test. '''
  1125. self.incr("calls")
  1126. no_pats = []
  1127. yes_pats = []
  1128. no_pats.append('%s .*resource "memory_used" failed!' % node)
  1129. yes_pats.append('%s .*resource "memory_used" deleted from objdb!' % node)
  1130. yes_w = self.create_watch(yes_pats, 10)
  1131. no_w = self.create_watch(no_pats, 10)
  1132. yes_w.setwatch()
  1133. no_w.setwatch()
  1134. time.sleep(2)
  1135. self.CM.rsh(node, 'corosync-objctl -d resources.system.memory_used')
  1136. yes_matched = yes_w.look()
  1137. no_matched = no_w.look()
  1138. if no_matched:
  1139. return self.failure("Patterns found: " + repr(no_matched))
  1140. else:
  1141. if not yes_matched:
  1142. return self.failure("Patterns NOT found: " + repr(yes_w.regexes))
  1143. return self.success()
  1144. ###################################################################
  1145. class ResourcePollAdjust(CoroTest):
  1146. '''config resource & start corosync
  1147. change the poll_period
  1148. check that we do NOT get watchdog'ed
  1149. '''
  1150. def __init__(self, cm):
  1151. CoroTest.__init__(self,cm)
  1152. self.name="ResourcePollAdjust"
  1153. self.need_all_up = True
  1154. self.config['logging/logger_subsys[1]/subsys'] = 'WD'
  1155. self.config['logging/logger_subsys[1]/debug'] = 'on'
  1156. self.config['logging/logger_subsys[2]/subsys'] = 'MON'
  1157. self.config['logging/logger_subsys[2]/debug'] = 'on'
  1158. self.config['resources/system/memory_used/recovery'] = 'none'
  1159. self.config['resources/system/memory_used/max'] = '80'
  1160. self.config['resources/system/memory_used/poll_period'] = '800'
  1161. def __call__(self, node):
  1162. '''Perform the test. '''
  1163. self.incr("calls")
  1164. no_pats = []
  1165. no_pats.append('%s .*resource "memory_used" failed!' % node)
  1166. no_pats.append('%s .*Could NOT use poll_period.*' % node)
  1167. no_w = self.create_watch(no_pats, 10)
  1168. no_w.setwatch()
  1169. changes = 0
  1170. while changes < 50:
  1171. changes = changes + 1
  1172. poll_period = int(random.random() * 5000)
  1173. if poll_period < 500:
  1174. poll_period = 500
  1175. self.CM.log("setting poll_period to: %d" % poll_period)
  1176. self.CM.rsh(node, 'corosync-objctl -w resources.system.memory_used.poll_period=%d' % poll_period)
  1177. sleep_time = poll_period * 2 / 1000
  1178. if sleep_time < 1:
  1179. sleep_time = 1
  1180. time.sleep(sleep_time)
  1181. no_matched = no_w.look()
  1182. if no_matched:
  1183. return self.failure("Patterns found: " + repr(no_matched))
  1184. return self.success()
  1185. ###################################################################
  1186. class RebootOnHighMem(CoroTest):
  1187. '''Configure memory resource
  1188. run memory leaker / forkbomb
  1189. confirm reboot action
  1190. '''
  1191. def __init__(self, cm):
  1192. CoroTest.__init__(self,cm)
  1193. self.name="RebootOnHighMem"
  1194. self.need_all_up = True
  1195. self.config['logging/logger_subsys[1]/subsys'] = 'WD'
  1196. self.config['logging/logger_subsys[1]/debug'] = 'on'
  1197. self.config['resources/system/memory_used/recovery'] = 'reboot'
  1198. self.config['resources/system/memory_used/max'] = '80'
  1199. self.config['resources/system/memory_used/poll_period'] = '800'
  1200. def __call__(self, node):
  1201. '''Perform the test. '''
  1202. self.incr("calls")
  1203. # get the uptime
  1204. up_before = self.CM.rsh(node, 'cut -d. -f1 /proc/uptime', 1).rstrip()
  1205. cmd = 'corosync-objctl resources.system.memory_used. | grep current | cut -d= -f2'
  1206. mem_current_str = self.CM.rsh(node, cmd, 1).rstrip()
  1207. mem_new_max = int(mem_current_str) + 5
  1208. self.CM.log("current mem usage: %s, new max:%d" % (mem_current_str, mem_new_max))
  1209. cmd = 'corosync-objctl -w resources.system.memory_used.max=' + str(mem_new_max)
  1210. self.CM.rsh(node, cmd)
  1211. self.CM.rsh(node, 'memhog -r10000 200m', blocking=0)
  1212. self.CM.log("wait for it to reboot")
  1213. time.sleep(60 * 3)
  1214. cmd = 'corosync-objctl resources.system.memory_used. | grep current | cut -d= -f2'
  1215. mem_current_str = self.CM.rsh(node, cmd, 1).rstrip()
  1216. self.CM.log("current mem usage: %s" % (mem_current_str))
  1217. ping_able = False
  1218. while not ping_able:
  1219. if self.CM.rsh("localhost", "ping -nq -c10 -w10 %s" % node) == 0:
  1220. ping_able = True
  1221. self.CM.log("can ping 10 in 10secs.")
  1222. else:
  1223. self.CM.log("not yet responding to pings.")
  1224. self.CM.ShouldBeStatus[node] = "down"
  1225. # wait for the node to come back up
  1226. self.CM.log("waiting for node to come back up.")
  1227. if self.CM.ns.WaitForNodeToComeUp(node):
  1228. up_after = self.CM.rsh(node, 'cut -d. -f1 /proc/uptime', 1).rstrip()
  1229. if int(up_after) < int(up_before):
  1230. return self.success()
  1231. else:
  1232. return self.failure("node didn't seem to watchdog uptime 1 %s; 2 %s" %(up_before, up_after))
  1233. else:
  1234. return self.failure("node didn't seem to come back up")
  1235. GenTestClasses = []
  1236. GenTestClasses.append(GenSimulStart)
  1237. GenTestClasses.append(GenSimulStop)
  1238. GenTestClasses.append(GenStopAllBeekhof)
  1239. GenTestClasses.append(CpgMsgOrderBasic)
  1240. GenTestClasses.append(CpgMsgOrderZcb)
  1241. GenTestClasses.append(CpgCfgChgOnExecCrash)
  1242. GenTestClasses.append(CpgCfgChgOnGroupLeave)
  1243. GenTestClasses.append(CpgCfgChgOnNodeLeave)
  1244. GenTestClasses.append(CpgCfgChgOnNodeIsolate)
  1245. #GenTestClasses.append(CpgCfgChgOnNodeRestart)
  1246. GenTestClasses.append(CpgCfgChgOnLowestNodeJoin)
  1247. GenTestClasses.append(VoteQuorumGoDown)
  1248. GenTestClasses.append(VoteQuorumGoUp)
  1249. AllTestClasses = []
  1250. AllTestClasses.append(ConfdbReplaceTest)
  1251. AllTestClasses.append(ConfdbIncrementTest)
  1252. AllTestClasses.append(ConfdbObjectFindTest)
  1253. AllTestClasses.append(ConfdbNotificationTest)
  1254. AllTestClasses.append(ConfdbContextTest)
  1255. AllTestClasses.append(CpgContextTest)
  1256. AllTestClasses.append(VoteQuorumContextTest)
  1257. AllTestClasses.append(SamTest1)
  1258. AllTestClasses.append(SamTest2)
  1259. AllTestClasses.append(SamTest4)
  1260. AllTestClasses.append(SamTest5)
  1261. AllTestClasses.append(SamTest6)
  1262. AllTestClasses.append(SamTestQuorum)
  1263. AllTestClasses.append(SamTest8)
  1264. AllTestClasses.append(SamTest9)
  1265. AllTestClasses.append(SamWdIntegration1)
  1266. AllTestClasses.append(SamWdIntegration2)
  1267. AllTestClasses.append(NoWDConfig)
  1268. AllTestClasses.append(WDConfigNoWd)
  1269. AllTestClasses.append(NoWDOnCorosyncStop)
  1270. #AllTestClasses.append(WDOnForkBomb)
  1271. AllTestClasses.append(WdDeleteResource)
  1272. #AllTestClasses.append(RebootOnHighMem)
  1273. AllTestClasses.append(ResourcePollAdjust)
  1274. AllTestClasses.append(ServiceLoadTest)
  1275. AllTestClasses.append(MemLeakObject)
  1276. AllTestClasses.append(MemLeakSession)
  1277. AllTestClasses.append(FlipTest)
  1278. AllTestClasses.append(RestartTest)
  1279. AllTestClasses.append(StartOnebyOne)
  1280. AllTestClasses.append(StopOnebyOne)
  1281. AllTestClasses.append(RestartOnebyOne)
  1282. class ConfigContainer(UserDict):
  1283. def __init__ (self, name):
  1284. self.name = name
  1285. UserDict.__init__(self)
  1286. def CoroTestList(cm, audits):
  1287. result = []
  1288. configs = []
  1289. for testclass in AllTestClasses:
  1290. bound_test = testclass(cm)
  1291. if bound_test.is_applicable():
  1292. bound_test.Audits = audits
  1293. result.append(bound_test)
  1294. default = ConfigContainer('default')
  1295. default['logging/fileline'] = 'on'
  1296. default['logging/function_name'] = 'off'
  1297. default['logging/logfile_priority'] = 'info'
  1298. default['logging/syslog_priority'] = 'info'
  1299. default['logging/syslog_facility'] = 'daemon'
  1300. default['uidgid/uid'] = '0'
  1301. default['uidgid/gid'] = '0'
  1302. configs.append(default)
  1303. a = ConfigContainer('none_5min')
  1304. a['compatibility'] = 'none'
  1305. a['totem/token'] = (5 * 60 * 1000)
  1306. a['totem/consensus'] = int(5 * 60 * 1000 * 1.2) + 1
  1307. configs.append(a)
  1308. b = ConfigContainer('pcmk_basic')
  1309. b['compatibility'] = 'whitetank'
  1310. b['totem/token'] = 5000
  1311. b['totem/token_retransmits_before_loss_const'] = 10
  1312. b['totem/join'] = 1000
  1313. b['totem/consensus'] = 7500
  1314. configs.append(b)
  1315. c = ConfigContainer('pcmk_sec_nss')
  1316. c['totem/secauth'] = 'on'
  1317. c['totem/crypto_accept'] = 'new'
  1318. c['totem/crypto_type'] = 'nss'
  1319. c['totem/token'] = 5000
  1320. c['totem/token_retransmits_before_loss_const'] = 10
  1321. c['totem/join'] = 1000
  1322. c['totem/consensus'] = 7500
  1323. configs.append(c)
  1324. s = ConfigContainer('pcmk_vq')
  1325. s['quorum/provider'] = 'corosync_votequorum'
  1326. s['quorum/expected_votes'] = len(cm.Env["nodes"])
  1327. s['totem/token'] = 5000
  1328. s['totem/token_retransmits_before_loss_const'] = 10
  1329. s['totem/join'] = 1000
  1330. s['totem/vsftype'] = 'none'
  1331. s['totem/consensus'] = 7500
  1332. s['totem/max_messages'] = 20
  1333. configs.append(s)
  1334. d = ConfigContainer('sec_sober')
  1335. d['totem/secauth'] = 'on'
  1336. d['totem/crypto_type'] = 'sober'
  1337. configs.append(d)
  1338. e = ConfigContainer('threads_4')
  1339. e['totem/threads'] = 4
  1340. configs.append(e)
  1341. if not cm.Env["RrpBindAddr"] is None:
  1342. g = ConfigContainer('rrp_passive')
  1343. g['totem/rrp_mode'] = 'passive'
  1344. g['totem/interface[2]/ringnumber'] = '1'
  1345. g['totem/interface[2]/bindnetaddr'] = cm.Env["RrpBindAddr"]
  1346. g['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  1347. g['totem/interface[2]/mcastport'] = '5405'
  1348. configs.append(g)
  1349. h = ConfigContainer('rrp_active')
  1350. h['totem/rrp_mode'] = 'active'
  1351. h['totem/interface[2]/ringnumber'] = '1'
  1352. h['totem/interface[2]/bindnetaddr'] = cm.Env["RrpBindAddr"]
  1353. h['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  1354. h['totem/interface[2]/mcastport'] = '5405'
  1355. configs.append(h)
  1356. else:
  1357. print 'Not including rrp tests. Use --rrp-binaddr to enable them.'
  1358. num=1
  1359. for cfg in configs:
  1360. for testclass in GenTestClasses:
  1361. bound_test = testclass(cm)
  1362. if bound_test.is_applicable() and bound_test.config_valid(cfg):
  1363. bound_test.Audits = audits
  1364. for c in cfg.keys():
  1365. bound_test.config[c] = cfg[c]
  1366. bound_test.name = bound_test.name + '_' + cfg.name
  1367. result.append(bound_test)
  1368. num = num + 1
  1369. return result