corotests.py 37 KB

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