106 lines
3.7 KiB
Python
106 lines
3.7 KiB
Python
#######################################################################
|
|
#
|
|
# This class is used to test each QA server on whether packages are successfully
|
|
# processed through SLEDS, utilizing the orc.sh script. The test will return
|
|
# a zero if it succeeds. The test is meant to be executed nightly, called by
|
|
# Jenkins, with the result affecting each QA server's test status on the
|
|
# docserver homepage.
|
|
#
|
|
# Note that java code actually checks this directory for the package: /sl/SLSync/testdata/NO_PI/src/
|
|
#
|
|
# Developer: Craig Millis
|
|
# Date: 060117
|
|
#
|
|
#######################################################################
|
|
|
|
import sys, os.path, subprocess, datetime, json, glob, getpass
|
|
|
|
class TestController:
|
|
msg = ''
|
|
test_result = 0
|
|
test_dir = '/group/it/auto_test/nightly_orchestration/packages'
|
|
network = 'SLCustomer_Test_Data'
|
|
workorder = 'SampleTestWorkorder'
|
|
test_results_dir = './test_results'
|
|
stdout_dir = './stdout'
|
|
|
|
def __init__(self):
|
|
dt_start = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
self.path_to_packages = os.path.abspath(self.test_dir) + '/' + self.network + '/' + self.workorder
|
|
|
|
if not os.path.exists(self.stdout_dir):
|
|
os.makedirs(self.stdout_dir)
|
|
if not os.path.exists(self.test_results_dir):
|
|
os.makedirs(self.test_results_dir)
|
|
|
|
self.set_packages()
|
|
for package in self.packages:
|
|
print package
|
|
self.process_package(package)
|
|
|
|
p = subprocess.Popen( ['facter'], stdout=subprocess.PIPE )
|
|
p.wait()
|
|
facts = p.stdout.readlines()
|
|
facts = dict(k.split(' => ') for k in [s.strip() for s in facts if ' => ' in s])
|
|
|
|
data = {}
|
|
if os.environ['myenv']:
|
|
myenv = os.environ['myenv']
|
|
else:
|
|
myenv = 'unknown'
|
|
data['myenv'] = myenv
|
|
data['test_result'] = self.test_result
|
|
data['dt_start'] = dt_start
|
|
data['dt_end'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
data['ipaddress'] = facts['ipaddress']
|
|
|
|
data['msg'] = self.msg
|
|
from pprint import pprint
|
|
pprint(data)
|
|
|
|
with open(self.test_results_dir + '/' + myenv + '.json', 'w') as outfile:
|
|
json.dump(data, outfile)
|
|
|
|
def process_package(self, package):
|
|
file_path = self.path_to_packages + '/' + package
|
|
stdout_path = self.stdout_dir + '/' + os.path.splitext(package)[0] + '.txt'
|
|
print stdout_path
|
|
if os.path.exists(stdout_path):
|
|
os.remove(stdout_path)
|
|
|
|
if os.path.exists(file_path) == False:
|
|
msg = '|Missing ' + os.path.abspath(file_path) + '...continuing'
|
|
self.msg = self.msg + msg
|
|
return
|
|
else:
|
|
msg = '|Processing ' + os.path.basename(file_path)
|
|
self.msg = self.msg + msg
|
|
print msg
|
|
|
|
cli = "/sequencelogic/bin/orc.sh -f '" + package + "' --test-directory " + os.path.abspath(self.test_dir) + " com.sequencelogic.robot.workflow.Orchestration 2>&1 | tee '" + stdout_path + "' ; test ${PIPESTATUS[0]} -eq 0"
|
|
print cli
|
|
|
|
test_result = 0 #this is used if next line is omitted (for testing this script)
|
|
if getpass.getuser() == 'sequencelogic':
|
|
print 'user is sequencelogic'
|
|
test_result = subprocess.call([cli], shell=True)
|
|
|
|
self.msg = self.msg + '|test_result: ' + str(test_result)
|
|
self.test_result = max(test_result, self.test_result)
|
|
|
|
def set_packages(self):
|
|
self.msg = self.msg + '|Getting packages from ' + self.path_to_packages
|
|
|
|
#get all pdf files in the test_dir
|
|
current_dir = os.path.abspath('.')
|
|
os.chdir(self.path_to_packages)
|
|
self.packages = glob.glob("*.pdf")
|
|
os.chdir(current_dir)
|
|
from pprint import pprint
|
|
pprint(self.packages)
|
|
|
|
#only process certain packages
|
|
#self.packages = self.packages[7:8]
|
|
#from pprint import pprint
|
|
#pprint(self.packages)
|