Skip to contentSkip to conversation

KVM test: No need close session when login timeout

PATCH Michael Goldish 2 participants 2 messages Dec 25, 2009 – Dec 26, 2009 1 message not in the archive KVM

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 21 lines · ----- "Amos Kong

If login timeout, wait_for() returned 'None' and assigned to 'session'.
When call session.close(), this prlblem was caused:
"AttributeError: 'NoneType' object has no attribute 'close'"

---
 client/tests/kvm/tests/timedrift_with_migration.py |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
client/tests/kvm/tests/timedrift_with_migration.py +0 -0
index a012db3..0b93183 100644
@@ -76,7 +76,8 @@ def run_timedrift_with_migration(test, params,

env):
time_filter_re,
time_format)

finally:

client/tests/kvm/tests/timedrift_with_migration.py

Quoted 3 lines
client/tests/kvm/tests/timedrift_with_migration.py +2 -1
-        session.close()
+        if session != None:
+            session.close()

Agreed, but we can make this simply:

if session:
session.close()

There's no need to explicitly check for None (and if there was, the preferred syntax would be 'is not None' rather than '!= None').

Also, just to be safe, we should make the same modification to timedrift_with_reboot.py.

We can also consider removing the try..finally clauses altogether because sessions are now closed automatically when they're no longer needed.

Quoted 10 lines

# Report results
host_delta = ht1 - ht0

Signature · 6 lines
1.5.5.6

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 30 lines · Michael Goldish
Quoted 21 lines · ----- "Amos Kong

If login timeout, wait_for() returned 'None' and assigned to 'session'.
When call session.close(), this prlblem was caused:
"AttributeError: 'NoneType' object has no attribute 'close'"

---
 client/tests/kvm/tests/timedrift_with_migration.py |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
client/tests/kvm/tests/timedrift_with_migration.py +0 -0
index a012db3..0b93183 100644
@@ -76,7 +76,8 @@ def run_timedrift_with_migration(test, params,

env):
time_filter_re,
time_format)

finally:

client/tests/kvm/tests/timedrift_with_migration.py

Quoted 3 lines
client/tests/kvm/tests/timedrift_with_migration.py +2 -1
-        session.close()
+        if session != None:
+            session.close()

Agreed, but we can make this simply:

Quoted 2 lines

if session:
session.close()

Yes,

Quoted 5 lines

There's no need to explicitly check for None (and if there was, the preferred syntax would be 'is not None' rather than '!= None').

Also, just to be safe, we should make the same modification to timedrift_with_reboot.py.

In timedrift_with_reboot.py, 'session' has been assigned before 'try'.
If re-login timout, kvm_test_utils.reboot() returns nothing, the value of 'session' isn't changed. So session.close() couldn't cause this problem:
"AttributeError: 'NoneType' object has no attribute 'close'"

In other testcases, if session wasn't assigned before 'try',
when calling kvm_test_utils.wait_for_login()/kvm_test_utils.reboot() timeout, It returns nothing, if close 'session' in finally part, Another problem will occur:
"NameError: name 'session' is not defined"

In this condition,
"""
if session:
session.close()
"""
also causes this error.

Quoted 9 lines

We can also consider removing the try..finally clauses altogether because sessions are now closed automatically when they're no longer needed.

Quoted 5 lines

# Report results
host_delta = ht1 - ht0

Signature · 1 line
1.5.5.6
Signature · 3 lines
Amos Kong
Quality Engineer
Raycom Office(Beijing), Red Hat Inc.