-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo.py
executable file
·797 lines (734 loc) · 28.2 KB
/
go.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
#!/usr/bin/python
#=====imports=====#
import common
import os, platform, pprint, re, shutil, socket, subprocess, sys, time, webbrowser
#=====globals=====#
import random, string
stamp=''.join(random.choice(string.ascii_lowercase) for i in range(16))
try: input=raw_input
except: pass
start=os.getcwd()
folder=os.path.split(os.path.realpath(__file__))[0]
os.chdir(folder)
megatron_master_path=os.path.join('megatron', 'master')
megatron_slave_path=os.path.join('megatron', 'slave')
devastator_master_path=os.path.join('devastator', 'master')
devastator_slave_path=os.path.join('devastator', 'slave')
#=====cybertron=====#
class Cybertron:
def __init__(self): self.contents=None
def __getitem__(self, key):
self._load()
return self.contents[key]
def __contains__(self, key):
self._load()
return key in self.contents
def items(self):
self._load()
return self.contents.items()
def descend(self, keys, default):
self._load()
x=self.contents
for key in keys:
if key in x: x=x[key]
else: return default
return x
def _load(self):
if not self.contents: self.contents=common.cybertron()
cybertron=Cybertron()
def cybertron_store_folder(cybertron_folder):
with open(os.path.join(folder, 'cybertron.txt'), 'w') as file:
file.write(os.path.realpath(cybertron_folder))
#=====helpers=====#
def timestamp():
import datetime
return '{:%Y-%m-%d %H:%M:%S.%f}'.format(datetime.datetime.now())
def invoke(invocation, async=False, path='.', fail_ok=False, capture=False):
start=os.getcwd()
os.chdir(path)
print(timestamp())
print('invoking{}{}: {}'.format(
' async' if async else '',
' fail-ok' if fail_ok else '',
invocation
))
print('in: '+os.getcwd())
try:
if capture:
if async: raise Exception("can't respect async and capture simultaneously")
p=subprocess.Popen(invocation, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
p.wait()
r=(p.returncode, p.stdout.read().decode('utf-8'))
if r[0]: raise subprocess.CalledProcessError(r[0], invocation)
else:
r=(subprocess.Popen if async else subprocess.check_call)(
invocation, shell=True
)
except:
if fail_ok: r=None
else: raise
os.chdir(start)
return r
def retry(f):
i=0
while True:
try: return f()
except:
i+=1
time.sleep(2)
if i>=15: raise
def check_port_closed(port):
return socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('localhost', port))
def assert_ports_clean():
for i, j in cybertron.items():
if i.endswith('_port'):
if not check_port_closed(j):
raise Exception('port {} is not closed'.format(j))
def log(system, content):
if os.environ.get('CONSTRUCTICON_DEBUG_'+system.upper(), None)=='1':
print('{} {}: {}'.format(timestamp(), system, content))
#=====forcer=====#
if sys.version_info[0]==2:
from cookielib import CookieJar
from urllib2 import Request
from urllib2 import build_opener
from urllib2 import HTTPCookieProcessor
from urllib import urlopen
from urllib import urlencode
else:
from http.cookiejar import CookieJar
from urllib.request import Request
from urllib.request import build_opener
from urllib.request import HTTPCookieProcessor
from urllib.request import urlopen
from urllib.parse import urlencode
class Forcer:
def __init__(self, server, port, builder, user=None, password=None):
self.master='http://{}:{}'.format(server, port)
self.builder=builder
if user:
self.url_opener=build_opener(HTTPCookieProcessor(CookieJar()))
r=str(self._request('{}/login'.format(self.master), {'username': user, 'passwd': password}).read())
if 'The username or password you entered were not correct' in r:
raise Exception('invalid login')
else:
self.url_opener=build_opener()
self.parameters=self.get_parameters()
def get_parameters(self, build=None):
result={}
#get required parameters
response=self._request('{}/builders/{}'.format(self.master, self.builder), {})
for line in response:
line=str(line)
if '<input' in line:
m=re.search(r"type='([^']*)'.*name='([^']*)'[\s]*value='([^']*)'[\s]*((?:checked)?)", line)
if m and (m.group(1)!='checkbox' or m.group(4)): result[m.group(2)]=m.group(3)
#get parameters from previous build request
if build!=None:
root=self.json_request(build)
for i in root['properties']:
if i[0] in result:
result[i[0]]=i[1]
if i[0]=='got_revision':
for repo, commit in i[1].items():
result['{}_revision'.format(repo)]=commit
result['{}_branch'.format(repo)]=''
for i in root['sourceStamps']:
result['{}_repository'.format(i['codebase'])]=i['repository']
#
return result
def force(self, parameters={}, dry=False):
self.requested_build=None
self.url=None
self.parameters.update(parameters)
self.parameters['reason']=self.parameters.get('reason', '')+'--'+stamp
self.force_url='{}/builders/{}/force'.format(self.master, self.builder)
print('{} forcing build, url: {}'.format(timestamp(), self.force_url))
if dry:
print('parameters')
pprint.pprint(self.parameters)
else:
r=self._request(self.force_url, self.parameters)
for line in r:
line=str(line)
if 'alert' in line:
raise Exception('invalid arguments\n{}\n{}'.format(self.force_url, self.parameters))
if 'Authorization Failed' in line:
raise Exception('authorization failed')
def wait(self, period=1):
while(True):
if self.get_progress()[0]: break
time.sleep(period)
def wait_all(self, period=1):
while self.json_request_generic('')['builders'][self.builder]['state']!='idle': time.sleep(period)
def get_progress(self):
if not self.requested_build:
root=self.json_request(-1)
if stamp in root['reason']:
self.requested_build=root['number']
self.url='{}/builders/{}/builds/{}'.format(self.master, self.builder, root['number'])
else: return (False, 'not started')
else:
root=self.json_request(self.requested_build)
if root['results']==None: return (False, 'started')
return (True, root['results'])
def get_url(self):
if not self.url: self.get_progress()
if self.url: return self.url
return 'no url, force url was: {}'.format(self.force_url)
def json_request_generic(self, suffix):
import json
try:
url='{}/json/{}'.format(self.master, suffix)
log('url', url)
result=retry(lambda: json.loads(urlopen(url).read().decode('utf-8')))
except:
import pdb; pdb.set_trace()
return result
def json_request(self, build):
return self.json_request_generic('builders/{}/builds/{}'.format(self.builder, build))
def request(self, suffix):
url='{}/{}'.format(self.master, suffix)
log('url', url)
return retry(lambda: urlopen(url).read().decode('utf-8'))
def _request(self, url, data):
headers={'Referer': '{}/builders/{}'.format(self.master, self.builder)}
request=Request(url, urlencode(data).encode('utf-8'), headers)
log('url', url)
return retry(lambda: self.url_opener.open(request))
#=====subfunctions=====#
def m1(args):
cybertron_store_folder(args.cybertron_folder)
if not args.slave_only:
invoke('buildbot --verbose create-master -r {}'.format(megatron_master_path))
restart_args=[]
if args.foreground: restart_args.append('--nodaemon')
restart_args.append(megatron_master_path)
invoke('buildbot --verbose restart '+' '.join(restart_args))
if not args.master_only:
invoke('buildslave --verbose create-slave {} localhost:{} megatron-slave {}'.format(
megatron_slave_path,
cybertron['megatron_slave_port'],
common.password
))
invoke('buildslave --verbose restart {}'.format(megatron_slave_path))
def m0(args):
if os.path.exists(os.path.join(megatron_master_path, 'buildbot.tac')):
invoke('buildbot --verbose stop {}'.format(megatron_master_path))
if os.path.exists(os.path.join(megatron_slave_path, 'buildbot.tac')):
invoke('buildslave --verbose stop {}'.format(megatron_slave_path))
if os.path.exists(os.path.join(devastator_master_path, 'buildbot.tac')):
invoke('buildbot --verbose stop {}'.format(devastator_master_path))
def mb(args):
webbrowser.open('http://localhost:{}'.format(cybertron['megatron_master_port']))
def mc(args):
invoke('buildbot checkconfig {}'.format(megatron_master_path))
def d1(args):
cybertron_store_folder(args.cybertron_folder)
if not os.path.exists(devastator_slave_path): os.makedirs(devastator_slave_path)
path=os.path.join(devastator_slave_path, args.devastator_slave_name)
tac=os.path.join(path, 'buildbot.tac')
if os.path.exists(tac):
invoke('buildslave --verbose stop {}'.format(path))
os.remove(tac)
invoke('buildslave --verbose create-slave -r {} {}:{} {} {}'.format(
path,
cybertron['megatron_hostname'],
cybertron['devastator_slave_port'],
args.devastator_slave_name,
common.password
))
with open(os.path.join(path, 'info', 'host'), 'w') as file:
file.write(socket.gethostbyname(socket.gethostname()))
invoke('buildslave --verbose restart {}'.format(path))
def d0(args):
if os.path.exists(devastator_slave_path):
os.chdir(devastator_slave_path)
import glob
for i in glob.glob('*'):
invoke('buildslave --verbose stop {}'.format(i))
def dr(args):
os.chdir(os.path.join('devastator', 'master'))
#create if necessary
if not os.path.exists('buildbot.tac'): invoke('buildbot create-master -r')
#start making invocation
invocation=['buildbot']
#figure out if master is running
s=socket.socket()
r=s.connect_ex(('localhost', cybertron['devastator_master_port']))
s.close()
#restart if necessary
invocation.append('reconfig' if r==0 else 'restart')
#on Windows, work around daemon problems
if platform.system()=='Windows': invocation.append('--nodaemon')
#
invoke(' '.join(invocation))
def df(args):
os.chdir(devastator_master_path)
import SimpleHTTPServer, SocketServer
SocketServer.TCPServer(
('', cybertron['devastator_file_server_port']),
SimpleHTTPServer.SimpleHTTPRequestHandler
).serve_forever()
def db(args):
webbrowser.open('http://localhost:{}'.format(cybertron['devastator_master_port']))
getmailrc_format='''
[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmail.com
username = {}
port = 995
password = {}
[destination]
type = Maildir
path = email/maildir/
[options]
read_all = false
'''
def mail(args):
def mkdir(*args):
path=os.path.join(*args)
if os.path.exists(path): return
os.makedirs(path)
mkdir('email', 'config')
with open(os.path.join('email', 'config', 'getmailrc'), 'w') as file:
file.write(getmailrc_format.format(
cybertron['email_username'], cybertron['email_password'])
)
for i in ['new', 'tmp', 'cur']: mkdir('email', 'maildir', i)
while True:
try: invoke('python '+os.path.join('email', 'getmail', 'getmail')+' --getmaildir email/config')
except Exception as e:
print(timestamp())
import traceback
traceback.print_exc(file=sys.stdout)
print(timestamp()+' sleeping')
time.sleep(30)
def check(args):
cybertron_store_folder(args.cybertron_folder)
sys.path.append('devastator')
import construct
construct.run([args.path])
def f(args):
port=cybertron['megatron_master_port' if args.megatron else 'devastator_master_port']
forcer=Forcer(cybertron['megatron_hostname'], port, args.builder)
forcer.force(parameters=dict(zip(args.key, args.value)))
def g(args):
print('getting')
#repos
print('getting repos')
folders=os.listdir(os.path.join(start, '..'))
def clean():
if not args.dont_destroy and not int(os.environ.get('CONSTRUCTICON_UNCLEAN', 0)):
invoke('git clean -ffxd')
os.chdir(start)
clean()
processed={os.path.split(start)[1]}
expected={}
def recurse(root, builder):
x=common.constructicon(root)['builders']
if builder not in x:
print('available builders are')
pprint.pprint(x.keys())
raise Exception('nonexistent builder')
builder=x[builder]
try: base=cybertron.descend(['builder_base', 'deps'], [])
except: base=[]
for dep in builder.get('deps', [])+base:
os.chdir(os.path.join(start, '..'))
if type(dep)==str: dep={'url': dep}
repo_folder=dep['url'].split('/')[-1]
if repo_folder.endswith('.git'): repo_folder=repo_folder[:-4]
if repo_folder in processed: continue
#clone or establish sanity and fetch
if not os.path.exists(repo_folder):
invoke('git clone '+dep['url'])
os.chdir(repo_folder)
else:
os.chdir(repo_folder)
a=os.path.realpath(invoke('git rev-parse --show-toplevel', capture=True)[1].strip())
b=os.path.realpath('.')
if a!=b: raise Exception((
'repo root is unequal to current working directory\n'
'repo root : "{}"\n'
'current working directory: "{}"\n'
).format(a, b))
invoke('git remote add origin '+dep['url'], fail_ok=True)
invoke('git remote set-url origin '+dep['url'])
invoke('git fetch')
#get the specified state
revision=dep.get('revision', 'master')
def split(x):
x=x.split(':')
return (':'.join(x[:-1]), x[-1])
override=[i for i in args.revision if split(i)[0] in dep['url']]
if len(override): revision=split(override[0])[1]
try:
if invoke('git rev-parse {}'.format(revision), capture=True)[1].strip()==revision:#raises exception if revision doesn't exist => not a commit hash
pass#revision is a commit hash, it's good how it is
else:#revision isn't a commit hash
raise Exception()#I want to treat this branch the same as the exception handler, but can't think of a cleaner way
except:
revision='origin/'+revision
if not args.dont_destroy:
invoke('git checkout '+revision)
invoke('git reset --hard HEAD', fail_ok=True)
clean()
assert not common.git_state_has_diff()
else:
invoke('git rebase', fail_ok=True)
expected[os.getcwd()]=invoke('git rev-parse {}'.format(revision), capture=True)[1].strip()
#recurse
processed.add(repo_folder)
if 'builder' in dep:
recurse(os.path.join(start, '..', repo_folder), dep['builder'])
if args.builder=='.':
for builder in common.constructicon(start)['builders']:
recurse(start, builder)
else:
recurse(start, args.builder)
os.chdir(start)
for i in folders:
if i not in processed:
x=os.path.join('..', i)
if args.dont_destroy:
print('extra: '+x)
else:
print('removing '+x)
if os.path.isfile(x): os.remove(x)
else:
last=None
import errno, stat
while True:
try: shutil.rmtree(x)
except WindowsError as e:
if e.errno==errno.EACCES and e.winerror==5 and e.filename!=last:
os.chmod(e.filename, stat.S_IWUSR)
last=e.filename
continue
raise
break
print('got repos')
for i in sorted(list(processed)):
os.chdir(os.path.join(start, '..', i))
unexpected=''
git_state=common.git_state()
if args.dont_destroy:
if os.getcwd() in expected:
expected_revision=expected[os.getcwd()]
actual_revision=git_state.split()[0]
if actual_revision!=expected_revision: unexpected=', expected '+expected_revision
else:
assert os.getcwd()==start
print('{}: {}{}'.format(i, git_state, unexpected))
os.chdir(start)
#products
print('getting products')
if args.builder=='.':
requirements={}
for _, builder in common.constructicon(start)['builders'].items():
requirements.update(builder.get('get', {}))
else:
builder=common.constructicon(start)['builders'][args.builder]
requirements=builder.get('get', {})
for builder, values in requirements.items():
#get builds from builder
forcer=Forcer(
cybertron['megatron_hostname'],
cybertron['devastator_master_port'],
builder,
)
builds=[i[1] for i in forcer.json_request('_all').items()]
#find build with max value
def calculate_value(build):
try: return [eval(value) for value in values]
except: return []
best_build=max(builds, key=lambda build: calculate_value(build))
assert calculate_value(best_build)!=[], 'no appropriate build!'
#download
downloads={}
for step in best_build['steps']: downloads.update(step.get('urls', {}))
for destination, url in downloads.items():
destination=os.path.join(start, '..', builder, destination)
x=os.path.split(destination)[0]
if not os.path.exists(x): os.makedirs(x)
log('url', url)
with open(destination, 'w') as file:
print('{} --> {}'.format(url, destination))
file.write(retry(lambda: urlopen(url).read()))
def help_cckl(args):
with open(os.path.join(folder, 'devastator', 'template', 'main.py')) as file: contents=file.read()
import ast, collections
d=lambda: collections.defaultdict(list)
key_listing={
'get_cybertron_spec' : (d(), "cybertron['{}']"),
'get_builder_base_spec' : (d(), "cybertron['builder_base']['{}']"),
'get_constructicon_spec': (d(), "constructicon['{}']"),
'get_spec' : (d(), "constructicon['builders'][builder]['{}']"),
'get_scheduler_spec' : (d(), "constructicon['schedulers'][scheduler]['{}']"),
}
for line in contents.splitlines():
if re.search('get_.*spec', line.strip()):
try: key=re.search(r"get_.*spec\([^']*'([^']+)'", line).group(1)
except: continue
for function, (keys, _) in key_listing.items():
if function in line:
keys[key]
break
else: assert(False)
m=re.search(r'#-\[(.*)\] ([^ ]+) (.*)', line)
if m:
contexts, key, note=m.groups()
contexts=contexts.split()
for context in contexts: key_listing[context][0][key].append(note)
def find_matching_parentheses(text):
n=0
for i in range(len(text)):
if text[i]=='(':
n+=1
elif text[i]==')':
n-=1
if n==0: return i
errors=d()
for m in re.finditer(r'check\(', contents):
close_paren_index=find_matching_parentheses(contents[m.start():])
args=ast.parse(contents[m.start():m.start()+close_paren_index+1]).body[0].value.args
try: errors[args[1].s]+=[i.elts[1].s for i in args[2].elts]
except: pass
for _, (keys, format) in sorted(key_listing.items()):
for key, notes in sorted(keys.items()):
print(format.format(key))
for note in notes: print('\t'+note)
for error in errors.get(key, []): print('\tpotential error: '+error)
def example(args):
cybertron_store_folder(folder)
global cybertron
assert_ports_clean()
print("When you hit enter, I'll start a megatron and open a browser to it.")
print("Wait for the megatron master to start.")
print("When it has, request a build with repo URL set to https://github.com/dansgithubuser/constructicon")
print("This will construct a constructicon for this repo.")
print("When you're done that, hit enter again.")
input()
invoke('python go.py m1 {}'.format(folder))
webbrowser.open('http://localhost:{}/builders/megatron-builder'.format(cybertron['megatron_master_port']))
input()
print("Now, when you hit enter, I'll open a browser to a constructicon builder we just made.")
print("I'll also start a devastator slave.")
print("Wait for the devastator slave to connect.")
print("Request a build from the constructicon builder, and it should print out this script's help.")
print("When you're done that, hit enter again.")
input()
webbrowser.open('http://localhost:{}/builders/constructicon-basic'.format(cybertron['devastator_master_port']))
invoke('python go.py d1 slave-1 {}'.format(folder))
input()
print("At the end of that build you just requested,")
print("a build result was uploaded from the devastator slave to the devastator master.")
print("To allow users to access this file, I'll start a devastator file server.")
print("When you're done checking that out, hit enter again to clean up and quit.")
input()
f=invoke('python go.py df'.format(folder), async=True)
input()
f.kill()
invoke('python go.py m0')
invoke('python go.py d0')
def expect(condition, description, information=None):
if not condition:
print('condition failed: '+description)
if information: print(information)
assert(False)
def test(args):
class TestLogger:
def enter_test(self, test):
self.test=test
self.section=''
self.log('=')
def enter_section(self, section):
self.section=section
self.log('-')
def log(self, separator):
x=self.test
if self.section: x+=' -- '+self.section
print(timestamp()+' '+separator*10+' '+x+' '+separator*10)
tl=TestLogger()
cybertron_store_folder(folder)
#setup
tl.enter_test('setup')
print('stamp is {}'.format(stamp))
tl.enter_section('freshen')
invoke('python go.py m0')
invoke('python go.py d0')
assert_ports_clean()
time.sleep(1)
tl.enter_section('start megatron')
invoke('python go.py m1 {}'.format(folder))
m_forcer=Forcer('localhost', cybertron['megatron_master_port'], 'megatron-builder')
tl.enter_section('start devastator master')
m_forcer.force({'constructicon_repo_url': 'https://github.com/dansgithubuser/constructicon', 'reason': 'test setup'})
m_forcer.wait()
r=m_forcer.json_request(-1)
expect(r['results']==0, 'setup - megatron build succeeded')
tl.enter_section('start devastator slave')
invoke('python go.py d1 slave-1 {}'.format(folder))
basic_forcer=Forcer('localhost', cybertron['devastator_master_port'], 'constructicon-basic')
#test
if re.match(args.regex, 'reconfig'):
tl.enter_test('reconfig')
#
tl.enter_section('modify constructicon.py')
constructicon=common.constructicon(folder)
constructicon['builders']['sleep']['commands'].append('python -c "import time; time.sleep(1)"')
os.chdir(os.path.join('devastator', 'constructicons', 'constructicon'))
with open('constructicon.py', 'w') as file:
file.write('constructicon='+pprint.pformat(constructicon))
invoke('git add -u :/')
invoke('git commit -m "test reconfig"')
os.chdir(folder)
#
tl.enter_section('request original build')
sleep_forcer=Forcer('localhost', cybertron['devastator_master_port'], 'constructicon-sleep')
sleep_forcer.force({'reason': 'test reconfig original'})
#
tl.enter_section('reconfig')
m_forcer.force({'constructicon_repo_url': '', 'reason': 'test reconfig reconfig'})
m_forcer.wait()
#
tl.enter_section('request reconfigged build')
sleep_forcer.force({'reason': 'test reconfig reconfigged'})
tl.enter_section('wait for builds')
sleep_forcer.wait_all()
#
tl.enter_section('check stuff')
r2=sleep_forcer.json_request(-2)
r1=sleep_forcer.json_request(-1)
expect(stamp in r1['reason'], 'reconfig - reconfigged build happened', pprint.pformat(r1))
expect(r1['results']==0, 'reconfig - reconfigged build succeeded', pprint.pformat(r1))
expect(stamp in r2['reason'], 'reconfig - original build happened', pprint.pformat(r2))
expect(r2['results']==0, 'reconfig - original build succeeded', pprint.pformat(r2))
expect(len(r1['steps'])==len(r2['steps'])+1, 'reconfig - reconfigged build had an extra step', pprint.pformat(r1)+'\n\n'+pprint.pformat(r2))
if re.match(args.regex, 'user-slave'):
tl.enter_test('user-slave')
invoke('python go.py d1 constructicon-user-slave-1 {}'.format(folder))
r=basic_forcer.json_request_generic('')
expect(r['slaves']['constructicon-user-slave-1']['connected'], 'user-slave - user slave connected to devastator', pprint.pformat(r))
if re.match(args.regex, 'builder-base'):
tl.enter_test('builder-base')
#
tl.enter_section('builder')
r=basic_forcer.json_request_generic('')['builders']['constructicon-basic']
#features
expect('slave-bad' not in r['slaves'], 'no bad slave', pprint.pformat(r))
expect('user-slave-bad' not in r['slaves'], 'no bad user slave', pprint.pformat(r))
#schedulers
expect('constructicon-force-cybertron' in r['schedulers'], 'builder_base force scheduler', pprint.pformat(r))
expect('constructicon-commit-cybertron' in r['schedulers'], 'builder_base commit scheduler', pprint.pformat(r))
#
tl.enter_section('build')
basic_forcer.force({'reason': 'test builder-base'})
basic_forcer.wait()
r=basic_forcer.json_request(-1)
#deps
logs_url=[i for i in r['steps'] if i['name']=='get'][0]['logs'][0][1]#this points to localhost:8080, not sure why
logs=basic_forcer.request(re.search('builders.*', logs_url).group(0))
got_repos=False
good=False
for line in logs.splitlines():
if line=='got repos': got_repos=True
if got_repos and 'crangen' in line: good=True; break
expect(good, 'builder_base dep', logs)
#precommands
expect(any([any(['cybertron precommand' in i['name']]) for i in r['steps']]), 'builder_base precommand', pprint.pformat(r))
#commands
expect(any([any(['cybertron command' in i['name']]) for i in r['steps']]), 'builder_base command', pprint.pformat(r))
#upload
expect(any(['upload' in i['name'] for i in r['steps']]), 'builder_base upload', pprint.pformat(r))
#teardown
invoke('python go.py m0')
invoke('python go.py d0')
def c(args):
cans={
't': ['test', '.*'],
}
if args.name not in cans or args.name=='h':
print('available cans:')
pprint.pprint(cans)
else: subprocess.check_call(['python', 'go.py']+cans[args.name])
#=====args=====#
import argparse
parser=argparse.ArgumentParser()
subparsers=parser.add_subparsers()
#-----megatron-----#
#start
subparser=subparsers.add_parser('m1', help='megatron start')
subparser.set_defaults(func=m1)
subparser.add_argument('cybertron_folder', help='folder containing cybertron.py')
subparser.add_argument('--foreground', '-f', action='store_true')
subparser.add_argument('--master-only', '-m', action='store_true')
subparser.add_argument('--slave-only', '-s', action='store_true')
#stop
subparsers.add_parser('m0', help='megatron stop').set_defaults(func=m0)
#browser
subparser=subparsers.add_parser('mb', help='megatron master browser')
subparser.set_defaults(func=mb)
#check config
subparsers.add_parser('mc', help='megatron master check').set_defaults(func=mc)
#-----devastator-----#
#start
subparser=subparsers.add_parser('d1', help='devastator slave start')
subparser.set_defaults(func=d1)
subparser.add_argument('devastator_slave_name')
subparser.add_argument('cybertron_folder', help='folder containing cybertron.py')
#stop
subparsers.add_parser('d0', help='devastator slave stop').set_defaults(func=d0)
#recombobulate
subparsers.add_parser('dr', help='devastator master create/restart/reconfig -- usually called by megatron').set_defaults(func=dr)
#file server
subparsers.add_parser('df', help='devastator file server').set_defaults(func=df)
#browser
subparsers.add_parser('db', help='devastator master browser').set_defaults(func=db)
#-----mail-----#
subparsers.add_parser('mail', help='get mail for email-based on-commit scheduling').set_defaults(func=mail)
#-----check-----#
subparser=subparsers.add_parser('check', help='check a constructicon.py')
subparser.set_defaults(func=check)
subparser.add_argument('path', help='folder containing constructicon.py')
subparser.add_argument('cybertron_folder', help='folder containing cybertron.py')
#-----force-----#
subparser=subparsers.add_parser('f', help='force a build')
subparser.set_defaults(func=f)
subparser.add_argument('--megatron', '-m', action='store_true', help='force on megatron, default is devastator')
subparser.add_argument('--builder', '-b', default='megatron-builder', help='which builder to force, default is megatron-builder')
subparser.add_argument('--key' , '-k', nargs='+', default=[], help='parameter keys, there should be an equal number of values')
subparser.add_argument('--value', '-v', nargs='+', default=[], help='parameter values, there should be an equal number of keys')
#-----get-----#
subparser=subparsers.add_parser('g', help='get deps and build results specified by builder in constructicon.py, use . for all builders')
subparser.set_defaults(func=g, dont_destroy=False)
subparser.add_argument('builder', help='builder to get build results for')
subparser.add_argument('--revision', '-r', nargs='+', default=[], help='repo:revision pairs to override default with')
#-----get-human-----#
subparser=subparsers.add_parser('gh', help='like g, but without destroying any information')
subparser.set_defaults(func=g, dont_destroy=True, builder='.')
subparser.add_argument('--builder', help='builder to get build results for')
subparser.add_argument('--revision', '-r', nargs='+', default=[], help='repo:revision pairs to override default with')
#-----help-----#
subparsers.add_parser('help-cckl', help='constructicon configuration key listing').set_defaults(func=help_cckl)
#-----example-----#
subparsers.add_parser('example', help='run example').set_defaults(func=example)
#-----test-----#
subparser=subparsers.add_parser('test', help='run tests')
subparser.set_defaults(func=test)
subparser.add_argument('regex')
#-----canned commands-----#
subparser=subparsers.add_parser('c', help='canned commands')
subparser.add_argument('name')
subparser.set_defaults(func=c)
#=====main=====#
if __name__=='__main__':#useful for debugging
args=parser.parse_args()
if platform.system()=='Windows' and 'CONSTRUCTICON_UNPORTABLE' not in os.environ:
os.environ['PATH']=(
os.environ['PATH']+os.pathsep+
os.path.join(folder, 'buildslave-portable', 'App')+os.pathsep+
os.path.join(folder, 'buildslave-portable', 'App', 'Scripts')
)
args.func(args)