forked from microsoft/lis-rpm-build-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 1
/
createrpms.py
executable file
·290 lines (236 loc) · 7.77 KB
/
createrpms.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
#
# Script to build RPM's using latest LIS code, it will build the RPM's and copy it to LISISO folder
# currently we have two source tree one for RHEL 5 and one for RHEL6
#
#
import os
import sys
import shutil
import subprocess
import datetime
homedir = os.getcwd()
directory = "lis-next"
if os.path.exists(directory):
shutil.rmtree(directory)
def run(cmd):
output = subprocess.call(cmd,shell=True)
return output
def updatebuildname(path, buildname):
regex='microsoft-hyper-v-kmod ='
file_list = []
linetosearch =[]
for file in os.listdir(path):
if file.endswith(".spec"):
file_list.append(file)
file_list = [path+list for list in file_list ]
for file in file_list:
with open(file, "r") as myfile:
for line in myfile :
if regex in line:
linetosearch = line.split(' ')
currentversion = linetosearch[-1].strip('\n')
cmdstring = "sed -i 's/%s/%s/g' %s" % (currentversion,buildname, file)
run(cmdstring)
def buildrhel5(branch, buildname,source):
os.makedirs(directory)
run("git clone "+source)
os.chdir(directory+"/hv-rhel5.x/")
run("git checkout "+ branch)
run("tar -cvzf lis-next-rh5.tar.gz hv")
shutil.copy("lis-next-rh5.tar.gz" , homedir+"/rh5/SOURCES/")
os.chdir(homedir)
shutil.rmtree(directory)
found = False
rhel5buildpath = homedir+"/rh5/pbuild"
rhel5specfiledpath = homedir+"/rh5/SPECS/"
pbuildconfigfile = homedir+"/rh5/pbuild/.pbuild"
pbuildMakefile = homedir+"/rh5/pbuild/Makefile"
# delete the logdir line form .pbuild file.
myfile = open(pbuildconfigfile,"r")
lines = myfile.readlines()
myfile.close()
myfile = open(pbuildconfigfile,"w")
for line in lines:
if not "logdir: " in line:
myfile.write(line)
myfile.close()
# set ENV variable in shell to expose config .pbuild file location
os.environ['PBUILD'] = pbuildconfigfile
with open(pbuildconfigfile, "a") as file:
file.write("logdir: "+homedir+"/Log/rh5")
# delete the homedir line form Makefile.
myfile = open(pbuildMakefile,"r")
lines = myfile.readlines()
myfile.close()
myfile = open(pbuildMakefile,"w")
for line in lines:
if not "homedir=" in line:
myfile.write(line)
myfile.close()
# write a new homedir to Makefile
with open(pbuildMakefile, "a") as myfile:
myfile.write("homedir="+homedir)
#update the buildname
print "rhel5specfiledpath is" +rhel5specfiledpath
updatebuildname(rhel5specfiledpath, buildname)
# Change direcoty to buildpath, before building .
os.chdir(rhel5buildpath)
# Now clean the destination VM's .
make = run("make")
if make :
print "make failed"
sys.exit(1)
os.chdir(homedir)
def buildrhel6(branch, buildname,source):
os.makedirs(directory)
run("git clone "+source)
os.chdir(directory+"/hv-rhel6.x/")
run("git checkout "+ branch)
run("tar -cvzf lis-next-rh6.tar.gz hv")
shutil.copy("lis-next-rh6.tar.gz" , homedir+"/rh6/SOURCES/")
os.chdir(homedir)
shutil.rmtree(directory)
found = False
rhel6buildpath=homedir+"/rh6/pbuild"
pbuildMakefile = homedir+"/rh6/pbuild/Makefile"
rhel6specfilepath = homedir+"/rh6/SPECS/"
pbuildconfigfile=homedir+"/rh6/pbuild/.pbuild"
# delete the logdir line form .pbuild file.
myfile = open(pbuildconfigfile,"r")
lines = myfile.readlines()
myfile.close()
myfile = open(pbuildconfigfile,"w")
for line in lines:
if not "logdir: " in line:
myfile.write(line)
myfile.close()
# set ENV variable in shell to expose config .pbuild file location
os.environ['PBUILD'] = pbuildconfigfile
with open(pbuildconfigfile, "a") as file:
file.write("logdir: "+homedir+"/Log/rh6")
# delete the homedir line form Makefile.
myfile = open(pbuildMakefile,"r")
lines = myfile.readlines()
myfile.close()
myfile = open(pbuildMakefile,"w")
for line in lines:
if not "homedir=" in line:
myfile.write(line)
myfile.close()
# write a new homedir to Makefile
with open(pbuildMakefile, "a") as myfile:
myfile.write("homedir="+homedir)
#update the buildname
updatebuildname(rhel6specfilepath, buildname)
# Change direcoty to buildpath, before building .
os.chdir(rhel6buildpath)
# Now clean the destination VM's .
make = run("make")
if make :
print "make failed"
sys.exit(1)
os.chdir(homedir)
def buildrhel7(branch, buildname,source):
os.makedirs(directory)
run("git clone "+source)
os.chdir(directory+"/hv-rhel7.x/")
run("git checkout "+ branch)
run("tar -cvzf lis-next-rh7-mlx.tar.gz hv")
run("rm -f hv/mlnx-ofa_kernel-4.5.tgz")
run("tar -cvzf lis-next-rh7.tar.gz hv")
shutil.copy("lis-next-rh7-mlx.tar.gz" , homedir+"/rh7/SOURCES/")
shutil.copy("lis-next-rh7.tar.gz" , homedir+"/rh7/SOURCES/")
os.chdir(homedir)
shutil.rmtree(directory)
found = False
rhel7buildpath = homedir+"/rh7/pbuild"
rhel7specfilepath= homedir+"/rh7/SPECS/"
pbuildMakefile = homedir+"/rh7/pbuild/Makefile"
pbuildconfigfile = homedir+"/rh7/pbuild/.pbuild"
# delete the logdir line form .pbuild file.
myfile = open(pbuildconfigfile,"r")
lines = myfile.readlines()
myfile.close()
myfile = open(pbuildconfigfile,"w")
for line in lines:
if not "logdir: " in line:
myfile.write(line)
myfile.close()
# set ENV variable in shell to expose config .pbuild file location
os.environ['PBUILD'] = pbuildconfigfile
with open(pbuildconfigfile, "a") as file:
file.write("logdir: "+homedir+"/Log/rh7")
# delete the homedir line form Makefile.
myfile = open(pbuildMakefile,"r")
lines = myfile.readlines()
myfile.close()
myfile = open(pbuildMakefile,"w")
for line in lines:
if not "homedir=" in line:
myfile.write(line)
myfile.close()
# write a new homedir to Makefile
with open(pbuildMakefile, "a") as myfile:
myfile.write("homedir="+homedir)
#update the buildname
updatebuildname(rhel7specfilepath, buildname)
# Change direcoty to buildpath, before building .
os.chdir(rhel7buildpath)
# Now clean the destination VM's .
make = run("make")
if make :
print "make failed"
sys.exit(1)
os.chdir(homedir)
### Main entry for script.###
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Provide argument for LIS RPM build.')
parser.add_argument("distro", help="Specify distro version you want to build, you can specify one at a time or all for all three. ")
parser.add_argument("--branch", help="Specify branch e.g. master,4.2.1")
parser.add_argument("buildname", help="Specify buildname e.g. master,4.2.1")
parser.add_argument("source", help="Specify GitHUb URL for source e.g. https://github.com/LIS/lis-next")
args = parser.parse_args()
distro = args.distro
if distro is None:
print "Nothing is spoecified for distro: will exit now"
sys.exit
branch = args.branch
if branch is None:
print "Nothing is spoecified for branch : will select master"
branch ="master"
source = args.source
if source is None:
print "Nothing is spoecified for source : will select LIS/lis-next"
source ="https://github.com/LIS/lis-next"
if not "github" in source:
print "Please specify github URL for source, exiting.."
sys.exit()
buildname = args.buildname
if buildname is None:
print "Nothing is spoecified for buildname : will exit now"
sys.exit()
if distro == "rh5":
print "RHEL5 Build initializing...."
buildrhel5(branch,buildname,source)
if distro == "rh6":
print "RHEL6 Build initializing...."
buildrhel6(branch, buildname,source)
if distro == "rh7":
print "RHEL7 Build initializing...."
buildrhel7(branch, buildname,source)
if distro == "all":
print "RHEL5 Build initializing...."
buildrhel5(branch,buildname,source)
print "RHEL6 Build initializing...."
buildrhel6(branch, buildname,source)
print "RHEL7 Build initializing...."
buildrhel7(branch, buildname,source)
# Claen all the RPMS from LISISO folder
# run("./cleanall.sh")
# copy all the RPMs back to LISISO folder
# run("./copyall.sh")
# Tar the LISISO directory.
# tarrpm = "lis-rpm-autogen-"+datetime.date.today().strftime("%d, %Y")
# tarcmd=("tar -cvzf %s LISISO") % (tarrpm)
# run("tarcmd")