diff options
| author | Vishvananda Ishaya <vishvananda@gmail.com> | 2013-02-20 19:05:44 -0800 |
|---|---|---|
| committer | Vishvananda Ishaya <vishvananda@gmail.com> | 2013-02-20 19:53:50 -0800 |
| commit | ce8cf3dcefb0a432381a4461b930a0a56ad22292 (patch) | |
| tree | 803393d1324ef2c7b569125190579fb7d1503d78 /nova/api | |
| parent | f080f1146f22b305ac720be3afc3eb9f94da4b14 (diff) | |
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
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/coverage_ext.py | 21 |
1 files changed, 13 insertions, 8 deletions
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(): |
