corotests.py 34 KB

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