Sleds/buildvm/scat/sledslocal_release.py

288 lines
10 KiB
Python

#!/bin/python3
"""
Created on Mar 3, 2014
author: tpweis
file name: sledslocal_release.py
"""
import os
import subprocess
#import shutil
#import json
import sys
sys.path.insert(0,'/sl/lib')
#from xml.dom import minidom
import urllib
import getopt
from sleds_utilities import *
def cleanup():
clean1 = ["rm", "-rf", "/tmp/sequencelogic/release-*.zip"]
clean2 = ["rm", "-rf", "/tmp/sequencelogic/release-*"]
clean3 = ["rm", "-rf", "/tmp/sequencelogic/releaseFR-*.zip"]
clean4 = ["rm", "-rf", "/tmp/sequencelogic/releaseFR-*"]
c1 = subprocess.Popen(clean1, stdout=subprocess.PIPE)
c1.wait()
rc1 = c1.returncode
c2 = subprocess.Popen(clean2, stdout=subprocess.PIPE)
c2.wait()
rc2 = c2.returncode
c3 = subprocess.Popen(clean3, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
c3.wait()
rc3 = c3.returncode
c4 = subprocess.Popen(clean4, stdout=subprocess.PIPE)
c4.wait()
rc4 = c4.returncode
# Lets check for errors
if rc1:
slscatlog('E',"Cannot clean: " + ", ".join(clean1))
if rc2:
slscatlog('E',"Cannot clean: " + clean2)
if rc3:
slscatlog('E',"Cannot clean: " + ", ".join(clean3))
if rc4:
slscatlog('E',"Cannot clean: " + clean4)
return (rc1 + rc2 + rc3 + rc4)
if __name__ == '__main__':
argv = sys.argv[1:]
try:
opts, args = getopt.getopt(argv,"hx:v:b:r:f:",["version=","branch=", "frversion", "frbranch="])
except getopt.GetoptError:
slscatlog('E', 'rtest.py -v <version to release> -b <branch> ')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print ('sledslocal_release.py -v <sleds version> -b <sleds branch> -r <fr version> -f <fr branch>')
sys.exit()
elif opt in ("-v", "--version"):
version = arg
elif opt in ("-b", "--branch"):
branch = version + "-" + arg
elif opt in ("-r", "--frversion"):
frversion = arg
elif opt in ("-f", "--frbranch"):
frbranch = frversion + "-" + arg
m1 = subprocess.Popen(["mkdir", "-p", "/tmp/sequencelogic"], stdout=-subprocess.PIPE)
m1.wait()
m1rc = m1.returncode
if m1rc:
slscatlog('E',"mkdir error, rc = " + str(m1rc))
artifactoryUrl = "http://artifactory.sl.int:8081/artifactory"
#Fetch the Sleds package, specified by version and branch
slscatlog('I',"Fetch Sleds: version " + version + ", branch " + branch )
geturl = artifactoryUrl + "/libs-release-local/com/sequencelogic/release/1.0.0/release-1.0.0-release_1_0_0.zip"
dest = "/tmp/sequencelogic/release-"+version+".zip"
g1 = subprocess.Popen(["wget", "-q", geturl, "-O", dest], stdout=subprocess.PIPE)
g1.wait()
g1rc = g1.returncode
if g1rc:
slscatlog('E',"wget return code: " + str(g1rc) + "; URL = " + geturl)
exit(1)
fromdir = "/tmp/sequencelogic/release-"+version+".zip"
todir = "/tmp/sequencelogic"
z1 = subprocess.Popen(["unzip", "-uoq", fromdir, "-d", todir], stdout=subprocess.PIPE)
z1.wait()
z1rc = z1.returncode
if z1rc:
slscatlog('E',"unzip return code: " + str(z1rc) + ", trying: " + fromdir)
exit(1)
slscatlog('I',"Fetch FR: version " + frversion + ", branch " + frbranch )
frgeturl = artifactoryUrl + "/libs-release-local/com/sequencelogic/releaseFR/"+frversion+"/releaseFR-"+frbranch+".zip"
frdest = "/tmp/sequencelogic/releaseFR-"+frversion+".zip"
g2 = subprocess.Popen(["wget", "-q", frgeturl, "-O", frdest], stdout=subprocess.PIPE)
g2.wait()
g2rc = g2.returncode
if g2rc:
slscatlog('E',"wget return code: " + str(g2rc) + ", URL = " + frgeturl)
exit(1)
frfromdir = "/tmp/sequencelogic/releaseFR-"+version+".zip"
frtodir = "/tmp/sequencelogic"
z2 = subprocess.Popen(["unzip", "-uoq", frfromdir, "-d", frtodir], stdout=subprocess.PIPE)
z2.wait()
z2rc = z2.returncode
if z2rc:
slscatlog('E',"unzip return code: " + str(z2rc) + "trying: " + fromdir)
exit(1)
# Log that the fetching is complete
slscatlog('I',"Completed fetching objects from " + artifactoryUrl)
bin_source="/tmp/sequencelogic/release-"+version+"/sequencelogic/bin/"
if not os.path.isdir(bin_source):
slscatlog('E',"Bad bin source: " + bin_source)
exit(1)
bin_destination="/sequencelogic/bin"
if not os.path.isdir(bin_destination):
slscatlog('E',"Bad bin destintation: " + bin_destination)
exit(1)
robot_source="/tmp/sequencelogic/release-"+version+"/sequencelogic/bin/linuxrobot/"
if not os.path.isdir(robot_source):
slscatlog('E',"Bad robot source: " + robot_source)
exit(1)
robot_destination="/sequencelogic/bin"
if not os.path.isdir(robot_destination):
slscatlog('E',"Bad robot destination: " + robot_destination)
exit(1)
config_source="/tmp/sequencelogic/release-"+version+"/sequencelogic/config/"
if not os.path.isdir(config_source):
slscatlog('E',"Bad config source: " + config_source)
exit(1)
config_destination="/sequencelogic/config"
if not os.path.isdir(config_destination):
slscatlog('E',"Bad config destination: " + config_destination)
exit(1)
slscatlog('D',"rsync from " +bin_source + " to " +bin_destination)
rsink1 = ["rsync", "-ar", bin_source, bin_destination]
rs1 = subprocess.Popen(rsink1, stdout=subprocess.PIPE)
rs1.wait()
rs1rc = rs1.returncode
if rs1rc:
slscatlog('E',"rsync return code: " + str(rs1rc) + + "CMD: " + ", ".join(rsink1))
exit(1)
slscatlog('D',"rsync from " +robot_source+ " to " +robot_destination)
rsink2 = ["rsync", "-ar", bin_source, bin_destination]
rs2 = subprocess.Popen(rsink2, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
rs2.wait()
rs2rc = rs2.returncode
if rs2rc:
slscatlog('E',"rsync return code: " + str(rs2rc) + + "CMD: " + ", ".join(rsink2))
exit(1)
slscatlog('D',"rsync from " +config_source+ " to " +config_destination)
rsink3 = ["rsync", "-ar", config_source, config_destination]
rs3 = subprocess.Popen(rsink3, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
rs3.wait()
rs3rc = rs3.returncode
if rs3rc:
slscatlog('E',"rsync return code: " + str(rs3rc) + + "CMD: " + ", ".join(rsink3))
exit(1)
#Transfer tomcat things to server location. First check all the directory definitions.
tclib_source="/tmp/sequencelogic/release-"+version+"/usr/local/tomcat/lib/"
if not os.path.isdir(tclib_source):
slscatlog('E',"bad tomcat lib source: " + tclib_source)
exit(1)
tclinux_source="/tmp/sequencelogic/release-"+version+"/usr/local/tomcat/lib/linux/"
if not os.path.isdir(tclinux_source):
slscatlog('E',"bad lib linux source: " + tclinux_source)
exit(1)
tcwar_source1="/tmp/sequencelogic/release-"+version+"/cg/usr/local/tomcat/webapps/cgsl.war"
if not os.path.isfile(tcwar_source1):
slscatlog('E',"bad cgsl war file: " + tcwar_source1)
exit(1)
tcwar_source2="/tmp/sequencelogic/release-"+version+"/sg/usr/local/tomcat/webapps/sg/sgsl.war"
if not os.path.isfile(tcwar_source2):
slscatlog('E',"bad sgsl war file: " + tcwar_source2)
exit(1)
tcwar_source3="/tmp/sequencelogic/release-"+version+"/clux/usr/local/tomcat/webapps/clux.war"
if not os.path.isfile(tcwar_source3):
slscatlog('E',"bad clux war file: " + tcwar_source3)
exit(1)
tclib_destination="/usr/local/tomcat/lib"
if not os.path.isdir(tclib_destination):
slscatlog('E',"bad tomcat lib destination: " + tclib_destination)
exit(1)
tcwar_destination="/sl/lib/webapps"
if not os.path.isdir(tcwar_destination):
slscatlog('E',"bad tomcat war file destination: " + tcwar_destination)
exit(1)
slscatlog('D',"rsync from " +tclib_source+ " to " +tclib_destination)
rsink4 = ["rsync", "-ar", tclib_source, tclib_destination]
rs4 = subprocess.Popen(rsink4, stdout = subprocess.PIPE)
rs4.wait()
rs4rc = rs4.returncode
if rs4rc:
slscatlog('E',"rsync return code: " + str(rs4rc) + + "CMD: " + ", ".join(rsink4))
exit(1)
slscatlog('D',"rsync from " +tclinux_source+ " to " +tclib_destination)
rsink5 = ["rsync", "-ar", tclinux_source, tclib_destination]
rs5 = subprocess.Popen(rsink5, stdout = subprocess.PIPE)
rs5.wait()
rs5rc = rs5.returncode
if rs5rc:
slscatlog('E',"rsync return code: " + str(rs5rc) + + "CMD: " + ", ".join(rsink5))
exit(1)
slscatlog('D',"rsync from " +tcwar_source1+ " to " +tcwar_destination)
rsink6 = ["rsync", "-ar", tcwar_source1, tcwar_destination]
rs6 = subprocess.Popen(rsink6, stdout = subprocess.PIPE)
rs6.wait()
rs6rc = rs6.returncode
if rs6rc:
slscatlog('E',"rsync return code: " + str(rs6rc) + + "CMD: " + ", ".join(rsink6))
exit(1)
slscatlog('D',"rsync from " +tcwar_source2+ " to " +tcwar_destination)
rsink7 = ["rsync", "-ar", tcwar_source2, tcwar_destination]
rs7 = subprocess.Popen(rsink7, stdout = subprocess.PIPE)
rs7.wait()
rs7rc = rs7.returncode
if rs7rc:
slscatlog('E',"rsync return code: " + str(rs7rc) + + "CMD: " + ", ".join(rsink7))
exit(1)
slscatlog('D',"rsync from " +tcwar_source3+ " to " +tcwar_destination)
rsink8 = ["rsync", "-ar", tcwar_source3, tcwar_destination]
rs8 = subprocess.Popen(rsink8, stdout = subprocess.PIPE)
rs8.wait()
rs8rc = rs8.returncode
if rs8rc:
slscatlog('E',"rsync return code: " + str(rs8rc) + + "CMD: " + ", ".join(rsink8))
exit(1)
# Now copy the FR files
fr_source="/tmp/sequencelogic/releaseFR-"+frversion+"/sequencelogic/bin/"
if not os.path.isdir(fr_source):
slscatlog('E',"bad FR source: " + fr_source)
exit(1)
fr_destination="/sequencelogic/bin"
if not os.path.isdir(fr_destination):
slscatlog('E',"bad FR destination path: " + fr_destination)
exit(1)
slscatlog('D',"rsync from " +fr_source+ " to " +fr_destination)
rsink9 = ["rsync", "-ar", fr_source, fr_destination]
rs9 = subprocess.Popen(rsink9, stdout = subprocess.PIPE)
rs9.wait()
rs9rc = rs9.returncode
if rs9rc:
slscatlog('E',"rsync return code: " + str(rs9rc) + + "CMD: " + ", ".join(rsink9))
exit(1)
cleanup()
pass