summaryrefslogtreecommitdiffstats
path: root/functest/utils/decorators.py
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2017-03-16 07:09:53 +0000
committerCédric Ollivier <cedric.ollivier@orange.com>2017-03-22 14:59:11 +0100
commit18bdde48e866f198b5d08b62fc9e26e3dfe4e818 (patch)
tree19bcb2a5af266a8eab590674c991820188a46c2d /functest/utils/decorators.py
parent52df520334dde18aa6b2773b44ce6157e21f7dc5 (diff)
Switch test_db_url to a directory
We must now set a dir (e.g. /home/opnfv/db) to dump results. It avoids replacing "results" and prevent from limiting the use of this decorator. All data will be dumped into url/dump.txt As also proposed in FUNCTEST-729, missing directories are created too. The decorator will raise exceptions if dir exists or if target is not a directory. Co-Authored-By: Cédric Ollivier <cedric.ollivier@orange.com> JIRA: FUNCTEST-729 Change-Id: I9650c72493043539f17725f5c328c12639ecc059 Signed-off-by: xudan <xudan16@huawei.com> Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/utils/decorators.py')
-rw-r--r--functest/utils/decorators.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/functest/utils/decorators.py b/functest/utils/decorators.py
index 99bcef3e6..276235d96 100644
--- a/functest/utils/decorators.py
+++ b/functest/utils/decorators.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
+import errno
import mock
+import os
import requests.sessions
import urlparse
@@ -10,7 +12,12 @@ def can_dump_request_to_file(method):
def dump_preparedrequest(request, **kwargs):
parseresult = urlparse.urlparse(request.url)
if parseresult.scheme == "file":
- with open(parseresult.path.replace('/results', ''), 'a') as f:
+ try:
+ os.makedirs(parseresult.path)
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+ with open(os.path.join(parseresult.path, 'dump.txt'), 'a') as f:
headers = ""
for key in request.headers:
headers += key + " " + request.headers[key] + "\n"