corotests.py 35 KB

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