corotests.py 33 KB

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