On 06/18/2011 02:31 PM, Nan Zhang wrote:
To support test cases loop in config, adding a pair of keywords "start_loop", "end_loop" follows loop times. For example: ----------------- domain:start guestname vm1 domain:save start_loop guestname vm1 domain:restore end_loop 10 guestname vm1 domain:destroy guestname vm1 ----------------- --- parser.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 46 insertions(+), 1 deletions(-) diff --git a/parser.py b/parser.py index 5b3ce58..8d41776 100644 --- a/parser.py +++ b/parser.py @@ -31,13 +31,18 @@ class CaseFileParser(object): """ Parser the case configuration file to generate a data list. """ def __init__(self, casefile=None, debug=False): - """ Initialize the list and optionally parse case file. """ self.list = [[]] self.variables = {} self.missing_variables = [] self.debug = debug self.casefile = casefile self.env = env_parser.Envparser("env.cfg") + self.loop_finish = False + self.loop_start = 0 + self.loop_end = 0 + self.loop_times = 0 + self.loop_list = [] + if casefile: self.parse_file(casefile) @@ -306,6 +311,7 @@ class CaseFileParser(object): def parse(self, fh, list): """ For the testcase name parsing. """ + while True: if self.debug: self.debug_print("the list is", list) @@ -330,6 +336,45 @@ class CaseFileParser(object): self.debug_print("we begin to handle the case", tripped_casename) + if self.loop_finish: + for i in range(len(list)): + self.loop_list.append([]) + + i = 0 + for caselist in list: + for j in range(self.loop_start, self.loop_end): + self.loop_list[i].append(caselist.pop()) + + self.loop_list[i].reverse() + self.debug_print("loop_list is", self.loop_list) + caselist.extend(self.loop_list[i] * self.loop_times) + i += 1 + + self.loop_finish = False + self.loop_list = [] + + if len(tripped_caselist) == 2 and \ + tripped_caselist[1] == "start_loop": + for caselist in list: + newdict = {} + newdict[tripped_casename] = {} + caselist.append(newdict) + self.loop_start = len(caselist) - 1 + continue + + if len(tripped_caselist) == 3 and \ + tripped_caselist[1] == "end_loop": + looptimes = tripped_caselist[2] + self.debug_print("looptimes is", looptimes) + self.loop_times = int(looptimes) + self.loop_finish = True + for caselist in list: + newdict = {} + newdict[tripped_casename] = {} + caselist.append(newdict) + self.loop_end = len(caselist) + continue + if len(tripped_caselist) == 3 and \ tripped_caselist[1] == "times": times = tripped_caselist[2]
ACK Guannan Ren -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list