From: Eduardo Habkost Subject: Re: [KVM-AUTOTEST PATCH v2 3/6] [RFC] Introduce exception context strings Date: Wed, 5 Jan 2011 13:54:06 -0200 Message-ID: <20110105155406.GD3361@otherpad.lan.raisama.net> References: <1294242329-11034-1-git-send-email-mgoldish@redhat.com> <1294242329-11034-3-git-send-email-mgoldish@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: Michael Goldish Return-path: Content-Disposition: inline In-Reply-To: <1294242329-11034-3-git-send-email-mgoldish@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 Wed, Jan 05, 2011 at 05:45:26PM +0200, Michael Goldish wrote: > In complex tests (KVM) an exception string is often not informative enough and > the traceback and source code have to be examined in order to figure out what > caused the exception. Context strings are a way for tests to provide > information about what they're doing, so that when an exception is raised, this > information will be embedded in the exception string. The result is a concise > yet highly informative exception string, which should make it very easy to > figure out where/when the exception was raised. > > A typical example for a test where this may be useful is KVM's reboot test. > Some exceptions can be raised either before or after the VM is rebooted (e.g. > logging into the guest can fail) and whether they are raised before or after > is critical to the understanding of the failure. Normally the traceback would > have to be examined, but the proposed method makes it easy to know where the > exception is raised without doing so. To achieve this, the reboot test should > place calls to error.context() as follows: > > error.context("before reboot") > > error.context("sending reboot command") > > error.context("after reboot") > > > If login fails in the pre-reboot section, the resulting exception string can > can have something like "context: before reboot" embedded in it. (The actual > embedding is done in the next patch in the series.) > > Signed-off-by: Michael Goldish > Signed-off-by: Eduardo Habkost > --- > client/common_lib/error.py | 97 +++++++++++++++++++++++++++++++++++++++++++- > 1 files changed, 95 insertions(+), 2 deletions(-) > Where's the automated test code? ;) > +# def a(): > +# error.context("hello") > +# b() > +# error.context("world") > +# get_context() ----> 'world' > +# > +# def b(): > +# error.context("foo") > +# c() > +# > +# def c(): > +# error.context("bar") > +# get_context() ----> 'hello --> foo --> bar' The example above is outdated, isn't? It doesn't have the @context_aware decorator. -- Eduardo