create_testcase.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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. # Find the lowest replica type in the deployment(consumer -> master)
  360. if consumers > 0:
  361. replica = 'consumer1'
  362. elif hubs > 0:
  363. replica = 'hub1'
  364. else:
  365. replica = 'master2'
  366. TEST.write(' # Check replication is working...\n')
  367. TEST.write(' if master1.testReplication(DEFAULT_SUFFIX, ' + replica + '):\n')
  368. TEST.write(" log.info('Replication is working.')\n")
  369. TEST.write(' else:\n')
  370. TEST.write(" log.fatal('Replication is not working.')\n")
  371. TEST.write(' assert False\n')
  372. TEST.write('\n')
  373. #
  374. # Write the finals steps for replication
  375. #
  376. TEST.write(' # Clear out the tmp dir\n')
  377. TEST.write(' master1.clearTmpDir(__file__)\n\n')
  378. TEST.write(' return TopologyReplication(master1')
  379. for idx in range(masters):
  380. idx += 1
  381. if idx == 1:
  382. continue
  383. TEST.write(', master' + str(idx))
  384. for idx in range(hubs):
  385. TEST.write(', hub' + str(idx + 1))
  386. for idx in range(consumers):
  387. TEST.write(', consumer' + str(idx + 1))
  388. TEST.write(')\n')
  389. else:
  390. #
  391. # Standalone servers
  392. #
  393. # Args for the standalone instance
  394. for idx in range(instances):
  395. idx += 1
  396. if idx == 1:
  397. idx = ''
  398. else:
  399. idx = str(idx)
  400. TEST.write(' # Creating standalone instance ' + idx + '...\n')
  401. TEST.write(' standalone' + idx + ' = DirSrv(verbose=False)\n')
  402. TEST.write(' args_instance[SER_HOST] = HOST_STANDALONE' + idx + '\n')
  403. TEST.write(' args_instance[SER_PORT] = PORT_STANDALONE' + idx + '\n')
  404. TEST.write(' args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE' + idx + '\n')
  405. TEST.write(' args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX\n')
  406. TEST.write(' args_standalone' + idx + ' = args_instance.copy()\n')
  407. TEST.write(' standalone' + idx + '.allocate(args_standalone' + idx + ')\n')
  408. # Get the status of the instance and restart it if it exists
  409. TEST.write(' instance_standalone' + idx + ' = standalone' + idx + '.exists()\n')
  410. # Remove the instance
  411. TEST.write(' if instance_standalone' + idx + ':\n')
  412. TEST.write(' standalone' + idx + '.delete()\n')
  413. # Create and open the instance
  414. TEST.write(' standalone' + idx + '.create()\n')
  415. TEST.write(' standalone' + idx + '.open()\n\n')
  416. TEST.write(' # Clear out the tmp dir\n')
  417. TEST.write(' standalone.clearTmpDir(__file__)\n')
  418. TEST.write('\n')
  419. TEST.write(' return TopologyStandalone(standalone')
  420. for idx in range(instances):
  421. idx += 1
  422. if idx == 1:
  423. continue
  424. TEST.write(', standalone' + str(idx))
  425. TEST.write(')\n')
  426. TEST.write('\n\n')
  427. #
  428. # Write the test function
  429. #
  430. TEST.write('def test_ticket' + ticket + '(topology):\n')
  431. TEST.write(" '''\n")
  432. if repl_deployment:
  433. TEST.write(' Write your replication testcase here.\n\n')
  434. TEST.write(' To access each DirSrv instance use: topology.master1, topology.master2,\n' +
  435. ' ..., topology.hub1, ..., topology.consumer1, ...\n')
  436. else:
  437. TEST.write(' Write your testcase here...\n')
  438. TEST.write(" '''\n\n")
  439. TEST.write(" log.info('Test complete')\n")
  440. TEST.write("\n\n")
  441. #
  442. # Write the final function here - delete each instance
  443. #
  444. TEST.write('def test_ticket' + ticket + '_final(topology):\n')
  445. if repl_deployment:
  446. for idx in range(masters):
  447. idx += 1
  448. TEST.write(' topology.master' + str(idx) + '.delete()\n')
  449. for idx in range(hubs):
  450. idx += 1
  451. TEST.write(' topology.hub' + str(idx) + '.delete()\n')
  452. for idx in range(consumers):
  453. idx += 1
  454. TEST.write(' topology.consumer' + str(idx) + '.delete()\n')
  455. else:
  456. for idx in range(instances):
  457. idx += 1
  458. if idx == 1:
  459. idx = ''
  460. else:
  461. idx = str(idx)
  462. TEST.write(' topology.standalone' + idx + '.delete()\n')
  463. TEST.write(" log.info('Testcase PASSED')\n")
  464. TEST.write('\n\n')
  465. #
  466. # Write the main function
  467. #
  468. TEST.write('def run_isolated():\n')
  469. TEST.write(' global installation1_prefix\n')
  470. TEST.write(' installation1_prefix = None\n\n')
  471. TEST.write(' topo = topology(True)\n')
  472. TEST.write(' test_ticket' + ticket + '(topo)\n')
  473. TEST.write(' test_ticket' + ticket + '_final(topo)\n')
  474. TEST.write('\n\n')
  475. TEST.write("if __name__ == '__main__':\n")
  476. TEST.write(' run_isolated()\n\n')
  477. #
  478. # Done, close things up
  479. #
  480. TEST.close()
  481. print('Created: ' + filename)