From da58c0828d9e9624ba109c4275daff63e76953be Mon Sep 17 00:00:00 2001 From: sslypushenko Date: Wed, 4 Mar 2015 17:41:51 +0200 Subject: [PATCH] Add parsing test uuids from test result Test uuids are parsed from subunit test results and posted to refstack API. Depends on git https://review.openstack.org/#/c/161760/ Change-Id: I04740e3b190cd2248aa09ebc7539963c21c1e140 --- refstack_client/subunit_processor.py | 21 ++++++++++++++++--- refstack_client/tests/unit/.testrepository/0 | 21 +++++++------------ .../tests/unit/.testrepository/0.json | 5 +++-- refstack_client/tests/unit/test_client.py | 21 +++++++++++++------ 4 files changed, 43 insertions(+), 25 deletions(-) diff --git a/refstack_client/subunit_processor.py b/refstack_client/subunit_processor.py index 27a1da1..7479358 100644 --- a/refstack_client/subunit_processor.py +++ b/refstack_client/subunit_processor.py @@ -31,15 +31,30 @@ class TempestSubunitTestResultPassOnly(testtools.TestResult): super(TempestSubunitTestResultPassOnly, self).__init__() self.results = [] + @staticmethod + def get_test_uuid(test): + attrs = None + try: + attrs = test.split('[')[1].split(']')[0].split(',') + except IndexError: + pass + if not attrs: + return + for attr in attrs: + if attr.startswith('id-'): + return '-'.join(attr.split('-')[1:]) + def addSuccess(self, testcase): """Overwrite super class method for additional data processing.""" super(TempestSubunitTestResultPassOnly, self).addSuccess(testcase) # Remove any [] from the test ID before appending it. # Will leave in any () for now as they are the only thing discerning # certain test cases. - self.results.append( - {'name': re.sub('\[.*\]', '', testcase.id())} - ) + test_result = {'name': str(re.sub('\[.*\]', '', testcase.id()))} + uuid = self.get_test_uuid(str(testcase.id())) + if uuid: + test_result['uuid'] = uuid + self.results.append(test_result) def get_results(self): return self.results diff --git a/refstack_client/tests/unit/.testrepository/0 b/refstack_client/tests/unit/.testrepository/0 index a47e06a..fab693e 100644 --- a/refstack_client/tests/unit/.testrepository/0 +++ b/refstack_client/tests/unit/.testrepository/0 @@ -4,20 +4,13 @@ test: tempest.passed.test time: 2014-08-15 10:34:51.020584Z successful: tempest.passed.test [ multipart ] -tags: -worker-0 -time: 2014-08-15 10:34:57.543400Z tags: worker-0 -test: tempest.failed.test -time: 2014-08-15 10:34:57.548225Z -failure: tempest.failed.test [ multipart -Content-Type: text/x-traceback;charset="utf8",language="python" -traceback -2E4 -Traceback (most recent call last): - File "/usr/lib/python2.7/some_file.py", line 2335, in exit - _sys.exit(status) -SystemExit: 2 -0 +time: 2014-08-15 10:34:58.010492Z +tags: worker-0 +test: tempest.tagged_passed.test[gate,id-0146f675-ffbd-4208-b3a4-60eb628dbc5e] +time: 2014-08-15 10:34:58.020584Z +successful: tempest.tagged_passed.test[gate,id-0146f675-ffbd-4208-b3a4-60eb628dbc5e] [ multipart ] tags: -worker-0 - +time: 2014-08-15 10:34:58.543400Z +tags: worker-0 \ No newline at end of file diff --git a/refstack_client/tests/unit/.testrepository/0.json b/refstack_client/tests/unit/.testrepository/0.json index c91b93c..9ee68c5 100644 --- a/refstack_client/tests/unit/.testrepository/0.json +++ b/refstack_client/tests/unit/.testrepository/0.json @@ -2,7 +2,8 @@ "duration_seconds": 0, "cpid": "test-id", "results": [ - {"name": "tempest.passed.test"} + {"name": "tempest.passed.test"}, + {"name": "tempest.tagged_passed.test", + "uuid": "0146f675-ffbd-4208-b3a4-60eb628dbc5e"} ] } - diff --git a/refstack_client/tests/unit/test_client.py b/refstack_client/tests/unit/test_client.py index 4f655cd..d7aa3a0 100755 --- a/refstack_client/tests/unit/test_client.py +++ b/refstack_client/tests/unit/test_client.py @@ -218,7 +218,11 @@ class TestRefstackClient(unittest.TestCase): client = rc.RefstackClient(args) subunit_file = self.test_path + "/.testrepository/0" results = client.get_passed_tests(subunit_file) - expected = [{'name': 'tempest.passed.test'}] + expected = [ + {'name': 'tempest.passed.test'}, + {'name': 'tempest.tagged_passed.test', + 'uuid': '0146f675-ffbd-4208-b3a4-60eb628dbc5e'} + ] self.assertEqual(expected, results) def test_post_results(self): @@ -230,7 +234,7 @@ class TestRefstackClient(unittest.TestCase): client.logger.info = MagicMock() content = {'duration_seconds': 0, 'cpid': 'test-id', - 'results': [{'name': 'tempest.passed.test'}]} + 'results': [{'name': 'tempest.passed.test', 'uid': None}]} expected_response = json.dumps({'test_id': 42}) @httmock.urlmatch(netloc=r'(.*\.)?127.0.0.1$', path='/v1/results/') @@ -372,10 +376,15 @@ class TestRefstackClient(unittest.TestCase): client.post_results = MagicMock() client.upload() - expected_json = {'duration_seconds': 0, - 'cpid': 'test-id', - 'results': [{'name': 'tempest.passed.test'}]} - + expected_json = { + 'duration_seconds': 0, + 'cpid': 'test-id', + 'results': [ + {'name': 'tempest.passed.test'}, + {'name': 'tempest.tagged_passed.test', + 'uuid': '0146f675-ffbd-4208-b3a4-60eb628dbc5e'} + ] + } client.post_results.assert_called_with('http://api.test.org', expected_json)