corolab.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. #!/usr/bin/python
  2. '''CTS: Cluster Testing System: Lab environment module
  3. '''
  4. __copyright__='''
  5. Copyright (c) 2010 Red Hat, Inc.
  6. '''
  7. # All rights reserved.
  8. #
  9. # Author: Angus Salkeld <asalkeld@redhat.com>
  10. #
  11. # This software licensed under BSD license, the text of which follows:
  12. #
  13. # Redistribution and use in source and binary forms, with or without
  14. # modification, are permitted provided that the following conditions are met:
  15. #
  16. # - Redistributions of source code must retain the above copyright notice,
  17. # this list of conditions and the following disclaimer.
  18. # - Redistributions in binary form must reproduce the above copyright notice,
  19. # this list of conditions and the following disclaimer in the documentation
  20. # and/or other materials provided with the distribution.
  21. # - Neither the name of the MontaVista Software, Inc. nor the names of its
  22. # contributors may be used to endorse or promote products derived from this
  23. # software without specific prior written permission.
  24. #
  25. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  29. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  35. # THE POSSIBILITY OF SUCH DAMAGE.
  36. import sys
  37. from cts.CTSscenarios import *
  38. from corotests import CoroTestList
  39. from corosync import *
  40. sys.path.append("/usr/share/pacemaker/tests/cts") # So that things work from the source directory
  41. try:
  42. from CTSlab import *
  43. except ImportError:
  44. sys.stderr.write("abort: couldn't find CTSLab in [%s]\n" %
  45. ' '.join(sys.path))
  46. sys.stderr.write("(check your install and PYTHONPATH)\n")
  47. sys.exit(-1)
  48. tests = None
  49. cm = None
  50. old_handler = None
  51. DefaultFacility = "daemon"
  52. def usage(arg):
  53. print "Illegal argument " + arg
  54. print "usage: " + sys.argv[0] +" [options] number-of-iterations"
  55. print "\nCommon options: "
  56. print "\t [--at-boot (1|0)], does the cluster software start at boot time"
  57. print "\t [--nodes 'node list'], list of cluster nodes separated by whitespace"
  58. print "\t [--limit-nodes max], only use the first 'max' cluster nodes supplied with --nodes"
  59. print "\t [--logfile path], where should the test software look for logs from cluster nodes"
  60. print "\t [--rrp-bindaddr addr], extra interface used for rrp, provide the bindaddr"
  61. print "\t [--outputfile path], optional location for the test software to write logs to"
  62. print "\t [--syslog-facility name], which syslog facility should the test software log to"
  63. print "\t [--choose testcase-name], run only the named test"
  64. print "\t [--list-tests], list the valid tests"
  65. print "\t [--benchmark], add the timing information"
  66. print "\t "
  67. print "Additional (less common) options: "
  68. print "\t [--trunc (truncate logfile before starting)]"
  69. print "\t [--xmit-loss lost-rate(0.0-1.0)]"
  70. print "\t [--recv-loss lost-rate(0.0-1.0)]"
  71. print "\t [--standby (1 | 0 | yes | no)]"
  72. print "\t [--fencing (1 | 0 | yes | no)]"
  73. print "\t [--once], run all valid tests once"
  74. print "\t [--no-loop-tests], dont run looping/time-based tests"
  75. print "\t [--no-unsafe-tests], dont run tests that are unsafe for use with ocfs2/drbd"
  76. print "\t [--valgrind-tests], include tests using valgrind"
  77. print "\t [--experimental-tests], include experimental tests"
  78. print "\t [--oprofile 'node list'], list of cluster nodes to run oprofile on]"
  79. print "\t [--qarsh] Use the QARSH backdoor to access nodes instead of SSH"
  80. print "\t [--seed random_seed]"
  81. print "\t [--set option=value]"
  82. sys.exit(1)
  83. class CoroLabEnvironment(CtsLab):
  84. def __init__(self):
  85. CtsLab.__init__(self)
  86. # Get a random seed for the random number generator.
  87. self["DoStonith"] = 0
  88. self["DoStandby"] = 0
  89. self["DoFencing"] = 0
  90. self["XmitLoss"] = "0.0"
  91. self["RecvLoss"] = "0.0"
  92. self["IPBase"] = "127.0.0.10"
  93. self["ClobberCIB"] = 0
  94. self["CIBfilename"] = None
  95. self["CIBResource"] = 0
  96. self["DoBSC"] = 0
  97. self["use_logd"] = 0
  98. self["oprofile"] = []
  99. self["RrpBindAddr"] = None
  100. self["warn-inactive"] = 0
  101. self["ListTests"] = 0
  102. self["benchmark"] = 0
  103. self["logrestartcmd"] = "systemctl restart rsyslog.service 2>&1 > /dev/null"
  104. self["syslogd"] ="rsyslog"
  105. self["Schema"] = "corosync 2.0"
  106. self["Stack"] = "corosync (needle)"
  107. self['CMclass'] = corosync_needle
  108. self["stonith-type"] = "external/ssh"
  109. self["stonith-params"] = "hostlist=all,livedangerously=yes"
  110. self["at-boot"] = 0 # Does the cluster software start automatically when the node boot
  111. self["logger"] = ([StdErrLog(self)])
  112. self["loop-minutes"] = 60
  113. self["valgrind-prefix"] = None
  114. self["valgrind-procs"] = "corosync"
  115. self["valgrind-opts"] = """--leak-check=full --show-reachable=yes --trace-children=no --num-callers=25 --gen-suppressions=all --suppressions="""+CTSvars.CTS_home+"""/cts.supp"""
  116. self["experimental-tests"] = 0
  117. self["valgrind-tests"] = 0
  118. self["unsafe-tests"] = 0
  119. self["loop-tests"] = 0
  120. self["all-once"] = 0
  121. self["LogWatcher"] = "remote"
  122. self["SyslogFacility"] = DefaultFacility
  123. self["stats"] = 0
  124. #
  125. # Main entry into the test system.
  126. #
  127. if __name__ == '__main__':
  128. Environment = CoroLabEnvironment()
  129. NumIter = 0
  130. Version = 1
  131. LimitNodes = 0
  132. TestCase = None
  133. TruncateLog = 0
  134. ListTests = 0
  135. HaveSeed = 0
  136. node_list = ''
  137. #
  138. # The values of the rest of the parameters are now properly derived from
  139. # the configuration files.
  140. #
  141. # Set the signal handler
  142. signal.signal(15, sig_handler)
  143. signal.signal(10, sig_handler)
  144. # Process arguments...
  145. skipthis=None
  146. args=sys.argv[1:]
  147. for i in range(0, len(args)):
  148. if skipthis:
  149. skipthis=None
  150. continue
  151. elif args[i] == "-l" or args[i] == "--limit-nodes":
  152. skipthis=1
  153. LimitNodes = int(args[i+1])
  154. elif args[i] == "-L" or args[i] == "--logfile":
  155. skipthis=1
  156. Environment["LogFileName"] = args[i+1]
  157. elif args[i] == "--outputfile":
  158. skipthis=1
  159. Environment["OutputFile"] = args[i+1]
  160. elif args[i] == "--rrp-bindaddr":
  161. skipthis=1
  162. Environment["RrpBindAddr"] = args[i+1]
  163. elif args[i] == "--oprofile":
  164. skipthis=1
  165. Environment["oprofile"] = args[i+1].split(' ')
  166. elif args[i] == "--trunc":
  167. Environment["TruncateLog"]=1
  168. elif args[i] == "--list-tests":
  169. Environment["ListTests"]=1
  170. elif args[i] == "--benchmark":
  171. Environment["benchmark"]=1
  172. elif args[i] == "--qarsh":
  173. Environment.rsh.enable_qarsh()
  174. elif args[i] == "--fencing":
  175. skipthis=1
  176. if args[i+1] == "1" or args[i+1] == "yes":
  177. Environment["DoFencing"] = 1
  178. elif args[i+1] == "0" or args[i+1] == "no":
  179. Environment["DoFencing"] = 0
  180. else:
  181. usage(args[i+1])
  182. elif args[i] == "--xmit-loss":
  183. try:
  184. float(args[i+1])
  185. except ValueError:
  186. print ("--xmit-loss parameter should be float")
  187. usage(args[i+1])
  188. skipthis=1
  189. Environment["XmitLoss"] = args[i+1]
  190. elif args[i] == "--recv-loss":
  191. try:
  192. float(args[i+1])
  193. except ValueError:
  194. print ("--recv-loss parameter should be float")
  195. usage(args[i+1])
  196. skipthis=1
  197. Environment["RecvLoss"] = args[i+1]
  198. elif args[i] == "--choose":
  199. skipthis=1
  200. TestCase = args[i+1]
  201. elif args[i] == "--nodes":
  202. skipthis=1
  203. node_list = args[i+1].split(' ')
  204. elif args[i] == "--at-boot" or args[i] == "--cluster-starts-at-boot":
  205. skipthis=1
  206. if args[i+1] == "1" or args[i+1] == "yes":
  207. Environment["at-boot"] = 1
  208. elif args[i+1] == "0" or args[i+1] == "no":
  209. Environment["at-boot"] = 0
  210. else:
  211. usage(args[i+1])
  212. elif args[i] == "--set":
  213. skipthis=1
  214. (name, value) = args[i+1].split('=')
  215. Environment[name] = value
  216. else:
  217. try:
  218. NumIter=int(args[i])
  219. except ValueError:
  220. usage(args[i])
  221. if Environment["OutputFile"]:
  222. Environment["logger"].append(FileLog(Environment, Environment["OutputFile"]))
  223. if len(node_list) < 1:
  224. print "No nodes specified!"
  225. sys.exit(1)
  226. if LimitNodes > 0:
  227. if len(node_list) > LimitNodes:
  228. print("Limiting the number of nodes configured=%d (max=%d)"
  229. %(len(node_list), LimitNodes))
  230. while len(node_list) > LimitNodes:
  231. node_list.pop(len(node_list)-1)
  232. Environment["nodes"] = node_list
  233. # Create the Cluster Manager object
  234. cm = Environment['CMclass'](Environment)
  235. Audits = CoroAuditList(cm)
  236. if Environment["ListTests"] == 1 :
  237. Tests = CoroTestList(cm, Audits)
  238. Environment.log("Total %d tests"%len(Tests))
  239. for test in Tests :
  240. Environment.log(str(test.name));
  241. sys.exit(0)
  242. if TruncateLog:
  243. Environment.log("Truncating %s" % LogFile)
  244. lf = open(LogFile, "w");
  245. if lf != None:
  246. lf.truncate(0)
  247. lf.close()
  248. if TestCase != None:
  249. for test in CoroTestList(cm, Audits):
  250. if test.name == TestCase:
  251. Tests.append(test)
  252. if Tests == []:
  253. usage("--choose: No applicable/valid tests chosen")
  254. else:
  255. Tests = CoroTestList(cm, Audits)
  256. # Scenario selection
  257. if Environment["DoBSC"]:
  258. scenario = RandomTests(cm, [ BasicSanityCheck(Environment) ], Audits, Tests)
  259. elif Environment["all-once"] or NumIter == 0:
  260. NumIter = len(Tests)
  261. scenario = AllOnce(
  262. cm, [ InitClusterManager(Environment), TestAgentComponent(Environment), PacketLoss(Environment) ], Audits, Tests)
  263. else:
  264. scenario = RandomTests(
  265. cm, [ InitClusterManager(Environment), TestAgentComponent(Environment), PacketLoss(Environment) ], Audits, Tests)
  266. Environment.log(">>>>>>>>>>>>>>>> BEGINNING " + repr(NumIter) + " TESTS ")
  267. Environment.log("Stack: %s" % Environment["Stack"])
  268. Environment.log("Schema: %s" % Environment["Schema"])
  269. Environment.log("Scenario: %s" % scenario.__doc__)
  270. Environment.log("Random Seed: %s" % Environment["RandSeed"])
  271. Environment.log("System log files: %s" % Environment["LogFileName"])
  272. Environment.dump()
  273. rc = Environment.run(scenario, NumIter)
  274. sys.exit(rc)