From: Yolkfull Chow <yzhou@redhat.com>
To: Michael Goldish <mgoldish@redhat.com>
Cc: autotest@test.kernel.org, kvm@vger.kernel.org
Subject: Re: [AUTOTEST PATCH 2/2] KVM-test: Move two 'remote_login' out of try block in kvm_vm.py
Date: Wed, 13 Jan 2010 10:22:46 +0800 [thread overview]
Message-ID: <20100113022246.GB2333@aFu.nay.redhat.com> (raw)
In-Reply-To: <1360006704.2246041262253801462.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com>
On Thu, Dec 31, 2009 at 05:03:21AM -0500, Michael Goldish wrote:
>
> ----- "Yolkfull Chow" <yzhou@redhat.com> wrote:
>
> > If vm.remote_login failed 'session.close()' can result in exception
> > in finally clause. This patch fix the problem.
> >
> > Signed-off-by: Yolkfull Chow <yzhou@redhat.com>
> > ---
> > client/tests/kvm/kvm_vm.py | 51
> > +++++++++++++++++++++----------------------
> > 1 files changed, 25 insertions(+), 26 deletions(-)
> >
> > diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
> > index 7229b79..f746331 100755
> > --- a/client/tests/kvm/kvm_vm.py
> > +++ b/client/tests/kvm/kvm_vm.py
> > @@ -827,40 +827,39 @@ class VM:
> > """
> > Get the cpu count of the VM.
> > """
> > + session = self.remote_login()
> > + cmd = self.params.get("cpu_chk_cmd")
> > try:
> > - session = self.remote_login()
> > - if session:
> > - cmd = self.params.get("cpu_chk_cmd")
> > - s, count = session.get_command_status_output(cmd)
> > - if s == 0:
> > - return int(count)
> > + s, count = session.get_command_status_output(cmd)
> > + if s == 0:
> > + return int(count)
> > return None
> > finally:
> > - session.close()
> > + if session:
> > + session.close()
>
> If self.remote_login() fails, session will be None, and then the attempted
> call to session.get_command_status_output() will raise an exception which
> will fail the test with a rather ugly "reason" string.
>
> I think this form is preferable:
>
> session = self.remote_login()
> if not session:
> return None
Reasonable, thanks Michael. :)
Will post the updated patch soon.
> try:
> cmd = ...
> s, count = ...
> if s == 0:
> return int(count)
> return None
> finally:
> session.close()
>
> There's no need for a second 'if session' in the finally block.
>
> > def get_memory_size(self):
> > """
> > Get memory size of the VM.
> > """
> > + session = self.remote_login()
> > + cmd = self.params.get("mem_chk_cmd")
> > try:
> > - session = self.remote_login()
> > - if session:
> > - cmd = self.params.get("mem_chk_cmd")
> > - s, mem_str = session.get_command_status_output(cmd)
> > - if s != 0:
> > - return None
> > - mem = re.findall("([0-9][0-9][0-9]+)", mem_str)
> > - mem_size = 0
> > - for m in mem:
> > - mem_size += int(m)
> > - if "GB" in mem_str:
> > - mem_size *= 1024
> > - elif "MB" in mem_str:
> > - pass
> > - else:
> > - mem_size /= 1024
> > - return int(mem_size)
> > - return None
> > + s, mem_str = session.get_command_status_output(cmd)
> > + if s != 0:
> > + return None
> > + mem = re.findall("([0-9][0-9][0-9]+)", mem_str)
> > + mem_size = 0
> > + for m in mem:
> > + mem_size += int(m)
> > + if "GB" in mem_str:
> > + mem_size *= 1024
> > + elif "MB" in mem_str:
> > + pass
> > + else:
> > + mem_size /= 1024
> > + return int(mem_size)
> > finally:
> > - session.close()
> > + if session:
> > + session.close()
>
> The same applies to this function.
>
> > --
> > 1.6.6
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe kvm" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2010-01-13 2:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <278734081.2246011262253625627.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com>
2009-12-31 10:03 ` [AUTOTEST PATCH 2/2] KVM-test: Move two 'remote_login' out of try block in kvm_vm.py Michael Goldish
2010-01-12 22:37 ` [Autotest] " Lucas Meneghel Rodrigues
2010-01-13 2:24 ` Yolkfull Chow
2010-01-13 2:22 ` Yolkfull Chow [this message]
2009-12-30 9:47 [AUTOTEST PATCH 1/2] KVM-test: Fix a bug that about list slice in scan_results.py Yolkfull Chow
2009-12-30 9:47 ` [AUTOTEST PATCH 2/2] KVM-test: Move two 'remote_login' out of try block in kvm_vm.py Yolkfull Chow
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=20100113022246.GB2333@aFu.nay.redhat.com \
--to=yzhou@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox