Add reset function to nova coverage.

Now nova coverage is standardized to accumulate coverage data.
It enables user to get combined coverage data of several tests.
In addition to it, we need to restart nova services when measuring
coverage of each test because there is no function to reset data.
This adds reset coverage data API.

Fixes bug: 1164331

Change-Id: Idd16cf3849b6510e7c620ed3bf16d507ed44c328
This commit is contained in:
Mitsuhiko Yamazaki 2013-04-05 10:17:06 +09:00
parent 147eebe613
commit 0611f19406
4 changed files with 55 additions and 1 deletions

View File

@ -0,0 +1,4 @@
{
"reset" : {
}
}

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<reset></reset>

View File

@ -259,18 +259,41 @@ class CoverageController(object):
output.close()
return {'path': path}
def _reset_coverage_telnet(self, tn):
tn.write("coverInst.erase()\n")
tn.write("print 'finished'\n")
tn.expect([re.compile('finished')])
def _reset_coverage(self, req):
# Reopen telnet connections if they are closed.
for service in self.services:
if not service['telnet'].get_socket():
service['telnet'].open(service['host'], service['port'])
# Stop coverage if it is started.
try:
self._stop_coverage(req)
except exc.HTTPNotFound:
pass
for service in self.services:
self._reset_coverage_telnet(service['telnet'])
service['telnet'].close()
self.coverInst.erase()
def action(self, req, body):
_actions = {
'start': self._start_coverage,
'stop': self._stop_coverage,
'report': self._report_coverage,
'reset': self._reset_coverage,
}
authorize(req.environ['nova.context'])
if not self.coverInst:
msg = _("Python coverage module is not installed.")
raise exc.HTTPServiceUnavailable(explanation=msg)
for action, data in body.iteritems():
if action == 'stop':
if action == 'stop' or action == 'reset':
return _actions[action](req)
elif action == 'report' or action == 'start':
return _actions[action](req, body)

View File

@ -56,6 +56,9 @@ class FakeCoverage(object):
def xml_report(self, outfile):
pass
def erase(self):
pass
class CoverageExtensionTest(test.TestCase):
@ -202,3 +205,25 @@ class CoverageExtensionTest(test.TestCase):
res = req.get_response(fakes.wsgi_app(
fake_auth_context=self.admin_context))
self.assertEqual(res.status_int, 404)
def test_reset_coverage_action_while_coverage_running(self):
self.stubs.Set(coverage_ext.CoverageController,
'_check_coverage', fake_check_coverage)
body = {'reset': {}}
req = webob.Request.blank('/v2/fake/os-coverage/action')
req.method = "POST"
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app(
fake_auth_context=self.admin_context))
self.assertEqual(res.status_int, 200)
def test_reset_coverage_action_while_coverage_stopped(self):
body = {'reset': {}}
req = webob.Request.blank('/v2/fake/os-coverage/action')
req.method = "POST"
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app(
fake_auth_context=self.admin_context))
self.assertEqual(res.status_int, 200)