blob: b9e9b4d1e4ed2d26b9e3610899dbe02a653a6cb0 [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
27try:
28 mp = Mixpanel("7d5ca3b3ff870dbeda89c9d5af59e9e9")
29 hostname = socket.gethostname()
30
31 context = {}
32 context['debian-version'] = open('/etc/debian_version').read().strip()
33
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010034 os.chdir(corddir+'/orchestration/xos')
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010035 p = subprocess.Popen(['git','rev-parse','HEAD'], stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE)
36
37 git_hash,err = p.communicate()
38
39 context['last-commit'] = git_hash
40
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010041 if (args.status):
42 context['status'] = args.status
43
44 config = open(corddir+'/build/config/cord_in_a_box.yml').read().splitlines()
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010045 for l in config:
46 if 'cord_profile:' in l:
47 context['profile'] = l.rstrip().rsplit(' ')[-1].replace("'","")
48
49 context['user'] = getpass.getuser()
50
51 name = ''
52 idx=0
53 lst = hostname.split('.')
54 lst.reverse()
55 for i in lst:
56 name='.'.join([name,i]).lstrip('.')
57
58 context['level-%d'%idx] = name
59 idx+=1
60
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010061 if (args.finish):
62 logfile = open(corddir+'/install.out').read().splitlines()
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010063 snapshot = logfile[-20:]
64 snapshot = filter(lambda x:x, snapshot)
65 context['snapshot'] = snapshot
66
67 try:
Sapan Bhatia77f26672017-03-13 18:30:25 +010068 build_id = open(build_version_file).read().rstrip()
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010069 except:
70 build_id = context['user'] + name
Sapan Bhatia77f26672017-03-13 18:30:25 +010071
72 # Figure out whether we're in master or what
73 try:
74 cord_version = open(cord_version_file).read().rstrip()
75 except:
76 os.chdir(corddir)
77 possible_versions = ['master','cord-1.0','cord-2.0']
78
79 cord_version = 'personal'
80 try:
81 for v in possible_versions:
82 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()
83 if (not diff):
84 cord_version = v
85 break
86 except:
87 pass
88
89 open(cord_version_file,'w').write(cord_version)
90 context['version'] = cord_version
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010091 mp.track(build_id, args.event, context)
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010092except Exception,e:
93 print str(e)
94 pass