Browse Source

job tools

refactor
Ulrich 2 years ago
parent
commit
a78543222b
  1. 4
      basic/constants.py
  2. 7
      basic/program.py
  3. 31
      basic/step.py
  4. 65
      start_dialog.py
  5. 5
      utils/data_const.py
  6. 64
      utils/job_tool.py
  7. 9
      utils/path_tool.py

4
basic/constants.py

@ -34,6 +34,8 @@ PAR_APP = 'application'
""" definition of the application which will be tested """ """ definition of the application which will be tested """
PAR_ENV = 'environment' PAR_ENV = 'environment'
""" definition of the environment where the application runs which will be tested """ """ definition of the environment where the application runs which will be tested """
PAR_VAR = 'variant'
""" definition of a variant dataflow especially the channel """
PAR_REL = 'release' PAR_REL = 'release'
""" definition of the release of the application which will be tested """ """ definition of the release of the application which will be tested """
PAR_TSDIR = 'tsdir' PAR_TSDIR = 'tsdir'
@ -67,7 +69,7 @@ PAR_DB_WHERE = "dbwhere"
""" optional parameter with a where-clause """ """ optional parameter with a where-clause """
PAR_DB_PARTITION = "dbparts" PAR_DB_PARTITION = "dbparts"
""" optional parameter for partitions of a partitioned tables """ """ optional parameter for partitions of a partitioned tables """
LIST_MAIN_PAR = [PAR_APP, PAR_ENV, PAR_VAR, PAR_REL, PAR_TSDIR, PAR_TSDIR]
# ------------------------------------------------------------- # -------------------------------------------------------------
# attributes # attributes

7
basic/program.py

