Skip to content

Commit

Permalink
Avoid hard dependency on python-coverage.
Browse files Browse the repository at this point in the history
Updates the coverage extension in the OpenStack Compute API to
avoid a hard dependency on the python coverage module. We now
try to import 'coverage' and if it isn't present we return
an HTTP 503 (service unavailable error).

This gets rid of WARNING errors which occur when running Nova API
when the 'coverage' module is not available:

2013-01-27 17:10:28.938 16018 WARNING nova.api.openstack.compute.contrib
[-] Failed to load extension
nova.api.openstack.compute.contrib.coverage_ext.Coverage_ext: No module
named coverage

Fixes LP Bug #1101057.

Change-Id: I573180aead44d68b8377cd66f30fc6ac849d0272
  • Loading branch information
dprince committed Jan 27, 2013
1 parent e1ce387 commit 2ca9553
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions nova/api/openstack/compute/contrib/coverage_ext.py
Expand Up @@ -23,7 +23,6 @@
import telnetlib
import tempfile

import coverage
from webob import exc

from nova.api.openstack import extensions
Expand All @@ -47,7 +46,6 @@ class CoverageController(object):
def __init__(self):
self.data_path = tempfile.mkdtemp(prefix='nova-coverage_')
data_out = os.path.join(self.data_path, '.nova-coverage')
self.coverInst = coverage.coverage(data_file=data_out)
self.compute_api = compute_api.API()
self.network_api = network_api.API()
self.conductor_api = conductor_api.API()
Expand All @@ -57,6 +55,12 @@ def __init__(self):
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
super(CoverageController, self).__init__()

def _find_services(self, req):
Expand Down Expand Up @@ -238,6 +242,9 @@ def action(self, req, body):
'report': self._report_coverage,
}
authorize(req.environ['nova.context'])
if not self.has_coverage:
msg = _("Python coverage module is not installed.")
raise exc.HTTPServiceUnavailable(explanation=msg)
for action, data in body.iteritems():
if action == 'stop':
return _actions[action](req)
Expand Down

0 comments on commit 2ca9553

Please sign in to comment.