diff options
author | Anton Kiselev <anton.kisel@gmail.com> | 2017-03-07 01:35:28 +0700 |
---|---|---|
committer | Yaroslav Brustinov <ybrustin@cisco.com> | 2017-03-07 18:13:23 +0200 |
commit | 029cbdcf5d183b344fe572b21157293cef1c62e0 (patch) | |
tree | 45843b5eeb2619802ed39e6ad9b30c3a57db6b4b /scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py | |
parent | 183f492cd3bba890291bd7cfc79624dbc1fb2b01 (diff) |
scapy_server: fix template tests
Signed-off-by: Anton Kiselev <anton.kisel@gmail.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py')
-rwxr-xr-x | scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py b/scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py index 7b19896b..98eeb749 100755 --- a/scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py +++ b/scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py @@ -981,41 +981,30 @@ class Scapy_service(Scapy_service_api): def _get_templates(self): - # Make sure you understand the three return values of os.walk: - # - # for root, subdirs, files in os.walk(rootdir): - # has the following meaning: - # - # root: Current path which is "walked through" - # subdirs: Files in root of type directory - # files: Files in root (not in subdirs) of type other than directory - # And please use os.path.join instead of concatenating with a slash! - # Your problem is filePath = rootdir + '/' + file - you must concatenate the currently "walked" folder instead of the topmost folder. - # So that must be filePath = os.path.join(root, file). BTW "file" is a builtin, so you don't normally use it as variable name. - templates = [] for root, subdirs, files in os.walk("templates"): for file in files: - if file.endswith('.trp'): - try: - f = os.path.join(root, file) - o = open(f) - c = json.loads(o.read()) - o.close() - id = f.replace("templates" + os.path.sep, "", 1) - id = id.split(os.path.sep) - id[-1] = id[-1].replace(".trp", "", 1) - id = "/".join(id) - t = { - "id": id, - "meta": { - "name": c["metadata"]["caption"], - "description": "" - } - } - templates.append(t) - except: - pass + if not file.endswith('.trp'): + next + try: + f = os.path.join(root, file) + c = None + with open(f, 'r') as templatefile: + c = json.loads(templatefile.read()) + id = f.replace("templates" + os.path.sep, "", 1) + id = id.split(os.path.sep) + id[-1] = id[-1].replace(".trp", "", 1) + id = "/".join(id) + t = { + "id": id, + "meta": { + "name": c["metadata"]["caption"], + "description": "" + } + } + templates.append(t) + except: + pass return templates def _get_template(self,template): |