~canonical-platform-qa/ubuntu-test-cases/memevent-nfss-data-file

« back to all changes in this revision

Viewing changes to tests/memevent/support_scripts/generate_nfss_result_file.py

  • Committer: Christopher Lee
  • Date: 2014-11-04 21:32:38 UTC
  • Revision ID: chris.lee@canonical.com-20141104213238-cse5xsjtl9ge5q0h
Initial move around and addition of testing for upload/gen. script/

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from collections import defaultdict
19
19
from glob import glob
20
20
 
21
 
source_file_path = ""
22
 
upload_script = ""
23
 
nfss_config = ""
24
 
 
25
 
 
26
21
def _get_run_details(app_name):
27
22
    return dict(
28
23
        image_arch='',
59
54
    _upload_data(run_details['application_name'], app_run_details)
60
55
 
61
56
 
62
 
def _upload_data(test_name, run_json):
63
 
    try:
64
 
        run_json_string = json.dumps(run_json)
65
 
    except ValueError as e:
66
 
        print("Error: Data does not appear to be valid json: %s" % e)
67
 
        sys.exit(3)
 
57
# def _upload_data(test_name, run_json):
 
58
#     try:
 
59
#         run_json_string = json.dumps(run_json)
 
60
#     except ValueError as e:
 
61
#         print("Error: Data does not appear to be valid json: %s" % e)
 
62
#         sys.exit(3)
68
63
 
69
 
    print("Uploading data for :memevent:-", test_name)
70
 
    global upload_script
71
 
    global nfss_config
72
 
    try:
73
 
        upload_process = subprocess.Popen(
74
 
            [upload_script, nfss_config, 'memevent', test_name],
75
 
            stdin=subprocess.PIPE,
76
 
            stdout=subprocess.PIPE,
77
 
            stderr=subprocess.PIPE,
78
 
        )
79
 
        stdout, stderr = upload_process.communicate(
80
 
            input=run_json_string.encode()
81
 
        )
82
 
        print("stdout: {}\n\nstderr: {}".format(stdout, stderr))
83
 
    except Exception as e:
84
 
        print("Something went terribly wrong: ", e)
85
 
    if upload_process.returncode != 0:
86
 
        raise subprocess.CalledProcessError('Failed to upload to nfss')
 
64
#     print("Uploading data for :memevent:-", test_name)
 
65
#     global upload_script
 
66
#     global nfss_config
 
67
#     try:
 
68
#         upload_process = subprocess.Popen(
 
69
#             [upload_script, nfss_config, 'memevent', test_name],
 
70
#             stdin=subprocess.PIPE,
 
71
#             stdout=subprocess.PIPE,
 
72
#             stderr=subprocess.PIPE,
 
73
#         )
 
74
#         stdout, stderr = upload_process.communicate(
 
75
#             input=run_json_string.encode()
 
76
#         )
 
77
#         print("stdout: {}\n\nstderr: {}".format(stdout, stderr))
 
78
#     except Exception as e:
 
79
#         print("Something went terribly wrong: ", e)
 
80
#     if upload_process.returncode != 0:
 
81
#         raise subprocess.CalledProcessError('Failed to upload to nfss')
87
82
 
88
83
 
89
84
def _get_files_app_name_and_test(filename):
131
126
    return app_result
132
127
 
133
128
 
134
 
def map_files_to_applications():
135
 
    """For any memory result files that exist, return a dictionary whos keys
136
 
    are the applications name mapped to the file.
 
129
def map_files_to_applications(source_file_path):
 
130
    """For any memory result files that exist at **source_file_path**, return a
 
131
    dictionary whos keys are the applications name and the values the file path
 
132
    for that apps results.
137
133
 
138
134
    We can then produce a single json result for each application regardless of
139
135
    there being many tests / results for it.
140
136
 
141
137
    """
142
 
 
143
 
    global source_file_path
144
138
    json_results_filename_pattern = os.path.join(
145
139
        source_file_path,
146
140
        "memory_usage_*.json"
153
147
 
154
148
 
155
149
def usage():
156
 
    print("{} <source file path> <nfss upload script> <nfss config file>"
157
 
          .format(sys.argv[0]))
 
150
    print("{} <source file path> <destination file>".format(sys.argv[0]))
 
151
 
 
152
 
 
153
def raise_on_invalid_args(argv):
 
154
    if len(argv) != 3:
 
155
        raise RuntimeError()
 
156
 
 
157
def parse_args(argv):
 
158
    try:
 
159
        source_file_path = argv[0]
 
160
        destination_file = argv[1]
 
161
        return (source_file_path, destination_file)
 
162
    except IndexError:
 
163
        raise RuntimeError("Need both source path and destination file.")
 
164
 
 
165
 
 
166
def get_all_applications_details(source_file_path):
 
167
    app_details = dict()
 
168
    file_map = map_files_to_applications(source_file_path)
 
169
    for app_name in file_map.keys():
 
170
        app_details[app_name] = get_application_details(file_map[app_name])
 
171
 
 
172
    return app_details
158
173
 
159
174
 
160
175
def main():
161
 
    if len(sys.argv) != 4:
 
176
    try:
 
177
        raise_on_invalid_args(sys.argv)
 
178
        source_file_path, destination_file = parse_args(sys.argv)
 
179
    except RuntimeError as e:
162
180
        usage()
163
181
        exit(1)
164
182
 
165
 
    global source_file_path
166
 
    source_file_path = sys.argv[1]
167
 
 
168
 
    global upload_script
169
 
    upload_script = sys.argv[2]
170
 
 
171
 
    global nfss_config
172
 
    nfss_config = sys.argv[3]
173
 
 
174
 
    app_details = dict()
175
 
    file_map = map_files_to_applications()
176
 
    for app_name in file_map.keys():
177
 
        app_details[app_name] = get_application_details(file_map[app_name])
 
183
    app_details = get_all_applications_details(source_file_path)
178
184
 
179
185
    for app_name in app_details.keys():
180
186
        run_details = _get_run_details(app_name)
181
 
        upload_json_details(run_details, app_details[app_name])
 
187
        # upload_json_details(run_details, app_details[app_name])
 
188
 
 
189
    # Write single large json blob to file.
182
190
 
183
191
 
184
192
if __name__ == '__main__':