corotests.py 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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. def refresh(self):
  535. info = self.CM.votequorum_agent[self.node].votequorum_getinfo()
  536. assert(info != 'FAIL')
  537. assert(info != 'NOT_SUPPORTED')
  538. #self.CM.log('refresh: ' + info)
  539. params = info.split(':')
  540. self.node_votes = int(params[0])
  541. self.expected_votes = int(params[1])
  542. self.highest_expected = int(params[2])
  543. self.total_votes = int(params[3])
  544. self.quorum = int(params[4])
  545. self.quorate = self.CM.votequorum_agent[self.node].quorum_getquorate()
  546. assert(self.quorate != 'FAIL')
  547. assert(self.quorate != 'NOT_SUPPORTED')
  548. #self.CM.log('quorate: ' + str(self.quorate))
  549. ###################################################################
  550. class VoteQuorumBase(CoroTest):
  551. '''
  552. '''
  553. def setup(self, node):
  554. ret = CoroTest.setup(self, node)
  555. self.id_map = {}
  556. self.listener = None
  557. for n in self.CM.Env["nodes"]:
  558. if self.listener is None:
  559. self.listener = n
  560. if self.need_all_up:
  561. self.CM.cpg_agent[n].clean_start()
  562. self.CM.cpg_agent[n].cpg_join(self.name)
  563. self.id_map[n] = self.CM.cpg_agent[n].cpg_local_get()
  564. #self.CM.votequorum_agent[self.listener].record_events()
  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. def wait_for_quorum_change(self):
  572. found = False
  573. max_timeout = 5 * 60
  574. waited = 0
  575. printit = 0
  576. self.CM.log("Waiting for quorum event on " + self.listener)
  577. while not found:
  578. try:
  579. event = self.CM.votequorum_agent[self.listener].read_event()
  580. except:
  581. return self.failure('connection to test agent failed.')
  582. if not event == None:
  583. self.CM.debug("RECEIVED: " + str(event))
  584. if event == None:
  585. if waited >= max_timeout:
  586. return self.failure("timedout(" + str(waited) + " sec) == no event!")
  587. else:
  588. time.sleep(1)
  589. waited = waited + 1
  590. printit = printit + 1
  591. if printit is 60:
  592. print 'waited 60 seconds'
  593. printit = 0
  594. elif str(event.node_id) in str(self.wobbly_id) and not event.is_member:
  595. self.CM.log("Got the config change in " + str(waited) + " seconds")
  596. found = True
  597. else:
  598. self.CM.debug("No match")
  599. self.CM.debug("wobbly nodeid:" + str(self.wobbly_id))
  600. self.CM.debug("event nodeid:" + str(event.node_id))
  601. self.CM.debug("event.is_member:" + str(event.is_member))
  602. if found:
  603. return self.success()
  604. # repeat below with equal and uneven votes
  605. ###################################################################
  606. class VoteQuorumGoDown(VoteQuorumBase):
  607. # all up
  608. # calc min expected votes to get Q
  609. # bring nodes down one-by-one
  610. # confirm cluster looses Q when V < EV
  611. #
  612. def __init__(self, cm):
  613. VoteQuorumBase.__init__(self, cm)
  614. self.name="VoteQuorumGoDown"
  615. self.victims = []
  616. self.expected = len(self.CM.Env["nodes"])
  617. self.config['quorum/provider'] = 'corosync_votequorum'
  618. self.config['quorum/expected_votes'] = self.expected
  619. #self.CM.log('set expected to %d' % (self.expected))
  620. def __call__(self, node):
  621. self.incr("calls")
  622. state = QuorumState(self.CM, self.listener)
  623. for n in self.CM.Env["nodes"]:
  624. if n is self.listener:
  625. continue
  626. self.victims.append(n)
  627. self.CM.StopaCM(n)
  628. nodes_alive = len(self.CM.Env["nodes"]) - len(self.victims)
  629. state.refresh()
  630. #self.expected = self.expected - 1
  631. if state.node_votes != 1:
  632. self.failure('unexpected number of node_votes')
  633. if state.expected_votes != self.expected:
  634. self.CM.log('nev: %d != exp %d' % (state.expected_votes, self.expected))
  635. self.failure('unexpected number of expected_votes')
  636. if state.total_votes != nodes_alive:
  637. self.failure('unexpected number of total votes')
  638. min = ((len(self.CM.Env["nodes"]) + 2) / 2)
  639. if min != state.quorum:
  640. self.failure('we should have %d (not %d) as quorum' % (min, state.quorum))
  641. if nodes_alive < state.quorum:
  642. if state.quorate == 1:
  643. self.failure('we should NOT have quorum(%d) %d > %d' % (state.quorate, state.quorum, nodes_alive))
  644. else:
  645. if state.quorate == 0:
  646. self.failure('we should have quorum(%d) %d <= %d' % (state.quorate, state.quorum, nodes_alive))
  647. return self.success()
  648. # all down
  649. # calc min expected votes to get Q
  650. # bring nodes up one-by-one
  651. # confirm cluster gains Q when V >= EV
  652. #
  653. ###################################################################
  654. class VoteQuorumGoUp(VoteQuorumBase):
  655. # all up
  656. # calc min expected votes to get Q
  657. # bring nodes down one-by-one
  658. # confirm cluster looses Q when V < EV
  659. #
  660. def __init__(self, cm):
  661. VoteQuorumBase.__init__(self, cm)
  662. self.name="VoteQuorumGoUp"
  663. self.need_all_up = False
  664. self.expected = len(self.CM.Env["nodes"])
  665. self.config['quorum/provider'] = 'corosync_votequorum'
  666. self.config['quorum/expected_votes'] = self.expected
  667. #self.CM.log('set expected to %d' % (self.expected))
  668. def __call__(self, node):
  669. self.incr("calls")
  670. self.CM.StartaCM(self.listener)
  671. nodes_alive = 1
  672. state = QuorumState(self.CM, self.listener)
  673. state.refresh()
  674. for n in self.CM.Env["nodes"]:
  675. if n is self.listener:
  676. continue
  677. if state.node_votes != 1:
  678. self.failure('unexpected number of node_votes')
  679. if state.expected_votes != self.expected:
  680. self.CM.log('nev: %d != exp %d' % (state.expected_votes, self.expected))
  681. self.failure('unexpected number of expected_votes')
  682. if state.total_votes != nodes_alive:
  683. self.failure('unexpected number of total votes')
  684. min = ((len(self.CM.Env["nodes"]) + 2) / 2)
  685. if min != state.quorum:
  686. self.failure('we should have %d (not %d) as quorum' % (min, state.quorum))
  687. if nodes_alive < state.quorum:
  688. if state.quorate == 1:
  689. self.failure('we should NOT have quorum(%d) %d > %d' % (state.quorate, state.quorum, nodes_alive))
  690. else:
  691. if state.quorate == 0:
  692. self.failure('we should have quorum(%d) %d <= %d' % (state.quorate, state.quorum, nodes_alive))
  693. self.CM.StartaCM(n)
  694. nodes_alive = nodes_alive + 1
  695. state.refresh()
  696. return self.success()
  697. ###################################################################
  698. class GenSimulStart(CoroTest):
  699. ###################################################################
  700. '''Start all the nodes ~ simultaneously'''
  701. def __init__(self, cm):
  702. CoroTest.__init__(self,cm)
  703. self.name="GenSimulStart"
  704. self.need_all_up = False
  705. self.stopall = SimulStopLite(cm)
  706. self.startall = SimulStartLite(cm)
  707. def __call__(self, dummy):
  708. '''Perform the 'SimulStart' test. '''
  709. self.incr("calls")
  710. # We ignore the "node" parameter...
  711. # Shut down all the nodes...
  712. ret = self.stopall(None)
  713. if not ret:
  714. return self.failure("Setup failed")
  715. self.CM.clear_all_caches()
  716. if not self.startall(None):
  717. return self.failure("Startall failed")
  718. return self.success()
  719. ###################################################################
  720. class GenSimulStop(CoroTest):
  721. ###################################################################
  722. '''Stop all the nodes ~ simultaneously'''
  723. def __init__(self, cm):
  724. CoroTest.__init__(self,cm)
  725. self.name="GenSimulStop"
  726. self.startall = SimulStartLite(cm)
  727. self.stopall = SimulStopLite(cm)
  728. self.need_all_up = True
  729. def __call__(self, dummy):
  730. '''Perform the 'GenSimulStop' test. '''
  731. self.incr("calls")
  732. # We ignore the "node" parameter...
  733. # Start up all the nodes...
  734. ret = self.startall(None)
  735. if not ret:
  736. return self.failure("Setup failed")
  737. if not self.stopall(None):
  738. return self.failure("Stopall failed")
  739. return self.success()
  740. GenTestClasses = []
  741. GenTestClasses.append(GenSimulStart)
  742. GenTestClasses.append(GenSimulStop)
  743. GenTestClasses.append(CpgMsgOrderBasic)
  744. GenTestClasses.append(CpgMsgOrderZcb)
  745. GenTestClasses.append(CpgCfgChgOnExecCrash)
  746. GenTestClasses.append(CpgCfgChgOnGroupLeave)
  747. GenTestClasses.append(CpgCfgChgOnNodeLeave)
  748. GenTestClasses.append(CpgCfgChgOnNodeIsolate)
  749. GenTestClasses.append(CpgCfgChgOnLowestNodeJoin)
  750. GenTestClasses.append(VoteQuorumGoDown)
  751. GenTestClasses.append(VoteQuorumGoUp)
  752. AllTestClasses = []
  753. AllTestClasses.append(ConfdbReplaceTest)
  754. AllTestClasses.append(ConfdbIncrementTest)
  755. AllTestClasses.append(ConfdbObjectFindTest)
  756. AllTestClasses.append(ConfdbNotificationTest)
  757. AllTestClasses.append(SamTest1)
  758. AllTestClasses.append(SamTest2)
  759. AllTestClasses.append(SamTest3)
  760. AllTestClasses.append(SamTest4)
  761. AllTestClasses.append(ServiceLoadTest)
  762. AllTestClasses.append(MemLeakObject)
  763. AllTestClasses.append(MemLeakSession)
  764. AllTestClasses.append(FlipTest)
  765. AllTestClasses.append(RestartTest)
  766. AllTestClasses.append(StartOnebyOne)
  767. AllTestClasses.append(StopOnebyOne)
  768. AllTestClasses.append(RestartOnebyOne)
  769. class ConfigContainer(UserDict):
  770. def __init__ (self, name):
  771. self.name = name
  772. UserDict.__init__(self)
  773. def CoroTestList(cm, audits):
  774. result = []
  775. configs = []
  776. for testclass in AllTestClasses:
  777. bound_test = testclass(cm)
  778. if bound_test.is_applicable():
  779. bound_test.Audits = audits
  780. result.append(bound_test)
  781. default = ConfigContainer('default')
  782. default['logging/function_name'] = 'off'
  783. default['logging/logfile_priority'] = 'info'
  784. default['logging/syslog_priority'] = 'info'
  785. default['logging/syslog_facility'] = 'daemon'
  786. default['uidgid/uid'] = '0'
  787. default['uidgid/gid'] = '0'
  788. configs.append(default)
  789. a = ConfigContainer('none_10000')
  790. a['compatibility'] = 'none'
  791. a['totem/token'] = 10000
  792. configs.append(a)
  793. b = ConfigContainer('whitetank_10000')
  794. b['compatibility'] = 'whitetank'
  795. b['totem/token'] = 10000
  796. configs.append(b)
  797. c = ConfigContainer('sec_nss')
  798. c['totem/secauth'] = 'on'
  799. c['totem/crypto_accept'] = 'new'
  800. c['totem/crypto_type'] = 'nss'
  801. configs.append(c)
  802. d = ConfigContainer('sec_sober')
  803. d['totem/secauth'] = 'on'
  804. d['totem/crypto_type'] = 'sober'
  805. configs.append(d)
  806. e = ConfigContainer('threads_4')
  807. e['totem/threads'] = 4
  808. configs.append(e)
  809. #quorum/provider=
  810. #f = {}
  811. #f['quorum/provider'] = 'corosync_quorum_ykd'
  812. #configs.append(f)
  813. if not cm.Env["RrpBindAddr"] is None:
  814. g = ConfigContainer('rrp_passive')
  815. g['totem/rrp_mode'] = 'passive'
  816. g['totem/interface[2]/ringnumber'] = '1'
  817. g['totem/interface[2]/bindnetaddr'] = cm.Env["RrpBindAddr"]
  818. g['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  819. g['totem/interface[2]/mcastport'] = '5405'
  820. configs.append(g)
  821. h = ConfigContainer('rrp_active')
  822. h['totem/rrp_mode'] = 'active'
  823. h['totem/interface[2]/ringnumber'] = '1'
  824. h['totem/interface[2]/bindnetaddr'] = cm.Env["RrpBindAddr"]
  825. h['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  826. h['totem/interface[2]/mcastport'] = '5405'
  827. configs.append(h)
  828. else:
  829. print 'Not including rrp tests. Use --rrp-binaddr to enable them.'
  830. num=1
  831. for cfg in configs:
  832. for testclass in GenTestClasses:
  833. bound_test = testclass(cm)
  834. if bound_test.is_applicable() and bound_test.config_valid(cfg):
  835. bound_test.Audits = audits
  836. for c in cfg.keys():
  837. bound_test.config[c] = cfg[c]
  838. bound_test.name = bound_test.name + '_' + cfg.name
  839. result.append(bound_test)
  840. num = num + 1
  841. return result