Merge lp:~canonical-platform-qa/ubuntu-test-cases/health-check_adding-nfss-file-generator-to-dep8 into lp:ubuntu-test-cases/touch

Proposed by Christopher Lee
Status: Merged
Merge reported by: Christopher Lee
Merged at revision: not available
Proposed branch: lp:~canonical-platform-qa/ubuntu-test-cases/health-check_adding-nfss-file-generator-to-dep8
Merge into: lp:ubuntu-test-cases/touch
Prerequisite: lp:~canonical-platform-qa/ubuntu-test-cases/healthcheck-to-dep8
Diff against target: 144 lines (+124/-0)
2 files modified
tests/health-check/debian/tests/health-check (+5/-0)
tests/health-check/generator-nfss-data-file.py (+119/-0)
To merge this branch: bzr merge lp:~canonical-platform-qa/ubuntu-test-cases/health-check_adding-nfss-file-generator-to-dep8
Reviewer Review Type Date Requested Status
Richard Huddie (community) Approve
Leo Arias (community) Approve
Allan LeSage (community) Approve
Review via email: mp+241478@code.launchpad.net

Commit message

Added a script that takes the results from this test and generates a nfss-data.json file.

Description of the change

Added a script that takes the results from this test and generates a nfss-data.json file.

Currently as there are no existing graphs for this data I just included everything from the resulting health-check result files and bring them into a single file.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

This looks good.
Just the same pita comment about using single quotes for strings.

You left this:
100 + import ipdb; ipdb.set_trace()

It would be nice if we find a way to run tests for these scripts. I think that's out of the scope of this sprint, and we won't have time anyway. Just something to think about, as I'm not sure it would make sense to add the scripts tests in the same place as the dep8 tests, and we don't have a make test step.

review: Needs Fixing
349. By Christopher Lee

Remove debugging statement

350. By Christopher Lee

Made use of single quotes consistent.

Revision history for this message
Richard Huddie (rhuddie) wrote :

Hi Chris,
I have updated my health-check-to-dep8 branch to move the debian files under tests/health-check/debian. So you will now need to re-apply your changes from debian/tests/health-check to tests/health-check/debian/tests/health-check.

Thanks.

review: Needs Fixing
351. By Christopher Lee

Undo changes for now

352. By Christopher Lee

Merge directory shuffle

353. By Christopher Lee

Re-introduce execution of nfss-gen script

354. By Christopher Lee

Write a different nfss data file if we're running on krillin

Revision history for this message
Allan LeSage (allanlesage) wrote :

These tests are still running on my mako but I was able to generate a large JSON file on the early output using veebers' script.

I have only teensy-minor comments here, balanced against our interest in landing this--you might add docstrings where they're missing, also maybe just use strip() instead of replace()? Approving nonetheless :) . . . .

review: Approve
355. By Christopher Lee

As per MP comment, clarify some code and docstrings

