create_testcase.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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 ldap.sasl\n' +
  86. 'import logging\nimport socket\nimport pytest\n')
  87. TEST.write('from lib389 import DirSrv, Entry, tools, tasks\nfrom lib389.tools import DirSrvTools\n' +
  88. 'from lib389._constants import *\nfrom lib389.properties import *\nfrom lib389.tasks import *\n\n')
  89. #
  90. # Set the logger and installation prefix
  91. #
  92. TEST.write('logging.getLogger(__name__).setLevel(logging.DEBUG)\n')
  93. TEST.write('log = logging.getLogger(__name__)\n\n')
  94. TEST.write('installation1_prefix = None\n\n\n')
  95. #
  96. # Write the replication or standalone classes
  97. #
  98. repl_deployment = False
  99. if masters + hubs + consumers > 0:
  100. #
  101. # Write the replication class
  102. #
  103. repl_deployment = True
  104. TEST.write('class TopologyReplication(object):\n')
  105. TEST.write(' def __init__(self')
  106. for idx in range(masters):
  107. TEST.write(', master' + str(idx + 1))
  108. for idx in range(hubs):
  109. TEST.write(', hub' + str(idx + 1))
  110. for idx in range(consumers):
  111. TEST.write(', consumer' + str(idx + 1))
  112. TEST.write('):\n')
  113. for idx in range(masters):
  114. TEST.write(' master' + str(idx + 1) + '.open()\n')
  115. TEST.write(' self.master' + str(idx + 1) + ' = master' + str(idx + 1) + '\n')
  116. for idx in range(hubs):
  117. TEST.write(' hub' + str(idx + 1) + '.open()\n')
  118. TEST.write(' self.hub' + str(idx + 1) + ' = hub' + str(idx + 1) + '\n')
  119. for idx in range(consumers):
  120. TEST.write(' consumer' + str(idx + 1) + '.open()\n')
  121. TEST.write(' self.consumer' + str(idx + 1) + ' = consumer' + str(idx + 1) + '\n')
  122. TEST.write('\n\n')
  123. else:
  124. #
  125. # Write the standalone class
  126. #
  127. TEST.write('class TopologyStandalone(object):\n')
  128. TEST.write(' def __init__(self')
  129. for idx in range(instances):
  130. idx += 1
  131. if idx == 1:
  132. idx = ''
  133. else:
  134. idx = str(idx)
  135. TEST.write(', standalone' + idx)
  136. TEST.write('):\n')
  137. for idx in range(instances):
  138. idx += 1
  139. if idx == 1:
  140. idx = ''
  141. else:
  142. idx = str(idx)
  143. TEST.write(' standalone' + idx + '.open()\n')
  144. TEST.write(' self.standalone' + idx + ' = standalone' + idx + '\n')
  145. TEST.write('\n\n')
  146. #
  147. # Write the 'topology function'
  148. #
  149. TEST.write('@pytest.fixture(scope="module")\n')
  150. TEST.write('def topology(request): \n')
  151. TEST.write(' global installation1_prefix\n')
  152. TEST.write(' if installation1_prefix:\n')
  153. TEST.write(' args_instance[SER_DEPLOYED_DIR] = installation1_prefix\n\n')
  154. if repl_deployment:
  155. #
  156. # Create the replication instances
  157. #
  158. for idx in range(masters):
  159. idx = str(idx + 1)
  160. TEST.write(' # Creating master ' + idx + '...\n')
  161. TEST.write(' master' + idx + ' = DirSrv(verbose=False)\n')
  162. TEST.write(' args_instance[SER_HOST] = HOST_MASTER_' + idx + '\n')
  163. TEST.write(' args_instance[SER_PORT] = PORT_MASTER_' + idx + '\n')
  164. TEST.write(' args_instance[SER_SERVERID_PROP] = SERVERID_MASTER_' + idx + '\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_hub = args_instance.copy()\n')
  183. TEST.write(' hub' + idx + '.allocate(args_hub)\n')
  184. TEST.write(' instance_hub' + idx + ' = hub' + idx + '.exists()\n')
  185. TEST.write(' if instance_hub' + idx + ':\n')
  186. TEST.write(' hub' + idx + '.delete()\n')
  187. TEST.write(' hub' + idx + '.create()\n')
  188. TEST.write(' hub' + idx + '.open()\n')
  189. TEST.write(' hub' + idx + '.replica.enableReplication(suffix=SUFFIX, ' +
  190. 'role=REPLICAROLE_HUB, ' +
  191. 'replicaId=REPLICAID_HUB_' + idx + ')\n\n')
  192. for idx in range(consumers):
  193. idx = str(idx + 1)
  194. TEST.write(' # Creating consumer ' + idx + '...\n')
  195. TEST.write(' consumer' + idx + ' = DirSrv(verbose=False)\n')
  196. TEST.write(' args_instance[SER_HOST] = HOST_CONSUMER_' + idx + '\n')
  197. TEST.write(' args_instance[SER_PORT] = PORT_CONSUMER_' + idx + '\n')
  198. TEST.write(' args_instance[SER_SERVERID_PROP] = SERVERID_CONSUMER_' + idx + '\n')
  199. TEST.write(' args_consumer = args_instance.copy()\n')
  200. TEST.write(' consumer' + idx + '.allocate(args_consumer)\n')
  201. TEST.write(' instance_consumer' + idx + ' = consumer' + idx + '.exists()\n')
  202. TEST.write(' if instance_consumer' + idx + ':\n')
  203. TEST.write(' consumer' + idx + '.delete()\n')
  204. TEST.write(' consumer' + idx + '.create()\n')
  205. TEST.write(' consumer' + idx + '.open()\n')
  206. TEST.write(' consumer' + idx + '.replica.enableReplication(suffix=SUFFIX, ' +
  207. 'role=REPLICAROLE_CONSUMER, ' +
  208. 'replicaId=CONSUMER_REPLICAID)\n\n')
  209. #
  210. # Create the master agreements
  211. #
  212. TEST.write(' #\n')
  213. TEST.write(' # Create all the agreements\n')
  214. TEST.write(' #\n')
  215. agmt_count = 0
  216. for idx in range(masters):
  217. master_idx = idx + 1
  218. for idx in range(masters):
  219. #
  220. # Create agreements with the other masters (master -> master)
  221. #
  222. idx += 1
  223. if master_idx == idx:
  224. # skip ourselves
  225. continue
  226. TEST.write(' # Creating agreement from master ' + str(master_idx) + ' to master ' + str(idx) + '\n')
  227. TEST.write(" properties = {RA_NAME: r'meTo_$host:$port',\n")
  228. TEST.write(" RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],\n")
  229. TEST.write(" RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],\n")
  230. TEST.write(" RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],\n")
  231. TEST.write(" RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}\n")
  232. TEST.write(' m' + str(idx) + '_agmt = master' + str(master_idx) +
  233. '.agreement.create(suffix=SUFFIX, host=master' +
  234. str(idx) + '.host, port=master' + str(idx) + '.port, properties=properties)\n')
  235. TEST.write(' if not m' + str(idx) + '_agmt:\n')
  236. TEST.write(' log.fatal("Fail to create a master -> master replica agreement")\n')
  237. TEST.write(' sys.exit(1)\n')
  238. TEST.write(' log.debug("%s created" % m' + str(idx) + '_agmt)\n\n')
  239. agmt_count += 1
  240. for idx in range(hubs):
  241. idx += 1
  242. #
  243. # Create agreements from each master to each hub (master -> hub)
  244. #
  245. TEST.write(' # Creating agreement from master ' + str(master_idx) + ' to hub ' + str(idx) + '\n')
  246. TEST.write(" properties = {RA_NAME: r'meTo_$host:$port',\n")
  247. TEST.write(" RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],\n")
  248. TEST.write(" RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],\n")
  249. TEST.write(" RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],\n")
  250. TEST.write(" RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}\n")
  251. TEST.write(' h' + str(idx) + '_agmt = master' + str(master_idx) +
  252. '.agreement.create(suffix=SUFFIX, host=hub' +
  253. str(idx) + '.host, port=hub' + str(idx) + '.port, properties=properties)\n')
  254. TEST.write(' if not h' + str(idx) + '_agmt:\n')
  255. TEST.write(' log.fatal("Fail to create a master -> hub replica agreement")\n')
  256. TEST.write(' sys.exit(1)\n')
  257. TEST.write(' log.debug("%s created" % h' + str(idx) + '_agmt)\n\n')
  258. agmt_count += 1
  259. #
  260. # Create the hub agreements
  261. #
  262. for idx in range(hubs):
  263. hub_idx = idx + 1
  264. #
  265. # Add agreements from each hub to each consumer (hub -> consumer)
  266. #
  267. for idx in range(consumers):
  268. idx += 1
  269. #
  270. # Create agreements from each hub to each consumer
  271. #
  272. TEST.write(' # Creating agreement from hub ' + str(hub_idx) + ' to consumer ' + str(idx) + '\n')
  273. TEST.write(" properties = {RA_NAME: r'meTo_$host:$port',\n")
  274. TEST.write(" RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],\n")
  275. TEST.write(" RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],\n")
  276. TEST.write(" RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],\n")
  277. TEST.write(" RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}\n")
  278. TEST.write(' c' + str(idx) + '_agmt = hub' +
  279. str(hub_idx) + '.agreement.create(suffix=SUFFIX, host=consumer' +
  280. str(idx) + '.host, port=consumer' + str(idx) + '.port, properties=properties)\n')
  281. TEST.write(' if not c' + str(idx) + '_agmt:\n')
  282. TEST.write(' log.fatal("Fail to create a hub -> consumer replica agreement")\n')
  283. TEST.write(' sys.exit(1)\n')
  284. TEST.write(' log.debug("%s created" % c' + str(idx) + '_agmt)\n\n')
  285. agmt_count += 1
  286. if hubs == 0:
  287. #
  288. # No Hubs, see if there are any consumers to create agreements to...
  289. #
  290. for idx in range(masters):
  291. master_idx = idx + 1
  292. #
  293. # Create agreements with the consumers (master -> consumer)
  294. #
  295. for idx in range(consumers):
  296. idx += 1
  297. #
  298. # Create agreements from each master to each consumer
  299. #
  300. TEST.write(' # Creating agreement fro master ' + str(master_idx) +
  301. ' to consumer ' + str(idx) + '\n')
  302. TEST.write(" properties = {RA_NAME: r'meTo_$host:$port',\n")
  303. TEST.write(" RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],\n")
  304. TEST.write(" RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],\n")
  305. TEST.write(" RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],\n")
  306. TEST.write(" RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}\n")
  307. TEST.write(' c' + str(idx) + '_agmt = master' + str(master_idx) +
  308. '.agreement.create(suffix=SUFFIX, host=consumer' +
  309. str(idx) + '.host, port=consumer' + str(idx) +
  310. '.port, properties=properties)\n')
  311. TEST.write(' if not c' + str(idx) + '_agmt:\n')
  312. TEST.write(' log.fatal("Fail to create a hub -> consumer replica agreement")\n')
  313. TEST.write(' sys.exit(1)\n')
  314. TEST.write(' log.debug("%s created" % c' + str(idx) + '_agmt)\n\n')
  315. agmt_count += 1
  316. #
  317. # Write the replication initializations
  318. #
  319. TEST.write(' #\n')
  320. TEST.write(' # Initialize all the agreements\n')
  321. TEST.write(' #\n')
  322. # Masters
  323. for idx in range(masters):
  324. idx += 1
  325. if idx == 1:
  326. continue
  327. TEST.write(' master1.agreement.init(SUFFIX, HOST_MASTER_' +
  328. str(idx) + ', PORT_MASTER_' + str(idx) + ')\n')
  329. TEST.write(' master1.waitForReplInit(m' + str(idx) + '_agmt)\n')
  330. # Hubs
  331. consumers_inited = False
  332. for idx in range(hubs):
  333. idx += 1
  334. TEST.write(' master1.agreement.init(SUFFIX, HOST_HUB_' +
  335. str(idx) + ', PORT_HUB_' + str(idx) + ')\n')
  336. TEST.write(' master1.waitForReplInit(h' + str(idx) + '_agmt)\n')
  337. for idx in range(consumers):
  338. if consumers_inited:
  339. continue
  340. idx += 1
  341. TEST.write(' hub1.agreement.init(SUFFIX, HOST_CONSUMER_' +
  342. str(idx) + ', PORT_CONSUMER_' + str(idx) + ')\n')
  343. TEST.write(' hub1.waitForReplInit(c' + str(idx) + '_agmt)\n')
  344. consumers_inited = True
  345. # Consumers (master -> consumer)
  346. if hubs == 0:
  347. for idx in range(consumers):
  348. idx += 1
  349. TEST.write(' master1.agreement.init(SUFFIX, HOST_CONSUMER_' +
  350. str(idx) + ', PORT_CONSUMER_' + str(idx) + ')\n')
  351. TEST.write(' master1.waitForReplInit(c' + str(idx) + '_agmt)\n')
  352. TEST.write('\n')
  353. #
  354. # Write replicaton check
  355. #
  356. if agmt_count > 0:
  357. TEST.write(' #\n')
  358. TEST.write(' # Check replication is working...\n')
  359. TEST.write(' #\n')
  360. TEST.write(" REPL_TEST_DN = 'cn=test repl,' + SUFFIX\n")
  361. TEST.write(' master1.add_s(Entry((REPL_TEST_DN, {\n')
  362. TEST.write(" 'objectclass': 'top person'.split(),\n")
  363. TEST.write(" 'sn': 'test_repl',\n")
  364. TEST.write(" 'cn': 'test_repl'})))\n")
  365. TEST.write(' loop = 0\n')
  366. TEST.write(' ent = None\n')
  367. # Find the lowest replica type in the deployment(consumer -> master)
  368. if consumers > 0:
  369. replica = 'consumer1'
  370. elif hubs > 0:
  371. replica = 'hub1'
  372. else:
  373. replica = 'master2'
  374. TEST.write(' while loop <= 10:\n')
  375. TEST.write(' try:\n')
  376. TEST.write(' ent = ' + replica + '.getEntry(REPL_TEST_DN, ldap.SCOPE_BASE, "(objectclass=*)")\n')
  377. TEST.write(' break\n')
  378. TEST.write(' except ldap.NO_SUCH_OBJECT:\n')
  379. TEST.write(' time.sleep(1)\n')
  380. TEST.write(' loop += 1\n')
  381. TEST.write(' if ent is None:\n')
  382. TEST.write(' assert False\n')
  383. TEST.write('\n')
  384. #
  385. # Write the finals steps for replication
  386. #
  387. TEST.write(' # Clear out the tmp dir\n')
  388. TEST.write(' master1.clearTmpDir(__file__)\n\n')
  389. TEST.write(' return TopologyReplication(master1')
  390. for idx in range(masters):
  391. idx += 1
  392. if idx == 1:
  393. continue
  394. TEST.write(', master' + str(idx))
  395. for idx in range(hubs):
  396. TEST.write(', hub' + str(idx + 1))
  397. for idx in range(consumers):
  398. TEST.write(', consumer' + str(idx + 1))
  399. TEST.write(')\n')
  400. else:
  401. #
  402. # Standalone servers
  403. #
  404. # Args for the standalone instance
  405. for idx in range(instances):
  406. idx += 1
  407. if idx == 1:
  408. idx = ''
  409. else:
  410. idx = str(idx)
  411. TEST.write(' # Creating standalone instance ' + idx + '...\n')
  412. TEST.write(' standalone' + idx + ' = DirSrv(verbose=False)\n')
  413. TEST.write(' args_instance[SER_HOST] = HOST_STANDALONE' + idx + '\n')
  414. TEST.write(' args_instance[SER_PORT] = PORT_STANDALONE' + idx + '\n')
  415. TEST.write(' args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE' + idx + '\n')
  416. TEST.write(' args_standalone' + idx + ' = args_instance.copy()\n')
  417. TEST.write(' standalone' + idx + '.allocate(args_standalone' + idx + ')\n')
  418. # Get the status of the instance and restart it if it exists
  419. TEST.write(' instance_standalone' + idx + ' = standalone' + idx + '.exists()\n')
  420. # Remove the instance
  421. TEST.write(' if instance_standalone' + idx + ':\n')
  422. TEST.write(' standalone' + idx + '.delete()\n')
  423. # Create and open the instance
  424. TEST.write(' standalone' + idx + '.create()\n')
  425. TEST.write(' standalone' + idx + '.open()\n\n')
  426. TEST.write(' # Clear out the tmp dir\n')
  427. TEST.write(' standalone.clearTmpDir(__file__)\n')
  428. TEST.write('\n')
  429. TEST.write(' return TopologyStandalone(standalone')
  430. for idx in range(instances):
  431. idx += 1
  432. if idx == 1:
  433. continue
  434. TEST.write(', standalone' + str(idx))
  435. TEST.write(')\n')
  436. TEST.write('\n\n')
  437. #
  438. # Write the test function
  439. #
  440. TEST.write('def test_ticket' + ticket + '(topology):\n')
  441. TEST.write(" '''\n")
  442. if repl_deployment:
  443. TEST.write(' Write your replication testcase here.\n\n')
  444. TEST.write(' To access each DirSrv instance use: topology.master1, topology.master2,\n' +
  445. ' ..., topology.hub1, ..., topology.consumer1, ...\n')
  446. else:
  447. TEST.write(' Write your testcase here...\n')
  448. TEST.write(" '''\n\n")
  449. TEST.write(" log.info('Test complete')\n")
  450. TEST.write("\n\n")
  451. #
  452. # Write the final function here - delete each instance
  453. #
  454. TEST.write('def test_ticket' + ticket + '_final(topology):\n')
  455. if repl_deployment:
  456. for idx in range(masters):
  457. idx += 1
  458. TEST.write(' topology.master' + str(idx) + '.delete()\n')
  459. for idx in range(hubs):
  460. idx += 1
  461. TEST.write(' topology.hub' + str(idx) + '.delete()\n')
  462. for idx in range(consumers):
  463. idx += 1
  464. TEST.write(' topology.consumer' + str(idx) + '.delete()\n')
  465. TEST.write('\n\n')
  466. else:
  467. for idx in range(instances):
  468. idx += 1
  469. if idx == 1:
  470. idx = ''
  471. else:
  472. idx = str(idx)
  473. TEST.write(' topology.standalone' + idx + '.delete()\n')
  474. TEST.write('\n\n')
  475. TEST.write(" log.info('Testcase PASSED')\n")
  476. #
  477. # Write the main function
  478. #
  479. TEST.write('def run_isolated():\n')
  480. TEST.write(' global installation1_prefix\n')
  481. TEST.write(' installation1_prefix = None\n\n')
  482. TEST.write(' topo = topology(True)\n')
  483. TEST.write(' test_ticket' + ticket + '(topo)\n')
  484. TEST.write(' test_ticket' + ticket + '_final(topo)\n')
  485. TEST.write('\n\n')
  486. TEST.write("if __name__ == '__main__':\n")
  487. TEST.write(' run_isolated()\n\n')
  488. #
  489. # Done, close things up
  490. #
  491. TEST.close()
  492. print('Created: ' + filename)