@ -22,6 +22,7 @@ import utils.file_tool
import utils.config_tool import utils.config_tool
import test.constants as T import test.constants as T
import utils.path_const as P import utils.path_const as P
import utils.job_tool
jobdef = { jobdef = {
"webflask": { "webflask": {
@ -289,7 +290,7 @@ class Job:
self.program = program self.program = program
basedir = jobdef[program]["basedir"] basedir = jobdef[program]["basedir"]
self.basedir = basedir self.basedir = basedir
if (self.par is not None): if (self.par is not None) and self.par in B.LIST_MAIN_PAR:
setattr(self.par, "program", program) setattr(self.par, "program", program)
setattr(self.par, "basedir", basedir) setattr(self.par, "basedir", basedir)
parstring = getattr(self.par, "parstring") parstring = getattr(self.par, "parstring")
@ -309,6 +310,7 @@ class Job:
logTime = self.start.strftime("%Y%m%d_%H%M%S") logTime = self.start.strftime("%Y%m%d_%H%M%S")
self.m = basic.message.Message(self, basic.message.LIMIT_DEBUG, logTime, None) self.m = basic.message.Message(self, basic.message.LIMIT_DEBUG, logTime, None)
print("prog-68 " + str(self.m.rc)) print("prog-68 " + str(self.m.rc))
utils.job_tool.startJobProcesses(self)
self.par.setParameterLoaded(self) self.par.setParameterLoaded(self)
self.m.logInfo("# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ") self.m.logInfo("# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ")
self.m.debug(basic.message.LIMIT_INFO, "# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ") self.m.debug(basic.message.LIMIT_INFO, "# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ")
@ -317,6 +319,7 @@ class Job:
def stopJob(self, reboot=0): def stopJob(self, reboot=0):
utils.job_tool.stopJobProcesses(self)
self.ende = datetime.now() self.ende = datetime.now()
self.dumpParameter() self.dumpParameter()
print("stopJob " + str(self.m.messages) + ", " + str(self.m.debugfile)) print("stopJob " + str(self.m.messages) + ", " + str(self.m.debugfile))
@ -329,6 +332,7 @@ class Job:
self.m.closeMessage() self.m.closeMessage()
rc = self.m.getFinalRc() rc = self.m.getFinalRc()
print ("rc " + str(rc)) print ("rc " + str(rc))
print(footer)
if reboot == 0: if reboot == 0:
exit(rc) exit(rc)
@ -519,6 +523,7 @@ class Parameter:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-a', '--'+B.SUBJECT_APPS, required=True, action='store') parser.add_argument('-a', '--'+B.SUBJECT_APPS, required=True, action='store')
parser.add_argument('-e', '--'+B.PAR_ENV, required=True, action='store') parser.add_argument('-e', '--'+B.PAR_ENV, required=True, action='store')
parser.add_argument('-v', '--'+B.PAR_VAR, required=False, action='store')
parser.add_argument('-r', '--release', action='store') parser.add_argument('-r', '--release', action='store')
parser.add_argument('-ts', '--'+B.PAR_TSDIR, action='store') parser.add_argument('-ts', '--'+B.PAR_TSDIR, action='store')
parser.add_argument('-tc', '--'+B.PAR_TCDIR, action='store') parser.add_argument('-tc', '--'+B.PAR_TCDIR, action='store')

31
basic/step.py

@ -28,11 +28,15 @@ class Step:
args = {} args = {}
""" """
the class contains each attribute of a test-step the class contains each attribute of a test-step
* comp : the component which implements the step
* refLine : reference to data-lines which has to be executed
+ execStep :
""" """
def __init__(self): def __init__(self):
self.comp = "" self.comp = ""
self.refLine = "" self.refLine = ""
self.execStep = "" self.execStep = ""
self.variante = ""
self.args = {} self.args = {}
def getStepText(self, job): def getStepText(self, job):
@ -41,38 +45,13 @@ class Step:
text += D.CSV_DELIMITER+k+":"+self.args[k] text += D.CSV_DELIMITER+k+":"+self.args[k]
return text+"\n" return text+"\n"
def parseOldStep(job, fields):
step = {}
step[B.DATA_NODE_COMP] = fields[D.STEP_COMP_I]
step[B.ATTR_EXEC_REF] = fields[D.STEP_EXECNR_I]
step[B.ATTR_DATA_REF] = fields[D.STEP_REFNR_I]
step[B.ATTR_STEP_ARGS] = {}
if D.STEP_ARGS_I == D.STEP_LIST_I:
args = ""
for i in range(D.STEP_ARGS_I, len(fields)):
if len(fields[i]) < 1:
continue
if fields[i][0:1] == "#":
continue
args += "," + fields[i]
args = args[1:]
else:
args = fields[D.STEP_ARGS_I]
a = args.split(",")
for arg in a:
print("arg " + arg)
b = arg.split(":")
if len(b) < 2:
raise Exception(D.EXCP_MALFORMAT + "" + l)
step[B.ATTR_STEP_ARGS][b[0]] = b[1]
# data[B.DATA_NODE_STEPS].append(step)
return step
def parseStep(job, fields): def parseStep(job, fields):
step = Step() step = Step()
step.comp = fields[D.STEP_COMP_I] step.comp = fields[D.STEP_COMP_I]
step.execStep = fields[D.STEP_EXECNR_I] step.execStep = fields[D.STEP_EXECNR_I]
step.refLine = fields[D.STEP_REFNR_I] step.refLine = fields[D.STEP_REFNR_I]
step.variante = fields[D.STEP_VARIANT_I]
setattr(step, B.ATTR_DATA_REF, step.refLine) setattr(step, B.ATTR_DATA_REF, step.refLine)
if D.STEP_ARGS_I == D.STEP_LIST_I: if D.STEP_ARGS_I == D.STEP_LIST_I:
args = "" args = ""

65
start_dialog.py

@ -15,14 +15,7 @@ import re
import basic.program import basic.program
import basic.constants as B import basic.constants as B
import collect_testcase import utils.job_tool
import compare_testcase
import copy_appdummy
import execute_testcase
import finish_testsuite
import init_testcase
import init_testsuite
import test_executer
import utils.file_tool import utils.file_tool
import utils.data_const as D import utils.data_const as D
import utils.date_tool import utils.date_tool
@ -46,7 +39,6 @@ DLG_CONTINUE = "fortsetzen"
DLG_DUMMY_STEP = "Dummy-Schritt" DLG_DUMMY_STEP = "Dummy-Schritt"
DLG_NEWJOB = "neuer Job" DLG_NEWJOB = "neuer Job"
JSON_FILE = "actualJob.json"
JOB_NR = { JOB_NR = {
DLG_TESTSUITE : { DLG_TESTSUITE : {
"start": "init_testsuite", "start": "init_testsuite",
@ -162,7 +154,7 @@ def restartActualProcess(job):
check if an actual process is open check if an actual process is open
:return: :return:
""" """
path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_DEBUG], JSON_FILE) path = utils.path_tool.getActualJsonPath(job)
if os.path.exists(path): if os.path.exists(path):
actProc = utils.file_tool.readFileDict(job, path, job.m) actProc = utils.file_tool.readFileDict(job, path, job.m)
print("restartActJob "+str(actProc)) print("restartActJob "+str(actProc))
@ -173,7 +165,8 @@ def restartActualProcess(job):
dialogProcess(job) dialogProcess(job)
else: else:
actProc["step"] = str(step+1) actProc["step"] = str(step+1)
startProcess(job, actProc) utils.job_tool.startProcess(job, actProc)
restartActualProcess(job)
selection = [DLG_NEWJOB, DLG_REDO] selection = [DLG_NEWJOB, DLG_REDO]
nr = int(JOB_NR[actProc["gran"]][actProc["program"]]["jobnr"]) nr = int(JOB_NR[actProc["gran"]][actProc["program"]]["jobnr"])
@ -184,10 +177,12 @@ def restartActualProcess(job):
choice = getChoice(job, selection, DLG_ENVIRONMENT) choice = getChoice(job, selection, DLG_ENVIRONMENT)
print(choice) print(choice)
if choice == DLG_REDO: if choice == DLG_REDO:
startProcess(job, actProc) utils.job_tool.startProcess(job, actProc)
restartActualProcess(job)
elif choice == DLG_DUMMY_STEP: elif choice == DLG_DUMMY_STEP:
actProc["program"] = JOB_LIST[nr+1] actProc["program"] = JOB_LIST[nr+1]
startProcess(job, actProc) utils.job_tool.startProcess(job, actProc)
restartActualProcess(job)
elif choice == DLG_CONTINUE: elif choice == DLG_CONTINUE:
if nr == 7: if nr == 7:
nr = 9 nr = 9
@ -196,7 +191,7 @@ def restartActualProcess(job):
print (" act nr "+str(nr)) print (" act nr "+str(nr))
actProc["step"] = str(step + 1) actProc["step"] = str(step + 1)
actProc["program"] = JOB_LIST[nr] actProc["program"] = JOB_LIST[nr]
startProcess(job, actProc) utils.job_tool.startProcess(job, actProc)
elif choice == DLG_NEWJOB: elif choice == DLG_NEWJOB:
dialogProcess(job) dialogProcess(job)
else: else:
@ -254,7 +249,8 @@ def dialogProcess(job):
setattr(job.par, B.PAR_TSTIME, utils.date_tool.getActdate(utils.date_tool.F_DIR)) setattr(job.par, B.PAR_TSTIME, utils.date_tool.getActdate(utils.date_tool.F_DIR))
path = utils.path_tool.composePattern(job, "{"+P.P_TSBASE+"}", None) path = utils.path_tool.composePattern(job, "{"+P.P_TSBASE+"}", None)
process[B.PAR_TSDIR] = path process[B.PAR_TSDIR] = path
startProcess(job, process) utils.job_tool.startProcess(job, process)
restartActualProcess(job)
def getChoice(job, choiselist, description): def getChoice(job, choiselist, description):
index = 0 index = 0
@ -277,45 +273,6 @@ def getChoice(job, choiselist, description):
return choiselist[int(choice) - 1] return choiselist[int(choice) - 1]
def startProcess(job, process):
print(str(process))
path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_DEBUG], JSON_FILE)
utils.file_tool.writeFileDict(job.m, job, path, process)
jobargs = {}
jobargs[B.PAR_APP] = process["app"]
jobargs[B.PAR_ENV] = process["env"]
if B.PAR_STEP in process:
jobargs[B.PAR_STEP] = process[B.PAR_STEP]
if B.PAR_TCDIR in process:
jobargs[B.PAR_TCDIR] = process[B.PAR_TCDIR]
jobargs[B.PAR_TESTCASE] = process["entity"]
elif B.PAR_TSDIR in process:
jobargs[B.PAR_TSDIR] = process[B.PAR_TSDIR]
jobargs[B.PAR_TESTSUITE] = process["entity"]
print("process-programm "+process["program"])
myjob = basic.program.Job(process["program"], jobargs)
myjob.startJob()
if process["program"] == "init_testcase":
init_testcase.startPyJob(myjob)
elif process["program"] == "execute_testcase":
execute_testcase.startPyJob(myjob)
elif process["program"] == "collect_testcase":
collect_testcase.startPyJob(myjob)
elif process["program"] == "compare_testcase":
compare_testcase.startPyJob(myjob)
elif process["program"] == "copy_appdummy":
copy_appdummy.startPyJob(myjob)
elif process["program"] == "init_testsuite":
init_testsuite.startPyJob(myjob)
elif process["program"] == "execute_testsuite":
print("execute_testsuite.startPyJob(myjob) not implemented")
elif process["program"] == "collect_testsuite":
print("collect_testsuite.startPyJob(myjob) not implemented")
elif process["program"] == "finish_testsuite":
finish_testsuite.startPyJob(myjob)
elif process["program"] == "test_executer":
test_executer.startPyJob(myjob)
restartActualProcess(job)
if __name__ == '__main__': if __name__ == '__main__':
job = basic.program.Job(PROGRAM_NAME, {}) job = basic.program.Job(PROGRAM_NAME, {})

5
utils/data_const.py

@ -89,8 +89,9 @@ LIST_BLOCK_CONST = ["CSV_BLOCK_HEAD", "CSV_BLOCK_OPTION", "CSV_BLOCK_STEP", "CSV
STEP_COMP_I = 1 STEP_COMP_I = 1
STEP_EXECNR_I = 2 STEP_EXECNR_I = 2
STEP_REFNR_I = 3 STEP_REFNR_I = 3
STEP_ARGS_I = 4 STEP_VARIANT_I = 4
STEP_LIST_I = 4 STEP_ARGS_I = 5
STEP_LIST_I = 5
STEP_ATTR_COMP = "component" STEP_ATTR_COMP = "component"
STEP_ATTR_EXECNR = "exec-step" STEP_ATTR_EXECNR = "exec-step"
STEP_ATTR_REFNR = "reference-nr" STEP_ATTR_REFNR = "reference-nr"

64
utils/job_tool.py

@ -20,8 +20,17 @@
13. Tool -- schraenkt Protokollierung/Verarbeitung auf parametriserte Tools ein 13. Tool -- schraenkt Protokollierung/Verarbeitung auf parametriserte Tools ein
""" """
import basic.program import basic.program
import basic.constants as B
import collect_testcase
import compare_testcase
import execute_testcase
import finish_testsuite
import init_testcase
import init_testsuite
import test_executer
import utils.path_tool
import utils.file_tool
import components.utils.job_tool
def hasModul(komp): def hasModul(komp):
#job = Job.getInstance() #job = Job.getInstance()
return False return False
@ -33,9 +42,56 @@ def hasTool(tool):
return False return False
def createJob(parentJob, jobargs): def createJob(parentJob, jobargs):
job = basic.program.Job("temp") # meaning temp job = basic.program.Job("temp") # meaning temp
job.par.setParameterArgs(job, jobargs) job.par.setParameterArgs(job, jobargs)
job.startJob() job.startJob()
return
def startJobProcesses(job):
""" function to open processes like db-connection """
components.utils.job_tool.startJobProcesses(job)
pass
def stopJobProcesses(job):
""" function to close processes like db-connection """
components.utils.job_tool.stopJobProcesses(job)
pass
def startProcess(job, process):
print(str(process))
path = utils.path_tool.getActualJsonPath(job)
print("------- "+path)
utils.file_tool.writeFileDict(job.m, job, path, process)
jobargs = {}
jobargs[B.PAR_APP] = process["app"]
jobargs[B.PAR_ENV] = process["env"]
if B.PAR_STEP in process:
jobargs[B.PAR_STEP] = process[B.PAR_STEP]
if B.PAR_TCDIR in process:
jobargs[B.PAR_TCDIR] = process[B.PAR_TCDIR]
jobargs[B.PAR_TESTCASE] = process["entity"]
elif B.PAR_TSDIR in process:
jobargs[B.PAR_TSDIR] = process[B.PAR_TSDIR]
jobargs[B.PAR_TESTSUITE] = process["entity"]
print("process-programm "+process["program"])
myjob = basic.program.Job(process["program"], jobargs)
myjob.startJob()
if process["program"] == "init_testcase":
init_testcase.startPyJob(myjob)
elif process["program"] == "execute_testcase":
execute_testcase.startPyJob(myjob)
elif process["program"] == "collect_testcase":
collect_testcase.startPyJob(myjob)
elif process["program"] == "compare_testcase":
compare_testcase.startPyJob(myjob)
elif process["program"] == "init_testsuite":
init_testsuite.startPyJob(myjob)
elif process["program"] == "execute_testsuite":
print("execute_testsuite.startPyJob(myjob) not implemented")
elif process["program"] == "collect_testsuite":
print("collect_testsuite.startPyJob(myjob) not implemented")
elif process["program"] == "finish_testsuite":
finish_testsuite.startPyJob(myjob)
elif process["program"] == "test_executer":
test_executer.startPyJob(myjob)
return

9
utils/path_tool.py

@ -13,6 +13,7 @@ import re
import basic.constants as B import basic.constants as B
import utils.path_const as P import utils.path_const as P
import utils.date_tool import utils.date_tool
import getpass
TOOL_NAME = "path_tool" TOOL_NAME = "path_tool"
def getHome(): def getHome():
@ -45,6 +46,14 @@ def getBasisConfigPath():
raise Exception("no basis-configuration found") raise Exception("no basis-configuration found")
def getActualJsonPath(job):
username = getpass.getuser()
path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_DEBUG], username+"Job.json")
print("------ path "+path)
#if os.path.exists(path):
# return path
return path
def getKeyValue(job, key, comp=None): def getKeyValue(job, key, comp=None):
""" """
this function gets the value for the key which relates to an attribute in the job or in the component this function gets the value for the key which relates to an attribute in the job or in the component

Loading…
Cancel
Save