All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: Michael Goldish <mgoldish@redhat.com>
Cc: autotest@test.kernel.org, kvm@vger.kernel.org
Subject: Re: [Autotest PATCH] KVM test: No need close session when login	timeout
Date: Sat, 26 Dec 2009 11:56:45 +0800	[thread overview]
Message-ID: <20091226035645.GD3258@debian> (raw)
In-Reply-To: <1816815221.2189471261747698769.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com>

On Fri, Dec 25, 2009 at 08:28:18AM -0500, Michael Goldish wrote:
> 
> ----- "Amos Kong" <akong@redhat.com> wrote:
> 
> > 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'"
> > 
> > Signed-off-by: Amos Kong <akong@redhat.com>
> > ---
> >  client/tests/kvm/tests/timedrift_with_migration.py |    3 ++-
> >  1 files changed, 2 insertions(+), 1 deletions(-)
> > 
> > diff --git a/client/tests/kvm/tests/timedrift_with_migration.py
> > b/client/tests/kvm/tests/timedrift_with_migration.py
> > index a012db3..0b93183 100644
> > --- a/client/tests/kvm/tests/timedrift_with_migration.py
> > +++ b/client/tests/kvm/tests/timedrift_with_migration.py
> > @@ -76,7 +76,8 @@ def run_timedrift_with_migration(test, params,
> > env):
> >                                               time_filter_re,
> > time_format)
> >  
> >      finally:
> > -        session.close()
> > +        if session != None:
> > +            session.close()
> 
> Agreed, but we can make this simply:
> 
> if session:
>     session.close()

Yes,

 
> 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.



> We can also consider removing the try..finally clauses altogether
> because sessions are now closed automatically when they're no longer
> needed.
> 
> >  
> >      # Report results
> >      host_delta = ht1 - ht0
> > -- 
> > 1.5.5.6

-- 
Amos Kong
Quality Engineer
Raycom Office(Beijing), Red Hat Inc.

  reply	other threads:[~2009-12-26  3:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <843369727.2189451261747394285.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com>
2009-12-25 13:28 ` [Autotest PATCH] KVM test: No need close session when login timeout Michael Goldish
2009-12-26  3:56   ` Amos Kong [this message]
     [not found] <1693251447.2192221261839864189.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com>
2009-12-26 15:07 ` Michael Goldish
2009-12-28  2:54   ` Amos Kong
2009-12-25  7:32 Amos Kong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091226035645.GD3258@debian \
    --to=akong@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=mgoldish@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.