Skip to content

Commit 627ed99

Browse files
authored
Merge pull request #179 from rdkcentral/bug/gh174-pingTest-unboundLocalError
GH174 - Incorrect handling of elapsed time in pingTest when logPingTime is False
2 parents bfbf296 + ef7904f commit 627ed99

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

framework/core/deviceManager.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,21 +228,28 @@ def pingTest(self, logPingTime=False):
228228
bool: True if host is up, False otherwise.
229229
"""
230230
#Ping the box till the box responds after the boot
231-
if(logPingTime):
231+
232+
elapsed_string = "unknown"
233+
234+
if logPingTime:
232235
pingStartTime = time.time()
233236
timeString = time.strftime("%H:%M:%S",time.gmtime(pingStartTime))
234237
self.log.step("ping start time: [{}]".format(timeString) )
238+
235239
self.alive = self._pingTestOnly()
236-
if(logPingTime):
240+
241+
if logPingTime:
237242
elapsed_time = time.time() - pingStartTime
238243
timeString = time.strftime("%H:%M:%S",time.gmtime(time.time()))
239244
self.log.step("ping response time: [{}]".format(timeString) )
240-
elasped_string = time.strftime( "%H:%M:%S", time.gmtime(elapsed_time))
241-
self.log.step("Time taken to get ping response: ["+elasped_string+"]")
245+
elapsed_string = time.strftime( "%H:%M:%S", time.gmtime(elapsed_time))
246+
self.log.step("Time taken to get ping response: ["+elapsed_string+"]")
242247
# We've not be able to ping the box, return an error
243-
if ( False == self.alive ):
244-
self.log.critical( "ping Up Check:[Box is not responding to ping within:"+elasped_string+"]")
248+
249+
if not self.alive:
250+
self.log.critical( "ping Up Check:[Box is not responding to ping within:"+elapsed_string+"]")
245251
raise Exception(" ping failed")
252+
246253
return self.alive
247254

248255
def _pingTestOnly(self):
@@ -253,31 +260,37 @@ def _pingTestOnly(self):
253260
"""
254261
hostIsUp = False
255262
ip = self.getField("ip")
256-
if (platform.system().lower() == 'windows') or ('cygwin' in platform.system().lower()):
263+
264+
if platform.system().lower() == 'windows' or 'cygwin' in platform.system().lower():
257265
ping_param_amount = " -n "
258266
ping_param_quiet = " "
259267
else:
260268
ping_param_amount = " -c "
261269
ping_param_quiet = " -q "
270+
262271
# Quick check for ping working first time round
263272
command = "ping" + ping_param_amount + "1" + ping_param_quiet + ip
264273
result = utilities(self.log).syscmd(command)
265-
if (0 == result[1]):
274+
275+
if result[1] == 0:
266276
self.log.debug("ping response 1 - Host Up")
267277
return True
278+
268279
#Host is currently down, we need to loop
269280
for x in range( 0, 15 ):
270281
self.log.debug("pingTest Inner Loop["+str(x)+"]")
271282
utilities(self.log).wait(5) # Wait 5 seconds before trying constant ping
272283
result = utilities(self.log).syscmd( "ping" + ping_param_amount + "10" + ping_param_quiet + ip)
273-
if ( 0 == result[1] ):
284+
285+
if result[1] == 0:
274286
# Check for 0% packet loss, otherwise reject it
275287
outputString = str(result[0])
276-
if ( ", 0% packet loss" in outputString ):
288+
if ", 0% packet loss" in outputString:
277289
hostIsUp = True
278290
self.log.debug("pingTest hostIsUp")
279291
break
280292
self.log.debug("pingTest hostIsDown")
293+
281294
return hostIsUp
282295

283296
class deviceManager():

0 commit comments

Comments
 (0)