Skip to content

Commit e7b8d33

Browse files
committed
convert ci-kubernetes-e2e-cri-gce-flaky to start with
1 parent 744a22f commit e7b8d33

File tree

8 files changed

+1067
-82
lines changed

8 files changed

+1067
-82
lines changed

jenkins/bootstrap_test.py

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,14 +1238,20 @@ def Check(job, name):
12381238
Check, use_json=is_modern)
12391239

12401240
def testBootstrapCIYaml(self):
1241+
is_modern = lambda name: 'kubernetes-e2e-cri-gce-flaky' in name
12411242
def Check(job, name):
12421243
job_name = 'ci-%s' % name
12431244
self.assertIn('frequency', job)
12441245
self.assertIn('trigger-job', job)
12451246
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)
12461252
return job_name
12471253

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)
12491255

12501256
def testBootstrapCICommitYaml(self):
12511257
def Check(job, name):
@@ -1403,10 +1409,33 @@ def CheckBootstrapYaml(self, path, check, suffix='suffix', use_json=False):
14031409
self.assertTrue(job_name)
14041410
self.assertEquals(job_name, real_job.get('job-name'))
14051411

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+
14061434
def testValidTimeout(self):
14071435
"""All jobs set a timeout less than 120m or set DOCKER_TIMEOUT."""
14081436
default_timeout = int(re.search(r'\$\{DOCKER_TIMEOUT:-(\d+)m', open('%s/dockerized-e2e-runner.sh' % os.path.dirname(__file__)).read()).group(1))
14091437
bad_jobs = set()
1438+
14101439
for job, job_path in self.jobs:
14111440
valids = [
14121441
'kubernetes-e2e-',
@@ -1434,7 +1463,14 @@ def testValidTimeout(self):
14341463
if 'KUBEKINS_TIMEOUT=' not in line:
14351464
continue
14361465
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
14381474
self.assertTrue(mat, line)
14391475
if int(mat.group(1)) > docker_timeout:
14401476
bad_jobs.add(job)
@@ -1445,7 +1481,7 @@ def testOnlyJobs(self):
14451481
"""Ensure that everything in jobs/ is a valid job name and script."""
14461482
for job, job_path in self.jobs:
14471483
# 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)
14491485
# Jobs should point to a real, executable file
14501486
# Note: it is easy to forget to chmod +x
14511487
self.assertTrue(os.path.isfile(job_path), job_path)
@@ -1485,7 +1521,7 @@ def testAllProjectAreUnique(self):
14851521
job = job.replace('-test', '-*').replace('-deploy', '-*')
14861522
if job.startswith('ci-kubernetes-node-'):
14871523
job = 'ci-kubernetes-node-*'
1488-
if not line.startswith('#'):
1524+
if not line.startswith('#') and job.endswith('.sh'):
14891525
self.assertIn('export', line, line)
14901526
project = re.search(r'PROJECT="([^"]+)"', line).group(1)
14911527
projects[project].add(allowed_list.get(job, job))
@@ -1503,13 +1539,15 @@ def testJobsDoNotSourceShell(self):
15031539
self.assertNotIn('source ', script, job)
15041540
self.assertNotIn('\n. ', script, job)
15051541

1506-
def testAllJobsHaveErrExit(self):
1542+
def testAllBashJobsHaveErrExit(self):
15071543
options = {
15081544
'errexit',
15091545
'nounset',
15101546
'pipefail',
15111547
}
15121548
for job, job_path in self.jobs:
1549+
if not job.endswith('.sh'):
1550+
continue
15131551
with open(job_path) as fp:
15141552
lines = list(fp)
15151553
for option in options:
@@ -1518,6 +1556,22 @@ def testAllJobsHaveErrExit(self):
15181556
expected, lines,
15191557
'%s not found in %s' % (expected, job_path))
15201558

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+
15211575
def testNoBadVarsInJobs(self):
15221576
"""Searches for jobs that contain ${{VAR}}"""
15231577
for job, job_path in self.jobs:
@@ -1527,6 +1581,19 @@ def testNoBadVarsInJobs(self):
15271581
if bad_vars:
15281582
self.fail('Job %s contains bad bash variables: %s' % (job, ' '.join(bad_vars)))
15291583

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+
15301597

15311598
if __name__ == '__main__':
15321599
unittest.main()

0 commit comments

Comments
 (0)