From ce8cf3dcefb0a432381a4461b930a0a56ad22292 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Wed, 20 Feb 2013 19:05:44 -0800 Subject: Use a fake coverage module instead of real one. Actually loading the coverage module was leading to odd concurrency conditions where it was interfering with mocked calls. This changes to stub out the coverage class with a fake one so that we don't have to worry about collisions. It also modifies the coverage class to be created lazily so it isn't automatically started at import time. Finally it removes the hack in run_tests.sh ignoring the coverage tests. Fixes bug 1131023 Change-Id: I39de434454f8b0903f6311e731e215a93027bc91 --- nova/api/openstack/compute/contrib/coverage_ext.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/coverage_ext.py b/nova/api/openstack/compute/contrib/coverage_ext.py index 6edf9244f..6eeb363f2 100644 --- a/nova/api/openstack/compute/contrib/coverage_ext.py +++ b/nova/api/openstack/compute/contrib/coverage_ext.py @@ -45,7 +45,6 @@ class CoverageController(object): """The Coverage report API controller for the OpenStack API.""" def __init__(self): self.data_path = tempfile.mkdtemp(prefix='nova-coverage_') - data_out = os.path.join(self.data_path, '.nova-coverage') self.compute_api = compute_api.API() self.network_api = network_api.API() self.conductor_api = conductor_api.API() @@ -55,14 +54,20 @@ class CoverageController(object): self.cert_api = cert_api.CertAPI() self.services = [] self.combine = False - try: - import coverage - self.coverInst = coverage.coverage(data_file=data_out) - self.has_coverage = True - except ImportError: - self.has_coverage = False + self._cover_inst = None super(CoverageController, self).__init__() + @property + def coverInst(self): + if not self._cover_inst: + try: + import coverage + data_out = os.path.join(self.data_path, '.nova-coverage') + self._cover_inst = coverage.coverage(data_file=data_out) + except ImportError: + pass + return self._cover_inst + def _find_services(self, req): """Returns a list of services.""" context = req.environ['nova.context'] @@ -242,7 +247,7 @@ class CoverageController(object): 'report': self._report_coverage, } authorize(req.environ['nova.context']) - if not self.has_coverage: + if not self.coverInst: msg = _("Python coverage module is not installed.") raise exc.HTTPServiceUnavailable(explanation=msg) for action, data in body.iteritems(): -- cgit