本文整理汇总了Python中plainbox.impl.session.SessionState.update_job_result方法的典型用法代码示例。如果您正苦于以下问题:Python SessionState.update_job_result方法的具体用法?Python SessionState.update_job_result怎么用?Python SessionState.update_job_result使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plainbox.impl.session.SessionState
的用法示例。
在下文中一共展示了SessionState.update_job_result方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_realistic_test_session
# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_job_result [as 别名]
def make_realistic_test_session(self, session_dir):
# Create a more realistic session with two jobs but with richer set
# of data in the actual jobs and results.
job_a = JobDefinition({
'plugin': 'shell',
'name': 'job_a',
'command': 'echo testing && true',
'requires': 'job_b.ready == "yes"'
})
job_b = JobDefinition({
'plugin': 'resource',
'name': 'job_b',
'command': 'echo ready: yes'
})
session = SessionState([job_a, job_b])
session.update_desired_job_list([job_a, job_b])
result_a = MemoryJobResult({
'outcome': IJobResult.OUTCOME_PASS,
'return_code': 0,
'io_log': [(0, 'stdout', b'testing\n')],
})
result_b = MemoryJobResult({
'outcome': IJobResult.OUTCOME_PASS,
'return_code': 0,
'comments': 'foo',
'io_log': [(0, 'stdout', b'ready: yes\n')],
})
session.update_job_result(job_a, result_a)
session.update_job_result(job_b, result_b)
return session
示例2: make_realistic_test_session
# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_job_result [as 别名]
def make_realistic_test_session(self):
# Create a more realistic session with two jobs but with richer set
# of data in the actual jobs and results.
job_a = JobDefinition({
'plugin': 'shell',
'name': 'job_a',
'command': 'echo testing && true',
'requires': 'job_b.ready == "yes"'
})
job_b = JobDefinition({
'plugin': 'resource',
'name': 'job_b',
'command': 'echo ready: yes'
})
session = SessionState([job_a, job_b])
session.update_desired_job_list([job_a, job_b])
result_a = JobResult({
'job': job_a,
'outcome': 'pass',
'return_code': 0,
'io_log': (
IOLogRecord(0, 'stdout', 'testing\n'),
)
})
result_b = JobResult({
'job': job_b,
'outcome': 'pass',
'return_code': 0,
'io_log': (
IOLogRecord(0, 'stdout', 'ready: yes\n'),
)
})
session.update_job_result(job_a, result_a)
session.update_job_result(job_b, result_b)
return session
示例3: make_test_session
# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_job_result [as 别名]
def make_test_session(self):
# Create a small session with two jobs and two results
job_a = make_job('job_a')
job_b = make_job('job_b')
session = SessionState([job_a, job_b])
session.update_desired_job_list([job_a, job_b])
result_a = make_job_result(job_a, 'pass')
result_b = make_job_result(job_b, 'fail')
session.update_job_result(job_a, result_a)
session.update_job_result(job_b, result_b)
return session
示例4: make_test_session
# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_job_result [as 别名]
def make_test_session(self):
# Create a small session with two jobs and two results
job_a = make_job('job_a')
job_b = make_job('job_b')
session = SessionState([job_a, job_b])
session.update_desired_job_list([job_a, job_b])
result_a = make_job_result(outcome=IJobResult.OUTCOME_PASS)
result_b = make_job_result(outcome=IJobResult.OUTCOME_FAIL)
session.update_job_result(job_a, result_a)
session.update_job_result(job_b, result_b)
return session
示例5: SessionStateReactionToJobResultTests
# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_job_result [as 别名]
class SessionStateReactionToJobResultTests(TestCase):
# This test checks how a simple session with a few typical job reacts to
# job results of various kinds. It checks most of the resource presentation
# error conditions that I could think of.
def setUp(self):
# All of the tests below are using one session. The session has four
# jobs, clustered into two independent groups. Job A depends on a
# resource provided by job R which has no dependencies at all. Job X
# depends on job Y which in turn has no dependencies at all.
#
# A -(resource dependency)-> R
#
# X -(direct dependency) -> Y
self.job_A = make_job("A", requires="R.attr == 'value'")
self.job_A_expr = self.job_A.get_resource_program().expression_list[0]
self.job_R = make_job("R", plugin="resource")
self.job_X = make_job("X", depends='Y')
self.job_Y = make_job("Y")
self.job_L = make_job("L", plugin="local")
self.job_list = [
self.job_A, self.job_R, self.job_X, self.job_Y, self.job_L]
self.session = SessionState(self.job_list)
def job_state(self, name):
# A helper function to avoid overly long expressions
return self.session.job_state_map[name]
def job_inhibitor(self, name, index):
# Another helper that shortens deep object nesting
return self.job_state(name).readiness_inhibitor_list[index]
def test_assumptions(self):
# This function checks the assumptions of SessionState initial state.
# The job list is what we set when constructing the session.
#
self.assertEqual(self.session.job_list, self.job_list)
# The run_list is still empty because the desired_job_list is equally
# empty.
self.assertEqual(self.session.run_list, [])
self.assertEqual(self.session.desired_job_list, [])
# All jobs have state objects that indicate they cannot run (because
# they have the UNDESIRED inhibitor set for them by default).
self.assertFalse(self.job_state('A').can_start())
self.assertFalse(self.job_state('R').can_start())
self.assertFalse(self.job_state('X').can_start())
self.assertFalse(self.job_state('Y').can_start())
self.assertEqual(self.job_inhibitor('A', 0).cause,
JobReadinessInhibitor.UNDESIRED)
self.assertEqual(self.job_inhibitor('R', 0).cause,
JobReadinessInhibitor.UNDESIRED)
self.assertEqual(self.job_inhibitor('X', 0).cause,
JobReadinessInhibitor.UNDESIRED)
self.assertEqual(self.job_inhibitor('Y', 0).cause,
JobReadinessInhibitor.UNDESIRED)
def test_desire_job_A_updates_state_map(self):
# This function checks what happens when the job A becomes desired via
# the update_desired_job_list() call.
self.session.update_desired_job_list([self.job_A])
self.assertEqual(self.session.desired_job_list, [self.job_A])
# This should topologically sort the job list, according to the
# relationship created by the resource requirement. This is not really
# testing the dependency solver (it has separate tests), just that this
# basic property is established and that the run_list properly shows
# that R must run before A can run.
self.assertEqual(self.session.run_list, [self.job_R, self.job_A])
# This also recomputes job readiness state so that job R is no longer
# undesired, has no other inhibitor and thus can start
self.assertEqual(self.job_state('R').readiness_inhibitor_list, [])
self.assertTrue(self.job_state('R').can_start())
# While the A job still cannot run it now has a different inhibitor,
# one with the PENDING_RESOURCE cause. The inhibitor also properly
# pinpoints the related job and related expression.
self.assertNotEqual(self.job_state('A').readiness_inhibitor_list, [])
self.assertEqual(self.job_inhibitor('A', 0).cause,
JobReadinessInhibitor.PENDING_RESOURCE)
self.assertEqual(self.job_inhibitor('A', 0).related_job, self.job_R)
self.assertEqual(self.job_inhibitor('A', 0).related_expression,
self.job_A_expr)
self.assertFalse(self.job_state('A').can_start())
def test_resource_job_result_updates_resource_and_job_states(self):
# This function checks what happens when a JobResult for job R (which
# is a resource job via the resource plugin) is presented to the
# session.
result_R = MemoryJobResult({
'io_log': [(0, 'stdout', b"attr: value\n")],
})
self.session.update_job_result(self.job_R, result_R)
# The most obvious thing that can happen, is that the result is simply
# stored in the associated job state object.
self.assertIs(self.job_state('R').result, result_R)
# Initially the _resource_map was empty. SessionState parses the io_log
# of results of resource jobs and creates appropriate resource objects.
self.assertIn("R", self.session._resource_map)
expected = {'R': [Resource({'attr': 'value'})]}
self.assertEqual(self.session._resource_map, expected)
# As job results are presented to the session the readiness of other
# jobs is changed. Since A depends on R via a resource expression and
#.........这里部分代码省略.........
示例6: __init__
# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_job_result [as 别名]
#.........这里部分代码省略.........
self.session.session_dir,
self.session.jobs_io_log_dir,
command_io_delegate=self,
outcome_callback=None, # SRU runs are never interactive
dry_run=self.ns.dry_run
)
self._run_all_jobs()
if self.config.fallback_file is not Unset:
self._save_results()
self._submit_results()
# FIXME: sensible return value
return 0
def _set_job_selection(self):
desired_job_list = get_matching_job_list(self.job_list, self.whitelist)
problem_list = self.session.update_desired_job_list(desired_job_list)
if problem_list:
logger.warning("There were some problems with the selected jobs")
for problem in problem_list:
logger.warning("- %s", problem)
logger.warning("Problematic jobs will not be considered")
def _save_results(self):
print("Saving results to {0}".format(self.config.fallback_file))
data = self.exporter.get_session_data_subset(self.session)
with open(self.config.fallback_file, "wt", encoding="UTF-8") as stream:
translating_stream = ByteStringStreamTranslator(stream, "UTF-8")
self.exporter.dump(data, translating_stream)
def _submit_results(self):
print("Submitting results to {0} for secure_id {1}".format(
self.config.c3_url, self.config.secure_id))
options_string = "secure_id={0}".format(self.config.secure_id)
# Create the transport object
try:
transport = CertificationTransport(
self.config.c3_url, options_string, self.config)
except InvalidSecureIDError as exc:
print(exc)
return False
# Prepare the data for submission
data = self.exporter.get_session_data_subset(self.session)
with tempfile.NamedTemporaryFile(mode='w+b') as stream:
# Dump the data to the temporary file
self.exporter.dump(data, stream)
# Flush and rewind
stream.flush()
stream.seek(0)
try:
# Send the data, reading from the temporary file
result = transport.send(stream)
if 'url' in result:
print("Successfully sent, submission status at {0}".format(
result['url']))
else:
print("Successfully sent, server response: {0}".format(
result))
except InvalidSchema as exc:
print("Invalid destination URL: {0}".format(exc))
except ConnectionError as exc:
print("Unable to connect to destination URL: {0}".format(exc))
except HTTPError as exc:
print(("Server returned an error when "
"receiving or processing: {0}").format(exc))
except IOError as exc:
print("Problem reading a file: {0}".format(exc))
def _run_all_jobs(self):
again = True
while again:
again = False
for job in self.session.run_list:
# Skip jobs that already have result, this is only needed when
# we run over the list of jobs again, after discovering new
# jobs via the local job output
result = self.session.job_state_map[job.name].result
if result.outcome is not None:
continue
self._run_single_job(job)
self.session.persistent_save()
if job.plugin == "local":
# After each local job runs rebuild the list of matching
# jobs and run everything again
self._set_job_selection()
again = True
break
def _run_single_job(self, job):
print("- {}:".format(job.name), end=' ')
job_state, job_result = run_job_if_possible(
self.session, self.runner, self.config, job)
print("{0}".format(job_result.outcome))
if job_result.comments is not None:
print("comments: {0}".format(job_result.comments))
if job_state.readiness_inhibitor_list:
print("inhibitors:")
for inhibitor in job_state.readiness_inhibitor_list:
print(" * {}".format(inhibitor))
self.session.update_job_result(job, job_result)
示例7: AnalyzeInvocation
# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_job_result [as 别名]
class AnalyzeInvocation(CheckBoxInvocationMixIn):
def __init__(self, provider_list, config, ns):
super().__init__(provider_list, config)
self.ns = ns
self.job_list = self.get_job_list(ns)
self.desired_job_list = self._get_matching_job_list(ns, self.job_list)
self.session = SessionState(self.job_list)
self.problem_list = self.session.update_desired_job_list(
self.desired_job_list)
def run(self):
if self.ns.run_local:
if self.ns.print_desired_job_list:
self._print_desired_job_list()
if self.ns.print_run_list:
self._print_run_list()
self._run_local_jobs()
if self.ns.print_stats:
self._print_general_stats()
if self.ns.print_dependency_report:
self._print_dependency_report()
if self.ns.print_interactivity_report:
self._print_interactivity_report()
if self.ns.print_estimated_duration_report:
self._print_estimated_duration_report()
if self.ns.print_validation_report:
self._print_validation_report(self.ns.only_errors)
if self.ns.print_requirement_report:
self._print_requirement_report()
if self.ns.print_desired_job_list:
self._print_desired_job_list()
if self.ns.print_run_list:
self._print_run_list()
def _print_desired_job_list(self):
print(_("[Desired Job List]").center(80, '='))
for job in self.session.desired_job_list:
print("{}".format(job.id))
def _print_run_list(self):
print(_("[Run List]").center(80, '='))
for job in self.session.run_list:
print("{}".format(job.id))
def _run_local_jobs(self):
print(_("[Running Local Jobs]").center(80, '='))
manager = SessionManager.create_with_state(self.session)
try:
manager.state.metadata.title = "plainbox dev analyze session"
manager.state.metadata.flags = [SessionMetaData.FLAG_INCOMPLETE]
manager.checkpoint()
runner = JobRunner(
manager.storage.location, self.provider_list,
os.path.join(manager.storage.location, 'io-logs'),
command_io_delegate=self)
again = True
while again:
for job in self.session.run_list:
if job.plugin == 'local':
if self.session.job_state_map[job.id].result.outcome is None:
self._run_local_job(manager, runner, job)
break
else:
again = False
manager.state.metadata.flags = []
manager.checkpoint()
finally:
manager.destroy()
def _run_local_job(self, manager, runner, job):
print("{job}".format(job=job.id))
manager.state.metadata.running_job_name = job.id
manager.checkpoint()
result = runner.run_job(job, self.config)
self.session.update_job_result(job, result)
new_desired_job_list = self._get_matching_job_list(
self.ns, self.session.job_list)
new_problem_list = self.session.update_desired_job_list(
new_desired_job_list)
if new_problem_list:
print(_("Problem list"), new_problem_list)
self.problem_list.extend(new_problem_list)
def _print_general_stats(self):
print(_("[General Statistics]").center(80, '='))
print(_("Known jobs: {}").format(len(self.job_list)))
print(_("Selected jobs: {}").format(len(self.desired_job_list)))
def _print_dependency_report(self):
print(_("[Dependency Report]").center(80, '='))
if self.problem_list:
for problem in self.problem_list:
print(" * {}".format(problem))
else:
print(_("Selected jobs have no dependency problems"))
def _print_interactivity_report(self):
print(_("[Interactivity Report]").center(80, '='))
if not self.session.run_list:
#.........这里部分代码省略.........
示例8: SessionStateLocalStorageTests
# 需要导入模块: from plainbox.impl.session import SessionState [as 别名]
# 或者: from plainbox.impl.session.SessionState import update_job_result [as 别名]
class SessionStateLocalStorageTests(TestCase):
def setUp(self):
# session data are kept in XDG_CACHE_HOME/plainbox/.session
# To avoid resuming a real session, we have to select a temporary
# location instead
self._sandbox = tempfile.mkdtemp()
self._env = os.environ
os.environ['XDG_CACHE_HOME'] = self._sandbox
def job_state(self, name):
# A helper function to avoid overly long expressions
return self.session.job_state_map[name]
def test_persistent_save(self):
self.job_A = make_job("A")
self.job_list = [self.job_A]
self.session = SessionState(self.job_list)
result_A = JobResult({
'job': self.job_A,
'outcome': JobResult.OUTCOME_PASS,
'comments': 'All good',
'return_code': 0,
'io_log': ((0, 'stdout', "Success !\n"),)
})
session_json_text = """{
"_job_state_map": {
"A": {
"_job": {
"data": {
"name": "A",
"plugin": "dummy",
"requires": null,
"depends": null
},
"_class_id": "JOB_DEFINITION"
},
"_result": {
"data": {
"job": {
"data": {
"name": "A",
"plugin": "dummy",
"requires": null,
"depends": null
},
"_class_id": "JOB_DEFINITION"
},
"outcome": "pass",
"return_code": 0,
"comments": "All good",
"io_log": [
[
0,
"stdout",
"Success !\\n"
]
]
},
"_class_id": "JOB_RESULT"
},
"_class_id": "JOB_STATE"
}
},
"_desired_job_list": [
{
"data": {
"name": "A",
"plugin": "dummy",
"requires": null,
"depends": null
},
"_class_id": "JOB_DEFINITION"
}
],
"_class_id": "SESSION_STATE"
}"""
self.session.open()
self.session.update_desired_job_list([self.job_A])
self.session.update_job_result(self.job_A, result_A)
self.session.persistent_save()
session_file = self.session.previous_session_file()
self.session.close()
self.assertIsNotNone(session_file)
with open(session_file) as f:
raw_json = json.load(f)
self.maxDiff = None
self.assertEqual(raw_json, json.loads(session_json_text))
def test_resume_session(self):
# All of the tests below are using one session. The session has four
# jobs, Job A depends on a resource provided by job R which has no
# dependencies at all. Both Job X and Y depend on job A.
#
# A -(resource dependency)-> R
#
# X -(direct dependency) -> A
#
# Y -(direct dependency) -> A
self.job_A = make_job("A", requires="R.attr == 'value'")
#.........这里部分代码省略.........