Stephen Lowrie | c8548fc | 2016-05-24 15:57:35 -0500 | [diff] [blame] | 1 | # Copyright 2016 Rackspace |
| 2 | # |
| 3 | # All Rights Reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
| 17 | import os |
| 18 | import subprocess |
| 19 | import tempfile |
| 20 | |
| 21 | from tempest.cmd import subunit_describe_calls |
| 22 | from tempest.tests import base |
| 23 | |
| 24 | |
| 25 | class TestSubunitDescribeCalls(base.TestCase): |
| 26 | def test_return_code(self): |
| 27 | subunit_file = os.path.join( |
| 28 | os.path.dirname(os.path.abspath(__file__)), |
| 29 | 'sample_streams/calls.subunit') |
| 30 | p = subprocess.Popen([ |
| 31 | 'subunit-describe-calls', '-s', subunit_file, |
| 32 | '-o', tempfile.mkstemp()[1]], stdin=subprocess.PIPE) |
| 33 | p.communicate() |
| 34 | self.assertEqual(0, p.returncode) |
| 35 | |
Doug Schveninger | 8b3dc86 | 2018-02-16 21:42:27 -0600 | [diff] [blame] | 36 | def test_verbose(self): |
| 37 | subunit_file = os.path.join( |
| 38 | os.path.dirname(os.path.abspath(__file__)), |
| 39 | 'sample_streams/calls.subunit') |
| 40 | p = subprocess.Popen([ |
| 41 | 'subunit-describe-calls', '-s', subunit_file, |
| 42 | '-v'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) |
| 43 | stdout = p.communicate() |
| 44 | self.assertEqual(0, p.returncode) |
| 45 | self.assertIn(b'- request headers:', stdout[0]) |
| 46 | self.assertIn(b'- request body:', stdout[0]) |
| 47 | self.assertIn(b'- response headers:', stdout[0]) |
| 48 | self.assertIn(b'- response body:', stdout[0]) |
| 49 | |
Andrea Frittoli | 29cc1f8 | 2017-02-27 16:42:41 +0000 | [diff] [blame] | 50 | def test_return_code_no_output(self): |
| 51 | subunit_file = os.path.join( |
| 52 | os.path.dirname(os.path.abspath(__file__)), |
| 53 | 'sample_streams/calls.subunit') |
| 54 | p = subprocess.Popen([ |
| 55 | 'subunit-describe-calls', '-s', subunit_file], |
Doug Schveninger | 8b3dc86 | 2018-02-16 21:42:27 -0600 | [diff] [blame] | 56 | stdin=subprocess.PIPE, stdout=subprocess.PIPE) |
| 57 | stdout = p.communicate() |
Andrea Frittoli | 29cc1f8 | 2017-02-27 16:42:41 +0000 | [diff] [blame] | 58 | self.assertEqual(0, p.returncode) |
Doug Schveninger | 8b3dc86 | 2018-02-16 21:42:27 -0600 | [diff] [blame] | 59 | self.assertIn(b'foo', stdout[0]) |
| 60 | self.assertIn(b'- 200 POST request for Nova to v2.1/<id>/', |
| 61 | stdout[0]) |
| 62 | self.assertIn(b'- 200 DELETE request for Nova to v2.1/<id>/', |
| 63 | stdout[0]) |
| 64 | self.assertIn(b'- 200 GET request for Nova to v2.1/<id>/', |
| 65 | stdout[0]) |
| 66 | self.assertIn(b'- 404 DELETE request for Nova to v2.1/<id>/', |
| 67 | stdout[0]) |
| 68 | self.assertNotIn(b'- request headers:', stdout[0]) |
| 69 | self.assertNotIn(b'- request body:', stdout[0]) |
| 70 | self.assertNotIn(b'- response headers:', stdout[0]) |
| 71 | self.assertNotIn(b'- response body:', stdout[0]) |
Andrea Frittoli | 29cc1f8 | 2017-02-27 16:42:41 +0000 | [diff] [blame] | 72 | |
Stephen Lowrie | c8548fc | 2016-05-24 15:57:35 -0500 | [diff] [blame] | 73 | def test_parse(self): |
| 74 | subunit_file = os.path.join( |
| 75 | os.path.dirname(os.path.abspath(__file__)), |
| 76 | 'sample_streams/calls.subunit') |
| 77 | parser = subunit_describe_calls.parse( |
Stephen Lowrie | b85502d | 2016-06-27 15:05:47 -0500 | [diff] [blame] | 78 | open(subunit_file), "pythonlogging", None) |
Stephen Lowrie | c8548fc | 2016-05-24 15:57:35 -0500 | [diff] [blame] | 79 | expected_result = { |
Stephen Lowrie | b85502d | 2016-06-27 15:05:47 -0500 | [diff] [blame] | 80 | 'bar': [{ |
| 81 | 'name': 'AgentsAdminTestJSON:setUp', |
| 82 | 'request_body': '{"agent": {"url": "xxx://xxxx/xxx/xxx", ' |
| 83 | '"hypervisor": "common", "md5hash": ' |
| 84 | '"add6bb58e139be103324d04d82d8f545", "version": "7.0", ' |
| 85 | '"architecture": "tempest-x86_64-424013832", "os": "linux"}}', |
| 86 | 'request_headers': "{'Content-Type': 'application/json', " |
| 87 | "'Accept': 'application/json', 'X-Auth-Token': '<omitted>'}", |
| 88 | 'response_body': '{"agent": {"url": "xxx://xxxx/xxx/xxx", ' |
| 89 | '"hypervisor": "common", "md5hash": ' |
| 90 | '"add6bb58e139be103324d04d82d8f545", "version": "7.0", ' |
| 91 | '"architecture": "tempest-x86_64-424013832", "os": "linux", ' |
| 92 | '"agent_id": 1}}', |
| 93 | 'response_headers': "{'status': '200', 'content-length': " |
| 94 | "'203', 'x-compute-request-id': " |
| 95 | "'req-25ddaae2-0ef1-40d1-8228-59bd64a7e75b', 'vary': " |
| 96 | "'X-OpenStack-Nova-API-Version', 'connection': 'close', " |
| 97 | "'x-openstack-nova-api-version': '2.1', 'date': " |
| 98 | "'Tue, 02 Feb 2016 03:27:00 GMT', 'content-type': " |
| 99 | "'application/json'}", |
| 100 | 'service': 'Nova', |
| 101 | 'status_code': '200', |
| 102 | 'url': 'v2.1/<id>/os-agents', |
| 103 | 'verb': 'POST'}, { |
| 104 | 'name': 'AgentsAdminTestJSON:test_create_agent', |
| 105 | 'request_body': '{"agent": {"url": "xxx://xxxx/xxx/xxx", ' |
| 106 | '"hypervisor": "kvm", "md5hash": ' |
| 107 | '"add6bb58e139be103324d04d82d8f545", "version": "7.0", ' |
| 108 | '"architecture": "tempest-x86-252246646", "os": "win"}}', |
| 109 | 'request_headers': "{'Content-Type': 'application/json', " |
| 110 | "'Accept': 'application/json', 'X-Auth-Token': '<omitted>'}", |
| 111 | 'response_body': '{"agent": {"url": "xxx://xxxx/xxx/xxx", ' |
| 112 | '"hypervisor": "kvm", "md5hash": ' |
| 113 | '"add6bb58e139be103324d04d82d8f545", "version": "7.0", ' |
| 114 | '"architecture": "tempest-x86-252246646", "os": "win", ' |
| 115 | '"agent_id": 2}}', |
| 116 | 'response_headers': "{'status': '200', 'content-length': " |
| 117 | "'195', 'x-compute-request-id': " |
| 118 | "'req-b4136f06-c015-4e7e-995f-c43831e3ecce', 'vary': " |
| 119 | "'X-OpenStack-Nova-API-Version', 'connection': 'close', " |
| 120 | "'x-openstack-nova-api-version': '2.1', 'date': " |
| 121 | "'Tue, 02 Feb 2016 03:27:00 GMT', 'content-type': " |
| 122 | "'application/json'}", |
| 123 | 'service': 'Nova', |
| 124 | 'status_code': '200', |
| 125 | 'url': 'v2.1/<id>/os-agents', |
| 126 | 'verb': 'POST'}, { |
| 127 | 'name': 'AgentsAdminTestJSON:tearDown', |
| 128 | 'request_body': 'None', |
| 129 | 'request_headers': "{'Content-Type': 'application/json', " |
| 130 | "'Accept': 'application/json', 'X-Auth-Token': '<omitted>'}", |
| 131 | 'response_body': '', |
| 132 | 'response_headers': "{'status': '200', 'content-length': " |
| 133 | "'0', 'x-compute-request-id': " |
| 134 | "'req-ee905fd6-a5b5-4da4-8c37-5363cb25bd9d', 'vary': " |
| 135 | "'X-OpenStack-Nova-API-Version', 'connection': 'close', " |
| 136 | "'x-openstack-nova-api-version': '2.1', 'date': " |
| 137 | "'Tue, 02 Feb 2016 03:27:00 GMT', 'content-type': " |
| 138 | "'application/json'}", |
| 139 | 'service': 'Nova', |
| 140 | 'status_code': '200', |
| 141 | 'url': 'v2.1/<id>/os-agents/1', |
| 142 | 'verb': 'DELETE'}, { |
| 143 | 'name': 'AgentsAdminTestJSON:_run_cleanups', |
| 144 | 'request_body': 'None', |
| 145 | 'request_headers': "{'Content-Type': 'application/json', " |
| 146 | "'Accept': 'application/json', 'X-Auth-Token': '<omitted>'}", |
| 147 | 'response_headers': "{'status': '200', 'content-length': " |
| 148 | "'0', 'x-compute-request-id': " |
| 149 | "'req-e912cac0-63e0-4679-a68a-b6d18ddca074', 'vary': " |
| 150 | "'X-OpenStack-Nova-API-Version', 'connection': 'close', " |
| 151 | "'x-openstack-nova-api-version': '2.1', 'date': " |
| 152 | "'Tue, 02 Feb 2016 03:27:00 GMT', 'content-type': " |
| 153 | "'application/json'}", |
| 154 | 'service': 'Nova', |
| 155 | 'status_code': '200', |
| 156 | 'url': 'v2.1/<id>/os-agents/2', |
| 157 | 'verb': 'DELETE'}], |
| 158 | 'foo': [{ |
| 159 | 'name': 'AgentsAdminTestJSON:setUp', |
| 160 | 'request_body': '{"agent": {"url": "xxx://xxxx/xxx/xxx", ' |
| 161 | '"hypervisor": "common", "md5hash": ' |
| 162 | '"add6bb58e139be103324d04d82d8f545", "version": "7.0", ' |
| 163 | '"architecture": "tempest-x86_64-948635295", "os": "linux"}}', |
| 164 | 'request_headers': "{'Content-Type': 'application/json', " |
| 165 | "'Accept': 'application/json', 'X-Auth-Token': '<omitted>'}", |
| 166 | 'response_body': '{"agent": {"url": "xxx://xxxx/xxx/xxx", ' |
| 167 | '"hypervisor": "common", "md5hash": ' |
| 168 | '"add6bb58e139be103324d04d82d8f545", "version": "7.0", ' |
| 169 | '"architecture": "tempest-x86_64-948635295", "os": "linux", ' |
| 170 | '"agent_id": 3}}', |
| 171 | 'response_headers': "{'status': '200', 'content-length': " |
| 172 | "'203', 'x-compute-request-id': " |
| 173 | "'req-ccd2116d-04b1-4ffe-ae32-fb623f68bf1c', 'vary': " |
| 174 | "'X-OpenStack-Nova-API-Version', 'connection': 'close', " |
| 175 | "'x-openstack-nova-api-version': '2.1', 'date': " |
| 176 | "'Tue, 02 Feb 2016 03:27:01 GMT', 'content-type': " |
| 177 | "'application/json'}", |
| 178 | 'service': 'Nova', |
| 179 | 'status_code': '200', |
| 180 | 'url': 'v2.1/<id>/os-agents', |
| 181 | 'verb': 'POST'}, { |
| 182 | 'name': 'AgentsAdminTestJSON:test_delete_agent', |
| 183 | 'request_body': 'None', |
| 184 | 'request_headers': "{'Content-Type': 'application/json', " |
| 185 | "'Accept': 'application/json', 'X-Auth-Token': '<omitted>'}", |
| 186 | 'response_body': '', |
| 187 | 'response_headers': "{'status': '200', 'content-length': " |
| 188 | "'0', 'x-compute-request-id': " |
| 189 | "'req-6e7fa28f-ae61-4388-9a78-947c58bc0588', 'vary': " |
| 190 | "'X-OpenStack-Nova-API-Version', 'connection': 'close', " |
| 191 | "'x-openstack-nova-api-version': '2.1', 'date': " |
| 192 | "'Tue, 02 Feb 2016 03:27:01 GMT', 'content-type': " |
| 193 | "'application/json'}", |
| 194 | 'service': 'Nova', |
| 195 | 'status_code': '200', |
| 196 | 'url': 'v2.1/<id>/os-agents/3', |
| 197 | 'verb': 'DELETE'}, { |
| 198 | 'name': 'AgentsAdminTestJSON:test_delete_agent', |
| 199 | 'request_body': 'None', |
| 200 | 'request_headers': "{'Content-Type': 'application/json', " |
| 201 | "'Accept': 'application/json', 'X-Auth-Token': '<omitted>'}", |
| 202 | 'response_body': '{"agents": []}', |
| 203 | 'response_headers': "{'status': '200', 'content-length': " |
| 204 | "'14', 'content-location': " |
| 205 | "'http://23.253.76.97:8774/v2.1/" |
| 206 | "cf6b1933fe5b476fbbabb876f6d1b924/os-agents', " |
| 207 | "'x-compute-request-id': " |
| 208 | "'req-e41aa9b4-41a6-4138-ae04-220b768eb644', 'vary': " |
| 209 | "'X-OpenStack-Nova-API-Version', 'connection': 'close', " |
| 210 | "'x-openstack-nova-api-version': '2.1', 'date': " |
| 211 | "'Tue, 02 Feb 2016 03:27:01 GMT', 'content-type': " |
| 212 | "'application/json'}", |
| 213 | 'service': 'Nova', |
| 214 | 'status_code': '200', |
| 215 | 'url': 'v2.1/<id>/os-agents', |
| 216 | 'verb': 'GET'}, { |
| 217 | 'name': 'AgentsAdminTestJSON:tearDown', |
| 218 | 'request_body': 'None', |
| 219 | 'request_headers': "{'Content-Type': 'application/json', " |
| 220 | "'Accept': 'application/json', 'X-Auth-Token': '<omitted>'}", |
| 221 | 'response_headers': "{'status': '404', 'content-length': " |
| 222 | "'82', 'x-compute-request-id': " |
| 223 | "'req-e297aeea-91cf-4f26-b49c-8f46b1b7a926', 'vary': " |
| 224 | "'X-OpenStack-Nova-API-Version', 'connection': 'close', " |
| 225 | "'x-openstack-nova-api-version': '2.1', 'date': " |
| 226 | "'Tue, 02 Feb 2016 03:27:02 GMT', 'content-type': " |
| 227 | "'application/json; charset=UTF-8'}", |
| 228 | 'service': 'Nova', |
| 229 | 'status_code': '404', |
| 230 | 'url': 'v2.1/<id>/os-agents/3', |
| 231 | 'verb': 'DELETE'}]} |
| 232 | |
Stephen Lowrie | c8548fc | 2016-05-24 15:57:35 -0500 | [diff] [blame] | 233 | self.assertEqual(expected_result, parser.test_logs) |