From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lucas Meneghel Rodrigues Subject: Re: [PATCH 2/3] KVM-Test: unattended_install.py: Get anaconda log and save it to log file Date: Tue, 05 Jul 2011 12:56:00 -0300 Message-ID: <1309881362.6594.35.camel@freedom> References: <1309254299-30095-1-git-send-email-qzhou@redhat.com> <1309254319-30182-1-git-send-email-qzhou@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: autotest@test.kernel.org, kvm@vger.kernel.org To: Qingtang Zhou Return-path: In-Reply-To: <1309254319-30182-1-git-send-email-qzhou@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: autotest-bounces@test.kernel.org Errors-To: autotest-bounces@test.kernel.org List-Id: kvm.vger.kernel.org On Tue, 2011-06-28 at 17:45 +0800, Qingtang Zhou wrote: > This patch will save guest's anaconda log to 'anaconda.log' in debug directory. > > Signed-off-by: Qingtang Zhou > --- > client/tests/kvm/tests/unattended_install.py | 31 ++++++++++++++++++++++++++ > 1 files changed, 31 insertions(+), 0 deletions(-) > > diff --git a/client/tests/kvm/tests/unattended_install.py b/client/tests/kvm/tests/unattended_install.py > index 50a8c7a..d631404 100644 > --- a/client/tests/kvm/tests/unattended_install.py > +++ b/client/tests/kvm/tests/unattended_install.py > @@ -494,6 +494,28 @@ class UnattendedInstallConfig(object): > raise ValueError("Unexpected installation method %s" % > self.medium) > > +def _get_anaconda_log(vm, log_file): > + port = int(vm.params.get("guest_port_unattended_install")) - 1 > + port = vm.get_port(port) > + > + anaconda_logfile = open(log_file, 'w') > + > + while True: > + client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > + try: > + client.connect((vm.get_address(), port)) > + install_log = client.recv(10240) > + if install_log != "": > + anaconda_logfile.write(install_log) > + anaconda_logfile.flush() > + client.send("ok %s\n" % str(time.time())) > + except (socket.error, virt_vm.VMAddressError): > + pass > + finally: > + client.close() > + time.sleep(1) ^ Here we have a try/except/finally block, which is illegal in py 2.4. This needs to be fixed. > + anaconda_logfile.close() > > @error.context_aware > def run_unattended_install(test, params, env): > @@ -524,6 +546,13 @@ def run_unattended_install(test, params, env): > "(%d min)", install_timeout, install_timeout/60) > error.context("waiting for installation to finish") > > + get_anaconda_log = params.get("get_anaconda_log") == "yes" ^ In case get_anaconda_log is not defined for that specific variant, better to make it default to 'no', so it'd be something like: get_anaconda_log = params.get("get_anaconda_log", "no") == "yes" > + if get_anaconda_log: > + log_file = os.path.join(test.debugdir, "anaconda.log") > + bg = virt_utils.Thread(_get_anaconda_log, > + kwargs={"vm": vm, "log_file": log_file}) > + bg.start() > + > start_time = time.time() > while (time.time() - start_time) < install_timeout: > try: > @@ -539,6 +568,8 @@ def run_unattended_install(test, params, env): > try: > client.connect((vm.get_address(), port)) > if client.recv(1024) == "done": > + if get_anaconda_log: > + bg.join() > break > except (socket.error, virt_vm.VMAddressError): > pass