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