Bug 1505086: move `verify_statedir` from telemetry submission script to `mozbuild.telemetry` r=ted
authorConnor Sheehan <sheehan@mozilla.com>
Mon, 12 Nov 2018 14:57:49 +0000
changeset 445884 12c35ad7e844ec1d1c555ef57acac71e5c97d656
parent 445883 7973a6c12bde2cc8262bc1462390e47ee0395835
child 445885 9a2f0d443bb1d94c38da120b790fcad6245b77d7
push id35028
push usercsabou@mozilla.com
push dateMon, 12 Nov 2018 21:54:15 +0000
treeherdermozilla-central@05331fb8f533 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1505086
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1505086: move `verify_statedir` from telemetry submission script to `mozbuild.telemetry` r=ted A subsequent commit will require similar logic to the checks found in this command. Moving to mozbuild will allow us to re-use the function instead of re-writing similar logic. Differential Revision: https://phabricator.services.mozilla.com/D11277
build/submit_telemetry_data.py
python/mozbuild/mozbuild/telemetry.py
--- a/build/submit_telemetry_data.py
+++ b/build/submit_telemetry_data.py
@@ -17,17 +17,20 @@ PYTHIRDPARTY = os.path.join(HERE, '..', 
 sys.path.append(os.path.join(HERE, '..', 'python', 'mozbuild', 'mozbuild'))
 sys.path.append(os.path.join(PYTHIRDPARTY, 'requests'))
 sys.path.append(os.path.join(PYTHIRDPARTY, 'voluptuous'))
 
 import requests
 import voluptuous
 import voluptuous.humanize
 
-from mozbuild.telemetry import schema as build_telemetry_schema
+from mozbuild.telemetry import (
+    schema as build_telemetry_schema,
+    verify_statedir,
+)
 
 BUILD_TELEMETRY_URL = 'https://incoming.telemetry.mozilla.org/{endpoint}'
 SUBMIT_ENDPOINT = 'submit/eng-workflow/build/1/{ping_uuid}'
 STATUS_ENDPOINT = 'status'
 
 
 def delete_expired_files(directory, days=30):
     '''Discards files in a directory older than a specified number
@@ -130,45 +133,16 @@ def submit_telemetry_data(outgoing, subm
                               'server: %s' % str(e))
                 break
 
     delete_expired_files(submitted)
 
     return 0
 
 
-def verify_statedir(statedir):
-    '''Verifies the statedir is structured according to the assumptions of
-    this script
-
-    Requires presence of the following directories; will raise if absent:
-    - statedir/telemetry
-    - statedir/telemetry/outgoing
-
-    Creates the following directories and files if absent (first submission):
-    - statedir/telemetry/submitted
-    '''
-
-    telemetry_dir = os.path.join(statedir, 'telemetry')
-    outgoing = os.path.join(telemetry_dir, 'outgoing')
-    submitted = os.path.join(telemetry_dir, 'submitted')
-    telemetry_log = os.path.join(telemetry_dir, 'telemetry.log')
-
-    if not os.path.isdir(telemetry_dir):
-        raise Exception('{} does not exist'.format(telemetry_dir))
-
-    if not os.path.isdir(outgoing):
-        raise Exception('{} does not exist'.format(outgoing))
-
-    if not os.path.isdir(submitted):
-        os.mkdir(submitted)
-
-    return outgoing, submitted, telemetry_log
-
-
 if __name__ == '__main__':
     if len(sys.argv) != 2:
         print('usage: python submit_telemetry_data.py <statedir>')
         sys.exit(1)
 
     statedir = sys.argv[1]
 
     try:
--- a/python/mozbuild/mozbuild/telemetry.py
+++ b/python/mozbuild/mozbuild/telemetry.py
@@ -273,8 +273,38 @@ def gather_telemetry(command='', success
         schema(data)
         return data
     except MultipleInvalid as exc:
         msg = ['Build telemetry is invalid:']
         for error in exc.errors:
             msg.append(str(error))
         print('\n'.join(msg) + '\n' + pprint.pformat(data))
     return None
+
+
+def verify_statedir(statedir):
+    '''
+    Verifies the statedir is structured correctly. Returns the outgoing,
+    submitted and log paths.
+
+    Requires presence of the following directories; will raise if absent:
+    - statedir/telemetry
+    - statedir/telemetry/outgoing
+
+    Creates the following directories and files if absent (first submission):
+    - statedir/telemetry/submitted
+    '''
+
+    telemetry_dir = os.path.join(statedir, 'telemetry')
+    outgoing = os.path.join(telemetry_dir, 'outgoing')
+    submitted = os.path.join(telemetry_dir, 'submitted')
+    telemetry_log = os.path.join(telemetry_dir, 'telemetry.log')
+
+    if not os.path.isdir(telemetry_dir):
+        raise Exception('{} does not exist'.format(telemetry_dir))
+
+    if not os.path.isdir(outgoing):
+        raise Exception('{} does not exist'.format(outgoing))
+
+    if not os.path.isdir(submitted):
+        os.mkdir(submitted)
+
+    return outgoing, submitted, telemetry_log