本文整理汇总了Python中osci.job.Job类的典型用法代码示例。如果您正苦于以下问题:Python Job类的具体用法?Python Job怎么用?Python Job使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Job类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_isRunning_timeout
def test_isRunning_timeout(self, mock_update):
job = Job(change_num="change_num", project_name="project")
job.node_ip = 'ip'
delta = datetime.timedelta(seconds=int(Configuration().MAX_RUNNING_TIME))
job.updated = datetime.datetime.now() - delta
self.assertFalse(job.isRunning("DB"))
mock_update.assert_called_with("DB", result='Aborted: Timed out')
示例2: test_isRunning_pid_fail
def test_isRunning_pid_fail(self, mock_execute_command, mock_update):
job = Job(change_num="change_num", project_name="project")
job.node_ip = 'ip'
delta = datetime.timedelta(seconds=350)
job.updated = datetime.datetime.now() - delta
mock_execute_command.side_effect=Exception('SSH error getting PID')
self.assertFalse(job.isRunning("DB"))
mock_update.assert_called_with("DB", result='Aborted: Exception checking for pid')
self.assertEqual(1, mock_execute_command.call_count)
示例3: test_runTest_deletes_bad_node
def test_runTest_deletes_bad_node(self, mock_getSSHObject, mock_update):
job = Job(change_num="change_num", project_name="project")
nodepool = mock.Mock()
nodepool.getNode.return_value = ('new_node', 'ip')
mock_getSSHObject.return_value = None
job.runJob("DB", nodepool)
nodepool.deleteNode.assert_called_once_with('new_node')
mock_update.assert_called_once_with("DB", node_id=0)
示例4: test_runTest_deletes_existing_node
def test_runTest_deletes_existing_node(self, mock_getSSHObject, mock_update):
job = Job(change_num="change_num", project_name="project")
job.node_id='existing_node'
nodepool = mock.Mock()
nodepool.getNode.return_value = (None, None)
job.runJob("DB", nodepool)
nodepool.deleteNode.assert_called_once_with('existing_node')
mock_update.assert_called_once_with("DB", node_id=0)
self.assertEqual(0, mock_getSSHObject.call_count)
示例5: test_runTest_update_test_runner
def test_runTest_update_test_runner(self, mock_update_testrunner,
mock_execute_command,
mock_update, mock_sleep):
job = Job(change_num="change_num", change_ref='change_ref',
project_name="openstack/xenapi-os-testing")
nodepool = mock.Mock()
nodepool.getNode.return_value = ('new_node', 'ip')
ssh = mock.Mock()
job.runJob("DB", nodepool)
mock_update_testrunner.assert_has_calls([mock.call('change_ref')])
示例6: test_isRunning_happy_path
def test_isRunning_happy_path(self, mock_execute_command, mock_update):
job = Job(change_num="change_num", project_name="project")
job.node_ip = 'ip'
delta = datetime.timedelta(seconds=350)
job.updated = datetime.datetime.now() - delta
mock_execute_command.return_value = False
self.assertFalse(job.isRunning("DB"))
self.assertEqual(0, mock_update.call_count)
mock_execute_command.return_value = True
self.assertTrue(job.isRunning("DB"))
self.assertEqual(0, mock_update.call_count)
示例7: func_failures
def func_failures(options, queue):
table = PrettyTable(["Project", "Change", "State", "Result", "Age",
"Duration", "URL"])
table.align = 'l'
now = time.time()
all_jobs = Job.getAllWhere(queue.db)
for job in all_jobs:
if not job.result or (job.result != 'Failed' and
job.result.find('Aborted') != 0):
continue
updated = time.mktime(job.updated.timetuple())
age_hours = (now - updated) / 3600
if options.recent:
if age_hours > int(options.recent):
continue
age = '%.02f' % (age_hours)
duration = '-'
if job.test_started and job.test_stopped:
started = time.mktime(job.test_started.timetuple())
stopped = time.mktime(job.test_stopped.timetuple())
duration = "%.02f"%((stopped - started)/3600)
table.add_row([job.project_name, job.change_num,
constants.STATES[job.state], job.result, age,
duration, job.logs_url])
return str(table)
示例8: get_jobs
def get_jobs(self):
ret_list = []
collectingJobs = Job.getAllWhere(self.jobQueue.db,
state=constants.COLLECTING)
for job in collectingJobs:
ret_list.append(job)
return ret_list
示例9: test_runTest_happy_path
def test_runTest_happy_path(self, mock_execute_command,
mock_update, mock_sleep):
job = Job(change_num="change_num", project_name="project")
nodepool = mock.Mock()
nodepool.getNode.return_value = ('new_node', 'ip')
ssh = mock.Mock()
job.runJob("DB", nodepool)
# The node should not be deleted(!)
self.assertEqual(0, nodepool.deleteNode.call_count)
# Two calls - one to set the node ID and the other to set the state to running
update_call1 = mock.call("DB", node_id='new_node', result='', node_ip='ip')
update_call2 = mock.call("DB", state=constants.RUNNING)
mock_update.assert_has_calls([update_call1, update_call2])
示例10: processResults
def processResults(self):
allJobs = Job.getAllWhere(self.db, state=constants.RUNNING)
self.log.info('%d jobs running...'%len(allJobs))
for job in allJobs:
if job.isRunning(self.db):
continue
job.update(self.db, state=constants.COLLECTING)
self.log.info('Tests for %s are done! Collecting'%job)
示例11: addJob
def addJob(self, change_ref, project_name, commit_id):
change_num = change_ref.split('/')[3]
existing_jobs = Job.retrieve(self.db, project_name, change_num)
for existing in existing_jobs:
self.log.info('Job for previous patchset (%s) already queued - replacing'%(existing))
existing.update(self.db, state=constants.OBSOLETE)
job = Job(change_num, change_ref, project_name, commit_id)
with self.db.get_session() as session:
self.log.info("Job for %s queued"%job.change_num)
session.add(job)
示例12: test_start_test_clears_time
def test_start_test_clears_time(self, now):
now.return_value = NOW
db = DB('sqlite://')
db.create_schema()
job = Job(change_num="change_num", project_name="project")
with db.get_session() as session:
session.add(job)
job.created=PAST
job.db = db
job.update(db, state=constants.RUNNING)
with db.get_session() as session:
job, = session.query(Job).all()
self.assertEquals(job.updated, NOW)
self.assertEquals(job.state, constants.RUNNING)
self.assertEquals(job.test_started, NOW)
self.assertEquals(job.test_stopped, None)
self.assertEquals("project", job.project_name)
self.assertEquals("change_num", job.change_num)
示例13: test_update
def test_update(self, now):
now.return_value = NOW
db = DB('sqlite://')
db.create_schema()
job = Job(change_num="change_num", project_name="project")
with db.get_session() as session:
session.add(job)
job.created=PAST
job.db = db
self.assertEqual(job.state, constants.QUEUED)
job.update(db, state=constants.FINISHED)
with db.get_session() as session:
job, = session.query(Job).all()
self.assertEquals(NOW, job.updated)
self.assertEquals(constants.FINISHED, job.state)
self.assertEquals("project", job.project_name)
self.assertEquals("change_num", job.change_num)
示例14: func_show
def func_show(options, queue):
table = PrettyTable()
table.add_column('Key', ['Project name', 'Change num', 'Change ref',
'state', 'created', 'Commit id', 'Node id',
'Node ip', 'Result', 'Logs', 'Report',
'Updated', 'Gerrit URL'])
job = Job.getAllWhere(queue.db, change_ref=options.change_ref)[0]
url = 'https://review.openstack.org/%s'%job.change_num
table.add_column('Value',
[job.project_name, job.change_num, job.change_ref,
constants.STATES[job.state], job.created,
job.commit_id, job.node_id, job.node_ip,
job.result, job.logs_url, job.report_url,
job.updated, url])
table.align = 'l'
return str(table)
示例15: func_list
def func_list(options, queue):
table = PrettyTable(["Project", "Change", "State", "IP", "Result",
"Age (hours)", "Duration"])
table.align = 'l'
now = time.time()
all_jobs = Job.getAllWhere(queue.db)
state_dict = {}
result_dict = {}
if options.states and len(options.states) > 0:
states = options.states.split(',')
else:
states = None
for job in all_jobs:
updated = time.mktime(job.updated.timetuple())
age_hours = (now - updated) / 3600
if options.recent:
if age_hours > int(options.recent):
continue
state_count = state_dict.get(constants.STATES[job.state], 0) + 1
state_dict[constants.STATES[job.state]] = state_count
result_count = result_dict.get(job.result, 0)+1
result_dict[job.result] = result_count
if states and constants.STATES[job.state] not in states:
continue
if job.node_id:
node_ip = job.node_ip
else:
node_ip = '(%s)'%job.node_ip
age = '%.02f' % (age_hours)
duration = '-'
if job.test_started and job.test_stopped:
started = time.mktime(job.test_started.timetuple())
stopped = time.mktime(job.test_stopped.timetuple())
if started < stopped:
duration = "%.02f"%((stopped - started)/3600)
table.add_row([job.project_name, job.change_ref,
constants.STATES[job.state], node_ip, job.result,
age, duration])
output_str = str(state_dict)+"\n"
output_str = output_str + str(result_dict)+"\n"
output_str = output_str + str(table)
return output_str