corotests.py 37 KB

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