Revision history for this message
Leo Arias (elopio) :
review: Approve
Revision history for this message
Richard Huddie (rhuddie) :
review: Approve
Revision history for this message
Christopher Lee (veebers) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/health-check/debian/tests/health-check'
2--- tests/health-check/debian/tests/health-check 2014-11-13 03:56:24 +0000
3+++ tests/health-check/debian/tests/health-check 2014-11-13 03:56:24 +0000
4@@ -5,6 +5,7 @@
5 GET_PIDS_SCRIPT=$LOCAL_SCRIPT_DIR"health-check-test-get-pids.py"
6 RUN_PIDS_SCRIPT=$LOCAL_SCRIPT_DIR"health-check-test-run-pids.py"
7 TEST_PID_SCRIPT=$LOCAL_SCRIPT_DIR"health-check-test-pid.py"
8+NFSS_GENERATOR_SCRIPT=$LOCAL_SCRIPT_DIR"generator-nfss-data-file.py"
9 PROCMAP_FILE=$LOCAL_SCRIPT_DIR"procmapping.txt"
10 # generate the procmapping file and copy to logs
11 python3 $GET_PIDS_SCRIPT
12@@ -15,4 +16,8 @@
13 RC=$?
14 # copy json logs to artifacts dir
15 cp *.json $ADT_ARTIFACTS
16+
17+# This script will leave a nfss-data.json file in $ADT_ARTIFACTS
18+python3 $NFSS_GENERATOR_SCRIPT $ADT_ARTIFACTS
19+
20 exit $RC
21
22=== added file 'tests/health-check/generator-nfss-data-file.py'
23--- tests/health-check/generator-nfss-data-file.py 1970-01-01 00:00:00 +0000
24+++ tests/health-check/generator-nfss-data-file.py 2014-11-13 03:56:24 +0000
25@@ -0,0 +1,119 @@
26+#!/usr/bin/python3
27+
28+"""This script takes all the resulting json files from the health-check run and
29+creates a single data file that can be uploaded to nfss.
30+
31+This script takes 1 argument which is the source (which will also be the
32+destination) directory in which to find all the .json files to process.
33+
34+The resulting output of this script will look like:
35+
36+[
37+ {
38+ project: 'health-check',
39+ test: '<process-name of pid from file 1>',
40+ data: { <contents of json file> }
41+ },
42+ {
43+ project: 'health-check',
44+ test: '<process-name of pid from file 2>',
45+ data: { <contents of json file> }
46+ },
47+ ... and so on ...
48+]
49+
50+"""
51+import json
52+import os
53+import psutil
54+import re
55+import sys
56+import subprocess
57+from glob import glob
58+
59+
60+def usage():
61+ print('{} <source file path containing .json files>'.format(sys.argv[0]))
62+
63+
64+def write_data_to_file(destination_path, run_data):
65+ if device_is_krillin():
66+ data_file_name = 'private-nfss-data.json'
67+ else:
68+ data_file_name = 'nfss-data.json'
69+
70+ file_output = os.path.join(destination_path, data_file_name)
71+ print('Writing results to %s' % (file_output))
72+ with open(file_output, 'w') as f:
73+ json.dump(run_data, f)
74+
75+
76+def device_is_krillin():
77+ """Returns True if the device executing this code is a Krillin."""
78+ try:
79+ prop_output = subprocess.check_output(
80+ ['getprop', 'ro.product.device'],
81+ universal_newlines=True
82+ ).strip('\n')
83+ return prop_output == 'krillin'
84+ except FileNotFoundError:
85+ return False
86+
87+ return False
88+
89+
90+def _get_process_name_from_filename(filename):
91+ """Given a file, determine the process name from it.
92+
93+ The file should be in the format health-check-xxx.json where xxx is a pid.
94+
95+ Returns process name for the pid contained within the filename.
96+ Returns the string "UNKNOWN PROCESS" if we fail to find the running pid.
97+
98+ """
99+ pid_search = re.search(
100+ 'health-check-([0-9]*)\.json',
101+ filename
102+ )
103+
104+ try:
105+ pid = pid_search.group(1)
106+ p = psutil.Process(int(pid))
107+ return p.name()
108+ except (IndexError, psutil.NoSuchProcess):
109+ print("PID %s no longer exists" % pid)
110+ return 'UNKNOWN PROCESS'
111+
112+
113+def main(source_path):
114+ """Goes through all sub directories in *source_path* generating json
115+ results from the results there and writing them all to a single file to be
116+ uploaded to the nfss backend.
117+
118+ """
119+ all_tests_data = []
120+
121+ file_name_pattern = os.path.join(source_path, 'health-check-*.json')
122+ all_data_files = glob(file_name_pattern)
123+ for json_file in all_data_files:
124+ with open(json_file, 'r') as f:
125+ process_name = _get_process_name_from_filename(json_file)
126+ json_data = json.load(f)
127+
128+ all_tests_data.append(dict(
129+ project='health-check',
130+ test=process_name,
131+ data=json_data
132+ ))
133+
134+ write_data_to_file(source_path, all_tests_data)
135+
136+
137+if __name__ == '__main__':
138+ try:
139+ source_path = sys.argv[1]
140+ except IndexError:
141+ usage()
142+ exit(1)
143+
144+ main(source_path)

Subscribers

People subscribed via source and target branches