-
Notifications
You must be signed in to change notification settings - Fork 3
/
client.py
executable file
·181 lines (145 loc) · 5.99 KB
/
client.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
'''
Created on Jun 24, 2011
@author: frank
'''
from common import *
def prepareEnvVar():
cfgPath = abspath(ENV_CFG_FILE)
if not exists(cfgPath): raise Exception("Cannot find %s"%cfgPath)
fd = open(cfgPath, 'r')
envs = fd.readlines()
fd.close()
for env in envs:
(key, value) = env.split("=")
value = value.strip('\n')
os.environ[key] = value
printd("Set environment variable %s=%s\n" % (key, value))
def isDeb():
return (os.environ["IS_DEB"] == "True")
def getResultDir():
fd = open(os.environ["RESULT_DIR"], "r")
resultDir = fd.readline()
fd.close()
return resultDir.strip('\n').strip()
def cloneSource():
if isDeb():
bash(['bash', abspath('clone.sh')])
else:
bash(['sh', abspath('clone.sh')])
# only after buildSource, environment variable has value
def buildSource():
def isPremium(f):
premiumLabel = ['usage', 'premium', 'test', 'baremetal']
for p in premiumLabel:
if p in f: return True
return False
def getBuildParams():
params = []
if useWaf():
excludeBranchs = ['2.2.beta1', '2.2.beta4', '2.1.4.kumquat', '2.1.banana',
'2.1.refactor', '2.1.vanilla', '2.1.x.217', '2.2.beta1.9', '2.1.6.kumquat',
'2.2.beta2', '2.2.beta3', 'fedorawork', 'hybrid', 'master.lime']
buildTarget = os.environ['BUILDABLE_TARGET'].replace('tag-', '').replace('-', '.')
prerelease = os.environ['LABEL_AS_PRERELEASE']
buildNumber = os.environ['BUILD_NUMBER']
pkgVer = os.environ['PACKAGE_VERSION']
if prerelease and prerelease != 'false':
params.append("--prerelease=%s"%buildTarget)
params.append("--build-number=%s"%buildNumber)
pkgVer = "%s.%s"%(pkgVer, buildNumber)
if buildTarget not in excludeBranchs:
params.append("--package-version=%s"%(pkgVer))
else:
pass
return ' '.join(params)
def buildRpm():
bash(["sh", abspath("buildrpm.sh"), getBuildParams()])
def buildDeb():
bash(["bash", abspath("builddeb.sh"), getBuildParams()])
def arrageResult(ext):
resDir = abspath(getResultDir())
printd("Packages locates at %s\n"%resDir)
ossrpms = []
premiumrpms = []
for root, dirs, files in os.walk(abspath(resDir)):
for f in files:
# since 2.2.12 cloudstack is full opensource, put all packages to oss dir
if os.environ['NO_PROPIRETARY'] == 'false':
if f.endswith(ext) and not isPremium(f):
ossrpms.append(join(root, f))
elif f.endswith(ext) and isPremium(f):
premiumrpms.append(join(root, f))
else:
if f.endswith(ext):
ossrpms.append(join(root, f))
ossDir = join(resDir, 'oss')
if not isdir(ossDir): os.makedirs(ossDir)
for r in ossrpms: bash(["mv", r, ossDir])
premiumDir = join(resDir, 'premium')
if not isdir(premiumDir): os.makedirs(premiumDir)
for r in premiumrpms: bash(["mv", r, premiumDir])
if isDeb():
buildDeb()
arrageResult(".deb")
else:
buildRpm()
arrageResult(".rpm")
def buildTarball():
def getS3repo(distro):
s3repo = os.environ['PUSH_TO_S3']
if s3repo == "none":
printd("No need to push to S3")
return ""
if distro != "rhel5" and distro != "rhel6.0" and distro != "rhel6.1":
printd("Only rhel5 and rhel6 build support this feature")
return ""
return s3repo
version = os.environ['PACKAGE_VERSION']
distro = os.environ['DO_DISTRO_PACKAGES']
if os.environ['LABEL_AS_PRERELEASE'] == 'true':
version = "%s.%s"%(version, os.environ['BUILD_NUMBER'])
else:
version = "%s-%s"%(version, os.environ['RELEASE_NUMBER'])
if isDeb():
if os.environ["BUILD_TARBALL"] == "oss&premium":
bash(["bash", abspath("builddebtarball.sh"), "True", distro, version, "CloudStack-oss"])
elif os.environ["BUILD_TARBALL"] == "oss":
bash(["bash", abspath("builddebtarball.sh"), "True", distro, version, "CloudStack-oss"])
elif os.environ['BUILD_TARBALL'] == "mycloud-agent":
bash(["bash", abspath("builddebtarball.sh"), "True", distro, version, "MyCloud"])
elif os.environ["BUILD_TARBALL"] == "premium":
bash(["bash", abspath("builddebtarball.sh"), "True", distro, version, "CloudStack-oss"])
else:
print("No need to build tarball")
else:
if os.environ["BUILD_TARBALL"] == "oss&premium":
bash(["sh", abspath("buildrpmtarball.sh"), "True", distro, version, "CloudStack-oss", getS3repo(distro)])
bash(["sh", abspath("buildrpmtarball.sh"), "False", distro, version, "CloudStack", getS3repo(distro)])
elif os.environ["BUILD_TARBALL"] == "oss":
bash(["sh", abspath("buildrpmtarball.sh"), "True", distro, version, "CloudStack-oss", getS3repo(distro)])
elif os.environ["BUILD_TARBALL"] == "premium":
bash(["sh", abspath("buildrpmtarball.sh"), "False", distro, version, "CloudStack", getS3repo(distro)])
else:
print("No need to build tarball")
def postPackages():
def postRpms():
bash(["sh", "postrpms.sh"])
def postDebs():
bash(["bash", "postdebs.sh"])
if isDeb():
postDebs()
else:
postRpms()
def main():
try:
prepareEnvVar()
cloneSource()
buildSource()
buildTarball()
postPackages()
except Exception, e:
printd(FormatErrMsg(e))
sys.exit(1)
if __name__ == '__main__':
main()
sys.exit(0)