corotests.py 31 KB

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