create_testcase.py 24 KB

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