blob: f2368b690ca42216b3af0ab4c1888827261824f1 [file] [log] [blame]
George Keishinge7e91712021-09-03 11:28:44 -05001#!/usr/bin/env python3
George Keishing04d93452017-05-03 09:14:15 -05002
3r"""
4This module contains keyword functions to supplement robot's built in
5functions and use in test where generic robot keywords don't support.
George Keishing04d93452017-05-03 09:14:15 -05006"""
Steven Sombar130a04f2017-07-16 10:02:37 -05007
8try:
9 from robot.libraries.BuiltIn import BuiltIn
10 from robot.libraries import DateTime
11except ImportError:
12 pass
George Keishing04d93452017-05-03 09:14:15 -050013import time
Steven Sombar130a04f2017-07-16 10:02:37 -050014import os
Steven Sombar130a04f2017-07-16 10:02:37 -050015
16
Steven Sombar130a04f2017-07-16 10:02:37 -050017def run_until_keyword_fails(retry,
18 retry_interval,
19 name,
20 *args):
George Keishing04d93452017-05-03 09:14:15 -050021 r"""
22 Execute a robot keyword repeatedly until it either fails or the timeout
23 value is exceeded.
24 Note: Opposite of robot keyword "Wait Until Keyword Succeeds".
25
26 Description of argument(s):
27 retry Max timeout time in hour(s).
28 retry_interval Time interval in minute(s) for looping.
29 name Robot keyword to execute.
30 args Robot keyword arguments.
31 """
32
33 # Convert the retry time in seconds
George Keishing4bbf5202017-05-18 06:55:53 -050034 retry_seconds = DateTime.convert_time(retry)
George Keishing04d93452017-05-03 09:14:15 -050035 timeout = time.time() + int(retry_seconds)
36
37 # Convert the interval time in seconds
George Keishing4bbf5202017-05-18 06:55:53 -050038 interval_seconds = DateTime.convert_time(retry_interval)
George Keishing04d93452017-05-03 09:14:15 -050039 interval = int(interval_seconds)
40
41 BuiltIn().log(timeout)
42 BuiltIn().log(interval)
43
44 while True:
George Keishing4bbf5202017-05-18 06:55:53 -050045 status = BuiltIn().run_keyword_and_return_status(name, *args)
George Keishing04d93452017-05-03 09:14:15 -050046
47 # Return if keywords returns as failure.
George Keishing4bbf5202017-05-18 06:55:53 -050048 if status is False:
George Keishing04d93452017-05-03 09:14:15 -050049 BuiltIn().log("Failed as expected")
George Keishing4bbf5202017-05-18 06:55:53 -050050 return False
George Keishing04d93452017-05-03 09:14:15 -050051 # Return if retry timeout as success.
52 elif time.time() > timeout > 0:
53 BuiltIn().log("Max retry timeout")
George Keishing4bbf5202017-05-18 06:55:53 -050054 return True
George Keishing04d93452017-05-03 09:14:15 -050055 time.sleep(interval)
56 BuiltIn().log(time.time())
57
George Keishing4bbf5202017-05-18 06:55:53 -050058 return True
George Keishing4bbf5202017-05-18 06:55:53 -050059
60
George Keishing4bbf5202017-05-18 06:55:53 -050061def htx_error_log_to_list(htx_error_log_output):
George Keishing4bbf5202017-05-18 06:55:53 -050062 r"""
63 Parse htx error log output string and return list of strings in the form
64 "<field name>:<field value>".
65 The output of this function may be passed to the build_error_dict function.
66
67 Description of argument(s):
68 htx_error_log_output Error entry string containing the stdout
69 generated by "htxcmdline -geterrlog".
70
71 Example of htx_error_log_output contents:
72
73 ######################## Result Starts Here ###############################
74 Currently running ECG/MDT : /usr/lpp/htx/mdt/mdt.whit
75 ===========================
76 ---------------------------------------------------------------------
77 Device id:/dev/nvidia0
78 Timestamp:Mar 29 19:41:54 2017
79 err=00000027
80 sev=1
81 Exerciser Name:hxenvidia
82 Serial No:Not Available
83 Part No:Not Available
84 Location:Not Available
85 FRU Number:Not Available
86 Device:Not Available
87 Error Text:cudaEventSynchronize for stopEvent returned err = 0039 from file
88 , line 430.
89 ---------------------------------------------------------------------
90 ---------------------------------------------------------------------
91 Device id:/dev/nvidia0
92 Timestamp:Mar 29 19:41:54 2017
93 err=00000027
94 sev=1
95 Exerciser Name:hxenvidia
96 Serial No:Not Available
97 Part No:Not Available
98 Location:Not Available
99 FRU Number:Not Available
100 Device:Not Available
101 Error Text:Hardware Exerciser stopped on error
102 ---------------------------------------------------------------------
103 ######################### Result Ends Here ################################
104
105 Example output:
106 Returns the lists of error string per entry
107 ['Device id:/dev/nvidia0',
108 'Timestamp:Mar 29 19:41:54 2017',
109 'err=00000027',
110 'sev=1',
111 'Exerciser Name:hxenvidia',
112 'Serial No:Not Available',
113 'Part No:Not Available',
114 'Location:Not Available',
115 'FRU Number:Not Available',
116 'Device:Not Available',
117 'Error Text:cudaEventSynchronize for stopEvent returned err = 0039
118 from file , line 430.']
119 """
120
121 # List which will hold all the list of entries.
122 error_list = []
123
124 temp_error_list = []
125 parse_walk = False
126
127 for line in htx_error_log_output.splitlines():
128 # Skip lines starting with "#"
129 if line.startswith("#"):
130 continue
131
132 # Mark line starting with "-" and set parse flag.
133 if line.startswith("-") and parse_walk is False:
134 parse_walk = True
135 continue
136 # Mark line starting with "-" and reset parse flag.
137 # Set temp error list to EMPTY.
138 elif line.startswith("-"):
139 error_list.append(temp_error_list)
140 parse_walk = False
141 temp_error_list = []
Gunnar Mills917ba1a2018-04-08 16:42:12 -0500142 # Add entry to list if line is not empty
George Keishing4bbf5202017-05-18 06:55:53 -0500143 elif parse_walk:
144 temp_error_list.append(str(line))
145
146 return error_list
George Keishing4bbf5202017-05-18 06:55:53 -0500147
148
George Keishing4bbf5202017-05-18 06:55:53 -0500149def build_error_dict(htx_error_log_output):
George Keishing4bbf5202017-05-18 06:55:53 -0500150 r"""
151 Builds error list into a list of dictionary entries.
152
153 Description of argument(s):
154 error_list Error list entries.
155
156 Example output dictionary:
157 {
158 0:
159 {
160 'sev': '1',
161 'err': '00000027',
162 'Timestamp': 'Mar 29 19:41:54 2017',
163 'Part No': 'Not Available',
164 'Serial No': 'Not Available',
165 'Device': 'Not Available',
166 'FRU Number': 'Not Available',
167 'Location': 'Not Available',
168 'Device id': '/dev/nvidia0',
169 'Error Text': 'cudaEventSynchronize for stopEvent returned err = 0039
170 from file , line 430.',
171 'Exerciser Name': 'hxenvidia'
172 },
173 1:
174 {
175 'sev': '1',
176 'err': '00000027',
177 'Timestamp': 'Mar 29 19:41:54 2017',
178 'Part No': 'Not Available',
179 'Serial No': 'Not Available',
180 'Device': 'Not Available',
181 'FRU Number': 'Not Available',
182 'Location': 'Not Available',
183 'Device id': '/dev/nvidia0',
184 'Error Text': 'Hardware Exerciser stopped on error',
185 'Exerciser Name': 'hxenvidia'
186 }
187 },
188
189 """
190
191 # List which will hold all the list of entries.
192 error_list = []
193 error_list = htx_error_log_to_list(htx_error_log_output)
194
195 # dictionary which holds the error dictionry entry.
196 error_dict = {}
197
198 temp_error_dict = {}
199 error_index = 0
200
201 # Loop through the error list.
202 for entry_list in error_list:
203 # Loop through the first error list entry.
204 for entry in entry_list:
205 # Split string into list for key value update.
206 # Example: 'Device id:/dev/nvidia0'
207 # Example: 'err=00000027'
208 parm_split = re.split("[:=]", entry)
209 # Populate temp dictionary with key value pair data.
210 temp_error_dict[str(parm_split[0])] = parm_split[1]
211
212 # Update the master dictionary per entry index.
213 error_dict[error_index] = temp_error_dict
214 # Reset temp dict to EMPTY and increment index count.
215 temp_error_dict = {}
216 error_index += 1
217
218 return error_dict