corotests.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. def setup(self, node):
  45. ret = CTSTest.setup(self, node)
  46. self.CM.apply_new_config()
  47. for n in self.CM.Env["nodes"]:
  48. if not self.CM.StataCM(n):
  49. self.incr("started")
  50. self.start(n)
  51. return ret
  52. def teardown(self, node):
  53. self.CM.apply_default_config()
  54. return CTSTest.teardown(self, node)
  55. ###################################################################
  56. class CpgConfigChangeBase(CoroTest):
  57. '''
  58. join a cpg group on each node, and test that the following
  59. causes a leave event:
  60. - a call to cpg_leave()
  61. - app exit
  62. - node leave
  63. - node leave (with large token timeout)
  64. '''
  65. def setup(self, node):
  66. ret = CoroTest.setup(self, node)
  67. self.listener = None
  68. self.wobbly = None
  69. for n in self.CM.Env["nodes"]:
  70. self.CM.agent[n].clean_start()
  71. self.CM.agent[n].cpg_join(self.name)
  72. if self.listener is None:
  73. self.listener = n
  74. elif self.wobbly is None:
  75. self.wobbly = n
  76. self.wobbly_id = self.CM.agent[self.wobbly].cpg_local_get()
  77. self.CM.agent[self.listener].record_config_events(truncate=True)
  78. return ret
  79. def wait_for_config_change(self):
  80. found = False
  81. max_timeout = 5 * 60
  82. waited = 0
  83. printit = 0
  84. self.CM.log("Waiting for config change on " + self.listener)
  85. while not found:
  86. try:
  87. event = self.CM.agent[self.listener].read_config_event()
  88. except:
  89. return self.failure('connection to test agent failed.')
  90. if not event == None:
  91. self.CM.debug("RECEIVED: " + str(event))
  92. if event == None:
  93. if waited >= max_timeout:
  94. return self.failure("timedout(" + str(waited) + " sec) == no event!")
  95. else:
  96. time.sleep(1)
  97. waited = waited + 1
  98. printit = printit + 1
  99. if printit is 60:
  100. print 'waited 60 seconds'
  101. printit = 0
  102. elif str(event.node_id) in str(self.wobbly_id) and not event.is_member:
  103. self.CM.log("Got the config change in " + str(waited) + " seconds")
  104. found = True
  105. else:
  106. self.CM.debug("No match")
  107. self.CM.debug("wobbly nodeid:" + str(self.wobbly_id))
  108. self.CM.debug("event nodeid:" + str(event.node_id))
  109. self.CM.debug("event.is_member:" + str(event.is_member))
  110. if found:
  111. return self.success()
  112. ###################################################################
  113. class CpgCfgChgOnGroupLeave(CpgConfigChangeBase):
  114. def __init__(self, cm):
  115. CpgConfigChangeBase.__init__(self,cm)
  116. self.name="CpgCfgChgOnGroupLeave"
  117. def failure_action(self):
  118. self.CM.log("calling cpg_leave() on " + self.wobbly)
  119. self.CM.agent[self.wobbly].cpg_leave(self.name)
  120. def __call__(self, node):
  121. self.incr("calls")
  122. self.failure_action()
  123. return self.wait_for_config_change()
  124. ###################################################################
  125. class CpgCfgChgOnNodeLeave(CpgConfigChangeBase):
  126. def __init__(self, cm):
  127. CpgConfigChangeBase.__init__(self,cm)
  128. self.name="CpgCfgChgOnNodeLeave"
  129. def failure_action(self):
  130. self.CM.log("stopping corosync on " + self.wobbly)
  131. self.stop(self.wobbly)
  132. def __call__(self, node):
  133. self.incr("calls")
  134. self.failure_action()
  135. return self.wait_for_config_change()
  136. ###################################################################
  137. class CpgCfgChgOnExecCrash(CpgConfigChangeBase):
  138. def __init__(self, cm):
  139. CpgConfigChangeBase.__init__(self,cm)
  140. self.name="CpgCfgChgOnExecCrash"
  141. def failure_action(self):
  142. self.CM.log("sending SIGSEGV to corosync on " + self.wobbly)
  143. self.CM.rsh(self.wobbly, "killall -SIGSEGV corosync")
  144. self.CM.rsh(self.wobbly, "rm -f /var/run/corosync.pid")
  145. def __call__(self, node):
  146. self.incr("calls")
  147. self.failure_action()
  148. return self.wait_for_config_change()
  149. ###################################################################
  150. class CpgCfgChgOnNodeLeave_v2(CpgConfigChangeBase):
  151. def __init__(self, cm):
  152. CpgConfigChangeBase.__init__(self,cm)
  153. self.name="CpgCfgChgOnNodeLeave_v2"
  154. def setup(self, node):
  155. self.CM.new_config['compatibility'] = 'none'
  156. self.CM.new_config['totem/token'] = 10000
  157. return CpgConfigChangeBase.setup(self, node)
  158. def failure_action(self):
  159. self.CM.log("isolating node " + self.wobbly)
  160. self.CM.isolate_node(self.wobbly)
  161. def __call__(self, node):
  162. self.incr("calls")
  163. self.failure_action()
  164. return self.wait_for_config_change()
  165. def teardown(self, node):
  166. self.CM.unisolate_node (self.wobbly)
  167. return CpgConfigChangeBase.teardown(self, node)
  168. ###################################################################
  169. class CpgCfgChgOnNodeLeave_v1(CpgConfigChangeBase):
  170. def __init__(self, cm):
  171. CpgConfigChangeBase.__init__(self,cm)
  172. self.name="CpgCfgChgOnNodeLeave_v1"
  173. def setup(self, node):
  174. self.CM.new_config['compatibility'] = 'whitetank'
  175. self.CM.new_config['totem/token'] = 10000
  176. return CpgConfigChangeBase.setup(self, node)
  177. def failure_action(self):
  178. self.CM.log("isolating node " + self.wobbly)
  179. self.CM.isolate_node(self.wobbly)
  180. def __call__(self, node):
  181. self.incr("calls")
  182. self.failure_action()
  183. return self.wait_for_config_change()
  184. def teardown(self, node):
  185. self.CM.unisolate_node (self.wobbly)
  186. return CpgConfigChangeBase.teardown(self, node)
  187. ###################################################################
  188. class CpgMsgOrderBase(CoroTest):
  189. def __init__(self, cm):
  190. CoroTest.__init__(self,cm)
  191. self.num_msgs_per_node = 0
  192. self.total_num_msgs = 0
  193. def setup(self, node):
  194. ret = CoroTest.setup(self, node)
  195. for n in self.CM.Env["nodes"]:
  196. self.total_num_msgs = self.total_num_msgs + self.num_msgs_per_node
  197. self.CM.agent[n].clean_start()
  198. self.CM.agent[n].cpg_join(self.name)
  199. self.CM.agent[n].record_messages()
  200. time.sleep(1)
  201. return ret
  202. def cpg_msg_blaster(self):
  203. for n in self.CM.Env["nodes"]:
  204. self.CM.agent[n].msg_blaster(self.num_msgs_per_node)
  205. def wait_and_validate_order(self):
  206. msgs = {}
  207. for n in self.CM.Env["nodes"]:
  208. msgs[n] = []
  209. got = False
  210. stopped = False
  211. self.CM.debug( " getting messages from " + n )
  212. while len(msgs[n]) < self.total_num_msgs and not stopped:
  213. msg = self.CM.agent[n].read_messages(25)
  214. if not msg == None:
  215. got = True
  216. msgl = msg.split(";")
  217. # remove empty entries
  218. not_done=True
  219. while not_done:
  220. try:
  221. msgl.remove('')
  222. except:
  223. not_done = False
  224. msgs[n].extend(msgl)
  225. elif msg == None and got:
  226. self.CM.debug(" done getting messages from " + n)
  227. stopped = True
  228. if not got:
  229. time.sleep(1)
  230. fail = False
  231. for i in range(0, self.total_num_msgs):
  232. first = None
  233. for n in self.CM.Env["nodes"]:
  234. if first == None:
  235. first = n
  236. else:
  237. if not msgs[first][i] == msgs[n][i]:
  238. # message order not the same!
  239. fail = True
  240. self.CM.log(msgs[first][i] + " != " + msgs[n][i])
  241. if fail:
  242. return self.failure()
  243. else:
  244. return self.success()
  245. ###################################################################
  246. class CpgMsgOrderBasic(CpgMsgOrderBase):
  247. '''
  248. each sends & logs 100 messages
  249. '''
  250. def __init__(self, cm):
  251. CpgMsgOrderBase.__init__(self,cm)
  252. self.name="CpgMsgOrderBasic"
  253. def __call__(self, node):
  254. self.incr("calls")
  255. # o > reconfigure corosync
  256. # o > reconfigure interfaces (mtu)
  257. # o > restart corosync
  258. # o > set node to die after x msgs
  259. self.num_msgs_per_node = 100
  260. self.cpg_msg_blaster()
  261. return self.wait_and_validate_order()
  262. ###################################################################
  263. class MemLeakObject(CoroTest):
  264. '''
  265. run mem_leak_test.sh -1
  266. '''
  267. def __init__(self, cm):
  268. CoroTest.__init__(self,cm)
  269. self.name="MemLeakObject"
  270. def __call__(self, node):
  271. self.incr("calls")
  272. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -1")
  273. if mem_leaked is 0:
  274. return self.success()
  275. else:
  276. return self.failure(str(mem_leaked) + 'kB memory leaked.')
  277. ###################################################################
  278. class MemLeakSession(CoroTest):
  279. '''
  280. run mem_leak_test.sh -2
  281. '''
  282. def __init__(self, cm):
  283. CoroTest.__init__(self,cm)
  284. self.name="MemLeakSession"
  285. def __call__(self, node):
  286. self.incr("calls")
  287. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -2")
  288. if mem_leaked is 0:
  289. return self.success()
  290. else:
  291. return self.failure(str(mem_leaked) + 'kB memory leaked.')
  292. AllTestClasses = []
  293. AllTestClasses.append(MemLeakObject)
  294. AllTestClasses.append(MemLeakSession)
  295. AllTestClasses.append(CpgCfgChgOnGroupLeave)
  296. AllTestClasses.append(CpgCfgChgOnNodeLeave)
  297. AllTestClasses.append(CpgCfgChgOnNodeLeave_v1)
  298. AllTestClasses.append(CpgCfgChgOnNodeLeave_v2)
  299. AllTestClasses.append(CpgCfgChgOnExecCrash)
  300. AllTestClasses.append(CpgMsgOrderBasic)
  301. AllTestClasses.append(FlipTest)
  302. AllTestClasses.append(RestartTest)
  303. AllTestClasses.append(StartOnebyOne)
  304. AllTestClasses.append(SimulStart)
  305. AllTestClasses.append(StopOnebyOne)
  306. AllTestClasses.append(SimulStop)
  307. AllTestClasses.append(RestartOnebyOne)
  308. #AllTestClasses.append(PartialStart)
  309. def CoroTestList(cm, audits):
  310. result = []
  311. for testclass in AllTestClasses:
  312. bound_test = testclass(cm)
  313. if bound_test.is_applicable():
  314. bound_test.Audits = audits
  315. result.append(bound_test)
  316. return result