@@ -1238,14 +1238,20 @@ def Check(job, name):
1238
1238
Check , use_json = is_modern )
1239
1239
1240
1240
def testBootstrapCIYaml (self ):
1241
+ is_modern = lambda name : 'kubernetes-e2e-cri-gce-flaky' in name
1241
1242
def Check (job , name ):
1242
1243
job_name = 'ci-%s' % name
1243
1244
self .assertIn ('frequency' , job )
1244
1245
self .assertIn ('trigger-job' , job )
1245
1246
self .assertNotIn ('branch' , job )
1247
+ self .assertIn ('json' , job )
1248
+ modern = is_modern (name )
1249
+ self .assertEquals (modern , job ['json' ])
1250
+ if is_modern (name ):
1251
+ self .assertGreater (job ['timeout' ], 0 )
1246
1252
return job_name
1247
1253
1248
- self .CheckBootstrapYaml ('job-configs/kubernetes-jenkins/bootstrap-ci.yaml' , Check )
1254
+ self .CheckBootstrapYaml ('job-configs/kubernetes-jenkins/bootstrap-ci.yaml' , Check , use_json = is_modern )
1249
1255
1250
1256
def testBootstrapCICommitYaml (self ):
1251
1257
def Check (job , name ):
@@ -1403,10 +1409,33 @@ def CheckBootstrapYaml(self, path, check, suffix='suffix', use_json=False):
1403
1409
self .assertTrue (job_name )
1404
1410
self .assertEquals (job_name , real_job .get ('job-name' ))
1405
1411
1412
+ def GetRealBootstrapJob (self , path , job ):
1413
+ with open (os .path .join (
1414
+ os .path .dirname (__file__ ), path )) as fp :
1415
+ doc = yaml .safe_load (fp )
1416
+
1417
+ project = None
1418
+ for item in doc :
1419
+ if not isinstance (item , dict ):
1420
+ continue
1421
+ if not isinstance (item .get ('project' ), dict ):
1422
+ continue
1423
+ project = item ['project' ]
1424
+ break
1425
+
1426
+ jobs = project .get ('suffix' )
1427
+
1428
+ for realjob in jobs :
1429
+ # cut ci- and .(env|sh)
1430
+ key = os .path .splitext (job .strip ())[0 ][3 :]
1431
+ if realjob .keys ()[0 ] == key :
1432
+ return realjob [key ]
1433
+
1406
1434
def testValidTimeout (self ):
1407
1435
"""All jobs set a timeout less than 120m or set DOCKER_TIMEOUT."""
1408
1436
default_timeout = int (re .search (r'\$\{DOCKER_TIMEOUT:-(\d+)m' , open ('%s/dockerized-e2e-runner.sh' % os .path .dirname (__file__ )).read ()).group (1 ))
1409
1437
bad_jobs = set ()
1438
+
1410
1439
for job , job_path in self .jobs :
1411
1440
valids = [
1412
1441
'kubernetes-e2e-' ,
@@ -1434,7 +1463,14 @@ def testValidTimeout(self):
1434
1463
if 'KUBEKINS_TIMEOUT=' not in line :
1435
1464
continue
1436
1465
found_timeout = True
1437
- mat = re .match (r'export KUBEKINS_TIMEOUT="(\d+)m".*' , line )
1466
+ if job .endswith ('.sh' ):
1467
+ mat = re .match (r'export KUBEKINS_TIMEOUT="(\d+)m".*' , line )
1468
+ else :
1469
+ mat = re .match (r'KUBEKINS_TIMEOUT="(\d+)m".*' , line )
1470
+ realjob = self .GetRealBootstrapJob ('job-configs/kubernetes-jenkins/bootstrap-ci.yaml' , job )
1471
+ self .assertTrue (realjob )
1472
+ docker_timeout = realjob ['timeout' ]
1473
+ print docker_timeout
1438
1474
self .assertTrue (mat , line )
1439
1475
if int (mat .group (1 )) > docker_timeout :
1440
1476
bad_jobs .add (job )
@@ -1445,7 +1481,7 @@ def testOnlyJobs(self):
1445
1481
"""Ensure that everything in jobs/ is a valid job name and script."""
1446
1482
for job , job_path in self .jobs :
1447
1483
# Jobs should have simple names: letters, numbers, -, .
1448
- self .assertTrue (re .match (r'[.0-9a-z-_]+.sh ' , job ), job )
1484
+ self .assertTrue (re .match (r'[.0-9a-z-_]+.(sh|env) ' , job ), job )
1449
1485
# Jobs should point to a real, executable file
1450
1486
# Note: it is easy to forget to chmod +x
1451
1487
self .assertTrue (os .path .isfile (job_path ), job_path )
@@ -1485,7 +1521,7 @@ def testAllProjectAreUnique(self):
1485
1521
job = job .replace ('-test' , '-*' ).replace ('-deploy' , '-*' )
1486
1522
if job .startswith ('ci-kubernetes-node-' ):
1487
1523
job = 'ci-kubernetes-node-*'
1488
- if not line .startswith ('#' ):
1524
+ if not line .startswith ('#' ) and job . endswith ( '.sh' ) :
1489
1525
self .assertIn ('export' , line , line )
1490
1526
project = re .search (r'PROJECT="([^"]+)"' , line ).group (1 )
1491
1527
projects [project ].add (allowed_list .get (job , job ))
@@ -1503,13 +1539,15 @@ def testJobsDoNotSourceShell(self):
1503
1539
self .assertNotIn ('source ' , script , job )
1504
1540
self .assertNotIn ('\n . ' , script , job )
1505
1541
1506
- def testAllJobsHaveErrExit (self ):
1542
+ def testAllBashJobsHaveErrExit (self ):
1507
1543
options = {
1508
1544
'errexit' ,
1509
1545
'nounset' ,
1510
1546
'pipefail' ,
1511
1547
}
1512
1548
for job , job_path in self .jobs :
1549
+ if not job .endswith ('.sh' ):
1550
+ continue
1513
1551
with open (job_path ) as fp :
1514
1552
lines = list (fp )
1515
1553
for option in options :
@@ -1518,6 +1556,22 @@ def testAllJobsHaveErrExit(self):
1518
1556
expected , lines ,
1519
1557
'%s not found in %s' % (expected , job_path ))
1520
1558
1559
+ def testEnvsNoExport (self ):
1560
+ for job , job_path in self .jobs :
1561
+ if not job .endswith ('.env' ):
1562
+ continue
1563
+ with open (job_path ) as fp :
1564
+ lines = list (fp )
1565
+ prev = ''
1566
+ for line in lines :
1567
+ m = re .match (r'[0-9A-Z_]+=' , line )
1568
+ empty = (line .strip () == '' )
1569
+ comment = line .startswith ('#' )
1570
+ continuation = prev .strip ().endswith ('\\ ' )
1571
+ prev = line
1572
+ if not (m or empty or comment or continuation ):
1573
+ self .fail ('Job %s contains invalid env: %s' % (job , line ))
1574
+
1521
1575
def testNoBadVarsInJobs (self ):
1522
1576
"""Searches for jobs that contain ${{VAR}}"""
1523
1577
for job , job_path in self .jobs :
@@ -1527,6 +1581,19 @@ def testNoBadVarsInJobs(self):
1527
1581
if bad_vars :
1528
1582
self .fail ('Job %s contains bad bash variables: %s' % (job , ' ' .join (bad_vars )))
1529
1583
1584
+ def testValidJobEnvs (self ):
1585
+ """Validate jobs/config.json."""
1586
+ with open (bootstrap .test_infra ('jobs/config.json' )) as fp :
1587
+ config = json .loads (fp .read ())
1588
+ for job in config :
1589
+ self .assertTrue ('scenario' in config [job ], job )
1590
+ self .assertTrue (os .path .isfile (bootstrap .test_infra ('scenarios/%s.py' % config [job ]['scenario' ])), job )
1591
+ if 'args' in config [job ]:
1592
+ for arg in config [job ].get ('args' , []):
1593
+ m = re .match (r'(--env_file|--env_template)=([^\"]+)' , arg )
1594
+ if m :
1595
+ self .assertTrue (os .path .isfile (bootstrap .test_infra ('jobs/%s.env' % m .group (2 ))), job )
1596
+
1530
1597
1531
1598
if __name__ == '__main__' :
1532
1599
unittest .main ()
0 commit comments