diff --git a/doc/api_samples/os-coverage/coverage-report-post-req.json b/doc/api_samples/os-coverage/coverage-report-post-req.json
new file mode 100644
index 000000000000..cb16cfc85fc2
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-report-post-req.json
@@ -0,0 +1,5 @@
+{
+ "report" : {
+ "file" : "report"
+ }
+}
\ No newline at end of file
diff --git a/doc/api_samples/os-coverage/coverage-report-post-req.xml b/doc/api_samples/os-coverage/coverage-report-post-req.xml
new file mode 100644
index 000000000000..1cc9b743394e
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-report-post-req.xml
@@ -0,0 +1,4 @@
+
+
+ report
+
\ No newline at end of file
diff --git a/doc/api_samples/os-coverage/coverage-report-post-resp.json b/doc/api_samples/os-coverage/coverage-report-post-resp.json
new file mode 100644
index 000000000000..e7db3076a967
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-report-post-resp.json
@@ -0,0 +1,3 @@
+{
+ "path": "/tmp/tmpV0Pno7/nova-coverage_D8L8SB/report"
+}
\ No newline at end of file
diff --git a/doc/api_samples/os-coverage/coverage-report-post-resp.xml b/doc/api_samples/os-coverage/coverage-report-post-resp.xml
new file mode 100644
index 000000000000..8b7188ad0647
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-report-post-resp.xml
@@ -0,0 +1,2 @@
+
+/tmp/tmpAqRtz5/nova-coverage_Iqja9E/report
\ No newline at end of file
diff --git a/doc/api_samples/os-coverage/coverage-start-combine-post-req.json b/doc/api_samples/os-coverage/coverage-start-combine-post-req.json
new file mode 100644
index 000000000000..6d41ba59825b
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-start-combine-post-req.json
@@ -0,0 +1,5 @@
+{
+ "start" : {
+ "combine": true
+ }
+}
\ No newline at end of file
diff --git a/doc/api_samples/os-coverage/coverage-start-combine-post-req.xml b/doc/api_samples/os-coverage/coverage-start-combine-post-req.xml
new file mode 100644
index 000000000000..10489b3be4c6
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-start-combine-post-req.xml
@@ -0,0 +1,4 @@
+
+
+ True
+
\ No newline at end of file
diff --git a/doc/api_samples/os-coverage/coverage-start-post-req.json b/doc/api_samples/os-coverage/coverage-start-post-req.json
new file mode 100644
index 000000000000..8e5ef033ca76
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-start-post-req.json
@@ -0,0 +1,4 @@
+{
+ "start" : {
+ }
+}
\ No newline at end of file
diff --git a/doc/api_samples/os-coverage/coverage-start-post-req.xml b/doc/api_samples/os-coverage/coverage-start-post-req.xml
new file mode 100644
index 000000000000..398971d54e37
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-start-post-req.xml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/doc/api_samples/os-coverage/coverage-stop-post-req.json b/doc/api_samples/os-coverage/coverage-stop-post-req.json
new file mode 100644
index 000000000000..57de881919b7
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-stop-post-req.json
@@ -0,0 +1,4 @@
+{
+ "stop" : {
+ }
+}
\ No newline at end of file
diff --git a/doc/api_samples/os-coverage/coverage-stop-post-req.xml b/doc/api_samples/os-coverage/coverage-stop-post-req.xml
new file mode 100644
index 000000000000..7092c81e25a4
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-stop-post-req.xml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/doc/api_samples/os-coverage/coverage-xml-report-post-req.json b/doc/api_samples/os-coverage/coverage-xml-report-post-req.json
new file mode 100644
index 000000000000..bcbe0c4a0fbd
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-xml-report-post-req.json
@@ -0,0 +1,6 @@
+{
+ "report": {
+ "xml": true,
+ "file": "report"
+ }
+}
diff --git a/doc/api_samples/os-coverage/coverage-xml-report-post-req.xml b/doc/api_samples/os-coverage/coverage-xml-report-post-req.xml
new file mode 100644
index 000000000000..62e5bc6f47b3
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-xml-report-post-req.xml
@@ -0,0 +1,5 @@
+
+
+ report
+ True
+
\ No newline at end of file
diff --git a/doc/api_samples/os-coverage/coverage-xml-report-post-resp.json b/doc/api_samples/os-coverage/coverage-xml-report-post-resp.json
new file mode 100644
index 000000000000..0648b2ebc0f8
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-xml-report-post-resp.json
@@ -0,0 +1,3 @@
+{
+ "path": "/tmp/tmp6kdYaa/nova-coverage_TOTUbz/report"
+}
\ No newline at end of file
diff --git a/doc/api_samples/os-coverage/coverage-xml-report-post-resp.xml b/doc/api_samples/os-coverage/coverage-xml-report-post-resp.xml
new file mode 100644
index 000000000000..72f58400329d
--- /dev/null
+++ b/doc/api_samples/os-coverage/coverage-xml-report-post-resp.xml
@@ -0,0 +1,2 @@
+
+/tmp/tmp4j87bp/nova-coverage_7ViTA7/report
\ No newline at end of file
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-report-post-req.json.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-report-post-req.json.tpl
new file mode 100644
index 000000000000..c228b05f0241
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-report-post-req.json.tpl
@@ -0,0 +1,5 @@
+{
+ "report" : {
+ "file" : "%(filename)s"
+ }
+}
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-report-post-req.xml.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-report-post-req.xml.tpl
new file mode 100644
index 000000000000..02b8fc97cd17
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-report-post-req.xml.tpl
@@ -0,0 +1,4 @@
+
+
+ %(filename)s
+
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-report-post-resp.json.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-report-post-resp.json.tpl
new file mode 100644
index 000000000000..6cdd1f37dcd0
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-report-post-resp.json.tpl
@@ -0,0 +1,3 @@
+{
+ "path" : "%(path)s"
+}
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-report-post-resp.xml.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-report-post-resp.xml.tpl
new file mode 100644
index 000000000000..51b9773d389a
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-report-post-resp.xml.tpl
@@ -0,0 +1,2 @@
+
+%(path)s
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-start-combine-post-req.json.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-start-combine-post-req.json.tpl
new file mode 100644
index 000000000000..296049df9c11
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-start-combine-post-req.json.tpl
@@ -0,0 +1,5 @@
+{
+ "start" : {
+ "combine": true
+ }
+}
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-start-combine-post-req.xml.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-start-combine-post-req.xml.tpl
new file mode 100644
index 000000000000..11bdb44f9bf8
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-start-combine-post-req.xml.tpl
@@ -0,0 +1,4 @@
+
+
+ True
+
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-start-post-req.json.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-start-post-req.json.tpl
new file mode 100644
index 000000000000..a046b9207a50
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-start-post-req.json.tpl
@@ -0,0 +1,4 @@
+{
+ "start" : {
+ }
+}
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-start-post-req.xml.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-start-post-req.xml.tpl
new file mode 100644
index 000000000000..aeaff102a55f
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-start-post-req.xml.tpl
@@ -0,0 +1,2 @@
+
+
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-stop-post-req.json.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-stop-post-req.json.tpl
new file mode 100644
index 000000000000..c46e49cca99e
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-stop-post-req.json.tpl
@@ -0,0 +1,4 @@
+{
+ "stop" : {
+ }
+}
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-stop-post-req.xml.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-stop-post-req.xml.tpl
new file mode 100644
index 000000000000..1dd5c7bc7510
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-stop-post-req.xml.tpl
@@ -0,0 +1,2 @@
+
+
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-xml-report-post-req.json.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-xml-report-post-req.json.tpl
new file mode 100644
index 000000000000..906d629ed452
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-xml-report-post-req.json.tpl
@@ -0,0 +1,6 @@
+{
+ "report": {
+ "xml": true,
+ "file": "%(filename)s"
+ }
+}
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-xml-report-post-req.xml.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-xml-report-post-req.xml.tpl
new file mode 100644
index 000000000000..902e0e537700
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-xml-report-post-req.xml.tpl
@@ -0,0 +1,5 @@
+
+
+ %(filename)s
+ True
+
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-xml-report-post-resp.json.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-xml-report-post-resp.json.tpl
new file mode 100644
index 000000000000..6cdd1f37dcd0
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-xml-report-post-resp.json.tpl
@@ -0,0 +1,3 @@
+{
+ "path" : "%(path)s"
+}
diff --git a/nova/tests/integrated/api_samples/os-coverage/coverage-xml-report-post-resp.xml.tpl b/nova/tests/integrated/api_samples/os-coverage/coverage-xml-report-post-resp.xml.tpl
new file mode 100644
index 000000000000..65f5e16bcda5
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-coverage/coverage-xml-report-post-resp.xml.tpl
@@ -0,0 +1,2 @@
+
+%(path)s
diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py
index a9fbb8fe3979..ab6770a23531 100644
--- a/nova/tests/integrated/test_api_samples.py
+++ b/nova/tests/integrated/test_api_samples.py
@@ -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):