create_test.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. #!/usr/bin/python
  2. import sys
  3. import optparse
  4. '''
  5. This script generates a template test script that handles the
  6. non-interesting parts of a test script:
  7. topology,
  8. test (to be completed by the user),
  9. final,
  10. and run-isolated functions
  11. '''
  12. def displayUsage():
  13. print ('\nUsage:\ncreate_ticket.py -t|--ticket <ticket number> -s|--suite <suite name> ' +
  14. '[ i|--instances <number of standalone instances> [ -m|--masters <number of masters> ' +
  15. '-h|--hubs <number of hubs> -c|--consumers <number of consumers> ] ' +
  16. '-o|--outputfile ]\n')
  17. print ('If only "-t" is provided then a single standalone instance is created. ' +
  18. 'Or you can create a test suite script using "-s|--suite" instead of using "-t|--ticket".' +
  19. 'The "-i" option can add mulitple standalone instances(maximum 10). ' +
  20. 'However, you can not mix "-i" with the replication options(-m, -h , -c). ' +
  21. 'There is a maximum of 10 masters, 10 hubs, and 10 consumers.')
  22. exit(1)
  23. desc = 'Script to generate an initial lib389 test script. ' + \
  24. 'This generates the topology, test, final, and run-isolated functions.'
  25. if len(sys.argv) > 0:
  26. parser = optparse.OptionParser(description=desc, add_help_option=False)
  27. # Script options
  28. parser.add_option('-t', '--ticket', dest='ticket', default=None)
  29. parser.add_option('-s', '--suite', dest='suite', default=None)
  30. parser.add_option('-i', '--instances', dest='inst', default=None)
  31. parser.add_option('-m', '--masters', dest='masters', default='0')
  32. parser.add_option('-h', '--hubs', dest='hubs', default='0')
  33. parser.add_option('-c', '--consumers', dest='consumers', default='0')
  34. parser.add_option('-o', '--outputfile', dest='filename', default=None)
  35. # Validate the options
  36. try:
  37. (args, opts) = parser.parse_args()
  38. except:
  39. displayUsage()
  40. if args.ticket is None and args.suite is None:
  41. print 'Missing required ticket number/suite name'
  42. displayUsage()
  43. if args.ticket and args.suite:
  44. print 'You must choose either "-t|--ticket" or "-s|--suite", but not both.'
  45. displayUsage()
  46. if int(args.masters) == 0:
  47. if int(args.hubs) > 0 or int(args.consumers) > 0:
  48. print 'You must use "-m|--masters" if you want to have hubs and/or consumers'
  49. displayUsage()
  50. if not args.masters.isdigit() or int(args.masters) > 10 or int(args.masters) < 0:
  51. print 'Invalid value for "--masters", it must be a number and it can not be greater than 10'
  52. displayUsage()
  53. if not args.hubs.isdigit() or int(args.hubs) > 10 or int(args.hubs) < 0:
  54. print 'Invalid value for "--hubs", it must be a number and it can not be greater than 10'
  55. displayUsage()
  56. if not args.consumers.isdigit() or int(args.consumers) > 10 or int(args.consumers) < 0:
  57. print 'Invalid value for "--consumers", it must be a number and it can not be greater than 10'
  58. displayUsage()
  59. if args.inst:
  60. if not args.inst.isdigit() or int(args.inst) > 10 or int(args.inst) < 1:
  61. print ('Invalid value for "--instances", it must be a number greater than 0 ' +
  62. 'and not greater than 10')
  63. displayUsage()
  64. if int(args.inst) > 0:
  65. if int(args.masters) > 0 or int(args.hubs) > 0 or int(args.consumers) > 0:
  66. print 'You can not mix "--instances" with replication.'
  67. displayUsage()
  68. # Extract usable values
  69. masters = int(args.masters)
  70. hubs = int(args.hubs)
  71. consumers = int(args.consumers)
  72. ticket = args.ticket
  73. suite = args.suite
  74. if not args.inst:
  75. instances = 1
  76. else:
  77. instances = int(args.inst)
  78. filename = args.filename
  79. #
  80. # Create/open the new test script file
  81. #
  82. if not filename:
  83. if ticket:
  84. filename = 'ticket' + ticket + '_test.py'
  85. else:
  86. # suite
  87. filename = suite + '_test.py'
  88. try:
  89. TEST = open(filename, "w")
  90. except IOError:
  91. print "Can\'t open file:", filename
  92. exit(1)
  93. #
  94. # Write the imports
  95. #
  96. TEST.write('import os\nimport sys\nimport time\nimport ldap\nimport logging\nimport pytest\n')
  97. TEST.write('from lib389 import DirSrv, Entry, tools, tasks\nfrom lib389.tools import DirSrvTools\n' +
  98. 'from lib389._constants import *\nfrom lib389.properties import *\n' +
  99. 'from lib389.tasks import *\nfrom lib389.utils import *\n\n')
  100. #
  101. # Set the logger and installation prefix
  102. #
  103. TEST.write('logging.getLogger(__name__).setLevel(logging.DEBUG)\n')
  104. TEST.write('log = logging.getLogger(__name__)\n\n')
  105. TEST.write('installation1_prefix = None\n\n\n')
  106. #
  107. # Write the replication or standalone classes
  108. #
  109. repl_deployment = False
  110. if masters + hubs + consumers > 0:
  111. #
  112. # Write the replication class
  113. #
  114. repl_deployment = True
  115. TEST.write('class TopologyReplication(object):\n')
  116. TEST.write(' def __init__(self')
  117. for idx in range(masters):
  118. TEST.write(', master' + str(idx + 1))
  119. for idx in range(hubs):
  120. TEST.write(', hub' + str(idx + 1))
  121. for idx in range(consumers):
  122. TEST.write(', consumer' + str(idx + 1))
  123. TEST.write('):\n')
  124. for idx in range(masters):
  125. TEST.write(' master' + str(idx + 1) + '.open()\n')
  126. TEST.write(' self.master' + str(idx + 1) + ' = master' + str(idx + 1) + '\n')
  127. for idx in range(hubs):
  128. TEST.write(' hub' + str(idx + 1) + '.open()\n')
  129. TEST.write(' self.hub' + str(idx + 1) + ' = hub' + str(idx + 1) + '\n')
  130. for idx in range(consumers):
  131. TEST.write(' consumer' + str(idx + 1) + '.open()\n')
  132. TEST.write(' self.consumer' + str(idx + 1) + ' = consumer' + str(idx + 1) + '\n')
  133. TEST.write('\n\n')
  134. else:
  135. #
  136. # Write the standalone class
  137. #
  138. TEST.write('class TopologyStandalone(object):\n')
  139. TEST.write(' def __init__(self')
  140. for idx in range(instances):
  141. idx += 1
  142. if idx == 1:
  143. idx = ''
  144. else:
  145. idx = str(idx)
  146. TEST.write(', standalone' + idx)
  147. TEST.write('):\n')
  148. for idx in range(instances):
  149. idx += 1
  150. if idx == 1:
  151. idx = ''
  152. else:
  153. idx = str(idx)
  154. TEST.write(' standalone' + idx + '.open()\n')
  155. TEST.write(' self.standalone' + idx + ' = standalone' + idx + '\n')
  156. TEST.write('\n\n')
  157. #
  158. # Write the 'topology function'
  159. #
  160. TEST.write('@pytest.fixture(scope="module")\n')
  161. TEST.write('def topology(request):\n')
  162. TEST.write(' global installation1_prefix\n')
  163. TEST.write(' if installation1_prefix:\n')
  164. TEST.write(' args_instance[SER_DEPLOYED_DIR] = installation1_prefix\n\n')
  165. if repl_deployment:
  166. #
  167. # Create the replication instances
  168. #
  169. for idx in range(masters):
  170. idx = str(idx + 1)
  171. TEST.write(' # Creating master ' + idx + '...\n')
  172. TEST.write(' master' + idx + ' = DirSrv(verbose=False)\n')
  173. TEST.write(' args_instance[SER_HOST] = HOST_MASTER_' + idx + '\n')
  174. TEST.write(' args_instance[SER_PORT] = PORT_MASTER_' + idx + '\n')
  175. TEST.write(' args_instance[SER_SERVERID_PROP] = SERVERID_MASTER_' + idx + '\n')
  176. TEST.write(' args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX\n')
  177. TEST.write(' args_master = args_instance.copy()\n')
  178. TEST.write(' master' + idx + '.allocate(args_master)\n')
  179. TEST.write(' instance_master' + idx + ' = master' + idx + '.exists()\n')
  180. TEST.write(' if instance_master' + idx + ':\n')
  181. TEST.write(' master' + idx + '.delete()\n')
  182. TEST.write(' master' + idx + '.create()\n')
  183. TEST.write(' master' + idx + '.open()\n')
  184. TEST.write(' master' + idx + '.replica.enableReplication(suffix=SUFFIX, ' +
  185. 'role=REPLICAROLE_MASTER, ' +
  186. 'replicaId=REPLICAID_MASTER_' + idx + ')\n\n')
  187. for idx in range(hubs):
  188. idx = str(idx + 1)
  189. TEST.write(' # Creating hub ' + idx + '...\n')
  190. TEST.write(' hub' + idx + ' = DirSrv(verbose=False)\n')
  191. TEST.write(' args_instance[SER_HOST] = HOST_HUB_' + idx + '\n')
  192. TEST.write(' args_instance[SER_PORT] = PORT_HUB_' + idx + '\n')
  193. TEST.write(' args_instance[SER_SERVERID_PROP] = SERVERID_HUB_' + idx + '\n')
  194. TEST.write(' args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX\n')
  195. TEST.write(' args_hub = args_instance.copy()\n')
  196. TEST.write(' hub' + idx + '.allocate(args_hub)\n')
  197. TEST.write(' instance_hub' + idx + ' = hub' + idx + '.exists()\n')
  198. TEST.write(' if instance_hub' + idx + ':\n')
  199. TEST.write(' hub' + idx + '.delete()\n')
  200. TEST.write(' hub' + idx + '.create()\n')
  201. TEST.write(' hub' + idx + '.open()\n')
  202. TEST.write(' hub' + idx + '.replica.enableReplication(suffix=SUFFIX, ' +
  203. 'role=REPLICAROLE_HUB, ' +
  204. 'replicaId=REPLICAID_HUB_' + idx + ')\n\n')
  205. for idx in range(consumers):
  206. idx = str(idx + 1)
  207. TEST.write(' # Creating consumer ' + idx + '...\n')
  208. TEST.write(' consumer' + idx + ' = DirSrv(verbose=False)\n')
  209. TEST.write(' args_instance[SER_HOST] = HOST_CONSUMER_' + idx + '\n')
  210. TEST.write(' args_instance[SER_PORT] = PORT_CONSUMER_' + idx + '\n')
  211. TEST.write(' args_instance[SER_SERVERID_PROP] = SERVERID_CONSUMER_' + idx + '\n')
  212. TEST.write(' args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX\n')
  213. TEST.write(' args_consumer = args_instance.copy()\n')
  214. TEST.write(' consumer' + idx + '.allocate(args_consumer)\n')
  215. TEST.write(' instance_consumer' + idx + ' = consumer' + idx + '.exists()\n')
  216. TEST.write(' if instance_consumer' + idx + ':\n')
  217. TEST.write(' consumer' + idx + '.delete()\n')
  218. TEST.write(' consumer' + idx + '.create()\n')
  219. TEST.write(' consumer' + idx + '.open()\n')
  220. TEST.write(' consumer' + idx + '.replica.enableReplication(suffix=SUFFIX, ' +
  221. 'role=REPLICAROLE_CONSUMER, ' +
  222. 'replicaId=CONSUMER_REPLICAID)\n\n')
  223. #
  224. # Create the master agreements
  225. #
  226. TEST.write(' #\n')
  227. TEST.write(' # Create all the agreements\n')
  228. TEST.write(' #\n')
  229. agmt_count = 0
  230. for idx in range(masters):
  231. master_idx = idx + 1
  232. for idx in range(masters):
  233. #
  234. # Create agreements with the other masters (master -> master)
  235. #
  236. idx += 1
  237. if master_idx == idx:
  238. # skip ourselves
  239. continue
  240. TEST.write(' # Creating agreement from master ' + str(master_idx) + ' to master ' + str(idx) + '\n')
  241. TEST.write(" properties = {RA_NAME: r'meTo_$host:$port',\n")
  242. TEST.write(" RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],\n")
  243. TEST.write(" RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],\n")
  244. TEST.write(" RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],\n")
  245. TEST.write(" RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}\n")
  246. TEST.write(' m' + str(master_idx) + '_m' + str(idx) + '_agmt = master' + str(master_idx) +
  247. '.agreement.create(suffix=SUFFIX, host=master' +
  248. str(idx) + '.host, port=master' + str(idx) + '.port, properties=properties)\n')
  249. TEST.write(' if not m' + str(master_idx) + '_m' + str(idx) + '_agmt:\n')
  250. TEST.write(' log.fatal("Fail to create a master -> master replica agreement")\n')
  251. TEST.write(' sys.exit(1)\n')
  252. TEST.write(' log.debug("%s created" % m' + str(master_idx) + '_m' + str(idx) + '_agmt)\n\n')
  253. agmt_count += 1
  254. for idx in range(hubs):
  255. idx += 1
  256. #
  257. # Create agreements from each master to each hub (master -> hub)
  258. #
  259. TEST.write(' # Creating agreement from master ' + str(master_idx) + ' to hub ' + str(idx) + '\n')
  260. TEST.write(" properties = {RA_NAME: r'meTo_$host:$port',\n")
  261. TEST.write(" RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],\n")
  262. TEST.write(" RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],\n")
  263. TEST.write(" RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],\n")
  264. TEST.write(" RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}\n")
  265. TEST.write(' m' + str(master_idx) + '_h' + str(idx) + '_agmt = master' + str(master_idx) +
  266. '.agreement.create(suffix=SUFFIX, host=hub' +
  267. str(idx) + '.host, port=hub' + str(idx) + '.port, properties=properties)\n')
  268. TEST.write(' if not m' + str(master_idx) + '_h' + str(idx) + '_agmt:\n')
  269. TEST.write(' log.fatal("Fail to create a master -> hub replica agreement")\n')
  270. TEST.write(' sys.exit(1)\n')
  271. TEST.write(' log.debug("%s created" % m' + str(master_idx) + '_h' + str(idx) + '_agmt)\n\n')
  272. agmt_count += 1
  273. #
  274. # Create the hub agreements
  275. #
  276. for idx in range(hubs):
  277. hub_idx = idx + 1
  278. #
  279. # Add agreements from each hub to each consumer (hub -> consumer)
  280. #
  281. for idx in range(consumers):
  282. idx += 1
  283. #
  284. # Create agreements from each hub to each consumer
  285. #
  286. TEST.write(' # Creating agreement from hub ' + str(hub_idx) + ' to consumer ' + str(idx) + '\n')
  287. TEST.write(" properties = {RA_NAME: r'meTo_$host:$port',\n")
  288. TEST.write(" RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],\n")
  289. TEST.write(" RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],\n")
  290. TEST.write(" RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],\n")
  291. TEST.write(" RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}\n")
  292. TEST.write(' h' + str(hub_idx) + '_c' + str(idx) + '_agmt = hub' +
  293. str(hub_idx) + '.agreement.create(suffix=SUFFIX, host=consumer' +
  294. str(idx) + '.host, port=consumer' + str(idx) + '.port, properties=properties)\n')
  295. TEST.write(' if not h' + str(hub_idx) + '_c' + str(idx) + '_agmt:\n')
  296. TEST.write(' log.fatal("Fail to create a hub -> consumer replica agreement")\n')
  297. TEST.write(' sys.exit(1)\n')
  298. TEST.write(' log.debug("%s created" % h' + str(hub_idx) + '_c' + str(idx) + '_agmt)\n\n')
  299. agmt_count += 1
  300. if hubs == 0:
  301. #
  302. # No Hubs, see if there are any consumers to create agreements to...
  303. #
  304. for idx in range(masters):
  305. master_idx = idx + 1
  306. #
  307. # Create agreements with the consumers (master -> consumer)
  308. #
  309. for idx in range(consumers):
  310. idx += 1
  311. #
  312. # Create agreements from each master to each consumer
  313. #
  314. TEST.write(' # Creating agreement from master ' + str(master_idx) +
  315. ' to consumer ' + str(idx) + '\n')
  316. TEST.write(" properties = {RA_NAME: r'meTo_$host:$port',\n")
  317. TEST.write(" RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],\n")
  318. TEST.write(" RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],\n")
  319. TEST.write(" RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],\n")
  320. TEST.write(" RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}\n")
  321. TEST.write(' m' + str(master_idx) + '_c' + str(idx) + '_agmt = master' + str(master_idx) +
  322. '.agreement.create(suffix=SUFFIX, host=consumer' +
  323. str(idx) + '.host, port=consumer' + str(idx) +
  324. '.port, properties=properties)\n')
  325. TEST.write(' if not m' + str(master_idx) + '_c' + str(idx) + '_agmt:\n')
  326. TEST.write(' log.fatal("Fail to create a hub -> consumer replica agreement")\n')
  327. TEST.write(' sys.exit(1)\n')
  328. TEST.write(' log.debug("%s created" % m' + str(master_idx) + '_c' + str(idx) + '_agmt)\n\n')
  329. agmt_count += 1
  330. #
  331. # Add sleep that allows all the agreemnts to get situated
  332. #
  333. TEST.write(' # Allow the replicas to get situated with the new agreements...\n')
  334. TEST.write(' time.sleep(5)\n\n')
  335. #
  336. # Write the replication initializations
  337. #
  338. TEST.write(' #\n')
  339. TEST.write(' # Initialize all the agreements\n')
  340. TEST.write(' #\n')
  341. # Masters
  342. for idx in range(masters):
  343. idx += 1
  344. if idx == 1:
  345. continue
  346. TEST.write(' master1.agreement.init(SUFFIX, HOST_MASTER_' +
  347. str(idx) + ', PORT_MASTER_' + str(idx) + ')\n')
  348. TEST.write(' master1.waitForReplInit(m1_m' + str(idx) + '_agmt)\n')
  349. # Hubs
  350. consumers_inited = False
  351. for idx in range(hubs):
  352. idx += 1
  353. TEST.write(' master1.agreement.init(SUFFIX, HOST_HUB_' +
  354. str(idx) + ', PORT_HUB_' + str(idx) + ')\n')
  355. TEST.write(' master1.waitForReplInit(m1_h' + str(idx) + '_agmt)\n')
  356. for idx in range(consumers):
  357. if consumers_inited:
  358. continue
  359. idx += 1
  360. TEST.write(' hub1.agreement.init(SUFFIX, HOST_CONSUMER_' +
  361. str(idx) + ', PORT_CONSUMER_' + str(idx) + ')\n')
  362. TEST.write(' hub1.waitForReplInit(h1_c' + str(idx) + '_agmt)\n')
  363. consumers_inited = True
  364. # Consumers (master -> consumer)
  365. if hubs == 0:
  366. for idx in range(consumers):
  367. idx += 1
  368. TEST.write(' master1.agreement.init(SUFFIX, HOST_CONSUMER_' +
  369. str(idx) + ', PORT_CONSUMER_' + str(idx) + ')\n')
  370. TEST.write(' master1.waitForReplInit(m1_c' + str(idx) + '_agmt)\n')
  371. TEST.write('\n')
  372. #
  373. # Write replicaton check
  374. #
  375. if agmt_count > 0:
  376. # Find the lowest replica type in the deployment(consumer -> master)
  377. if consumers > 0:
  378. replica = 'consumer1'
  379. elif hubs > 0:
  380. replica = 'hub1'
  381. else:
  382. replica = 'master2'
  383. TEST.write(' # Check replication is working...\n')
  384. TEST.write(' if master1.testReplication(DEFAULT_SUFFIX, ' + replica + '):\n')
  385. TEST.write(" log.info('Replication is working.')\n")
  386. TEST.write(' else:\n')
  387. TEST.write(" log.fatal('Replication is not working.')\n")
  388. TEST.write(' assert False\n')
  389. TEST.write('\n')
  390. #
  391. # Write the finals steps for replication
  392. #
  393. TEST.write(' # Clear out the tmp dir\n')
  394. TEST.write(' master1.clearTmpDir(__file__)\n\n')
  395. TEST.write(' return TopologyReplication(master1')
  396. for idx in range(masters):
  397. idx += 1
  398. if idx == 1:
  399. continue
  400. TEST.write(', master' + str(idx))
  401. for idx in range(hubs):
  402. TEST.write(', hub' + str(idx + 1))
  403. for idx in range(consumers):
  404. TEST.write(', consumer' + str(idx + 1))
  405. TEST.write(')\n')
  406. else:
  407. #
  408. # Standalone servers
  409. #
  410. # Args for the standalone instance
  411. for idx in range(instances):
  412. idx += 1
  413. if idx == 1:
  414. idx = ''
  415. else:
  416. idx = str(idx)
  417. TEST.write(' # Creating standalone instance ' + idx + '...\n')
  418. TEST.write(' standalone' + idx + ' = DirSrv(verbose=False)\n')
  419. TEST.write(' args_instance[SER_HOST] = HOST_STANDALONE' + idx + '\n')
  420. TEST.write(' args_instance[SER_PORT] = PORT_STANDALONE' + idx + '\n')
  421. TEST.write(' args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE' + idx + '\n')
  422. TEST.write(' args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX\n')
  423. TEST.write(' args_standalone' + idx + ' = args_instance.copy()\n')
  424. TEST.write(' standalone' + idx + '.allocate(args_standalone' + idx + ')\n')
  425. # Get the status of the instance and restart it if it exists
  426. TEST.write(' instance_standalone' + idx + ' = standalone' + idx + '.exists()\n')
  427. # Remove the instance
  428. TEST.write(' if instance_standalone' + idx + ':\n')
  429. TEST.write(' standalone' + idx + '.delete()\n')
  430. # Create and open the instance
  431. TEST.write(' standalone' + idx + '.create()\n')
  432. TEST.write(' standalone' + idx + '.open()\n\n')
  433. TEST.write(' # Clear out the tmp dir\n')
  434. TEST.write(' standalone.clearTmpDir(__file__)\n')
  435. TEST.write('\n')
  436. TEST.write(' return TopologyStandalone(standalone')
  437. for idx in range(instances):
  438. idx += 1
  439. if idx == 1:
  440. continue
  441. TEST.write(', standalone' + str(idx))
  442. TEST.write(')\n')
  443. TEST.write('\n\n')
  444. #
  445. # Write the test function
  446. #
  447. if ticket:
  448. TEST.write('def test_ticket' + ticket + '(topology):\n')
  449. TEST.write(" '''\n")
  450. if repl_deployment:
  451. TEST.write(' Write your replication testcase here.\n\n')
  452. TEST.write(' To access each DirSrv instance use: topology.master1, topology.master2,\n' +
  453. ' ..., topology.hub1, ..., topology.consumer1, ...\n')
  454. else:
  455. TEST.write(' Write your testcase here...\n')
  456. TEST.write(" '''\n\n")
  457. TEST.write(" log.info('Test complete')\n")
  458. TEST.write("\n\n")
  459. else:
  460. # For suite we start with an init function
  461. TEST.write('def test_' + suite + '_init(topology):\n')
  462. TEST.write(" '''\n")
  463. TEST.write(' Write any test suite initialization here(if needed)\n')
  464. TEST.write(" '''\n\n return\n\n\n")
  465. # Write the first initial empty test function
  466. TEST.write('def test_' + suite + '_#####(topology):\n')
  467. TEST.write(" '''\n")
  468. TEST.write(' Write a single test here...\n')
  469. TEST.write(" '''\n\n return\n\n\n")
  470. #
  471. # Write the final function here - delete each instance
  472. #
  473. if ticket:
  474. TEST.write('def test_ticket' + ticket + '_final(topology):\n')
  475. else:
  476. # suite
  477. TEST.write('def test_' + suite + '_final(topology):\n')
  478. if repl_deployment:
  479. for idx in range(masters):
  480. idx += 1
  481. TEST.write(' topology.master' + str(idx) + '.delete()\n')
  482. for idx in range(hubs):
  483. idx += 1
  484. TEST.write(' topology.hub' + str(idx) + '.delete()\n')
  485. for idx in range(consumers):
  486. idx += 1
  487. TEST.write(' topology.consumer' + str(idx) + '.delete()\n')
  488. else:
  489. for idx in range(instances):
  490. idx += 1
  491. if idx == 1:
  492. idx = ''
  493. else:
  494. idx = str(idx)
  495. TEST.write(' topology.standalone' + idx + '.delete()\n')
  496. if ticket:
  497. TEST.write(" log.info('Testcase PASSED')\n")
  498. else:
  499. # suite
  500. TEST.write(" log.info('" + suite + " test suite PASSED')\n")
  501. TEST.write('\n\n')
  502. #
  503. # Write the main function
  504. #
  505. TEST.write('def run_isolated():\n')
  506. TEST.write(' global installation1_prefix\n')
  507. TEST.write(' installation1_prefix = None\n\n')
  508. TEST.write(' topo = topology(True)\n')
  509. if ticket:
  510. TEST.write(' test_ticket' + ticket + '(topo)\n')
  511. TEST.write(' test_ticket' + ticket + '_final(topo)\n')
  512. else:
  513. # suite
  514. TEST.write(' test_' + suite + '_init(topo)\n')
  515. TEST.write(' test_' + suite + '_#####(topo)\n')
  516. TEST.write(' test_' + suite + '_final(topo)\n')
  517. TEST.write('\n\n')
  518. TEST.write("if __name__ == '__main__':\n")
  519. TEST.write(' run_isolated()\n\n')
  520. #
  521. # Done, close things up
  522. #
  523. TEST.close()
  524. print('Created: ' + filename)