corotests.py 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  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. from UserDict import UserDict
  34. from cts.CTStests import *
  35. from corosync import CpgTestAgent
  36. ###################################################################
  37. class CoroTest(CTSTest):
  38. '''
  39. basic class to make sure that new configuration is applied
  40. and old configuration is removed.
  41. '''
  42. def __init__(self, cm):
  43. CTSTest.__init__(self,cm)
  44. self.start = StartTest(cm)
  45. self.stop = StopTest(cm)
  46. self.config = {}
  47. self.need_all_up = True
  48. self.CM.start_cpg = True
  49. def setup(self, node):
  50. ret = CTSTest.setup(self, node)
  51. # setup the authkey
  52. localauthkey = '/tmp/authkey'
  53. if not os.path.exists(localauthkey):
  54. self.CM.rsh(node, 'corosync-keygen')
  55. self.CM.rsh.cp("%s:%s" % (node, "/etc/corosync/authkey"), localauthkey)
  56. for n in self.CM.Env["nodes"]:
  57. if n is not node:
  58. #copy key onto other nodes
  59. self.CM.rsh.cp(localauthkey, "%s:%s" % (n, "/etc/corosync/authkey"))
  60. # copy over any new config
  61. for c in self.config:
  62. self.CM.new_config[c] = self.config[c]
  63. # apply the config
  64. self.CM.apply_new_config()
  65. # start/stop all corosyncs'
  66. for n in self.CM.Env["nodes"]:
  67. if self.need_all_up and not self.CM.StataCM(n):
  68. self.incr("started")
  69. self.start(n)
  70. if self.need_all_up and self.CM.start_cpg:
  71. self.CM.cpg_agent[n].clean_start()
  72. self.CM.cpg_agent[n].cpg_join(self.name)
  73. if not self.need_all_up and self.CM.StataCM(n):
  74. self.incr("stopped")
  75. self.stop(n)
  76. return ret
  77. def config_valid(self, config):
  78. return True
  79. def teardown(self, node):
  80. self.CM.apply_default_config()
  81. return CTSTest.teardown(self, node)
  82. ###################################################################
  83. class CpgContextTest(CoroTest):
  84. def __init__(self, cm):
  85. CoroTest.__init__(self, cm)
  86. self.name="CpgContextTest"
  87. self.CM.start_cpg = True
  88. def __call__(self, node):
  89. self.incr("calls")
  90. res = self.CM.cpg_agent[node].context_test()
  91. if 'OK' in res:
  92. return self.success()
  93. else:
  94. return self.failure('context_test failed')
  95. ###################################################################
  96. class CpgConfigChangeBase(CoroTest):
  97. '''
  98. join a cpg group on each node, and test that the following
  99. causes a leave event:
  100. - a call to cpg_leave()
  101. - app exit
  102. - node leave
  103. - node leave (with large token timeout)
  104. '''
  105. def setup(self, node):
  106. ret = CoroTest.setup(self, node)
  107. self.listener = None
  108. self.wobbly = None
  109. for n in self.CM.Env["nodes"]:
  110. if self.wobbly is None:
  111. self.wobbly = n
  112. elif self.listener is None:
  113. self.listener = n
  114. if self.CM.cpg_agent.has_key(self.wobbly):
  115. self.wobbly_id = self.CM.cpg_agent[self.wobbly].cpg_local_get()
  116. if self.CM.cpg_agent.has_key(self.listener):
  117. self.CM.cpg_agent[self.listener].record_config_events(truncate=True)
  118. return ret
  119. def wait_for_config_change(self):
  120. found = False
  121. max_timeout = 30 * 60
  122. waited = 0
  123. printit = 0
  124. self.CM.log("Waiting for config change on " + self.listener)
  125. while not found:
  126. try:
  127. event = self.CM.cpg_agent[self.listener].read_config_event()
  128. except:
  129. return self.failure('connection to test cpg_agent failed.')
  130. if not event == None:
  131. self.CM.debug("RECEIVED: " + str(event))
  132. if event == None:
  133. if waited >= max_timeout:
  134. return self.failure("timedout(" + str(waited) + " sec) == no event!")
  135. else:
  136. time.sleep(1)
  137. waited = waited + 1
  138. printit = printit + 1
  139. if printit is 60:
  140. print 'waited ' + str(waited) + ' seconds'
  141. printit = 0
  142. elif str(event.node_id) in str(self.wobbly_id) and not event.is_member:
  143. self.CM.log("Got the config change in " + str(waited) + " seconds")
  144. found = True
  145. else:
  146. self.CM.debug("No match")
  147. self.CM.debug("wobbly nodeid:" + str(self.wobbly_id))
  148. self.CM.debug("event nodeid:" + str(event.node_id))
  149. self.CM.debug("event.is_member:" + str(event.is_member))
  150. if found:
  151. return self.success()
  152. ###################################################################
  153. class CpgCfgChgOnGroupLeave(CpgConfigChangeBase):
  154. def __init__(self, cm):
  155. CpgConfigChangeBase.__init__(self,cm)
  156. self.name="CpgCfgChgOnGroupLeave"
  157. def failure_action(self):
  158. self.CM.log("calling cpg_leave() on " + self.wobbly)
  159. self.CM.cpg_agent[self.wobbly].cpg_leave(self.name)
  160. def __call__(self, node):
  161. self.incr("calls")
  162. self.failure_action()
  163. return self.wait_for_config_change()
  164. ###################################################################
  165. class CpgCfgChgOnNodeLeave(CpgConfigChangeBase):
  166. def __init__(self, cm):
  167. CpgConfigChangeBase.__init__(self,cm)
  168. self.name="CpgCfgChgOnNodeLeave"
  169. def failure_action(self):
  170. self.CM.log("stopping corosync on " + self.wobbly)
  171. self.stop(self.wobbly)
  172. def __call__(self, node):
  173. self.incr("calls")
  174. self.failure_action()
  175. return self.wait_for_config_change()
  176. ###################################################################
  177. class CpgCfgChgOnLowestNodeJoin(CTSTest):
  178. '''
  179. 1) stop all nodes
  180. 2) start all but the node with the smallest ip address
  181. 3) start recording events
  182. 4) start the last node
  183. '''
  184. def __init__(self, cm):
  185. CTSTest.__init__(self, cm)
  186. self.name="CpgCfgChgOnLowestNodeJoin"
  187. self.start = StartTest(cm)
  188. self.stop = StopTest(cm)
  189. self.config = {}
  190. self.need_all_up = False
  191. self.config['compatibility'] = 'none'
  192. def config_valid(self, config):
  193. return True
  194. def lowest_ip_set(self):
  195. self.lowest = None
  196. for n in self.CM.Env["nodes"]:
  197. if self.lowest is None:
  198. self.lowest = n
  199. self.CM.log("lowest node is " + self.lowest)
  200. def setup(self, node):
  201. # stop all nodes
  202. for n in self.CM.Env["nodes"]:
  203. self.CM.StopaCM(n)
  204. self.lowest_ip_set()
  205. # copy over any new config
  206. for c in self.config:
  207. self.CM.new_config[c] = self.config[c]
  208. # install the config
  209. self.CM.install_all_config()
  210. # start all but lowest
  211. self.listener = None
  212. for n in self.CM.Env["nodes"]:
  213. if n is not self.lowest:
  214. if self.listener is None:
  215. self.listener = n
  216. self.incr("started")
  217. self.CM.log("starting " + n)
  218. self.start(n)
  219. self.CM.cpg_agent[n].clean_start()
  220. self.CM.cpg_agent[n].cpg_join(self.name)
  221. # start recording events
  222. pats = []
  223. pats.append("%s .*sync: node joined.*" % self.listener)
  224. pats.append("%s .*sync: activate correctly.*" % self.listener)
  225. self.sync_log = self.create_watch(pats, 60)
  226. self.sync_log.setwatch()
  227. self.CM.log("setup done")
  228. return CTSTest.setup(self, node)
  229. def __call__(self, node):
  230. self.incr("calls")
  231. self.start(self.lowest)
  232. self.CM.cpg_agent[self.lowest].clean_start()
  233. self.CM.cpg_agent[self.lowest].cpg_join(self.name)
  234. self.wobbly_id = self.CM.cpg_agent[self.lowest].cpg_local_get()
  235. self.CM.log("waiting for sync events")
  236. if not self.sync_log.lookforall():
  237. return self.failure("Patterns not found: " + repr(self.sync_log.unmatched))
  238. else:
  239. return self.success()
  240. ###################################################################
  241. class CpgCfgChgOnExecCrash(CpgConfigChangeBase):
  242. def __init__(self, cm):
  243. CpgConfigChangeBase.__init__(self,cm)
  244. self.name="CpgCfgChgOnExecCrash"
  245. def failure_action(self):
  246. self.CM.log("sending KILL to corosync on " + self.wobbly)
  247. self.CM.rsh(self.wobbly, "killall -9 corosync")
  248. self.CM.rsh(self.wobbly, "rm -f /var/run/corosync.pid")
  249. self.CM.ShouldBeStatus[self.wobbly] = "down"
  250. def __call__(self, node):
  251. self.incr("calls")
  252. self.failure_action()
  253. return self.wait_for_config_change()
  254. ###################################################################
  255. class CpgCfgChgOnNodeIsolate(CpgConfigChangeBase):
  256. def __init__(self, cm):
  257. CpgConfigChangeBase.__init__(self,cm)
  258. self.name="CpgCfgChgOnNodeIsolate"
  259. def config_valid(self, config):
  260. if config.has_key('totem/rrp_mode'):
  261. return False
  262. else:
  263. return True
  264. def failure_action(self):
  265. self.CM.log("isolating node " + self.wobbly)
  266. self.CM.isolate_node(self.wobbly)
  267. def __call__(self, node):
  268. self.incr("calls")
  269. self.failure_action()
  270. return self.wait_for_config_change()
  271. def teardown(self, node):
  272. self.CM.unisolate_node (self.wobbly)
  273. return CpgConfigChangeBase.teardown(self, node)
  274. ###################################################################
  275. class CpgCfgChgOnNodeRestart(CpgConfigChangeBase):
  276. def __init__(self, cm):
  277. CpgConfigChangeBase.__init__(self,cm)
  278. self.name="CpgCfgChgOnNodeRestart"
  279. self.CM.start_cpg = False
  280. def config_valid(self, config):
  281. if config.has_key('totem/secauth'):
  282. if config['totem/secauth'] is 'on':
  283. return False
  284. else:
  285. return True
  286. if config.has_key('totem/rrp_mode'):
  287. return False
  288. else:
  289. return True
  290. def failure_action(self):
  291. self.CM.log("2: isolating node " + self.wobbly)
  292. self.CM.isolate_node(self.wobbly)
  293. self.CM.log("3: Killing corosync on " + self.wobbly)
  294. self.CM.rsh(self.wobbly, "killall -9 corosync")
  295. self.CM.rsh(self.wobbly, "rm -f /var/run/corosync.pid")
  296. self.CM.ShouldBeStatus[self.wobbly] = "down"
  297. self.CM.log("4: unisolating node " + self.wobbly)
  298. self.CM.unisolate_node (self.wobbly)
  299. self.CM.log("5: starting corosync on " + self.wobbly)
  300. self.CM.StartaCM(self.wobbly)
  301. time.sleep(5)
  302. self.CM.log("6: starting cpg on all nodes")
  303. self.CM.start_cpg = True
  304. for node in self.CM.Env["nodes"]:
  305. self.CM.cpg_agent[node] = CpgTestAgent(node, self.CM.Env)
  306. self.CM.cpg_agent[node].start()
  307. self.CM.cpg_agent[node].cpg_join(self.name)
  308. self.wobbly_id = self.CM.cpg_agent[self.wobbly].cpg_local_get()
  309. self.CM.cpg_agent[self.listener].record_config_events(truncate=True)
  310. self.CM.log("7: isolating node " + self.wobbly)
  311. self.CM.isolate_node(self.wobbly)
  312. self.CM.log("8: Killing corosync on " + self.wobbly)
  313. self.CM.rsh(self.wobbly, "killall -9 corosync")
  314. self.CM.rsh(self.wobbly, "rm -f /var/run/corosync.pid")
  315. self.CM.ShouldBeStatus[self.wobbly] = "down"
  316. self.CM.log("9: unisolating node " + self.wobbly)
  317. self.CM.unisolate_node (self.wobbly)
  318. self.CM.log("10: starting corosync on " + self.wobbly)
  319. self.CM.StartaCM(self.wobbly)
  320. def __call__(self, node):
  321. self.incr("calls")
  322. self.failure_action()
  323. return self.wait_for_config_change()
  324. def teardown(self, node):
  325. self.CM.unisolate_node (self.wobbly)
  326. return CpgConfigChangeBase.teardown(self, node)
  327. ###################################################################
  328. class CpgMsgOrderBase(CoroTest):
  329. def __init__(self, cm):
  330. CoroTest.__init__(self,cm)
  331. self.num_msgs_per_node = 0
  332. self.total_num_msgs = 0
  333. def setup(self, node):
  334. ret = CoroTest.setup(self, node)
  335. for n in self.CM.Env["nodes"]:
  336. self.total_num_msgs = self.total_num_msgs + self.num_msgs_per_node
  337. self.CM.cpg_agent[n].clean_start()
  338. self.CM.cpg_agent[n].cpg_join(self.name)
  339. self.CM.cpg_agent[n].record_messages()
  340. time.sleep(1)
  341. return ret
  342. def cpg_msg_blaster(self):
  343. for n in self.CM.Env["nodes"]:
  344. self.CM.cpg_agent[n].msg_blaster(self.num_msgs_per_node)
  345. def wait_and_validate_order(self):
  346. msgs = {}
  347. for n in self.CM.Env["nodes"]:
  348. msgs[n] = []
  349. stopped = False
  350. waited = 0
  351. while len(msgs[n]) < self.total_num_msgs and waited < 360:
  352. msg = self.CM.cpg_agent[n].read_messages(50)
  353. if not msg == None:
  354. msgl = msg.split(";")
  355. # remove empty entries
  356. not_done=True
  357. while not_done:
  358. try:
  359. msgl.remove('')
  360. except:
  361. not_done = False
  362. msgs[n].extend(msgl)
  363. elif msg == None:
  364. time.sleep(2)
  365. waited = waited + 2
  366. if len(msgs[n]) < self.total_num_msgs:
  367. return self.failure("expected %d messages from %s got %d" % (self.total_num_msgs, n, len(msgs[n])))
  368. fail = False
  369. error_message = ''
  370. for i in range(0, self.total_num_msgs):
  371. first = None
  372. for n in self.CM.Env["nodes"]:
  373. # first test for errors
  374. params = msgs[n][i].split(":")
  375. if not 'OK' in params[3]:
  376. fail = True
  377. error_message = 'error: ' + params[3] + ' in received message'
  378. self.CM.log(str(params))
  379. # then look for out of order messages
  380. if first == None:
  381. first = n
  382. else:
  383. if not msgs[first][i] == msgs[n][i]:
  384. # message order not the same!
  385. fail = True
  386. error_message = 'message out of order'
  387. self.CM.log(msgs[first][i] + " != " + msgs[n][i])
  388. if fail:
  389. return self.failure(error_message)
  390. else:
  391. return self.success()
  392. ###################################################################
  393. class CpgMsgOrderBasic(CpgMsgOrderBase):
  394. '''
  395. each sends & logs lots of messages
  396. '''
  397. def __init__(self, cm):
  398. CpgMsgOrderBase.__init__(self,cm)
  399. self.name="CpgMsgOrderBasic"
  400. self.num_msgs_per_node = 9000
  401. def __call__(self, node):
  402. self.incr("calls")
  403. for n in self.CM.Env["nodes"]:
  404. self.CM.cpg_agent[n].msg_blaster(self.num_msgs_per_node)
  405. return self.wait_and_validate_order()
  406. ###################################################################
  407. class CpgMsgOrderZcb(CpgMsgOrderBase):
  408. '''
  409. each sends & logs lots of messages
  410. '''
  411. def __init__(self, cm):
  412. CpgMsgOrderBase.__init__(self,cm)
  413. self.name="CpgMsgOrderZcb"
  414. self.num_msgs_per_node = 9000
  415. def __call__(self, node):
  416. self.incr("calls")
  417. for n in self.CM.Env["nodes"]:
  418. self.CM.cpg_agent[n].msg_blaster_zcb(self.num_msgs_per_node)
  419. return self.wait_and_validate_order()
  420. ###################################################################
  421. class MemLeakObject(CoroTest):
  422. '''
  423. run mem_leak_test.sh -1
  424. '''
  425. def __init__(self, cm):
  426. CoroTest.__init__(self,cm)
  427. self.name="MemLeakObject"
  428. def __call__(self, node):
  429. self.incr("calls")
  430. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -1")
  431. if mem_leaked is 0:
  432. return self.success()
  433. else:
  434. return self.failure(str(mem_leaked) + 'kB memory leaked.')
  435. ###################################################################
  436. class MemLeakSession(CoroTest):
  437. '''
  438. run mem_leak_test.sh -2
  439. '''
  440. def __init__(self, cm):
  441. CoroTest.__init__(self,cm)
  442. self.name="MemLeakSession"
  443. def __call__(self, node):
  444. self.incr("calls")
  445. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -2")
  446. if mem_leaked is 0:
  447. return self.success()
  448. else:
  449. return self.failure(str(mem_leaked) + 'kB memory leaked.')
  450. ###################################################################
  451. class ServiceLoadTest(CoroTest):
  452. '''
  453. Test loading and unloading of service engines
  454. '''
  455. def __init__(self, cm):
  456. CoroTest.__init__(self, cm)
  457. self.name="ServiceLoadTest"
  458. def is_loaded(self, node):
  459. check = 'corosync-objctl runtime.services. | grep evs'
  460. (res, out) = self.CM.rsh(node, check, stdout=2)
  461. if res is 0:
  462. return True
  463. else:
  464. return False
  465. def service_unload(self, node):
  466. # unload evs
  467. pats = []
  468. pats.append("%s .*Service engine unloaded: corosync extended.*" % node)
  469. unloaded = self.create_watch(pats, 60)
  470. unloaded.setwatch()
  471. self.CM.rsh(node, 'corosync-cfgtool -u corosync_evs')
  472. if not unloaded.lookforall():
  473. self.CM.log("Patterns not found: " + repr(unloaded.unmatched))
  474. self.error_message = "evs service not unloaded"
  475. return False
  476. if self.is_loaded(node):
  477. self.error_message = "evs has been unload, why are it's session objects are still there?"
  478. return False
  479. return True
  480. def service_load(self, node):
  481. # now reload it.
  482. pats = []
  483. pats.append("%s .*Service engine loaded.*" % node)
  484. loaded = self.create_watch(pats, 60)
  485. loaded.setwatch()
  486. self.CM.rsh(node, 'corosync-cfgtool -l corosync_evs')
  487. if not loaded.lookforall():
  488. self.CM.log("Patterns not found: " + repr(loaded.unmatched))
  489. self.error_message = "evs service not unloaded"
  490. return False
  491. return True
  492. def __call__(self, node):
  493. self.incr("calls")
  494. should_be_loaded = True
  495. if self.is_loaded(node):
  496. ret = self.service_unload(node)
  497. should_be_loaded = False
  498. else:
  499. ret = self.service_load(node)
  500. should_be_loaded = True
  501. if not ret:
  502. return self.failure(self.error_message)
  503. if self.is_loaded(node):
  504. ret = self.service_unload(node)
  505. else:
  506. ret = self.service_load(node)
  507. if not ret:
  508. return self.failure(self.error_message)
  509. return self.success()
  510. ###################################################################
  511. class ConfdbReplaceTest(CoroTest):
  512. def __init__(self, cm):
  513. CoroTest.__init__(self, cm)
  514. self.name="ConfdbReplaceTest"
  515. def __call__(self, node):
  516. self.incr("calls")
  517. res = self.CM.confdb_agent[node].set_get_test()
  518. if 'OK' in res:
  519. return self.success()
  520. else:
  521. return self.failure('set_get_test failed')
  522. ###################################################################
  523. class ConfdbContextTest(CoroTest):
  524. def __init__(self, cm):
  525. CoroTest.__init__(self, cm)
  526. self.name="ConfdbContextTest"
  527. def __call__(self, node):
  528. self.incr("calls")
  529. res = self.CM.confdb_agent[node].context_test()
  530. if 'OK' in res:
  531. return self.success()
  532. else:
  533. return self.failure('context_test failed')
  534. ###################################################################
  535. class ConfdbIncrementTest(CoroTest):
  536. def __init__(self, cm):
  537. CoroTest.__init__(self, cm)
  538. self.name="ConfdbIncrementTest"
  539. def __call__(self, node):
  540. self.incr("calls")
  541. res = self.CM.confdb_agent[node].increment_decrement_test()
  542. if 'OK' in res:
  543. return self.success()
  544. else:
  545. return self.failure('increment_decrement_test failed')
  546. ###################################################################
  547. class ConfdbObjectFindTest(CoroTest):
  548. def __init__(self, cm):
  549. CoroTest.__init__(self, cm)
  550. self.name="ConfdbObjectFindTest"
  551. def __call__(self, node):
  552. self.incr("calls")
  553. res = self.CM.confdb_agent[node].object_find_test()
  554. if 'OK' in res:
  555. return self.success()
  556. else:
  557. return self.failure('object_find_test failed')
  558. ###################################################################
  559. class ConfdbNotificationTest(CoroTest):
  560. def __init__(self, cm):
  561. CoroTest.__init__(self, cm)
  562. self.name="ConfdbNotificationTest"
  563. def __call__(self, node):
  564. self.incr("calls")
  565. res = self.CM.confdb_agent[node].notification_test()
  566. if 'OK' in res:
  567. return self.success()
  568. else:
  569. return self.failure('notification_test failed')
  570. ###################################################################
  571. class SamTest1(CoroTest):
  572. def __init__(self, cm):
  573. CoroTest.__init__(self, cm)
  574. self.name="SamTest1"
  575. def __call__(self, node):
  576. self.incr("calls")
  577. res = self.CM.sam_agent[node].test1()
  578. if 'OK' in res:
  579. return self.success()
  580. else:
  581. return self.failure('sam test 1 failed')
  582. ###################################################################
  583. class SamTest2(CoroTest):
  584. def __init__(self, cm):
  585. CoroTest.__init__(self, cm)
  586. self.name="SamTest2"
  587. def __call__(self, node):
  588. self.incr("calls")
  589. res = self.CM.sam_agent[node].test2()
  590. if 'OK' in res:
  591. return self.success()
  592. else:
  593. return self.failure('sam test 2 failed')
  594. ###################################################################
  595. class SamTest3(CoroTest):
  596. def __init__(self, cm):
  597. CoroTest.__init__(self, cm)
  598. self.name="SamTest3"
  599. def __call__(self, node):
  600. self.incr("calls")
  601. res = self.CM.sam_agent[node].test3()
  602. if 'OK' in res:
  603. return self.success()
  604. else:
  605. return self.failure('sam test 3 failed')
  606. ###################################################################
  607. class SamTest4(CoroTest):
  608. def __init__(self, cm):
  609. CoroTest.__init__(self, cm)
  610. self.name="SamTest4"
  611. def __call__(self, node):
  612. self.incr("calls")
  613. res = self.CM.sam_agent[node].test4()
  614. if 'OK' in res:
  615. return self.success()
  616. else:
  617. return self.failure('sam test 4 failed')
  618. class QuorumState(object):
  619. def __init__(self, cm, node):
  620. self.node = node
  621. self.CM = cm
  622. self.CM.votequorum_agent[self.node].init()
  623. def refresh(self):
  624. info = self.CM.votequorum_agent[self.node].votequorum_getinfo()
  625. assert(info != 'FAIL')
  626. assert(info != 'NOT_SUPPORTED')
  627. #self.CM.log('refresh: ' + info)
  628. params = info.split(':')
  629. self.node_votes = int(params[0])
  630. self.expected_votes = int(params[1])
  631. self.highest_expected = int(params[2])
  632. self.total_votes = int(params[3])
  633. self.quorum = int(params[4])
  634. self.quorate = self.CM.votequorum_agent[self.node].quorum_getquorate()
  635. assert(self.quorate != 'FAIL')
  636. assert(self.quorate != 'NOT_SUPPORTED')
  637. #self.CM.log('quorate: ' + str(self.quorate))
  638. ###################################################################
  639. class VoteQuorumBase(CoroTest):
  640. '''
  641. '''
  642. def setup(self, node):
  643. ret = CoroTest.setup(self, node)
  644. self.id_map = {}
  645. self.listener = None
  646. for n in self.CM.Env["nodes"]:
  647. if self.listener is None:
  648. self.listener = n
  649. if self.need_all_up:
  650. self.CM.cpg_agent[n].clean_start()
  651. self.CM.cpg_agent[n].cpg_join(self.name)
  652. self.id_map[n] = self.CM.cpg_agent[n].cpg_local_get()
  653. return ret
  654. def config_valid(self, config):
  655. if config.has_key('totem/rrp_mode'):
  656. return False
  657. else:
  658. return True
  659. ###################################################################
  660. class VoteQuorumGoDown(VoteQuorumBase):
  661. # all up
  662. # calc min expected votes to get Q
  663. # bring nodes down one-by-one
  664. # confirm cluster looses Q when V < EV
  665. #
  666. def __init__(self, cm):
  667. VoteQuorumBase.__init__(self, cm)
  668. self.name="VoteQuorumGoDown"
  669. self.victims = []
  670. self.expected = len(self.CM.Env["nodes"])
  671. self.config['quorum/provider'] = 'corosync_votequorum'
  672. self.config['quorum/expected_votes'] = self.expected
  673. #self.CM.log('set expected to %d' % (self.expected))
  674. def __call__(self, node):
  675. self.incr("calls")
  676. pats = []
  677. pats.append("%s .*VQ notification quorate: 0" % self.listener)
  678. pats.append("%s .*NQ notification quorate: 0" % self.listener)
  679. quorum = self.create_watch(pats, 30)
  680. quorum.setwatch()
  681. state = QuorumState(self.CM, self.listener)
  682. state.refresh()
  683. for n in self.CM.Env["nodes"]:
  684. if n is self.listener:
  685. continue
  686. self.victims.append(n)
  687. self.CM.StopaCM(n)
  688. #if not self.wait_for_quorum_change():
  689. # return self.failure(self.error_message)
  690. nodes_alive = len(self.CM.Env["nodes"]) - len(self.victims)
  691. state.refresh()
  692. #self.expected = self.expected - 1
  693. if state.node_votes != 1:
  694. self.failure('unexpected number of node_votes')
  695. if state.expected_votes != self.expected:
  696. self.CM.log('nev: %d != exp %d' % (state.expected_votes, self.expected))
  697. self.failure('unexpected number of expected_votes')
  698. if state.total_votes != nodes_alive:
  699. self.failure('unexpected number of total votes')
  700. min = ((len(self.CM.Env["nodes"]) + 2) / 2)
  701. if min != state.quorum:
  702. self.failure('we should have %d (not %d) as quorum' % (min, state.quorum))
  703. if nodes_alive < state.quorum:
  704. if state.quorate == 1:
  705. self.failure('we should NOT have quorum(%d) %d > %d' % (state.quorate, state.quorum, nodes_alive))
  706. else:
  707. if state.quorate == 0:
  708. self.failure('we should have quorum(%d) %d <= %d' % (state.quorate, state.quorum, nodes_alive))
  709. if not quorum.lookforall():
  710. self.CM.log("Patterns not found: " + repr(quorum.unmatched))
  711. return self.failure('quorm event not found')
  712. return self.success()
  713. # all down
  714. # calc min expected votes to get Q
  715. # bring nodes up one-by-one
  716. # confirm cluster gains Q when V >= EV
  717. #
  718. ###################################################################
  719. class VoteQuorumGoUp(VoteQuorumBase):
  720. # all up
  721. # calc min expected votes to get Q
  722. # bring nodes down one-by-one
  723. # confirm cluster looses Q when V < EV
  724. #
  725. def __init__(self, cm):
  726. VoteQuorumBase.__init__(self, cm)
  727. self.name="VoteQuorumGoUp"
  728. self.need_all_up = False
  729. self.expected = len(self.CM.Env["nodes"])
  730. self.config['quorum/provider'] = 'corosync_votequorum'
  731. self.config['quorum/expected_votes'] = self.expected
  732. #self.CM.log('set expected to %d' % (self.expected))
  733. def __call__(self, node):
  734. self.incr("calls")
  735. pats = []
  736. pats.append("%s .*VQ notification quorate: 1" % self.listener)
  737. pats.append("%s .*NQ notification quorate: 1" % self.listener)
  738. quorum = self.create_watch(pats, 30)
  739. quorum.setwatch()
  740. self.CM.StartaCM(self.listener)
  741. nodes_alive = 1
  742. state = QuorumState(self.CM, self.listener)
  743. state.refresh()
  744. for n in self.CM.Env["nodes"]:
  745. if n is self.listener:
  746. continue
  747. #if not self.wait_for_quorum_change():
  748. # return self.failure(self.error_message)
  749. if state.node_votes != 1:
  750. self.failure('unexpected number of node_votes')
  751. if state.expected_votes != self.expected:
  752. self.CM.log('nev: %d != exp %d' % (state.expected_votes, self.expected))
  753. self.failure('unexpected number of expected_votes')
  754. if state.total_votes != nodes_alive:
  755. self.failure('unexpected number of total votes')
  756. min = ((len(self.CM.Env["nodes"]) + 2) / 2)
  757. if min != state.quorum:
  758. self.failure('we should have %d (not %d) as quorum' % (min, state.quorum))
  759. if nodes_alive < state.quorum:
  760. if state.quorate == 1:
  761. self.failure('we should NOT have quorum(%d) %d > %d' % (state.quorate, state.quorum, nodes_alive))
  762. else:
  763. if state.quorate == 0:
  764. self.failure('we should have quorum(%d) %d <= %d' % (state.quorate, state.quorum, nodes_alive))
  765. self.CM.StartaCM(n)
  766. nodes_alive = nodes_alive + 1
  767. state.refresh()
  768. if not quorum.lookforall():
  769. self.CM.log("Patterns not found: " + repr(quorum.unmatched))
  770. return self.failure('quorm event not found')
  771. return self.success()
  772. ###################################################################
  773. class VoteQuorumContextTest(CoroTest):
  774. def __init__(self, cm):
  775. CoroTest.__init__(self, cm)
  776. self.name="VoteQuorumContextTest"
  777. self.expected = len(self.CM.Env["nodes"])
  778. self.config['quorum/provider'] = 'corosync_votequorum'
  779. self.config['quorum/expected_votes'] = self.expected
  780. def __call__(self, node):
  781. self.incr("calls")
  782. res = self.CM.votequorum_agent[node].context_test()
  783. if 'OK' in res:
  784. return self.success()
  785. else:
  786. return self.failure('context_test failed')
  787. ###################################################################
  788. class GenSimulStart(CoroTest):
  789. '''Start all the nodes ~ simultaneously'''
  790. def __init__(self, cm):
  791. CoroTest.__init__(self,cm)
  792. self.name="GenSimulStart"
  793. self.need_all_up = False
  794. self.stopall = SimulStopLite(cm)
  795. self.startall = SimulStartLite(cm)
  796. def __call__(self, dummy):
  797. '''Perform the 'SimulStart' test. '''
  798. self.incr("calls")
  799. # We ignore the "node" parameter...
  800. # Shut down all the nodes...
  801. ret = self.stopall(None)
  802. if not ret:
  803. return self.failure("Setup failed")
  804. self.CM.clear_all_caches()
  805. if not self.startall(None):
  806. return self.failure("Startall failed")
  807. return self.success()
  808. ###################################################################
  809. class GenSimulStop(CoroTest):
  810. '''Stop all the nodes ~ simultaneously'''
  811. def __init__(self, cm):
  812. CoroTest.__init__(self,cm)
  813. self.name="GenSimulStop"
  814. self.startall = SimulStartLite(cm)
  815. self.stopall = SimulStopLite(cm)
  816. self.need_all_up = True
  817. def __call__(self, dummy):
  818. '''Perform the 'GenSimulStop' test. '''
  819. self.incr("calls")
  820. # We ignore the "node" parameter...
  821. # Start up all the nodes...
  822. ret = self.startall(None)
  823. if not ret:
  824. return self.failure("Setup failed")
  825. if not self.stopall(None):
  826. return self.failure("Stopall failed")
  827. return self.success()
  828. GenTestClasses = []
  829. GenTestClasses.append(GenSimulStart)
  830. GenTestClasses.append(GenSimulStop)
  831. GenTestClasses.append(CpgMsgOrderBasic)
  832. GenTestClasses.append(CpgMsgOrderZcb)
  833. GenTestClasses.append(CpgCfgChgOnExecCrash)
  834. GenTestClasses.append(CpgCfgChgOnGroupLeave)
  835. GenTestClasses.append(CpgCfgChgOnNodeLeave)
  836. GenTestClasses.append(CpgCfgChgOnNodeIsolate)
  837. #GenTestClasses.append(CpgCfgChgOnNodeRestart)
  838. GenTestClasses.append(CpgCfgChgOnLowestNodeJoin)
  839. GenTestClasses.append(VoteQuorumGoDown)
  840. GenTestClasses.append(VoteQuorumGoUp)
  841. AllTestClasses = []
  842. AllTestClasses.append(ConfdbReplaceTest)
  843. AllTestClasses.append(ConfdbIncrementTest)
  844. AllTestClasses.append(ConfdbObjectFindTest)
  845. AllTestClasses.append(ConfdbNotificationTest)
  846. AllTestClasses.append(ConfdbContextTest)
  847. AllTestClasses.append(CpgContextTest)
  848. AllTestClasses.append(VoteQuorumContextTest)
  849. AllTestClasses.append(SamTest1)
  850. AllTestClasses.append(SamTest2)
  851. AllTestClasses.append(SamTest3)
  852. AllTestClasses.append(SamTest4)
  853. AllTestClasses.append(ServiceLoadTest)
  854. AllTestClasses.append(MemLeakObject)
  855. AllTestClasses.append(MemLeakSession)
  856. AllTestClasses.append(FlipTest)
  857. AllTestClasses.append(RestartTest)
  858. AllTestClasses.append(StartOnebyOne)
  859. AllTestClasses.append(StopOnebyOne)
  860. AllTestClasses.append(RestartOnebyOne)
  861. class ConfigContainer(UserDict):
  862. def __init__ (self, name):
  863. self.name = name
  864. UserDict.__init__(self)
  865. def CoroTestList(cm, audits):
  866. result = []
  867. configs = []
  868. for testclass in AllTestClasses:
  869. bound_test = testclass(cm)
  870. if bound_test.is_applicable():
  871. bound_test.Audits = audits
  872. result.append(bound_test)
  873. default = ConfigContainer('default')
  874. default['logging/function_name'] = 'off'
  875. default['logging/logfile_priority'] = 'info'
  876. default['logging/syslog_priority'] = 'info'
  877. default['logging/syslog_facility'] = 'daemon'
  878. default['uidgid/uid'] = '0'
  879. default['uidgid/gid'] = '0'
  880. configs.append(default)
  881. a = ConfigContainer('none_5min')
  882. a['compatibility'] = 'none'
  883. a['totem/token'] = (5 * 60 * 1000)
  884. configs.append(a)
  885. b = ConfigContainer('whitetank_5min')
  886. b['compatibility'] = 'whitetank'
  887. b['totem/token'] = (5 * 60 * 1000)
  888. configs.append(b)
  889. c = ConfigContainer('sec_nss')
  890. c['totem/secauth'] = 'on'
  891. c['totem/crypto_accept'] = 'new'
  892. c['totem/crypto_type'] = 'nss'
  893. configs.append(c)
  894. d = ConfigContainer('sec_sober')
  895. d['totem/secauth'] = 'on'
  896. d['totem/crypto_type'] = 'sober'
  897. configs.append(d)
  898. e = ConfigContainer('threads_4')
  899. e['totem/threads'] = 4
  900. configs.append(e)
  901. #quorum/provider=
  902. #f = {}
  903. #f['quorum/provider'] = 'corosync_quorum_ykd'
  904. #configs.append(f)
  905. if not cm.Env["RrpBindAddr"] is None:
  906. g = ConfigContainer('rrp_passive')
  907. g['totem/rrp_mode'] = 'passive'
  908. g['totem/interface[2]/ringnumber'] = '1'
  909. g['totem/interface[2]/bindnetaddr'] = cm.Env["RrpBindAddr"]
  910. g['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  911. g['totem/interface[2]/mcastport'] = '5405'
  912. configs.append(g)
  913. h = ConfigContainer('rrp_active')
  914. h['totem/rrp_mode'] = 'active'
  915. h['totem/interface[2]/ringnumber'] = '1'
  916. h['totem/interface[2]/bindnetaddr'] = cm.Env["RrpBindAddr"]
  917. h['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  918. h['totem/interface[2]/mcastport'] = '5405'
  919. configs.append(h)
  920. else:
  921. print 'Not including rrp tests. Use --rrp-binaddr to enable them.'
  922. num=1
  923. for cfg in configs:
  924. for testclass in GenTestClasses:
  925. bound_test = testclass(cm)
  926. if bound_test.is_applicable() and bound_test.config_valid(cfg):
  927. bound_test.Audits = audits
  928. for c in cfg.keys():
  929. bound_test.config[c] = cfg[c]
  930. bound_test.name = bound_test.name + '_' + cfg.name
  931. result.append(bound_test)
  932. num = num + 1
  933. return result