corotests.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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.cpg_agent[n].clean_start()
  86. self.CM.cpg_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.cpg_agent[self.wobbly].cpg_local_get()
  92. self.CM.cpg_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.cpg_agent[self.listener].read_config_event()
  103. except:
  104. return self.failure('connection to test cpg_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.cpg_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. self.CM.ShouldBeStatus[self.wobbly] = "down"
  161. def __call__(self, node):
  162. self.incr("calls")
  163. self.failure_action()
  164. return self.wait_for_config_change()
  165. ###################################################################
  166. class CpgCfgChgOnNodeIsolate(CpgConfigChangeBase):
  167. def __init__(self, cm):
  168. CpgConfigChangeBase.__init__(self,cm)
  169. self.name="CpgCfgChgOnNodeIsolate"
  170. def failure_action(self):
  171. self.CM.log("isolating node " + self.wobbly)
  172. self.CM.isolate_node(self.wobbly)
  173. def __call__(self, node):
  174. self.incr("calls")
  175. self.failure_action()
  176. return self.wait_for_config_change()
  177. def teardown(self, node):
  178. self.CM.unisolate_node (self.wobbly)
  179. return CpgConfigChangeBase.teardown(self, node)
  180. ###################################################################
  181. class CpgMsgOrderBase(CoroTest):
  182. def __init__(self, cm):
  183. CoroTest.__init__(self,cm)
  184. self.num_msgs_per_node = 0
  185. self.total_num_msgs = 0
  186. def setup(self, node):
  187. ret = CoroTest.setup(self, node)
  188. for n in self.CM.Env["nodes"]:
  189. self.total_num_msgs = self.total_num_msgs + self.num_msgs_per_node
  190. self.CM.cpg_agent[n].clean_start()
  191. self.CM.cpg_agent[n].cpg_join(self.name)
  192. self.CM.cpg_agent[n].record_messages()
  193. time.sleep(1)
  194. return ret
  195. def cpg_msg_blaster(self):
  196. for n in self.CM.Env["nodes"]:
  197. self.CM.cpg_agent[n].msg_blaster(self.num_msgs_per_node)
  198. def wait_and_validate_order(self):
  199. msgs = {}
  200. for n in self.CM.Env["nodes"]:
  201. msgs[n] = []
  202. stopped = False
  203. waited = 0
  204. while len(msgs[n]) < self.total_num_msgs and waited < 360:
  205. msg = self.CM.cpg_agent[n].read_messages(50)
  206. if not msg == None:
  207. msgl = msg.split(";")
  208. # remove empty entries
  209. not_done=True
  210. while not_done:
  211. try:
  212. msgl.remove('')
  213. except:
  214. not_done = False
  215. msgs[n].extend(msgl)
  216. elif msg == None:
  217. time.sleep(2)
  218. waited = waited + 2
  219. if len(msgs[n]) < self.total_num_msgs:
  220. return self.failure("expected %d messages from %s got %d" % (self.total_num_msgs, n, len(msgs[n])))
  221. fail = False
  222. error_message = ''
  223. for i in range(0, self.total_num_msgs):
  224. first = None
  225. for n in self.CM.Env["nodes"]:
  226. # first test for errors
  227. params = msgs[n][i].split(":")
  228. if not 'OK' in params[3]:
  229. fail = True
  230. error_message = 'error: ' + params[3] + ' in received message'
  231. self.CM.log(str(params))
  232. # then look for out of order messages
  233. if first == None:
  234. first = n
  235. else:
  236. if not msgs[first][i] == msgs[n][i]:
  237. # message order not the same!
  238. fail = True
  239. error_message = 'message out of order'
  240. self.CM.log(msgs[first][i] + " != " + msgs[n][i])
  241. if fail:
  242. return self.failure(error_message)
  243. else:
  244. return self.success()
  245. ###################################################################
  246. class CpgMsgOrderBasic(CpgMsgOrderBase):
  247. '''
  248. each sends & logs 1000 messages
  249. '''
  250. def __init__(self, cm):
  251. CpgMsgOrderBase.__init__(self,cm)
  252. self.name="CpgMsgOrderBasic"
  253. self.num_msgs_per_node = 9000
  254. def __call__(self, node):
  255. self.incr("calls")
  256. self.cpg_msg_blaster()
  257. return self.wait_and_validate_order()
  258. ###################################################################
  259. class MemLeakObject(CoroTest):
  260. '''
  261. run mem_leak_test.sh -1
  262. '''
  263. def __init__(self, cm):
  264. CoroTest.__init__(self,cm)
  265. self.name="MemLeakObject"
  266. def __call__(self, node):
  267. self.incr("calls")
  268. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -1")
  269. if mem_leaked is 0:
  270. return self.success()
  271. else:
  272. return self.failure(str(mem_leaked) + 'kB memory leaked.')
  273. ###################################################################
  274. class MemLeakSession(CoroTest):
  275. '''
  276. run mem_leak_test.sh -2
  277. '''
  278. def __init__(self, cm):
  279. CoroTest.__init__(self,cm)
  280. self.name="MemLeakSession"
  281. def __call__(self, node):
  282. self.incr("calls")
  283. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -2")
  284. if mem_leaked is 0:
  285. return self.success()
  286. else:
  287. return self.failure(str(mem_leaked) + 'kB memory leaked.')
  288. ###################################################################
  289. class ServiceLoadTest(CoroTest):
  290. '''
  291. Test loading and unloading of service engines
  292. '''
  293. def __init__(self, cm):
  294. CoroTest.__init__(self, cm)
  295. self.name="ServiceLoadTest"
  296. def is_loaded(self, node):
  297. check = 'corosync-objctl runtime.services. | grep evs'
  298. (res, out) = self.CM.rsh(node, check, stdout=2)
  299. if res is 0:
  300. return True
  301. else:
  302. return False
  303. def service_unload(self, node):
  304. # unload evs
  305. pats = []
  306. pats.append("%s .*Service engine unloaded: corosync extended.*" % node)
  307. unloaded = self.create_watch(pats, 60)
  308. unloaded.setwatch()
  309. self.CM.rsh(node, 'corosync-cfgtool -u corosync_evs')
  310. if not unloaded.lookforall():
  311. self.CM.log("Patterns not found: " + repr(unloaded.unmatched))
  312. self.error_message = "evs service not unloaded"
  313. return False
  314. if self.is_loaded(node):
  315. self.error_message = "evs has been unload, why are it's session objects are still there?"
  316. return False
  317. return True
  318. def service_load(self, node):
  319. # now reload it.
  320. pats = []
  321. pats.append("%s .*Service engine loaded.*" % node)
  322. loaded = self.create_watch(pats, 60)
  323. loaded.setwatch()
  324. self.CM.rsh(node, 'corosync-cfgtool -l corosync_evs')
  325. if not loaded.lookforall():
  326. self.CM.log("Patterns not found: " + repr(loaded.unmatched))
  327. self.error_message = "evs service not unloaded"
  328. return False
  329. return True
  330. def __call__(self, node):
  331. self.incr("calls")
  332. should_be_loaded = True
  333. if self.is_loaded(node):
  334. ret = self.service_unload(node)
  335. should_be_loaded = False
  336. else:
  337. ret = self.service_load(node)
  338. should_be_loaded = True
  339. if not ret:
  340. return self.failure(self.error_message)
  341. if self.is_loaded(node):
  342. ret = self.service_unload(node)
  343. else:
  344. ret = self.service_load(node)
  345. if not ret:
  346. return self.failure(self.error_message)
  347. return self.success()
  348. ###################################################################
  349. class ConfdbReplaceTest(CoroTest):
  350. def __init__(self, cm):
  351. CoroTest.__init__(self, cm)
  352. self.name="ConfdbReplaceTest"
  353. def __call__(self, node):
  354. self.incr("calls")
  355. res = self.CM.confdb_agent[node].set_get_test()
  356. if 'OK' in res:
  357. return self.success()
  358. else:
  359. return self.failure('set_get_test failed')
  360. ###################################################################
  361. class ConfdbIncrementTest(CoroTest):
  362. def __init__(self, cm):
  363. CoroTest.__init__(self, cm)
  364. self.name="ConfdbIncrementTest"
  365. def __call__(self, node):
  366. self.incr("calls")
  367. res = self.CM.confdb_agent[node].increment_decrement_test()
  368. if 'OK' in res:
  369. return self.success()
  370. else:
  371. return self.failure('increment_decrement_test failed')
  372. ###################################################################
  373. class ConfdbObjectFindTest(CoroTest):
  374. def __init__(self, cm):
  375. CoroTest.__init__(self, cm)
  376. self.name="ConfdbObjectFindTest"
  377. def __call__(self, node):
  378. self.incr("calls")
  379. res = self.CM.confdb_agent[node].object_find_test()
  380. if 'OK' in res:
  381. return self.success()
  382. else:
  383. return self.failure('object_find_test failed')
  384. ###################################################################
  385. class ConfdbNotificationTest(CoroTest):
  386. def __init__(self, cm):
  387. CoroTest.__init__(self, cm)
  388. self.name="ConfdbNotificationTest"
  389. def __call__(self, node):
  390. self.incr("calls")
  391. res = self.CM.confdb_agent[node].notification_test()
  392. if 'OK' in res:
  393. return self.success()
  394. else:
  395. return self.failure('notification_test failed')
  396. GenTestClasses = []
  397. GenTestClasses.append(CpgMsgOrderBasic)
  398. GenTestClasses.append(CpgCfgChgOnExecCrash)
  399. GenTestClasses.append(CpgCfgChgOnGroupLeave)
  400. GenTestClasses.append(CpgCfgChgOnNodeLeave)
  401. GenTestClasses.append(CpgCfgChgOnNodeIsolate)
  402. AllTestClasses = []
  403. AllTestClasses.append(ConfdbReplaceTest)
  404. AllTestClasses.append(ConfdbIncrementTest)
  405. AllTestClasses.append(ConfdbObjectFindTest)
  406. AllTestClasses.append(ConfdbNotificationTest)
  407. AllTestClasses.append(ServiceLoadTest)
  408. AllTestClasses.append(MemLeakObject)
  409. AllTestClasses.append(MemLeakSession)
  410. AllTestClasses.append(FlipTest)
  411. AllTestClasses.append(RestartTest)
  412. AllTestClasses.append(StartOnebyOne)
  413. AllTestClasses.append(SimulStart)
  414. AllTestClasses.append(StopOnebyOne)
  415. AllTestClasses.append(SimulStop)
  416. AllTestClasses.append(RestartOnebyOne)
  417. #AllTestClasses.append(PartialStart)
  418. def CoroTestList(cm, audits):
  419. result = []
  420. configs = []
  421. for testclass in AllTestClasses:
  422. bound_test = testclass(cm)
  423. if bound_test.is_applicable():
  424. bound_test.Audits = audits
  425. result.append(bound_test)
  426. default = {}
  427. default['logging/function_name'] = 'off'
  428. default['logging/logfile_priority'] = 'info'
  429. default['logging/syslog_priority'] = 'info'
  430. default['logging/syslog_facility'] = 'daemon'
  431. configs.append(default)
  432. a = {}
  433. a['compatibility'] = 'none'
  434. a['totem/token'] = 10000
  435. configs.append(a)
  436. b = {}
  437. b['compatibility'] = 'whitetank'
  438. b['totem/token'] = 10000
  439. configs.append(b)
  440. c = {}
  441. c['totem/secauth'] = 'on'
  442. c['totem/crypto_accept'] = 'new'
  443. c['totem/crypto_type'] = 'nss'
  444. configs.append(c)
  445. d = {}
  446. d['totem/secauth'] = 'on'
  447. d['totem/crypto_type'] = 'sober'
  448. configs.append(d)
  449. e = {}
  450. e['totem/threads'] = 4
  451. configs.append(e)
  452. #quorum/provider=
  453. #f = {}
  454. #f['quorum/provider'] = 'corosync_quorum_ykd'
  455. #configs.append(f)
  456. g = {}
  457. g['totem/rrp_mode'] = 'passive'
  458. g['totem/interface[2]/ringnumber'] = '1'
  459. g['totem/interface[2]/bindnetaddr'] = '192.168.200.0'
  460. g['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  461. g['totem/interface[2]/mcastport'] = '5405'
  462. configs.append(g)
  463. h = {}
  464. h['totem/rrp_mode'] = 'active'
  465. h['totem/interface[2]/ringnumber'] = '1'
  466. h['totem/interface[2]/bindnetaddr'] = '192.168.200.0'
  467. h['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  468. h['totem/interface[2]/mcastport'] = '5405'
  469. configs.append(h)
  470. num=1
  471. for cfg in configs:
  472. for testclass in GenTestClasses:
  473. bound_test = testclass(cm)
  474. if bound_test.is_applicable():
  475. bound_test.Audits = audits
  476. bound_test.config = cfg
  477. bound_test.name = bound_test.name + '_' + str(num)
  478. result.append(bound_test)
  479. num = num + 1
  480. return result