corotests.py 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521
  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. import random
  34. import socket
  35. from UserDict import UserDict
  36. from cts.CTStests import *
  37. from corosync import CpgTestAgent
  38. ###################################################################
  39. class CoroTest(CTSTest):
  40. '''
  41. basic class to make sure that new configuration is applied
  42. and old configuration is removed.
  43. '''
  44. def __init__(self, cm):
  45. CTSTest.__init__(self,cm)
  46. self.start = StartTest(cm)
  47. self.stop = StopTest(cm)
  48. self.config = {}
  49. self.config['logging/logger_subsys[1]/subsys'] = 'MAIN'
  50. self.config['logging/logger_subsys[1]/debug'] = 'on'
  51. self.need_all_up = True
  52. self.CM.start_cpg = True
  53. def setup(self, node):
  54. ret = CTSTest.setup(self, node)
  55. # setup the authkey
  56. localauthkey = '/tmp/authkey'
  57. if not os.path.exists(localauthkey):
  58. self.CM.rsh(node, 'corosync-keygen -l')
  59. self.CM.rsh.cp("%s:%s" % (node, "/etc/corosync/authkey"), localauthkey)
  60. for n in self.CM.Env["nodes"]:
  61. if n is not node:
  62. #copy key onto other nodes
  63. self.CM.rsh.cp(localauthkey, "%s:%s" % (n, "/etc/corosync/authkey"))
  64. # copy over any new config
  65. for c in self.config:
  66. self.CM.new_config[c] = self.config[c]
  67. # apply the config
  68. self.CM.apply_new_config()
  69. # start/stop all corosyncs'
  70. for n in self.CM.Env["nodes"]:
  71. if self.need_all_up and not self.CM.StataCM(n):
  72. self.incr("started")
  73. self.start(n)
  74. if self.need_all_up and self.CM.start_cpg:
  75. self.CM.cpg_agent[n].clean_start()
  76. self.CM.cpg_agent[n].cpg_join(self.name)
  77. self.CM.cpg_agent[n].cfg_initialize()
  78. if not self.need_all_up and self.CM.StataCM(n):
  79. self.incr("stopped")
  80. self.stop(n)
  81. return ret
  82. def config_valid(self, config):
  83. return True
  84. def teardown(self, node):
  85. self.CM.apply_default_config()
  86. return CTSTest.teardown(self, node)
  87. ###################################################################
  88. class CpgContextTest(CoroTest):
  89. def __init__(self, cm):
  90. CoroTest.__init__(self, cm)
  91. self.name="CpgContextTest"
  92. self.CM.start_cpg = True
  93. def __call__(self, node):
  94. self.incr("calls")
  95. res = self.CM.cpg_agent[node].context_test()
  96. if 'OK' in res:
  97. return self.success()
  98. else:
  99. return self.failure('context_test failed')
  100. ###################################################################
  101. class CpgConfigChangeBase(CoroTest):
  102. '''
  103. join a cpg group on each node, and test that the following
  104. causes a leave event:
  105. - a call to cpg_leave()
  106. - app exit
  107. - node leave
  108. - node leave (with large token timeout)
  109. '''
  110. def setup(self, node):
  111. ret = CoroTest.setup(self, node)
  112. self.listener = None
  113. self.wobbly = None
  114. for n in self.CM.Env["nodes"]:
  115. if self.wobbly is None:
  116. self.wobbly = n
  117. elif self.listener is None:
  118. self.listener = n
  119. if self.CM.cpg_agent.has_key(self.wobbly):
  120. self.wobbly_id = self.CM.cpg_agent[self.wobbly].cpg_local_get()
  121. if self.CM.cpg_agent.has_key(self.listener):
  122. self.CM.cpg_agent[self.listener].record_config_events(truncate=True)
  123. return ret
  124. def wait_for_config_change(self):
  125. found = False
  126. max_timeout = 60 * 15
  127. waited = 0
  128. printit = 0
  129. self.CM.log("Waiting for config change on " + self.listener)
  130. while not found:
  131. try:
  132. event = self.CM.cpg_agent[self.listener].read_config_event()
  133. except:
  134. return self.failure('connection to test cpg_agent failed.')
  135. if not event == None:
  136. self.CM.debug("RECEIVED: " + str(event))
  137. if event == None:
  138. if waited >= max_timeout:
  139. return self.failure("timedout(" + str(waited) + " sec) == no event!")
  140. else:
  141. time.sleep(1)
  142. waited = waited + 1
  143. printit = printit + 1
  144. if printit is 60:
  145. print 'waited ' + str(waited) + ' seconds'
  146. printit = 0
  147. elif str(event.node_id) in str(self.wobbly_id) and not event.is_member:
  148. self.CM.log("Got the config change in " + str(waited) + " seconds")
  149. found = True
  150. else:
  151. self.CM.debug("No match")
  152. self.CM.debug("wobbly nodeid:" + str(self.wobbly_id))
  153. self.CM.debug("event nodeid:" + str(event.node_id))
  154. self.CM.debug("event.is_member:" + str(event.is_member))
  155. if found:
  156. return self.success()
  157. ###################################################################
  158. class CpgCfgChgOnGroupLeave(CpgConfigChangeBase):
  159. def __init__(self, cm):
  160. CpgConfigChangeBase.__init__(self,cm)
  161. self.name="CpgCfgChgOnGroupLeave"
  162. def failure_action(self):
  163. self.CM.log("calling cpg_leave() on " + self.wobbly)
  164. self.CM.cpg_agent[self.wobbly].cpg_leave(self.name)
  165. def __call__(self, node):
  166. self.incr("calls")
  167. self.failure_action()
  168. return self.wait_for_config_change()
  169. ###################################################################
  170. class CpgCfgChgOnNodeLeave(CpgConfigChangeBase):
  171. def __init__(self, cm):
  172. CpgConfigChangeBase.__init__(self,cm)
  173. self.name="CpgCfgChgOnNodeLeave"
  174. def failure_action(self):
  175. self.CM.log("stopping corosync on " + self.wobbly)
  176. self.stop(self.wobbly)
  177. def __call__(self, node):
  178. self.incr("calls")
  179. self.failure_action()
  180. return self.wait_for_config_change()
  181. ###################################################################
  182. class CpgCfgChgOnLowestNodeJoin(CTSTest):
  183. '''
  184. 1) stop all nodes
  185. 2) start all but the node with the smallest ip address
  186. 3) start recording events
  187. 4) start the last node
  188. '''
  189. def __init__(self, cm):
  190. CTSTest.__init__(self, cm)
  191. self.name="CpgCfgChgOnLowestNodeJoin"
  192. self.start = StartTest(cm)
  193. self.stop = StopTest(cm)
  194. self.config = {}
  195. self.need_all_up = False
  196. self.config['compatibility'] = 'none'
  197. def config_valid(self, config):
  198. return True
  199. def lowest_ip_set(self):
  200. self.lowest = None
  201. for n in self.CM.Env["nodes"]:
  202. if self.lowest is None:
  203. self.lowest = n
  204. self.CM.log("lowest node is " + self.lowest)
  205. def setup(self, node):
  206. # stop all nodes
  207. for n in self.CM.Env["nodes"]:
  208. self.CM.StopaCM(n)
  209. self.lowest_ip_set()
  210. # copy over any new config
  211. for c in self.config:
  212. self.CM.new_config[c] = self.config[c]
  213. # install the config
  214. self.CM.install_all_config()
  215. # start all but lowest
  216. self.listener = None
  217. for n in self.CM.Env["nodes"]:
  218. if n is not self.lowest:
  219. if self.listener is None:
  220. self.listener = n
  221. self.incr("started")
  222. self.CM.log("starting " + n)
  223. self.start(n)
  224. self.CM.cpg_agent[n].clean_start()
  225. self.CM.cpg_agent[n].cpg_join(self.name)
  226. # start recording events
  227. pats = []
  228. pats.append("%s .*sync: node joined.*" % self.listener)
  229. pats.append("%s .*sync: activate correctly.*" % self.listener)
  230. self.sync_log = self.create_watch(pats, 60)
  231. self.sync_log.setwatch()
  232. self.CM.log("setup done")
  233. return CTSTest.setup(self, node)
  234. def __call__(self, node):
  235. self.incr("calls")
  236. self.start(self.lowest)
  237. self.CM.cpg_agent[self.lowest].clean_start()
  238. self.CM.cpg_agent[self.lowest].cpg_join(self.name)
  239. self.wobbly_id = self.CM.cpg_agent[self.lowest].cpg_local_get()
  240. self.CM.log("waiting for sync events")
  241. if not self.sync_log.lookforall():
  242. return self.failure("Patterns not found: " + repr(self.sync_log.unmatched))
  243. else:
  244. return self.success()
  245. ###################################################################
  246. class CpgCfgChgOnExecCrash(CpgConfigChangeBase):
  247. def __init__(self, cm):
  248. CpgConfigChangeBase.__init__(self,cm)
  249. self.name="CpgCfgChgOnExecCrash"
  250. def failure_action(self):
  251. self.CM.log("sending KILL to corosync on " + self.wobbly)
  252. self.CM.rsh(self.wobbly, "killall -9 corosync")
  253. self.CM.rsh(self.wobbly, "rm -f /var/run/corosync.pid")
  254. self.CM.ShouldBeStatus[self.wobbly] = "down"
  255. def __call__(self, node):
  256. self.incr("calls")
  257. self.failure_action()
  258. return self.wait_for_config_change()
  259. ###################################################################
  260. class CpgCfgChgOnNodeIsolate(CpgConfigChangeBase):
  261. def __init__(self, cm):
  262. CpgConfigChangeBase.__init__(self,cm)
  263. self.name="CpgCfgChgOnNodeIsolate"
  264. def config_valid(self, config):
  265. if config.has_key('totem/rrp_mode'):
  266. return False
  267. else:
  268. return True
  269. def failure_action(self):
  270. self.CM.log("isolating node " + self.wobbly)
  271. self.CM.isolate_node(self.wobbly)
  272. def __call__(self, node):
  273. self.incr("calls")
  274. self.failure_action()
  275. return self.wait_for_config_change()
  276. def teardown(self, node):
  277. self.CM.unisolate_node (self.wobbly)
  278. return CpgConfigChangeBase.teardown(self, node)
  279. ###################################################################
  280. class CpgCfgChgOnNodeRestart(CpgConfigChangeBase):
  281. def __init__(self, cm):
  282. CpgConfigChangeBase.__init__(self,cm)
  283. self.name="CpgCfgChgOnNodeRestart"
  284. self.CM.start_cpg = False
  285. def config_valid(self, config):
  286. if config.has_key('totem/secauth'):
  287. if config['totem/secauth'] is 'on':
  288. return False
  289. else:
  290. return True
  291. if config.has_key('totem/rrp_mode'):
  292. return False
  293. else:
  294. return True
  295. def failure_action(self):
  296. self.CM.log("2: isolating node " + self.wobbly)
  297. self.CM.isolate_node(self.wobbly)
  298. self.CM.log("3: Killing corosync on " + self.wobbly)
  299. self.CM.rsh(self.wobbly, "killall -9 corosync")
  300. self.CM.rsh(self.wobbly, "rm -f /var/run/corosync.pid")
  301. self.CM.ShouldBeStatus[self.wobbly] = "down"
  302. self.CM.log("4: unisolating node " + self.wobbly)
  303. self.CM.unisolate_node (self.wobbly)
  304. self.CM.log("5: starting corosync on " + self.wobbly)
  305. self.CM.StartaCM(self.wobbly)
  306. time.sleep(5)
  307. self.CM.log("6: starting cpg on all nodes")
  308. self.CM.start_cpg = True
  309. for node in self.CM.Env["nodes"]:
  310. self.CM.cpg_agent[node] = CpgTestAgent(node, self.CM.Env)
  311. self.CM.cpg_agent[node].start()
  312. self.CM.cpg_agent[node].cpg_join(self.name)
  313. self.wobbly_id = self.CM.cpg_agent[self.wobbly].cpg_local_get()
  314. self.CM.cpg_agent[self.listener].record_config_events(truncate=True)
  315. self.CM.log("7: isolating node " + self.wobbly)
  316. self.CM.isolate_node(self.wobbly)
  317. self.CM.log("8: Killing corosync on " + self.wobbly)
  318. self.CM.rsh(self.wobbly, "killall -9 corosync")
  319. self.CM.rsh(self.wobbly, "rm -f /var/run/corosync.pid")
  320. self.CM.ShouldBeStatus[self.wobbly] = "down"
  321. self.CM.log("9: unisolating node " + self.wobbly)
  322. self.CM.unisolate_node (self.wobbly)
  323. self.CM.log("10: starting corosync on " + self.wobbly)
  324. self.CM.StartaCM(self.wobbly)
  325. def __call__(self, node):
  326. self.incr("calls")
  327. self.failure_action()
  328. return self.wait_for_config_change()
  329. def teardown(self, node):
  330. self.CM.unisolate_node (self.wobbly)
  331. return CpgConfigChangeBase.teardown(self, node)
  332. ###################################################################
  333. class CpgMsgOrderBase(CoroTest):
  334. def __init__(self, cm):
  335. CoroTest.__init__(self,cm)
  336. self.num_msgs_per_node = 0
  337. self.total_num_msgs = 0
  338. def setup(self, node):
  339. ret = CoroTest.setup(self, node)
  340. for n in self.CM.Env["nodes"]:
  341. self.CM.cpg_agent[n].clean_start()
  342. self.CM.cpg_agent[n].cpg_join(self.name)
  343. self.CM.cpg_agent[n].record_messages()
  344. time.sleep(1)
  345. return ret
  346. def cpg_msg_blaster(self):
  347. for n in self.CM.Env["nodes"]:
  348. self.CM.cpg_agent[n].msg_blaster(self.num_msgs_per_node)
  349. def wait_and_validate_order(self):
  350. msgs = {}
  351. self.total_num_msgs = 0
  352. for n in self.CM.Env["nodes"]:
  353. self.total_num_msgs = self.total_num_msgs + self.num_msgs_per_node
  354. for n in self.CM.Env["nodes"]:
  355. msgs[n] = []
  356. stopped = False
  357. waited = 0
  358. while len(msgs[n]) < self.total_num_msgs and waited < 360:
  359. try:
  360. msg = self.CM.cpg_agent[n].read_messages(50)
  361. except:
  362. return self.failure('connection to test cpg_agent failed.')
  363. if not msg == None:
  364. msgl = msg.split(";")
  365. # remove empty entries
  366. not_done=True
  367. while not_done:
  368. try:
  369. msgl.remove('')
  370. except:
  371. not_done = False
  372. msgs[n].extend(msgl)
  373. elif msg == None:
  374. time.sleep(2)
  375. waited = waited + 2
  376. if len(msgs[n]) < self.total_num_msgs:
  377. return self.failure("expected %d messages from %s got %d" % (self.total_num_msgs, n, len(msgs[n])))
  378. fail = False
  379. error_message = ''
  380. for i in range(0, self.total_num_msgs):
  381. first = None
  382. for n in self.CM.Env["nodes"]:
  383. # first test for errors
  384. params = msgs[n][i].split(":")
  385. if not 'OK' in params[3]:
  386. fail = True
  387. error_message = 'error: ' + params[3] + ' in received message'
  388. self.CM.log(str(params))
  389. # then look for out of order messages
  390. if first == None:
  391. first = n
  392. else:
  393. if not msgs[first][i] == msgs[n][i]:
  394. # message order not the same!
  395. fail = True
  396. error_message = 'message out of order'
  397. self.CM.log(msgs[first][i] + " != " + msgs[n][i])
  398. if fail:
  399. return self.failure(error_message)
  400. else:
  401. return self.success()
  402. ###################################################################
  403. class CpgMsgOrderBasic(CpgMsgOrderBase):
  404. '''
  405. each sends & logs lots of messages
  406. '''
  407. def __init__(self, cm):
  408. CpgMsgOrderBase.__init__(self,cm)
  409. self.name="CpgMsgOrderBasic"
  410. self.num_msgs_per_node = 9000
  411. def __call__(self, node):
  412. self.incr("calls")
  413. for n in self.CM.Env["nodes"]:
  414. self.CM.cpg_agent[n].msg_blaster(self.num_msgs_per_node)
  415. return self.wait_and_validate_order()
  416. ###################################################################
  417. class CpgMsgOrderZcb(CpgMsgOrderBase):
  418. '''
  419. each sends & logs lots of messages
  420. '''
  421. def __init__(self, cm):
  422. CpgMsgOrderBase.__init__(self,cm)
  423. self.name="CpgMsgOrderZcb"
  424. self.num_msgs_per_node = 9000
  425. def __call__(self, node):
  426. self.incr("calls")
  427. for n in self.CM.Env["nodes"]:
  428. self.CM.cpg_agent[n].msg_blaster_zcb(self.num_msgs_per_node)
  429. return self.wait_and_validate_order()
  430. ###################################################################
  431. class MemLeakObject(CoroTest):
  432. '''
  433. run mem_leak_test.sh -1
  434. '''
  435. def __init__(self, cm):
  436. CoroTest.__init__(self,cm)
  437. self.name="MemLeakObject"
  438. def __call__(self, node):
  439. self.incr("calls")
  440. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -1")
  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 MemLeakSession(CoroTest):
  447. '''
  448. run mem_leak_test.sh -2
  449. '''
  450. def __init__(self, cm):
  451. CoroTest.__init__(self,cm)
  452. self.name="MemLeakSession"
  453. def __call__(self, node):
  454. self.incr("calls")
  455. mem_leaked = self.CM.rsh(node, "/usr/share/corosync/tests/mem_leak_test.sh -2")
  456. if mem_leaked is 0:
  457. return self.success()
  458. else:
  459. return self.failure(str(mem_leaked) + 'kB memory leaked.')
  460. ###################################################################
  461. class CMapDispatchDeadlock(CoroTest):
  462. '''
  463. run cmap-dispatch-deadlock.sh
  464. '''
  465. def __init__(self, cm):
  466. CoroTest.__init__(self,cm)
  467. self.name="CMapDispatchDeadlock"
  468. def __call__(self, node):
  469. self.incr("calls")
  470. result = self.CM.rsh(node, "/usr/share/corosync/tests/cmap-dispatch-deadlock.sh")
  471. if result is 0:
  472. return self.success()
  473. else:
  474. return self.failure('Deadlock detected')
  475. ###################################################################
  476. class SamTest1(CoroTest):
  477. def __init__(self, cm):
  478. CoroTest.__init__(self, cm)
  479. self.name="SamTest1"
  480. def __call__(self, node):
  481. self.incr("calls")
  482. res = self.CM.sam_agent[node].test1()
  483. if 'OK' in res:
  484. return self.success()
  485. else:
  486. return self.failure(self.name + ' failed')
  487. ###################################################################
  488. class SamTest2(CoroTest):
  489. def __init__(self, cm):
  490. CoroTest.__init__(self, cm)
  491. self.name="SamTest2"
  492. def __call__(self, node):
  493. self.incr("calls")
  494. res = self.CM.sam_agent[node].test2()
  495. if 'OK' in res:
  496. return self.success()
  497. else:
  498. return self.failure(self.name + ' failed')
  499. ###################################################################
  500. class SamTest4(CoroTest):
  501. def __init__(self, cm):
  502. CoroTest.__init__(self, cm)
  503. self.name="SamTest4"
  504. def __call__(self, node):
  505. self.incr("calls")
  506. res = self.CM.sam_agent[node].test4()
  507. if 'OK' in res:
  508. return self.success()
  509. else:
  510. return self.failure(self.name + ' failed')
  511. ###################################################################
  512. class SamTest5(CoroTest):
  513. def __init__(self, cm):
  514. CoroTest.__init__(self, cm)
  515. self.name="SamTest5"
  516. def __call__(self, node):
  517. self.incr("calls")
  518. res = self.CM.sam_agent[node].test5()
  519. if 'OK' in res:
  520. return self.success()
  521. else:
  522. return self.failure(self.name + ' failed')
  523. ###################################################################
  524. class SamTest6(CoroTest):
  525. def __init__(self, cm):
  526. CoroTest.__init__(self, cm)
  527. self.name="SamTest6"
  528. def __call__(self, node):
  529. self.incr("calls")
  530. res = self.CM.sam_agent[node].test6()
  531. if 'OK' in res:
  532. return self.success()
  533. else:
  534. return self.failure(self.name + ' failed')
  535. ###################################################################
  536. class SamTestQuorum(CoroTest):
  537. def __init__(self, cm):
  538. CoroTest.__init__(self, cm)
  539. self.name="SamTestQuorum"
  540. self.config['quorum/provider'] = 'testquorum'
  541. self.config['quorum/quorate'] = '1'
  542. def __call__(self, node):
  543. self.incr("calls")
  544. res = self.CM.sam_agent[node].test_quorum()
  545. if 'OK' in res:
  546. return self.success()
  547. else:
  548. return self.failure(self.name + ' failed')
  549. ###################################################################
  550. class SamTest8(CoroTest):
  551. def __init__(self, cm):
  552. CoroTest.__init__(self, cm)
  553. self.name="SamTest8"
  554. def __call__(self, node):
  555. self.incr("calls")
  556. res = self.CM.sam_agent[node].test8()
  557. if 'OK' in res:
  558. return self.success()
  559. else:
  560. return self.failure(self.name + ' failed')
  561. ###################################################################
  562. class SamTest9(CoroTest):
  563. def __init__(self, cm):
  564. CoroTest.__init__(self, cm)
  565. self.name="SamTest9"
  566. def __call__(self, node):
  567. self.incr("calls")
  568. res = self.CM.sam_agent[node].test9()
  569. if 'OK' in res:
  570. return self.success()
  571. else:
  572. return self.failure(self.name + ' failed')
  573. class QuorumState(object):
  574. def __init__(self, cm, node):
  575. self.node = node
  576. self.CM = cm
  577. self.CM.votequorum_agent[self.node].init()
  578. def refresh(self):
  579. info = self.CM.votequorum_agent[self.node].votequorum_getinfo()
  580. assert(info != 'FAIL')
  581. assert(info != 'NOT_SUPPORTED')
  582. #self.CM.log('refresh: ' + info)
  583. params = info.split(':')
  584. self.node_votes = int(params[0])
  585. self.expected_votes = int(params[1])
  586. self.highest_expected = int(params[2])
  587. self.total_votes = int(params[3])
  588. self.quorum = int(params[4])
  589. self.quorate = self.CM.votequorum_agent[self.node].quorum_getquorate()
  590. assert(self.quorate != 'FAIL')
  591. assert(self.quorate != 'NOT_SUPPORTED')
  592. #self.CM.log('quorate: ' + str(self.quorate))
  593. ###################################################################
  594. class VoteQuorumBase(CoroTest):
  595. def setup(self, node):
  596. ret = CoroTest.setup(self, node)
  597. self.id_map = {}
  598. self.listener = None
  599. for n in self.CM.Env["nodes"]:
  600. if self.listener is None:
  601. self.listener = n
  602. if self.need_all_up:
  603. self.CM.cpg_agent[n].clean_start()
  604. self.CM.cpg_agent[n].cpg_join(self.name)
  605. self.id_map[n] = self.CM.cpg_agent[n].cpg_local_get()
  606. return ret
  607. def config_valid(self, config):
  608. if config.has_key('totem/rrp_mode'):
  609. return False
  610. if config.has_key('quorum/provider'):
  611. return False
  612. return True
  613. ###################################################################
  614. class VoteQuorumGoDown(VoteQuorumBase):
  615. # all up
  616. # calc min expected votes to get Q
  617. # bring nodes down one-by-one
  618. # confirm cluster looses Q when V < EV
  619. #
  620. def __init__(self, cm):
  621. VoteQuorumBase.__init__(self, cm)
  622. self.name="VoteQuorumGoDown"
  623. self.victims = []
  624. self.expected = len(self.CM.Env["nodes"])
  625. self.config['quorum/provider'] = 'corosync_votequorum'
  626. self.config['quorum/expected_votes'] = self.expected
  627. #self.CM.log('set expected to %d' % (self.expected))
  628. def __call__(self, node):
  629. self.incr("calls")
  630. self.victims = []
  631. pats = []
  632. pats.append("%s .*VQ notification quorate: 0" % self.listener)
  633. pats.append("%s .*NQ notification quorate: 0" % self.listener)
  634. quorum = self.create_watch(pats, 30)
  635. quorum.setwatch()
  636. state = QuorumState(self.CM, self.listener)
  637. state.refresh()
  638. for n in self.CM.Env["nodes"]:
  639. if n is self.listener:
  640. continue
  641. self.victims.append(n)
  642. self.CM.StopaCM(n)
  643. #if not self.wait_for_quorum_change():
  644. # return self.failure(self.error_message)
  645. nodes_alive = len(self.CM.Env["nodes"]) - len(self.victims)
  646. state.refresh()
  647. #self.expected = self.expected - 1
  648. if state.node_votes != 1:
  649. self.failure('unexpected number of node_votes')
  650. if state.expected_votes != self.expected:
  651. self.CM.log('nev: %d != exp %d' % (state.expected_votes, self.expected))
  652. self.failure('unexpected number of expected_votes')
  653. if state.total_votes != nodes_alive:
  654. self.failure('unexpected number of total votes:%d, nodes_alive:%d' % (state.total_votes, nodes_alive))
  655. min = ((len(self.CM.Env["nodes"]) + 2) / 2)
  656. if min != state.quorum:
  657. self.failure('we should have %d (not %d) as quorum' % (min, state.quorum))
  658. if nodes_alive < state.quorum:
  659. if state.quorate == 1:
  660. self.failure('we should NOT have quorum(%d) %d > %d' % (state.quorate, state.quorum, nodes_alive))
  661. else:
  662. if state.quorate == 0:
  663. self.failure('we should have quorum(%d) %d <= %d' % (state.quorate, state.quorum, nodes_alive))
  664. if not quorum.lookforall():
  665. self.CM.log("Patterns not found: " + repr(quorum.unmatched))
  666. return self.failure('quorm event not found')
  667. return self.success()
  668. # all down
  669. # calc min expected votes to get Q
  670. # bring nodes up one-by-one
  671. # confirm cluster gains Q when V >= EV
  672. #
  673. ###################################################################
  674. class VoteQuorumGoUp(VoteQuorumBase):
  675. # all up
  676. # calc min expected votes to get Q
  677. # bring nodes down one-by-one
  678. # confirm cluster looses Q when V < EV
  679. #
  680. def __init__(self, cm):
  681. VoteQuorumBase.__init__(self, cm)
  682. self.name="VoteQuorumGoUp"
  683. self.need_all_up = False
  684. self.expected = len(self.CM.Env["nodes"])
  685. self.config['quorum/provider'] = 'corosync_votequorum'
  686. self.config['quorum/expected_votes'] = self.expected
  687. #self.CM.log('set expected to %d' % (self.expected))
  688. def __call__(self, node):
  689. self.incr("calls")
  690. pats = []
  691. pats.append("%s .*VQ notification quorate: 1" % self.listener)
  692. pats.append("%s .*NQ notification quorate: 1" % self.listener)
  693. quorum = self.create_watch(pats, 30)
  694. quorum.setwatch()
  695. self.CM.StartaCM(self.listener)
  696. nodes_alive = 1
  697. state = QuorumState(self.CM, self.listener)
  698. state.refresh()
  699. for n in self.CM.Env["nodes"]:
  700. if n is self.listener:
  701. continue
  702. #if not self.wait_for_quorum_change():
  703. # return self.failure(self.error_message)
  704. if state.node_votes != 1:
  705. self.failure('unexpected number of node_votes')
  706. if state.expected_votes != self.expected:
  707. self.CM.log('nev: %d != exp %d' % (state.expected_votes, self.expected))
  708. self.failure('unexpected number of expected_votes')
  709. if state.total_votes != nodes_alive:
  710. self.failure('unexpected number of total votes')
  711. min = ((len(self.CM.Env["nodes"]) + 2) / 2)
  712. if min != state.quorum:
  713. self.failure('we should have %d (not %d) as quorum' % (min, state.quorum))
  714. if nodes_alive < state.quorum:
  715. if state.quorate == 1:
  716. self.failure('we should NOT have quorum(%d) %d > %d' % (state.quorate, state.quorum, nodes_alive))
  717. else:
  718. if state.quorate == 0:
  719. self.failure('we should have quorum(%d) %d <= %d' % (state.quorate, state.quorum, nodes_alive))
  720. self.CM.StartaCM(n)
  721. nodes_alive = nodes_alive + 1
  722. state.refresh()
  723. if not quorum.lookforall():
  724. self.CM.log("Patterns not found: " + repr(quorum.unmatched))
  725. return self.failure('quorm event not found')
  726. return self.success()
  727. ###################################################################
  728. class VoteQuorumContextTest(CoroTest):
  729. def __init__(self, cm):
  730. CoroTest.__init__(self, cm)
  731. self.name="VoteQuorumContextTest"
  732. self.expected = len(self.CM.Env["nodes"])
  733. self.config['quorum/provider'] = 'corosync_votequorum'
  734. self.config['quorum/expected_votes'] = self.expected
  735. def __call__(self, node):
  736. self.incr("calls")
  737. res = self.CM.votequorum_agent[node].context_test()
  738. if 'OK' in res:
  739. return self.success()
  740. else:
  741. return self.failure('context_test failed')
  742. ###################################################################
  743. class GenSimulStart(CoroTest):
  744. '''Start all the nodes ~ simultaneously'''
  745. def __init__(self, cm):
  746. CoroTest.__init__(self,cm)
  747. self.name="GenSimulStart"
  748. self.need_all_up = False
  749. self.stopall = SimulStopLite(cm)
  750. self.startall = SimulStartLite(cm)
  751. def __call__(self, dummy):
  752. '''Perform the 'SimulStart' test. '''
  753. self.incr("calls")
  754. # We ignore the "node" parameter...
  755. # Shut down all the nodes...
  756. ret = self.stopall(None)
  757. if not ret:
  758. return self.failure("Setup failed")
  759. self.CM.clear_all_caches()
  760. if not self.startall(None):
  761. return self.failure("Startall failed")
  762. return self.success()
  763. ###################################################################
  764. class GenSimulStop(CoroTest):
  765. '''Stop all the nodes ~ simultaneously'''
  766. def __init__(self, cm):
  767. CoroTest.__init__(self,cm)
  768. self.name="GenSimulStop"
  769. self.startall = SimulStartLite(cm)
  770. self.stopall = SimulStopLite(cm)
  771. self.need_all_up = True
  772. def __call__(self, dummy):
  773. '''Perform the 'GenSimulStop' test. '''
  774. self.incr("calls")
  775. # We ignore the "node" parameter...
  776. # Start up all the nodes...
  777. ret = self.startall(None)
  778. if not ret:
  779. return self.failure("Setup failed")
  780. if not self.stopall(None):
  781. return self.failure("Stopall failed")
  782. return self.success()
  783. ###################################################################
  784. class GenStopAllBeekhof(CoroTest):
  785. '''Stop all the nodes ~ simultaneously'''
  786. def __init__(self, cm):
  787. CoroTest.__init__(self,cm)
  788. self.name="GenStopAllBeekhof"
  789. self.need_all_up = True
  790. self.config['logging/logger_subsys[2]/subsys'] = 'CFG'
  791. self.config['logging/logger_subsys[2]/debug'] = 'on'
  792. def __call__(self, node):
  793. '''Perform the 'GenStopAllBeekhof' test. '''
  794. self.incr("calls")
  795. stopping = int(time.time())
  796. for n in self.CM.Env["nodes"]:
  797. self.CM.cpg_agent[n].pcmk_test()
  798. for n in self.CM.Env["nodes"]:
  799. self.CM.cpg_agent[n].msg_blaster(1000)
  800. for n in self.CM.Env["nodes"]:
  801. self.CM.cpg_agent[n].cfg_shutdown()
  802. self.CM.ShouldBeStatus[n] = "down"
  803. waited = 0
  804. max_wait = 60 * 15
  805. still_up = list(self.CM.Env["nodes"])
  806. while len(still_up) > 0:
  807. waited = int(time.time()) - stopping
  808. self.CM.log("%s still up %s; waited %d secs" % (self.name, str(still_up), waited))
  809. if waited > max_wait:
  810. break
  811. time.sleep(3)
  812. for v in self.CM.Env["nodes"]:
  813. if v in still_up:
  814. self.CM.ShouldBeStatus[n] = "down"
  815. if not self.CM.StataCM(v):
  816. still_up.remove(v)
  817. waited = int(time.time()) - stopping
  818. if waited > max_wait:
  819. return self.failure("Waited %d secs for nodes: %s to stop" % (waited, str(still_up)))
  820. self.CM.log("%s ALL good (waited %d secs)" % (self.name, waited))
  821. return self.success()
  822. ###################################################################
  823. class NoWDConfig(CoroTest):
  824. '''Assertion: no config == no watchdog
  825. Setup: no config, kmod inserted
  826. 1] make sure watchdog is not enabled
  827. '''
  828. def __init__(self, cm):
  829. CoroTest.__init__(self,cm)
  830. self.name="NoWDConfig"
  831. self.need_all_up = False
  832. def config_valid(self, config):
  833. return not config.has_key('resources')
  834. def __call__(self, node):
  835. '''Perform the 'NoWDConfig' test. '''
  836. self.incr("calls")
  837. self.CM.StopaCM(node)
  838. pats = []
  839. pats.append("%s .*no resources configured." % node)
  840. w = self.create_watch(pats, 60)
  841. w.setwatch()
  842. self.CM.StartaCM(node)
  843. if not w.lookforall():
  844. return self.failure("Patterns not found: " + repr(w.unmatched))
  845. else:
  846. return self.success()
  847. ###################################################################
  848. class WDConfigNoWd(CoroTest):
  849. '''Assertion: watchdog config but no watchdog kmod will emit a log
  850. Setup: config watchdog, but no kmod
  851. 1] look in the log for warning that there is no kmod
  852. '''
  853. def __init__(self, cm):
  854. CoroTest.__init__(self,cm)
  855. self.name="WDConfigNoWd"
  856. self.need_all_up = False
  857. def __call__(self, node):
  858. '''Perform the 'WDConfigNoWd' test. '''
  859. self.incr("calls")
  860. self.CM.StopaCM(node)
  861. self.CM.rsh(node, 'rmmod softdog')
  862. pats = []
  863. pats.append("%s .*No Watchdog, try modprobe.*" % node)
  864. w = self.create_watch(pats, 60)
  865. w.setwatch()
  866. self.CM.StartaCM(node)
  867. if not w.lookforall():
  868. return self.failure("Patterns not found: " + repr(w.unmatched))
  869. else:
  870. return self.success()
  871. ###################################################################
  872. class NoWDOnCorosyncStop(CoroTest):
  873. '''Configure WD then /etc/init.d/corosync stop
  874. must stay up for > 60 secs
  875. '''
  876. def __init__(self, cm):
  877. CoroTest.__init__(self,cm)
  878. self.name="NoWDOnCorosyncStop"
  879. self.need_all_up = False
  880. def __call__(self, node):
  881. '''Perform the test. '''
  882. self.incr("calls")
  883. self.CM.StopaCM(node)
  884. self.CM.rsh(node, 'modprobe softdog')
  885. self.CM.StartaCM(node)
  886. pats = []
  887. pats.append("%s .*Unexpected close, not stopping watchdog.*" % node)
  888. w = self.create_watch(pats, 60)
  889. w.setwatch()
  890. self.CM.StopaCM(node)
  891. if w.lookforall():
  892. return self.failure("Should have closed the WD better: " + repr(w.matched))
  893. else:
  894. return self.success()
  895. ###################################################################
  896. class WDOnForkBomb(CoroTest):
  897. '''Configure memory resource
  898. run memory leaker / forkbomb
  899. confirm watchdog action
  900. '''
  901. def __init__(self, cm):
  902. CoroTest.__init__(self,cm)
  903. self.name="WDOnForkBomb"
  904. self.need_all_up = False
  905. self.config['logging/logger_subsys[2]/subsys'] = 'WD'
  906. self.config['logging/logger_subsys[2]/debug'] = 'on'
  907. self.config['resources/system/memory_used/recovery'] = 'watchdog'
  908. self.config['resources/system/memory_used/max'] = '80'
  909. self.config['resources/system/memory_used/poll_period'] = '800'
  910. def __call__(self, node):
  911. '''Perform the test. '''
  912. self.incr("calls")
  913. # get the uptime
  914. up_before = self.CM.rsh(node, 'cut -d. -f1 /proc/uptime', 1).rstrip()
  915. self.CM.StopaCM(node)
  916. self.CM.rsh(node, 'modprobe softdog')
  917. self.CM.StartaCM(node)
  918. self.CM.rsh(node, ':(){ :|:& };:', synchronous=0)
  919. self.CM.log("wait for it to watchdog")
  920. time.sleep(60 * 5)
  921. ping_able = False
  922. while not ping_able:
  923. if self.CM.rsh("localhost", "ping -nq -c10 -w10 %s" % node) == 0:
  924. ping_able = True
  925. self.CM.log("can ping 10 in 10secs.")
  926. else:
  927. self.CM.log("not yet responding to pings.")
  928. self.CM.ShouldBeStatus[node] = "down"
  929. # wait for the node to come back up
  930. self.CM.log("waiting for node to come back up.")
  931. if self.CM.ns.WaitForNodeToComeUp(node):
  932. up_after = self.CM.rsh(node, 'cut -d. -f1 /proc/uptime', 1).rstrip()
  933. if int(up_after) < int(up_before):
  934. return self.success()
  935. else:
  936. return self.failure("node didn't seem to watchdog uptime 1 %s; 2 %s" %(up_before, up_after))
  937. else:
  938. return self.failure("node didn't seem to come back up")
  939. ###################################################################
  940. class SamWdIntegration1(CoroTest):
  941. '''start sam hc
  942. kill agent
  943. confirm action
  944. '''
  945. def __init__(self, cm):
  946. CoroTest.__init__(self,cm)
  947. self.name="SamWdIntegration1"
  948. self.need_all_up = True
  949. self.config['logging/logger_subsys[2]/subsys'] = 'WD'
  950. self.config['logging/logger_subsys[2]/debug'] = 'on'
  951. def __call__(self, node):
  952. '''Perform the test. '''
  953. self.incr("calls")
  954. self.CM.sam_agent[node].setup_hc()
  955. pids = self.CM.sam_agent[node].getpid().rstrip().split(" ")
  956. pats = []
  957. for pid in pids:
  958. pats.append('%s .*resource "sam_test_agent:%s" failed!' % (node, pid))
  959. w = self.create_watch(pats, 60)
  960. w.setwatch()
  961. self.CM.sam_agent[node].kill()
  962. look_result = w.look()
  963. if not look_result:
  964. return self.failure("Patterns not found: " + repr(w.regexes))
  965. else:
  966. return self.success()
  967. ###################################################################
  968. class SamWdIntegration2(CoroTest):
  969. '''start sam hc
  970. call sam_stop()
  971. confirm resource "stopped" and no watchdog action.
  972. '''
  973. def __init__(self, cm):
  974. CoroTest.__init__(self,cm)
  975. self.name="SamWdIntegration2"
  976. self.need_all_up = True
  977. self.config['logging/logger_subsys[2]/subsys'] = 'WD'
  978. self.config['logging/logger_subsys[2]/debug'] = 'on'
  979. def __call__(self, node):
  980. '''Perform the test. '''
  981. self.incr("calls")
  982. self.CM.sam_agent[node].setup_hc()
  983. pids = self.CM.sam_agent[node].getpid().rstrip().split(" ")
  984. no_pats = []
  985. yes_pats = []
  986. for pid in pids:
  987. no_pats.append('%s .*resource "sam_test_agent:%s" failed!' % (node, pid))
  988. yes_pats.append('%s .*Fsm:sam_test_agent:%s event "config_changed", state "running" --> "stopped"' % (node, pid))
  989. yes_w = self.create_watch(yes_pats, 10)
  990. no_w = self.create_watch(no_pats, 10)
  991. yes_w.setwatch()
  992. no_w.setwatch()
  993. time.sleep(2)
  994. self.CM.sam_agent[node].sam_stop()
  995. yes_matched = yes_w.look()
  996. no_matched = no_w.look()
  997. if no_matched:
  998. return self.failure("Patterns found: " + repr(no_matched))
  999. else:
  1000. if not yes_matched:
  1001. return self.failure("Patterns NOT found: " + repr(yes_w.regexes))
  1002. return self.success()
  1003. ###################################################################
  1004. class WdDeleteResource(CoroTest):
  1005. '''config resource & start corosync
  1006. check that it is getting checked
  1007. delete the object resource object
  1008. check that we do NOT get watchdog'ed
  1009. '''
  1010. def __init__(self, cm):
  1011. CoroTest.__init__(self,cm)
  1012. self.name="WdDeleteResource"
  1013. self.need_all_up = True
  1014. self.config['logging/logger_subsys[2]/subsys'] = 'MON'
  1015. self.config['logging/logger_subsys[2]/debug'] = 'on'
  1016. self.config['logging/logger_subsys[3]/subsys'] = 'WD'
  1017. self.config['logging/logger_subsys[3]/debug'] = 'on'
  1018. self.config['resources/system/memory_used/recovery'] = 'watchdog'
  1019. self.config['resources/system/memory_used/max'] = '80'
  1020. self.config['resources/system/memory_used/poll_period'] = '800'
  1021. def __call__(self, node):
  1022. '''Perform the test. '''
  1023. self.incr("calls")
  1024. no_pats = []
  1025. yes_pats = []
  1026. no_pats.append('%s .*resource "memory_used" failed!' % node)
  1027. yes_pats.append('%s .*resource "memory_used" deleted from objdb!' % node)
  1028. yes_w = self.create_watch(yes_pats, 10)
  1029. no_w = self.create_watch(no_pats, 10)
  1030. yes_w.setwatch()
  1031. no_w.setwatch()
  1032. time.sleep(2)
  1033. self.CM.rsh(node, 'corosync-cmapctl -d resources.system.memory_used')
  1034. yes_matched = yes_w.look()
  1035. no_matched = no_w.look()
  1036. if no_matched:
  1037. return self.failure("Patterns found: " + repr(no_matched))
  1038. else:
  1039. if not yes_matched:
  1040. return self.failure("Patterns NOT found: " + repr(yes_w.regexes))
  1041. return self.success()
  1042. ###################################################################
  1043. class ResourcePollAdjust(CoroTest):
  1044. '''config resource & start corosync
  1045. change the poll_period
  1046. check that we do NOT get watchdog'ed
  1047. '''
  1048. def __init__(self, cm):
  1049. CoroTest.__init__(self,cm)
  1050. self.name="ResourcePollAdjust"
  1051. self.need_all_up = True
  1052. self.config['logging/logger_subsys[2]/subsys'] = 'MON'
  1053. self.config['logging/logger_subsys[2]/debug'] = 'on'
  1054. self.config['logging/logger_subsys[3]/subsys'] = 'WD'
  1055. self.config['logging/logger_subsys[3]/debug'] = 'on'
  1056. self.config['resources/system/memory_used/recovery'] = 'none'
  1057. self.config['resources/system/memory_used/max'] = '80'
  1058. self.config['resources/system/memory_used/poll_period'] = '800'
  1059. def __call__(self, node):
  1060. '''Perform the test. '''
  1061. self.incr("calls")
  1062. no_pats = []
  1063. no_pats.append('%s .*resource "memory_used" failed!' % node)
  1064. no_pats.append('%s .*Could NOT use poll_period.*' % node)
  1065. no_w = self.create_watch(no_pats, 10)
  1066. no_w.setwatch()
  1067. changes = 0
  1068. while changes < 50:
  1069. changes = changes + 1
  1070. poll_period = int(random.random() * 5000)
  1071. if poll_period < 500:
  1072. poll_period = 500
  1073. self.CM.log("setting poll_period to: %d" % poll_period)
  1074. self.CM.rsh(node, 'corosync-cmapctl -s resources.system.memory_used.poll_period str %d' % poll_period)
  1075. sleep_time = poll_period * 2 / 1000
  1076. if sleep_time < 1:
  1077. sleep_time = 1
  1078. time.sleep(sleep_time)
  1079. no_matched = no_w.look()
  1080. if no_matched:
  1081. return self.failure("Patterns found: " + repr(no_matched))
  1082. return self.success()
  1083. ###################################################################
  1084. class RebootOnHighMem(CoroTest):
  1085. '''Configure memory resource
  1086. run memory leaker / forkbomb
  1087. confirm reboot action
  1088. '''
  1089. def __init__(self, cm):
  1090. CoroTest.__init__(self,cm)
  1091. self.name="RebootOnHighMem"
  1092. self.need_all_up = True
  1093. self.config['logging/logger_subsys[2]/subsys'] = 'WD'
  1094. self.config['logging/logger_subsys[2]/debug'] = 'on'
  1095. self.config['resources/system/memory_used/recovery'] = 'reboot'
  1096. self.config['resources/system/memory_used/max'] = '80'
  1097. self.config['resources/system/memory_used/poll_period'] = '800'
  1098. def __call__(self, node):
  1099. '''Perform the test. '''
  1100. self.incr("calls")
  1101. # get the uptime
  1102. up_before = self.CM.rsh(node, 'cut -d. -f1 /proc/uptime', 1).rstrip()
  1103. cmd = 'corosync-cmapctl resources.system.memory_used. | grep current | cut -d= -f2'
  1104. mem_current_str = self.CM.rsh(node, cmd, 1).rstrip()
  1105. mem_new_max = int(mem_current_str) + 5
  1106. self.CM.log("current mem usage: %s, new max:%d" % (mem_current_str, mem_new_max))
  1107. cmd = 'corosync-cmapctl -s resources.system.memory_used.max str ' + str(mem_new_max)
  1108. self.CM.rsh(node, cmd)
  1109. self.CM.rsh(node, 'memhog -r10000 200m', synchronous=0)
  1110. self.CM.log("wait for it to reboot")
  1111. time.sleep(60 * 3)
  1112. cmd = 'corosync-cmapctl resources.system.memory_used. | grep current | cut -d= -f2'
  1113. mem_current_str = self.CM.rsh(node, cmd, 1).rstrip()
  1114. self.CM.log("current mem usage: %s" % (mem_current_str))
  1115. ping_able = False
  1116. while not ping_able:
  1117. if self.CM.rsh("localhost", "ping -nq -c10 -w10 %s" % node) == 0:
  1118. ping_able = True
  1119. self.CM.log("can ping 10 in 10secs.")
  1120. else:
  1121. self.CM.log("not yet responding to pings.")
  1122. self.CM.ShouldBeStatus[node] = "down"
  1123. # wait for the node to come back up
  1124. self.CM.log("waiting for node to come back up.")
  1125. if self.CM.ns.WaitForNodeToComeUp(node):
  1126. up_after = self.CM.rsh(node, 'cut -d. -f1 /proc/uptime', 1).rstrip()
  1127. if int(up_after) < int(up_before):
  1128. return self.success()
  1129. else:
  1130. return self.failure("node didn't seem to watchdog uptime 1 %s; 2 %s" %(up_before, up_after))
  1131. else:
  1132. return self.failure("node didn't seem to come back up")
  1133. GenTestClasses = []
  1134. GenTestClasses.append(GenSimulStart)
  1135. GenTestClasses.append(GenSimulStop)
  1136. GenTestClasses.append(GenStopAllBeekhof)
  1137. GenTestClasses.append(CpgMsgOrderBasic)
  1138. GenTestClasses.append(CpgMsgOrderZcb)
  1139. GenTestClasses.append(CpgCfgChgOnExecCrash)
  1140. GenTestClasses.append(CpgCfgChgOnGroupLeave)
  1141. GenTestClasses.append(CpgCfgChgOnNodeLeave)
  1142. GenTestClasses.append(CpgCfgChgOnNodeIsolate)
  1143. #GenTestClasses.append(CpgCfgChgOnNodeRestart)
  1144. AllTestClasses = []
  1145. AllTestClasses.append(CpgContextTest)
  1146. AllTestClasses.append(VoteQuorumContextTest)
  1147. AllTestClasses.append(SamTest1)
  1148. AllTestClasses.append(SamTest2)
  1149. AllTestClasses.append(SamTest4)
  1150. AllTestClasses.append(SamTest5)
  1151. AllTestClasses.append(SamTest6)
  1152. AllTestClasses.append(SamTest8)
  1153. AllTestClasses.append(SamTest9)
  1154. AllTestClasses.append(SamWdIntegration1)
  1155. AllTestClasses.append(SamWdIntegration2)
  1156. AllTestClasses.append(NoWDConfig)
  1157. AllTestClasses.append(WDConfigNoWd)
  1158. AllTestClasses.append(NoWDOnCorosyncStop)
  1159. #AllTestClasses.append(WDOnForkBomb)
  1160. AllTestClasses.append(WdDeleteResource)
  1161. #AllTestClasses.append(RebootOnHighMem)
  1162. AllTestClasses.append(ResourcePollAdjust)
  1163. AllTestClasses.append(MemLeakObject)
  1164. AllTestClasses.append(MemLeakSession)
  1165. #AllTestClasses.append(CMapDispatchDeadlock)
  1166. AllTestClasses.append(FlipTest)
  1167. AllTestClasses.append(RestartTest)
  1168. AllTestClasses.append(StartOnebyOne)
  1169. AllTestClasses.append(StopOnebyOne)
  1170. AllTestClasses.append(RestartOnebyOne)
  1171. # FIXME quorum tests
  1172. #AllTestClasses.append(SamTestQuorum)
  1173. #GenTestClasses.append(VoteQuorumGoDown)
  1174. #GenTestClasses.append(VoteQuorumGoUp)
  1175. # FIXME need log messages in sync
  1176. #GenTestClasses.append(CpgCfgChgOnLowestNodeJoin)
  1177. class ConfigContainer(UserDict):
  1178. def __init__ (self, name):
  1179. self.name = name
  1180. UserDict.__init__(self)
  1181. def CoroTestList(cm, audits):
  1182. result = []
  1183. configs = []
  1184. for testclass in AllTestClasses:
  1185. bound_test = testclass(cm)
  1186. if bound_test.is_applicable():
  1187. bound_test.Audits = audits
  1188. result.append(bound_test)
  1189. default = ConfigContainer('default')
  1190. default['logging/fileline'] = 'on'
  1191. default['logging/function_name'] = 'off'
  1192. default['logging/logfile_priority'] = 'info'
  1193. default['logging/syslog_priority'] = 'info'
  1194. default['logging/syslog_facility'] = 'daemon'
  1195. default['uidgid/uid'] = '0'
  1196. default['uidgid/gid'] = '0'
  1197. configs.append(default)
  1198. a = ConfigContainer('none_5min')
  1199. a['compatibility'] = 'none'
  1200. a['totem/token'] = (5 * 60 * 1000)
  1201. a['totem/consensus'] = int(5 * 60 * 1000 * 1.2) + 1
  1202. configs.append(a)
  1203. b = ConfigContainer('pcmk_basic')
  1204. b['compatibility'] = 'whitetank'
  1205. b['totem/token'] = 5000
  1206. b['totem/token_retransmits_before_loss_const'] = 10
  1207. b['totem/join'] = 1000
  1208. b['totem/consensus'] = 7500
  1209. configs.append(b)
  1210. c = ConfigContainer('pcmk_sec_nss')
  1211. c['totem/secauth'] = 'on'
  1212. c['totem/crypto_accept'] = 'new'
  1213. c['totem/crypto_type'] = 'nss'
  1214. c['totem/token'] = 5000
  1215. c['totem/token_retransmits_before_loss_const'] = 10
  1216. c['totem/join'] = 1000
  1217. c['totem/consensus'] = 7500
  1218. configs.append(c)
  1219. #
  1220. # s = ConfigContainer('pcmk_vq')
  1221. # s['quorum/provider'] = 'corosync_votequorum'
  1222. # s['quorum/expected_votes'] = len(cm.Env["nodes"])
  1223. # s['totem/token'] = 5000
  1224. # s['totem/token_retransmits_before_loss_const'] = 10
  1225. # s['totem/join'] = 1000
  1226. # s['totem/vsftype'] = 'none'
  1227. # s['totem/consensus'] = 7500
  1228. # s['totem/max_messages'] = 20
  1229. # configs.append(s)
  1230. #
  1231. d = ConfigContainer('sec_sober')
  1232. d['totem/secauth'] = 'on'
  1233. d['totem/crypto_type'] = 'sober'
  1234. configs.append(d)
  1235. if not cm.Env["RrpBindAddr"] is None:
  1236. g = ConfigContainer('rrp_passive')
  1237. g['totem/rrp_mode'] = 'passive'
  1238. g['totem/interface[2]/ringnumber'] = '1'
  1239. g['totem/interface[2]/bindnetaddr'] = cm.Env["RrpBindAddr"]
  1240. g['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  1241. g['totem/interface[2]/mcastport'] = '5405'
  1242. configs.append(g)
  1243. h = ConfigContainer('rrp_active')
  1244. h['totem/rrp_mode'] = 'active'
  1245. h['totem/interface[2]/ringnumber'] = '1'
  1246. h['totem/interface[2]/bindnetaddr'] = cm.Env["RrpBindAddr"]
  1247. h['totem/interface[2]/mcastaddr'] = '226.94.1.2'
  1248. h['totem/interface[2]/mcastport'] = '5405'
  1249. configs.append(h)
  1250. else:
  1251. print 'Not including rrp tests. Use --rrp-binaddr to enable them.'
  1252. num=1
  1253. for cfg in configs:
  1254. for testclass in GenTestClasses:
  1255. bound_test = testclass(cm)
  1256. if bound_test.is_applicable() and bound_test.config_valid(cfg):
  1257. bound_test.Audits = audits
  1258. for c in cfg.keys():
  1259. bound_test.config[c] = cfg[c]
  1260. bound_test.name = bound_test.name + '_' + cfg.name
  1261. result.append(bound_test)
  1262. num = num + 1
  1263. return result