forked from Juniper/nita-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot.py
90 lines (81 loc) · 2.22 KB
/
robot.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
#!/usr/bin/python3
import yaml
import os
import sys
# insist on the user providing the name of the job
if len(sys.argv) < 2:
print("Must provide job name as the first argument")
sys.exit(1)
job_ansible = sys.argv[1]
# insist on the user providing the image name as the second argument
if len(sys.argv) < 3:
print("Must provide image name as the second argument")
sys.exit(1)
image_name = sys.argv[2]
if len(sys.argv) < 4:
print("Must provide job-robot name")
sys.exit(1)
job_robot = sys.argv[3]
if len (sys.argv) < 5:
print("Must provide ROBOT image name")
sys.exit(1)
robot_image = sys.argv[4]
# get path that is to be used inside the job for the working directory
path = os.getcwd()
job_1 = f"""apiVersion: batch/v1
kind: Job
metadata:
namespace: nita
name: {job_ansible}
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 120
template:
spec:
serviceAccountName: internal-jenknis-pod
containers:
- name: nita-ansible
image: {image_name}
workingDir: {path}
command: ["/bin/bash"]
args: ["-c", "bash test_setup.sh", "/tmp"]
volumeMounts:
- name: default
mountPath: /project/
volumes:
- name: default
hostPath:
path: /var/nita_project
restartPolicy: Never"""
with open(f'{job_ansible}.yaml', 'w') as file:
print(job_1, file=file)
job_2 = f"""apiVersion: batch/v1
kind: Job
metadata:
namespace: nita
name: {job_robot}
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 120
template:
spec:
serviceAccountName: internal-jenknis-pod
containers:
- name: nita-robot
image: {robot_image}
workingDir: {path}/test
command: ["/bin/bash"]
args: ["-c", "robot -C ansi -L TRACE {path}/test/tests"]
env:
- name: ROBOT_OPTIONS
value: "-d {path}/test/outputs"
volumeMounts:
- name: default
mountPath: /project/
volumes:
- name: default
hostPath:
path: /var/nita_project
restartPolicy: Never"""
with open(f'{job_robot}.yaml', 'w') as file:
print(job_2, file=file)