blob: 08c1ee923b94c0e50a84c423a00d1b2567b223a5 [file] [log] [blame]
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +01001#!/usr/bin/python
2
3from mixpanel import Mixpanel
Sapan Bhatia77f26672017-03-13 18:30:25 +01004import pdb
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +01005
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +01006import argparse
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +01007import sys
8import getpass
9import socket
10import subprocess
11import os
12
13from os.path import expanduser
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010014
15parse = argparse.ArgumentParser(description='Send CORD logs to mixpanel.')
16parse.add_argument('--corddir', dest='corddir', action='store',default=None, help='CORD Directory')
17parse.add_argument('--event', dest='event', action='store',default=None, help='Event Name')
18parse.add_argument('--finish', dest='finish', action='store_true',default=False, help='Finish')
19parse.add_argument('--status', dest='status', action='store',default=None, help='Exit status')
20
21args = parse.parse_args()
22
23corddir = expanduser(args.corddir)
Sapan Bhatia77f26672017-03-13 18:30:25 +010024build_version_file = '/tmp/cord-build'
25cord_version_file = '/tmp/cord-build-version'
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010026
Sapan Bhatiab734bca2017-03-20 07:55:10 +010027build_features = []
28
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010029try:
30 mp = Mixpanel("7d5ca3b3ff870dbeda89c9d5af59e9e9")
31 hostname = socket.gethostname()
32
33 context = {}
34 context['debian-version'] = open('/etc/debian_version').read().strip()
35
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010036 os.chdir(corddir+'/orchestration/xos')
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010037 p = subprocess.Popen(['git','rev-parse','HEAD'], stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE)
38
39 git_hash,err = p.communicate()
40
41 context['last-commit'] = git_hash
Sapan Bhatiab734bca2017-03-20 07:55:10 +010042 context['build-features'] = build_features
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010043
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010044 if (args.status):
45 context['status'] = args.status
46
47 config = open(corddir+'/build/config/cord_in_a_box.yml').read().splitlines()
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010048 for l in config:
49 if 'cord_profile:' in l:
50 context['profile'] = l.rstrip().rsplit(' ')[-1].replace("'","")
51
52 context['user'] = getpass.getuser()
53
54 name = ''
55 idx=0
56 lst = hostname.split('.')
57 lst.reverse()
58 for i in lst:
59 name='.'.join([name,i]).lstrip('.')
60
61 context['level-%d'%idx] = name
62 idx+=1
63
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010064 if (args.finish):
65 logfile = open(corddir+'/install.out').read().splitlines()
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010066 snapshot = logfile[-20:]
67 snapshot = filter(lambda x:x, snapshot)
68 context['snapshot'] = snapshot
69
70 try:
Sapan Bhatia77f26672017-03-13 18:30:25 +010071 build_id = open(build_version_file).read().rstrip()
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010072 except:
73 build_id = context['user'] + name
Sapan Bhatia77f26672017-03-13 18:30:25 +010074
75 # Figure out whether we're in master or what
76 try:
77 cord_version = open(cord_version_file).read().rstrip()
78 except:
79 os.chdir(corddir)
80 possible_versions = ['master','cord-1.0','cord-2.0']
81
82 cord_version = 'personal'
83 try:
84 for v in possible_versions:
85 diff = os.popen('repo forall -c "git stash 2>/dev/null 1>/dev/null;git diff -b opencord/%s 2>/dev/null;git stash pop 2>/dev/null 1>/dev/null"'%v).read()
86 if (not diff):
87 cord_version = v
88 break
89 except:
90 pass
91
92 open(cord_version_file,'w').write(cord_version)
93 context['version'] = cord_version
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010094 mp.track(build_id, args.event, context)
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010095except Exception,e:
96 print str(e)
97 pass