corotests.py 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  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 failure_action(self):
  254. self.CM.log("isolating node " + self.wobbly)
  255. self.CM.isolate_node(self.wobbly)
  256. def __call__(self, node):
  257. self.incr("calls")
  258. self.failure_action()
  259. return self.wait_for_config_change()
  260. def teardown(self, node):
  261. self.CM.unisolate_node (self.wobbly)
  262. return CpgConfigChangeBase.teardown(self, node)
  263. ###################################################################
  264. class CpgMsgOrderBase(CoroTest):
  265. def __init__(self, cm):
  266. CoroTest.__init__(self,cm)
  267. self.num_msgs_per_node = 0
  268. self.total_num_msgs = 0
  269. def setup(self, node):
  270. ret = CoroTest.setup(self, node)
  271. for n in self.CM.Env["nodes"]:
  272. self.total_num_msgs = self.total_num_msgs + self.num_msgs_per_node
  273. self.CM.cpg_agent[n].clean_start()
  274. self.CM.cpg_agent[n].cpg_join(self.name)
  275. self.CM.cpg_agent[n].record_messages()
  276. time.sleep(1)
  277. return ret
  278. def cpg_msg_blaster(self):
  279. for n in self.CM.Env["nodes"]:
  280. self.CM.cpg_agent[n].msg_blaster(self.num_msgs_per_node)
  281. def wait_and_validate_order(self):
  282. msgs = {}
  283. for n in self.CM.Env["nodes"]:
  284. msgs[n] = []
  285. stopped = False
  286. waited = 0
  287. while len(msgs[n]) < self.total_num_msgs and waited < 360:
  288. msg = self.CM.cpg_agent[n].read_messages(50)
  289. if not msg == None:
  290. msgl = msg.split(";")
  291. # remove empty entries
  292. not_done=True
  293. while not_done:
  294. try:
  295. msgl.remove('')
  296. except:
  297. not_done = False
  298. msgs[n].extend(msgl)
  299. elif msg == None:
  300. time.sleep(2)
  301. waited = waited + 2
  302. if len(msgs[n]) < self.total_num_msgs:
  303. return self.failure("expected %d messages from %s got %d" % (self.total_num_msgs, n, len(msgs[n])))
  304. fail = False
  305. error_message = ''
  306. for i in range(0, self.total_num_msgs):
  307. first = None
  308. for n in self.CM.Env["nodes"]:
  309. # first test for errors
  310. params = msgs[n][i].split(":")
  311. if not 'OK' in params[3]:
  312. fail = True
  313. error_message = 'error: ' + params[3] + ' in received message'
  314. self.CM.log(str(params))
  315. # then look for out of order messages
  316. if first == None:
  317. first = n
  318. else:
  319. if not msgs[first][i] == msgs[n][i]:
  320. # message order not the same!
  321. fail = True
  322. error_message = 'message out of order'
  323. self.CM.log(msgs[first][i] + " != " + msgs[n][i])
  324. if fail:
  325. return self.failure(error_message)
  326. else:
  327. return self.success()
  328. ###################################################################
  329. class CpgMsgOrderBasic(CpgMsgOrderBase):
  330. '''
  331. each sends & logs lots of messages
  332. '''
  333. def __init__(self, cm):
  334. CpgMsgOrderBase.__init__(self,cm)
  335. self.name="CpgMsgOrderBasic"
  336. self.num_msgs_per_node = 9000
  337. def __call__(self, node):
  338. self.incr("calls")
  339. for n in self.CM.Env["nodes"]:
  340. self.CM.cpg_agent[n].msg_blaster(self.num_msgs_per_node)
  341. return self.wait_and_validate_order()
  342. ###################################################################
  343. class CpgMsgOrderZcb(CpgMsgOrderBase):
  344. '''
  345. each sends & logs lots of messages
  346. '''
  347. def __init__(self, cm):
  348. CpgMsgOrderBase.__init__(self,cm)
  349. self.name="CpgMsgOrderZcb"
  350. self.num_msgs_per_node = 9000
  351. def __call__(self, node):
  352. self.incr("calls")
  353. for n in self.CM.Env["nodes"]:
  354. self.CM.cpg_agent[n].msg_blaster_zcb(self.num_msgs_per_node)
  355. return self.wait_and_validate_order()
  356. ###################################################################
  357. class MemLeakObject(CoroTest):
  358. '''
  359. run mem_leak_test.sh -1
  360. '''
  361. def __init__(self, cm):
  362. CoroTest.__init__(self,cm)
  363. self.name="MemLeakObject"
  364. def __call__(self, node):
  365. self.incr("calls")
  366. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -1")
  367. if mem_leaked is 0:
  368. return self.success()
  369. else:
  370. return self.failure(str(mem_leaked) + 'kB memory leaked.')
  371. ###################################################################
  372. class MemLeakSession(CoroTest):
  373. '''
  374. run mem_leak_test.sh -2
  375. '''
  376. def __init__(self, cm):
  377. CoroTest.__init__(self,cm)
  378. self.name="MemLeakSession"
  379. def __call__(self, node):
  380. self.incr("calls")
  381. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -2")
  382. if mem_leaked is 0:
  383. return self.success()
  384. else:
  385. return self.failure(str(mem_leaked) + 'kB memory leaked.')
  386. ###################################################################
  387. class ServiceLoadTest(CoroTest):
  388. '''
  389. Test loading and unloading of service engines
  390. '''
  391. def __init__(self, cm):
  392. CoroTest.__init__(self, cm)
  393. self.name="ServiceLoadTest"
  394. def is_loaded(self, node):
  395. check = 'corosync-objctl runtime.services. | grep evs'
  396. (res, out) = self.CM.rsh(node, check, stdout=2)
  397. if res is 0:
  398. return True
  399. else:
  400. return False
  401. def service_unload(self, node):
  402. # unload evs
  403. pats = []
  404. pats.append("%s .*Service engine unloaded: corosync extended.*" % node)
  405. unloaded = self.create_watch(pats, 60)
  406. unloaded.setwatch()
  407. self.CM.rsh(node, 'corosync-cfgtool -u corosync_evs')
  408. if not unloaded.lookforall():
  409. self.CM.log("Patterns not found: " + repr(unloaded.unmatched))
  410. self.error_message = "evs service not unloaded"
  411. return False
  412. if self.is_loaded(node):
  413. self.error_message = "evs has been unload, why are it's session objects are still there?"
  414. return False
  415. return True
  416. def service_load(self, node):
  417. # now reload it.
  418. pats = []
  419. pats.append("%s .*Service engine loaded.*" % node)
  420. loaded = self.create_watch(pats, 60)
  421. loaded.setwatch()
  422. self.CM.rsh(node, 'corosync-cfgtool -l corosync_evs')
  423. if not loaded.lookforall():
  424. self.CM.log("Patterns not found: " + repr(loaded.unmatched))
  425. self.error_message = "evs service not unloaded"
  426. return False
  427. return True
  428. def __call__(self, node):
  429. self.incr("calls")
  430. should_be_loaded = True
  431. if self.is_loaded(node):
  432. ret = self.service_unload(node)
  433. should_be_loaded = False
  434. else:
  435. ret = self.service_load(node)
  436. should_be_loaded = True
  437. if not ret:
  438. return self.failure(self.error_message)
  439. if self.is_loaded(node):
  440. ret = self.service_unload(node)
  441. else:
  442. ret = self.service_load(node)
  443. if not ret:
  444. return self.failure(self.error_message)
  445. return self.success()
  446. ###################################################################
  447. class ConfdbReplaceTest(CoroTest):
  448. def __init__(self, cm):
  449. CoroTest.__init__(self, cm)
  450. self.name="ConfdbReplaceTest"
  451. def __call__(self, node):
  452. self.incr("calls")
  453. res = self.CM.confdb_agent[node].set_get_test()
  454. if 'OK' in res:
  455. return self.success()
  456. else:
  457. return self.failure('set_get_test failed')
  458. ###################################################################
  459. class ConfdbContextTest(CoroTest):
  460. def __init__(self, cm):
  461. CoroTest.__init__(self, cm)
  462. self.name="ConfdbContextTest"
  463. def __call__(self, node):
  464. self.incr("calls")
  465. res = self.CM.confdb_agent[node].context_test()
  466. if 'OK' in res:
  467. return self.success()
  468. else:
  469. return self.failure('context_test failed')
  470. ###################################################################
  471. class ConfdbIncrementTest(CoroTest):
  472. def __init__(self, cm):
  473. CoroTest.__init__(self, cm)
  474. self.name="ConfdbIncrementTest"
  475. def __call__(self, node):
  476. self.incr("calls")
  477. res = self.CM.confdb_agent[node].increment_decrement_test()
  478. if 'OK' in res:
  479. return self.success()
  480. else:
  481. return self.failure('increment_decrement_test failed')
  482. ###################################################################
  483. class ConfdbObjectFindTest(CoroTest):
  484. def __init__(self, cm):
  485. CoroTest.__init__(self, cm)
  486. self.name="ConfdbObjectFindTest"
  487. def __call__(self, node):
  488. self.incr("calls")
  489. res = self.CM.confdb_agent[node].object_find_test()
  490. if 'OK' in res:
  491. return self.success()
  492. else:
  493. return self.failure('object_find_test failed')
  494. ###################################################################
  495. class ConfdbNotificationTest(CoroTest):
  496. def __init__(self, cm):
  497. CoroTest.__init__(self, cm)
  498. self.name="ConfdbNotificationTest"
  499. def __call__(self, node):
  500. self.incr("calls")
  501. res = self.CM.confdb_agent[node].notification_test()
  502. if 'OK' in res:
  503. return self.success()
  504. else:
  505. return self.failure('notification_test failed')
  506. ###################################################################
  507. class SamTest1(CoroTest):
  508. def __init__(self, cm):
  509. CoroTest.__init__(self, cm)
  510. self.name="SamTest1"
  511. def __call__(self, node):
  512. self.incr("calls")
  513. res = self.CM.sam_agent[node].test1()
  514. if 'OK' in res:
  515. return self.success()
  516. else:
  517. return self.failure('sam test 1 failed')
  518. ###################################################################
  519. class SamTest2(CoroTest):
  520. def __init__(self, cm):
  521. CoroTest.__init__(self, cm)
  522. self.name="SamTest2"
  523. def __call__(self, node):
  524. self.incr("calls")
  525. res = self.CM.sam_agent[node].test2()
  526. if 'OK' in res:
  527. return self.success()
  528. else:
  529. return self.failure('sam test 2 failed')
  530. ###################################################################
  531. class SamTest3(CoroTest):
  532. def __init__(self, cm):
  533. CoroTest.__init__(self, cm)
  534. self.name="SamTest3"
  535. def __call__(self, node):
  536. self.incr("calls")
  537. res = self.CM.sam_agent[node].test3()
  538. if 'OK' in res:
  539. return self.success()
  540. else:
  541. return self.failure('sam test 3 failed')
  542. ###################################################################
  543. class SamTest4(CoroTest):
  544. def __init__(self, cm):
  545. CoroTest.__init__(self, cm)
  546. self.name="SamTest4"
  547. def __call__(self, node):
  548. self.incr("calls")
  549. res = self.CM.sam_agent[node].test4()
  550. if 'OK' in res:
  551. return self.success()
  552. else:
  553. return self.failure('sam test 4 failed')
  554. class QuorumState(object):
  555. def __init__(self, cm, node):
  556. self.node = node
  557. self.CM = cm
  558. self.CM.votequorum_agent[self.node].init()
  559. def refresh(self):
  560. info = self.CM.votequorum_agent[self.node].votequorum_getinfo()
  561. assert(info != 'FAIL')
  562. assert(info != 'NOT_SUPPORTED')
  563. #self.CM.log('refresh: ' + info)
  564. params = info.split(':')
  565. self.node_votes = int(params[0])
  566. self.expected_votes = int(params[1])
  567. self.highest_expected = int(params[2])
  568. self.total_votes = int(params[3])
  569. self.quorum = int(params[4])
  570. self.quorate = self.CM.votequorum_agent[self.node].quorum_getquorate()
  571. assert(self.quorate != 'FAIL')
  572. assert(self.quorate != 'NOT_SUPPORTED')
  573. #self.CM.log('quorate: ' + str(self.quorate))
  574. ###################################################################
  575. class VoteQuorumBase(CoroTest):
  576. '''
  577. '''
  578. def setup(self, node):
  579. ret = CoroTest.setup(self, node)
  580. self.id_map = {}
  581. self.listener = None
  582. for n in self.CM.Env["nodes"]:
  583. if self.listener is None:
  584. self.listener = n
  585. if self.need_all_up:
  586. self.CM.cpg_agent[n].clean_start()
  587. self.CM.cpg_agent[n].cpg_join(self.name)
  588. self.id_map[n] = self.CM.cpg_agent[n].cpg_local_get()
  589. return ret
  590. def config_valid(self, config):
  591. if config.has_key('totem/rrp_mode'):
  592. return False
  593. else:
  594. return True
  595. ###################################################################
  596. class VoteQuorumGoDown(VoteQuorumBase):
  597. # all up
  598. # calc min expected votes to get Q
  599. # bring nodes down one-by-one
  600. # confirm cluster looses Q when V < EV
  601. #
  602. def __init__(self, cm):
  603. VoteQuorumBase.__init__(self, cm)
  604. self.name="VoteQuorumGoDown"
  605. self.victims = []
  606. self.expected = len(self.CM.Env["nodes"])
  607. self.config['quorum/provider'] = 'corosync_votequorum'
  608. self.config['quorum/expected_votes'] = self.expected
  609. #self.CM.log('set expected to %d' % (self.expected))
  610. def __call__(self, node):
  611. self.incr("calls")
  612. pats = []
  613. pats.append("%s .*VQ notification quorate: 0" % self.listener)
  614. pats.append("%s .*NQ notification quorate: 0" % self.listener)
  615. quorum = self.create_watch(pats, 30)
  616. quorum.setwatch()
  617. state = QuorumState(self.CM, self.listener)
  618. state.refresh()
  619. for n in self.CM.Env["nodes"]:
  620. if n is self.listener:
  621. continue
  622. self.victims.append(n)
  623. self.CM.StopaCM(n)
  624. #if not self.wait_for_quorum_change():
  625. # return self.failure(self.error_message)
  626. nodes_alive = len(self.CM.Env["nodes"]) - len(self.victims)
  627. state.refresh()
  628. #self.expected = self.expected - 1
  629. if state.node_votes != 1:
  630. self.failure('unexpected number of node_votes')
  631. if state.expected_votes != self.expected:
  632. self.CM.log('nev: %d != exp %d' % (state.expected_votes, self.expected))
  633. self.failure('unexpected number of expected_votes')
  634. if state.total_votes != nodes_alive:
  635. self.failure('unexpected number of total votes')
  636. min = ((len(self.CM.Env["nodes"]) + 2) / 2)
  637. if min != state.quorum:
  638. self.failure('we should have %d (not %d) as quorum' % (min, state.quorum))
  639. if nodes_alive < state.quorum:
  640. if state.quorate == 1:
  641. self.failure('we should NOT have quorum(%d) %d > %d' % (state.quorate, state.quorum, nodes_alive))
  642. else:
  643. if state.quorate == 0:
  644. self.failure('we should have quorum(%d) %d <= %d' % (state.quorate, state.quorum, nodes_alive))
  645. if not quorum.lookforall():
  646. self.CM.log("Patterns not found: " + repr(quorum.unmatched))
  647. return self.failure('quorm event not found')
  648. return self.success()
  649. # all down
  650. # calc min expected votes to get Q
  651. # bring nodes up one-by-one
  652. # confirm cluster gains Q when V >= EV
  653. #
  654. ###################################################################
  655. class VoteQuorumGoUp(VoteQuorumBase):
  656. # all up
  657. # calc min expected votes to get Q
  658. # bring nodes down one-by-one
  659. # confirm cluster looses Q when V < EV
  660. #
  661. def __init__(self, cm):
  662. VoteQuorumBase.__init__(self, cm)
  663. self.name="VoteQuorumGoUp"
  664. self.need_all_up = False
  665. self.expected = len(self.CM.Env["nodes"])
  666. self.config['quorum/provider'] = 'corosync_votequorum'
  667. self.config['quorum/expected_votes'] = self.expected
  668. #self.CM.log('set expected to %d' % (self.expected))
  669. def __call__(self, node):
  670. self.incr("calls")
  671. pats = []
  672. pats.append("%s .*VQ notification quorate: 1" % self.listener)
  673. pats.append("%s .*NQ notification quorate: 1" % self.listener)
  674. quorum = self.create_watch(pats, 30)
  675. quorum.setwatch()
  676. self.CM.StartaCM(self.listener)
  677. nodes_alive = 1
  678. state = QuorumState(self.CM, self.listener)
  679. state.refresh()
  680. for n in self.CM.Env["nodes"]:
  681. if n is self.listener:
  682. continue
  683. #if not self.wait_for_quorum_change():
  684. # return self.failure(self.error_message)
  685. if state.node_votes != 1:
  686. self.failure('unexpected number of node_votes')
  687. if state.expected_votes != self.expected:
  688. self.CM.log('nev: %d != exp %d' % (state.expected_votes, self.expected))
  689. self.failure('unexpected number of expected_votes')
  690. if state.total_votes != nodes_alive:
  691. self.failure('unexpected number of total votes')
  692. min = ((len(self.CM.Env["nodes"]) + 2) / 2)
  693. if min != state.quorum:
  694. self.failure('we should have %d (not %d) as quorum' % (min, state.quorum))
  695. if nodes_alive < state.quorum:
  696. if state.quorate == 1:
  697. self.failure('we should NOT have quorum(%d) %d > %d' % (state.quorate, state.quorum, nodes_alive))
  698. else:
  699. if state.quorate == 0:
  700. self.failure('we should have quorum(%d) %d <= %d' % (state.quorate, state.quorum, nodes_alive))
  701. self.CM.StartaCM(n)
  702. nodes_alive = nodes_alive + 1
  703. state.refresh()
  704. if not quorum.lookforall():
  705. self.CM.log("Patterns not found: " + repr(quorum.unmatched))
  706. return self.failure('quorm event not found')
  707. return self.success()
  708. ###################################################################
  709. class VoteQuorumContextTest(CoroTest):
  710. def __init__(self, cm):
  711. CoroTest.__init__(self, cm)
  712. self.name="VoteQuorumContextTest"
  713. self.expected = len(self.CM.Env["nodes"])
  714. self.config['quorum/provider'] = 'corosync_votequorum'
  715. self.config['quorum/expected_votes'] = self.expected
  716. def __call__(self, node):
  717. self.incr("calls")
  718. res = self.CM.votequorum_agent[node].context_test()
  719. if 'OK' in res:
  720. return self.success()
  721. else:
  722. return self.failure('context_test failed')
  723. ###################################################################
  724. class GenSimulStart(CoroTest):
  725. '''Start all the nodes ~ simultaneously'''
  726. def __init__(self, cm):
  727. CoroTest.__init__(self,cm)
  728. self.name="GenSimulStart"
  729. self.need_all_up = False
  730. self.stopall = SimulStopLite(cm)
  731. self.startall = SimulStartLite(cm)
  732. def __call__(self, dummy):
  733. '''Perform the 'SimulStart' test. '''
  734. self.incr("calls")
  735. # We ignore the "node" parameter...
  736. # Shut down all the nodes...
  737. ret = self.stopall(None)
  738. if not ret:
  739. return self.failure("Setup failed")
  740. self.CM.clear_all_caches()
  741. if not self.startall(None):
  742. return self.failure("Startall failed")
  743. return self.success()
  744. ###################################################################
  745. class GenSimulStop(CoroTest):
  746. '''Stop all the nodes ~ simultaneously'''
  747. def __init__(self, cm):
  748. CoroTest.__init__(self,cm)
  749. self.name="GenSimulStop"
  750. self.startall = SimulStartLite(cm)
  751. self.stopall = SimulStopLite(cm)
  752. self.need_all_up = True
  753. def __call__(self, dummy):
  754. '''Perform the 'GenSimulStop' test. '''
  755. self.incr("calls")
  756. # We ignore the "node" parameter...
  757. # Start up all the nodes...
  758. ret = self.startall(None)
  759. if not ret:
  760. return self.failure("Setup failed")
  761. if not self.stopall(None):
  762. return self.failure("Stopall failed")
  763. return self.success()
  764. GenTestClasses = []
  765. GenTestClasses.append(GenSimulStart)
  766. GenTestClasses.append(GenSimulStop)
  767. GenTestClasses.append(CpgMsgOrderBasic)
  768. GenTestClasses.append(CpgMsgOrderZcb)
  769. GenTestClasses.append(CpgCfgChgOnExecCrash)
  770. GenTestClasses.append(CpgCfgChgOnGroupLeave)
  771. GenTestClasses.append(CpgCfgChgOnNodeLeave)
  772. GenTestClasses.append(CpgCfgChgOnNodeIsolate)
  773. GenTestClasses.append(CpgCfgChgOnLowestNodeJoin)
  774. GenTestClasses.append(VoteQuorumGoDown)
  775. GenTestClasses.append(VoteQuorumGoUp)
  776. AllTestClasses = []
  777. AllTestClasses.append(ConfdbReplaceTest)
  778. AllTestClasses.append(ConfdbIncrementTest)
  779. AllTestClasses.append(ConfdbObjectFindTest)
  780. AllTestClasses.append(ConfdbNotificationTest)
  781. AllTestClasses.append(ConfdbContextTest)
  782. AllTestClasses.append(CpgContextTest)
  783. AllTestClasses.append(VoteQuorumContextTest)
  784. AllTestClasses.append(SamTest1)
  785. AllTestClasses.append(SamTest2)
  786. AllTestClasses.append(SamTest3)
  787. AllTestClasses.append(SamTest4)
  788. AllTestClasses.append(ServiceLoadTest)
  789. AllTestClasses.append(MemLeakObject)
  790. AllTestClasses.append(MemLeakSession)
  791. AllTestClasses.append(FlipTest)
  792. AllTestClasses.append(RestartTest)
  793. AllTestClasses.append(StartOnebyOne)
  794. AllTestClasses.append(StopOnebyOne)
  795. AllTestClasses.append(RestartOnebyOne)
  796. class ConfigContainer(UserDict):
  797. def __init__ (self, name):
  798. self.name = name
  799. UserDict.__init__(self)
  800. def CoroTestList(cm, audits):
  801. result = []
  802. configs = []
  803. for testclass in AllTestClasses:
  804. bound_test = testclass(cm)
  805. if bound_test.is_applicable():
  806. bound_test.Audits = audits
  807. result.append(bound_test)
  808. default = ConfigContainer('default')
  809. default['logging/function_name'] = 'off'
  810. default['logging/logfile_priority'] = 'info'
  811. default['logging/syslog_priority'] = 'info'
  812. default['logging/syslog_facility'] = 'daemon'
  813. default['uidgid/uid'] = '0'
  814. default['uidgid/gid'] = '0'
  815. configs.append(default)
  816. a = ConfigContainer('none_10000')
  817. a['compatibility'] = 'none'
  818. a['totem/token'] = 10000
  819. configs.append(a)
  820. b = ConfigContainer('whitetank_10000')
  821. b['compatibility'] = 'whitetank'
  822. b['totem/token'] = 10000
  823. configs.append(b)
  824. c = ConfigContainer('sec_nss')
  825. c['totem/secauth'] = 'on'
  826. c['totem/crypto_accept'] = 'new'
  827. c['totem/crypto_type'] = 'nss'
  828. configs.append(c)
  829. d = ConfigContainer('sec_sober')
  830. d['totem/secauth'] = 'on'
  831. d['totem/crypto_type'] = 'sober'
  832. configs.append(d)
  833. e = ConfigContainer('threads_4')
  834. e['totem/threads'] = 4
  835. configs.append(e)
  836. #quorum/provider=
  837. #f = {}
  838. #f['quorum/provider'] = 'corosync_quorum_ykd'
  839. #configs.append(f)
  840. if not cm.Env["RrpBindAddr"] is None:
  841. g = ConfigContainer('rrp_passive')
  842. g['totem/rrp_mode'] = 'passive'
  843. g['totem/interface[2]/ringnumber'] = '1'
  844. g['totem/interface[2]/bindnetaddr'] = cm.Env["RrpBindAddr"]
  845. g['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  846. g['totem/interface[2]/mcastport'] = '5405'
  847. configs.append(g)
  848. h = ConfigContainer('rrp_active')
  849. h['totem/rrp_mode'] = 'active'
  850. h['totem/interface[2]/ringnumber'] = '1'
  851. h['totem/interface[2]/bindnetaddr'] = cm.Env["RrpBindAddr"]
  852. h['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  853. h['totem/interface[2]/mcastport'] = '5405'
  854. configs.append(h)
  855. else:
  856. print 'Not including rrp tests. Use --rrp-binaddr to enable them.'
  857. num=1
  858. for cfg in configs:
  859. for testclass in GenTestClasses:
  860. bound_test = testclass(cm)
  861. if bound_test.is_applicable() and bound_test.config_valid(cfg):
  862. bound_test.Audits = audits
  863. for c in cfg.keys():
  864. bound_test.config[c] = cfg[c]
  865. bound_test.name = bound_test.name + '_' + cfg.name
  866. result.append(bound_test)
  867. num = num + 1
  868. return result