-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsimple.py
More file actions
121 lines (94 loc) · 3.31 KB
/
Copy pathsimple.py
File metadata and controls
121 lines (94 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import ocptv.output as tv
from ocptv.output import (
DiagnosisType,
LogSeverity,
SoftwareType,
TestResult,
TestStatus,
)
from . import demo
@demo
def demo_no_contexts():
"""
Show that a run/step can be manually started and ended.
The scope version should be preferred, as it makes it safer not to miss the end
artifacts in case of unhandled exceptions or code misuse.
"""
run = tv.TestRun(name="no with", version="1.0", parameters={"param": "test"})
run.start(dut=tv.Dut(id="dut0"))
step = run.add_step("step0")
step.start()
step.add_log(LogSeverity.DEBUG, "Some interesting message.")
step.end(status=TestStatus.COMPLETE)
run.end(status=TestStatus.COMPLETE, result=TestResult.PASS)
@demo
def demo_context_run_skip():
"""
Show a context-scoped run that automatically exits the whole func
because of the marker exception that triggers SKIP outcome.
"""
run = tv.TestRun(name="run_skip", version="1.0", parameters={"param": "test"})
with run.scope(dut=tv.Dut(id="dut0")):
raise tv.TestRunError(status=TestStatus.SKIP, result=TestResult.NOT_APPLICABLE)
@demo
def demo_context_step_fail():
"""
Show a scoped run with scoped steps, everything starts at "with" time and
ends automatically when the block ends (regardless of unhandled exceptions).
"""
run = tv.TestRun(name="step_fail", version="1.0")
with run.scope(dut=tv.Dut(id="dut0")):
step = run.add_step("step0")
with step.scope():
step.add_log(LogSeverity.INFO, "info log")
step = run.add_step("step1")
with step.scope():
# TODO: maybe this should fail the whole run?
raise tv.TestStepError(status=TestStatus.ERROR)
@demo
def demo_diagnosis():
"""
Show outputting a diagnosis message for the given step.
Normally the diagnosis is one of the later messages in an output, likely
right before exiting the test step scope.
In this case, the diagnosis does not reference any particular hardware component.
"""
class Verdict:
# str consts for error classifier
PASS = "pass-default"
run = tv.TestRun(name="run_with_diagnosis", version="1.0")
with run.scope(dut=tv.Dut(id="dut0")):
step = run.add_step("step0")
with step.scope():
step.add_diagnosis(DiagnosisType.PASS, verdict=Verdict.PASS)
@demo
def demo_error_while_gathering_duts():
"""
In case of failure to discover DUT hardware before needing to present it at test run
start, we can error out right at the beginning.
"""
class Symptom:
# str consts for error classifier
NO_DUT = "no-dut"
run = tv.TestRun(name="test", version="1.0")
run.add_error(
symptom=Symptom.NO_DUT,
message="could not find any valid DUTs",
)
@demo
def demo_run_error_with_dut():
"""
Show outputting an error message, triggered by a specific software component of the DUT.
"""
dut = tv.Dut(id="dut0", name="dut0.server.net")
bmc_software = dut.add_software_info(
name="bmc",
type=SoftwareType.FIRMWARE,
version="2.5",
)
run = tv.TestRun(name="test", version="1.0")
with run.scope(dut=dut):
run.add_error(
symptom="power-fail",
software_infos=[bmc_software],
)