Add API samples tests for the coverage extension.

Partially implements blueprint nova-api-samples
Fixes bug 1089531

Change-Id: I5b287ea210f275a0c316a28d6dc3614d107aff05
This commit is contained in:
Matthew Treinish 2012-12-14 15:04:50 -05:00
parent 67d188cf4a
commit 2655ac9f3c
29 changed files with 172 additions and 1 deletions

View File

@ -0,0 +1,5 @@
{
"report" : {
"file" : "report"
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<report>
<file>report</file>
</report>

View File

@ -0,0 +1,3 @@
{
"path": "/tmp/tmpV0Pno7/nova-coverage_D8L8SB/report"
}

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<path>/tmp/tmpAqRtz5/nova-coverage_Iqja9E/report</path>

View File

@ -0,0 +1,5 @@
{
"start" : {
"combine": true
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<start>
<combine>True</combine>
</start>

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,6 @@
{
"report": {
"xml": true,
"file": "report"
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<report>
<file>report</file>
<xml>True</xml>
</report>

View File

@ -0,0 +1,3 @@
{
"path": "/tmp/tmp6kdYaa/nova-coverage_TOTUbz/report"
}

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<path>/tmp/tmp4j87bp/nova-coverage_7ViTA7/report</path>

View File

@ -0,0 +1,5 @@
{
"report" : {
"file" : "%(filename)s"
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<report>
<file>%(filename)s</file>
</report>

View File

@ -0,0 +1,3 @@
{
"path" : "%(path)s"
}

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<path>%(path)s</path>

View File

@ -0,0 +1,5 @@
{
"start" : {
"combine": true
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<start>
<combine>True</combine>
</start>

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,6 @@
{
"report": {
"xml": true,
"file": "%(filename)s"
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<report>
<file>%(filename)s</file>
<xml>True</xml>
</report>

View File

@ -0,0 +1,3 @@
{
"path" : "%(path)s"
}

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<path>%(path)s</path>

View File

@ -21,8 +21,10 @@ import re
import urllib
import uuid as uuid_lib
from coverage import coverage
from lxml import etree
from nova.api.openstack.compute.contrib import coverage_ext
# Import extensions to pull in osapi_compute_extension CONF option used below.
from nova.api.openstack.compute import extensions
from nova.cloudpipe.pipelib import CloudPipe
@ -353,7 +355,6 @@ class ApiSamplesTrap(ApiSampleTestBase):
do_not_approve_additions.append('NMN')
do_not_approve_additions.append('OS-FLV-DISABLED')
do_not_approve_additions.append('os-config-drive')
do_not_approve_additions.append('os-coverage')
do_not_approve_additions.append('os-create-server-ext')
do_not_approve_additions.append('os-fixed-ips')
do_not_approve_additions.append('os-flavor-access')
@ -719,6 +720,74 @@ class LimitsSampleXmlTest(LimitsSampleJsonTest):
ctype = 'xml'
class CoverageExtJsonTests(ApiSampleTestBase):
extension_name = ("nova.api.openstack.compute.contrib.coverage_ext."
"Coverage_ext")
def setUp(self):
super(CoverageExtJsonTests, self).setUp()
def _fake_check_coverage(self):
return False
def _fake_xml_report(self, outfile=None):
return
self.stubs.Set(coverage_ext.CoverageController, '_check_coverage',
_fake_check_coverage)
self.stubs.Set(coverage, 'xml_report', _fake_xml_report)
def test_start_coverage(self):
"""Start coverage data collection"""
subs = {}
response = self._do_post('os-coverage/action',
'coverage-start-post-req', subs)
self.assertEqual(response.status, 200)
def test_start_coverage_combine(self):
"""Start coverage data collection"""
subs = {}
response = self._do_post('os-coverage/action',
'coverage-start-combine-post-req', subs)
self.assertEqual(response.status, 200)
def test_stop_coverage(self):
"""Stop coverage data collection"""
subs = {}
response = self._do_post('os-coverage/action',
'coverage-stop-post-req', subs)
self.assertEqual(response.status, 200)
def test_report_coverage(self):
"""Generate a coverage report"""
subs = {
'filename': 'report',
'path': '/.*/report',
}
response = self._do_post('os-coverage/action',
'coverage-report-post-req', subs)
self.assertEqual(response.status, 200)
subs.update(self._get_regexes())
return self._verify_response('coverage-report-post-resp',
subs, response)
def test_xml_report_coverage(self):
subs = {
'filename': 'report',
'path': '/.*/report',
}
response = self._do_post('os-coverage/action',
'coverage-xml-report-post-req', subs)
self.assertEqual(response.status, 200)
subs.update(self._get_regexes())
return self._verify_response('coverage-xml-report-post-resp',
subs, response)
class CoverageExtXmlTests(CoverageExtJsonTests):
ctype = "xml"
class ServersActionsJsonTest(ServersSampleBase):
def _test_server_action(self, uuid, action,
subs={}, resp_tpl=None, code=202):