corotests.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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 cts.CTStests import *
  34. ###################################################################
  35. class CoroTest(CTSTest):
  36. '''
  37. basic class to make sure that new configuration is applied
  38. and old configuration is removed.
  39. '''
  40. def __init__(self, cm):
  41. CTSTest.__init__(self,cm)
  42. self.start = StartTest(cm)
  43. self.stop = StopTest(cm)
  44. self.config = {}
  45. def setup(self, node):
  46. ret = CTSTest.setup(self, node)
  47. # setup the authkey
  48. localauthkey = '/tmp/authkey'
  49. if not os.path.exists(localauthkey):
  50. self.CM.rsh(node, 'corosync-keygen')
  51. self.CM.rsh.cp("%s:%s" % (node, "/etc/corosync/authkey"), localauthkey)
  52. for n in self.CM.Env["nodes"]:
  53. if n is not node:
  54. #copy key onto other nodes
  55. self.CM.rsh.cp(localauthkey, "%s:%s" % (n, "/etc/corosync/authkey"))
  56. # copy over any new config
  57. for c in self.config:
  58. self.CM.new_config[c] = self.config[c]
  59. # apply the config
  60. self.CM.apply_new_config()
  61. # start any killed corosync's
  62. for n in self.CM.Env["nodes"]:
  63. if not self.CM.StataCM(n):
  64. self.incr("started")
  65. self.start(n)
  66. return ret
  67. def teardown(self, node):
  68. self.CM.apply_default_config()
  69. return CTSTest.teardown(self, node)
  70. ###################################################################
  71. class CpgConfigChangeBase(CoroTest):
  72. '''
  73. join a cpg group on each node, and test that the following
  74. causes a leave event:
  75. - a call to cpg_leave()
  76. - app exit
  77. - node leave
  78. - node leave (with large token timeout)
  79. '''
  80. def setup(self, node):
  81. ret = CoroTest.setup(self, node)
  82. self.listener = None
  83. self.wobbly = None
  84. for n in self.CM.Env["nodes"]:
  85. self.CM.agent[n].clean_start()
  86. self.CM.agent[n].cpg_join(self.name)
  87. if self.listener is None:
  88. self.listener = n
  89. elif self.wobbly is None:
  90. self.wobbly = n
  91. self.wobbly_id = self.CM.agent[self.wobbly].cpg_local_get()
  92. self.CM.agent[self.listener].record_config_events(truncate=True)
  93. return ret
  94. def wait_for_config_change(self):
  95. found = False
  96. max_timeout = 5 * 60
  97. waited = 0
  98. printit = 0
  99. self.CM.log("Waiting for config change on " + self.listener)
  100. while not found:
  101. try:
  102. event = self.CM.agent[self.listener].read_config_event()
  103. except:
  104. return self.failure('connection to test agent failed.')
  105. if not event == None:
  106. self.CM.debug("RECEIVED: " + str(event))
  107. if event == None:
  108. if waited >= max_timeout:
  109. return self.failure("timedout(" + str(waited) + " sec) == no event!")
  110. else:
  111. time.sleep(1)
  112. waited = waited + 1
  113. printit = printit + 1
  114. if printit is 60:
  115. print 'waited 60 seconds'
  116. printit = 0
  117. elif str(event.node_id) in str(self.wobbly_id) and not event.is_member:
  118. self.CM.log("Got the config change in " + str(waited) + " seconds")
  119. found = True
  120. else:
  121. self.CM.debug("No match")
  122. self.CM.debug("wobbly nodeid:" + str(self.wobbly_id))
  123. self.CM.debug("event nodeid:" + str(event.node_id))
  124. self.CM.debug("event.is_member:" + str(event.is_member))
  125. if found:
  126. return self.success()
  127. ###################################################################
  128. class CpgCfgChgOnGroupLeave(CpgConfigChangeBase):
  129. def __init__(self, cm):
  130. CpgConfigChangeBase.__init__(self,cm)
  131. self.name="CpgCfgChgOnGroupLeave"
  132. def failure_action(self):
  133. self.CM.log("calling cpg_leave() on " + self.wobbly)
  134. self.CM.agent[self.wobbly].cpg_leave(self.name)
  135. def __call__(self, node):
  136. self.incr("calls")
  137. self.failure_action()
  138. return self.wait_for_config_change()
  139. ###################################################################
  140. class CpgCfgChgOnNodeLeave(CpgConfigChangeBase):
  141. def __init__(self, cm):
  142. CpgConfigChangeBase.__init__(self,cm)
  143. self.name="CpgCfgChgOnNodeLeave"
  144. def failure_action(self):
  145. self.CM.log("stopping corosync on " + self.wobbly)
  146. self.stop(self.wobbly)
  147. def __call__(self, node):
  148. self.incr("calls")
  149. self.failure_action()
  150. return self.wait_for_config_change()
  151. ###################################################################
  152. class CpgCfgChgOnExecCrash(CpgConfigChangeBase):
  153. def __init__(self, cm):
  154. CpgConfigChangeBase.__init__(self,cm)
  155. self.name="CpgCfgChgOnExecCrash"
  156. def failure_action(self):
  157. self.CM.log("sending SIGSEGV to corosync on " + self.wobbly)
  158. self.CM.rsh(self.wobbly, "killall -9 corosync")
  159. self.CM.rsh(self.wobbly, "rm -f /var/run/corosync.pid")
  160. def __call__(self, node):
  161. self.incr("calls")
  162. self.failure_action()
  163. return self.wait_for_config_change()
  164. ###################################################################
  165. class CpgCfgChgOnNodeIsolate(CpgConfigChangeBase):
  166. def __init__(self, cm):
  167. CpgConfigChangeBase.__init__(self,cm)
  168. self.name="CpgCfgChgOnNodeIsolate"
  169. def failure_action(self):
  170. self.CM.log("isolating node " + self.wobbly)
  171. self.CM.isolate_node(self.wobbly)
  172. def __call__(self, node):
  173. self.incr("calls")
  174. self.failure_action()
  175. return self.wait_for_config_change()
  176. def teardown(self, node):
  177. self.CM.unisolate_node (self.wobbly)
  178. return CpgConfigChangeBase.teardown(self, node)
  179. ###################################################################
  180. class CpgMsgOrderBase(CoroTest):
  181. def __init__(self, cm):
  182. CoroTest.__init__(self,cm)
  183. self.num_msgs_per_node = 0
  184. self.total_num_msgs = 0
  185. def setup(self, node):
  186. ret = CoroTest.setup(self, node)
  187. for n in self.CM.Env["nodes"]:
  188. self.total_num_msgs = self.total_num_msgs + self.num_msgs_per_node
  189. self.CM.agent[n].clean_start()
  190. self.CM.agent[n].cpg_join(self.name)
  191. self.CM.agent[n].record_messages()
  192. time.sleep(1)
  193. return ret
  194. def cpg_msg_blaster(self):
  195. for n in self.CM.Env["nodes"]:
  196. self.CM.agent[n].msg_blaster(self.num_msgs_per_node)
  197. def wait_and_validate_order(self):
  198. msgs = {}
  199. for n in self.CM.Env["nodes"]:
  200. msgs[n] = []
  201. stopped = False
  202. waited = 0
  203. while len(msgs[n]) < self.total_num_msgs and waited < 60:
  204. msg = self.CM.agent[n].read_messages(25)
  205. if not msg == None:
  206. msgl = msg.split(";")
  207. # remove empty entries
  208. not_done=True
  209. while not_done:
  210. try:
  211. msgl.remove('')
  212. except:
  213. not_done = False
  214. msgs[n].extend(msgl)
  215. elif msg == None:
  216. time.sleep(1)
  217. waited = waited + 1
  218. if len(msgs[n]) < self.total_num_msgs:
  219. return self.failure("expected %d messages from %s got %d" % (self.total_num_msgs, n, len(msgs[n])))
  220. fail = False
  221. error_message = ''
  222. for i in range(0, self.total_num_msgs):
  223. first = None
  224. for n in self.CM.Env["nodes"]:
  225. # first test for errors
  226. params = msgs[n][i].split(":")
  227. if not 'OK' in params[3]:
  228. fail = True
  229. error_message = 'error: ' + params[3] + ' in received message'
  230. self.CM.log(str(params))
  231. # then look for out of order messages
  232. if first == None:
  233. first = n
  234. else:
  235. if not msgs[first][i] == msgs[n][i]:
  236. # message order not the same!
  237. fail = True
  238. error_message = 'message out of order'
  239. self.CM.log(msgs[first][i] + " != " + msgs[n][i])
  240. if fail:
  241. return self.failure(error_message)
  242. else:
  243. return self.success()
  244. ###################################################################
  245. class CpgMsgOrderBasic(CpgMsgOrderBase):
  246. '''
  247. each sends & logs 1000 messages
  248. '''
  249. def __init__(self, cm):
  250. CpgMsgOrderBase.__init__(self,cm)
  251. self.name="CpgMsgOrderBasic"
  252. self.num_msgs_per_node = 9000
  253. def __call__(self, node):
  254. self.incr("calls")
  255. self.cpg_msg_blaster()
  256. return self.wait_and_validate_order()
  257. ###################################################################
  258. class MemLeakObject(CoroTest):
  259. '''
  260. run mem_leak_test.sh -1
  261. '''
  262. def __init__(self, cm):
  263. CoroTest.__init__(self,cm)
  264. self.name="MemLeakObject"
  265. def __call__(self, node):
  266. self.incr("calls")
  267. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -1")
  268. if mem_leaked is 0:
  269. return self.success()
  270. else:
  271. return self.failure(str(mem_leaked) + 'kB memory leaked.')
  272. ###################################################################
  273. class MemLeakSession(CoroTest):
  274. '''
  275. run mem_leak_test.sh -2
  276. '''
  277. def __init__(self, cm):
  278. CoroTest.__init__(self,cm)
  279. self.name="MemLeakSession"
  280. def __call__(self, node):
  281. self.incr("calls")
  282. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -2")
  283. if mem_leaked is 0:
  284. return self.success()
  285. else:
  286. return self.failure(str(mem_leaked) + 'kB memory leaked.')
  287. ###################################################################
  288. class ServiceLoadTest(CoroTest):
  289. '''
  290. Test loading and unloading of service engines
  291. '''
  292. def __init__(self, cm):
  293. CoroTest.__init__(self, cm)
  294. self.name="ServiceLoadTest"
  295. def is_loaded(self, node):
  296. check = 'corosync-objctl runtime.services. | grep evs'
  297. (res, out) = self.CM.rsh(node, check, stdout=2)
  298. if res is 0:
  299. return True
  300. else:
  301. return False
  302. def service_unload(self, node):
  303. # unload evs
  304. pats = []
  305. pats.append("%s .*Service engine unloaded: corosync extended.*" % node)
  306. unloaded = self.create_watch(pats, 60)
  307. unloaded.setwatch()
  308. self.CM.rsh(node, 'corosync-cfgtool -u corosync_evs')
  309. if not unloaded.lookforall():
  310. self.CM.log("Patterns not found: " + repr(unloaded.unmatched))
  311. self.error_message = "evs service not unloaded"
  312. return False
  313. if self.is_loaded(node):
  314. self.error_message = "evs has been unload, why are it's session objects are still there?"
  315. return False
  316. return True
  317. def service_load(self, node):
  318. # now reload it.
  319. pats = []
  320. pats.append("%s .*Service engine loaded.*" % node)
  321. loaded = self.create_watch(pats, 60)
  322. loaded.setwatch()
  323. self.CM.rsh(node, 'corosync-cfgtool -l corosync_evs')
  324. if not loaded.lookforall():
  325. self.CM.log("Patterns not found: " + repr(loaded.unmatched))
  326. self.error_message = "evs service not unloaded"
  327. return False
  328. return True
  329. def __call__(self, node):
  330. self.incr("calls")
  331. should_be_loaded = True
  332. if self.is_loaded(node):
  333. ret = self.service_unload(node)
  334. should_be_loaded = False
  335. else:
  336. ret = self.service_load(node)
  337. should_be_loaded = True
  338. if not ret:
  339. return self.failure(self.error_message)
  340. if self.is_loaded(node):
  341. ret = self.service_unload(node)
  342. else:
  343. ret = self.service_load(node)
  344. if not ret:
  345. return self.failure(self.error_message)
  346. return self.success()
  347. GenTestClasses = []
  348. GenTestClasses.append(CpgMsgOrderBasic)
  349. GenTestClasses.append(CpgCfgChgOnExecCrash)
  350. GenTestClasses.append(CpgCfgChgOnGroupLeave)
  351. GenTestClasses.append(CpgCfgChgOnNodeLeave)
  352. GenTestClasses.append(CpgCfgChgOnNodeIsolate)
  353. AllTestClasses = []
  354. AllTestClasses.append(ServiceLoadTest)
  355. AllTestClasses.append(MemLeakObject)
  356. AllTestClasses.append(MemLeakSession)
  357. AllTestClasses.append(FlipTest)
  358. AllTestClasses.append(RestartTest)
  359. AllTestClasses.append(StartOnebyOne)
  360. AllTestClasses.append(SimulStart)
  361. AllTestClasses.append(StopOnebyOne)
  362. AllTestClasses.append(SimulStop)
  363. AllTestClasses.append(RestartOnebyOne)
  364. #AllTestClasses.append(PartialStart)
  365. def CoroTestList(cm, audits):
  366. result = []
  367. configs = []
  368. empty = {}
  369. configs.append(empty)
  370. a = {}
  371. a['compatibility'] = 'none'
  372. a['totem/token'] = 10000
  373. configs.append(a)
  374. b = {}
  375. b['compatibility'] = 'whitetank'
  376. b['totem/token'] = 10000
  377. configs.append(b)
  378. c = {}
  379. c['totem/secauth'] = 'on'
  380. c['totem/crypto_accept'] = 'new'
  381. c['totem/crypto_type'] = 'nss'
  382. configs.append(c)
  383. d = {}
  384. d['totem/secauth'] = 'on'
  385. d['totem/crypto_type'] = 'sober'
  386. configs.append(d)
  387. e = {}
  388. e['totem/threads'] = 4
  389. configs.append(e)
  390. #quorum/provider=
  391. f = {}
  392. f['quorum/provider'] = 'corosync_quorum_ykd'
  393. configs.append(f)
  394. num=1
  395. for cfg in configs:
  396. for testclass in GenTestClasses:
  397. bound_test = testclass(cm)
  398. if bound_test.is_applicable():
  399. bound_test.Audits = audits
  400. bound_test.config = cfg
  401. bound_test.name = bound_test.name + '_' + str(num)
  402. result.append(bound_test)
  403. num = num + 1
  404. for testclass in AllTestClasses:
  405. bound_test = testclass(cm)
  406. if bound_test.is_applicable():
  407. bound_test.Audits = audits
  408. result.append(bound_test)
  409. return result