corotests.py 12 KB

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