/
test_sel.py
154 lines (130 loc) · 5.89 KB
/
test_sel.py
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from unittest.mock import MagicMock
from pyipmi import interfaces, create_connection
from pyipmi.msgs.registry import create_response_by_name
from pyipmi.sel import SelEntry, SelInfo
class TestSel:
def test_get_sel_entries(self):
rsps = list()
rsp = create_response_by_name('GetSelInfo')
rsp .entries = 1
rsps.append(rsp)
rsp = create_response_by_name('ReserveSel')
rsps.append(rsp)
rsp = create_response_by_name('GetSelEntry')
rsp.record_data = [0, 0, SelEntry.TYPE_SYSTEM_EVENT, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
rsps.append(rsp)
rsp = create_response_by_name('GetSelEntry')
rsp.record_data = [0, 0, SelEntry.TYPE_SYSTEM_EVENT, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
rsp.next_record_id = 0xffff
rsps.append(rsp)
mock_send_message = MagicMock(side_effect=rsps)
interface = interfaces.create_interface('mock')
ipmi = create_connection(interface)
ipmi.send_message = mock_send_message
entries = ipmi.get_sel_entries()
assert len(entries) == 2
class TestSelInfo:
rsp = create_response_by_name('GetSelInfo')
rsp.version = 1
rsp.entries = 1023
rsp.free_bytes = 512
info = SelInfo(rsp)
assert info.version == 1
assert info.entries == 1023
assert info.free_bytes == 512
rsp.operation_support.get_sel_allocation_info = 1
rsp.operation_support.reserve_sel = 0
rsp.operation_support.partial_add_sel_entry = 0
rsp.operation_support.delete_sel = 0
rsp.operation_support.overflow_flag = 0
info = SelInfo(rsp)
assert 'get_sel_allocation_info' in info.operation_support
assert 'reserve_sel' not in info.operation_support
assert 'partial_add_sel_entry' not in info.operation_support
assert 'delete_sel' not in info.operation_support
assert 'overflow_flag' not in info.operation_support
rsp.operation_support.get_sel_allocation_info = 0
rsp.operation_support.reserve_sel = 1
rsp.operation_support.partial_add_sel_entry = 0
rsp.operation_support.delete_sel = 0
rsp.operation_support.overflow_flag = 0
info = SelInfo(rsp)
assert 'get_sel_allocation_info' not in info.operation_support
assert 'reserve_sel' in info.operation_support
assert 'partial_add_sel_entry' not in info.operation_support
assert 'delete_sel' not in info.operation_support
assert 'overflow_flag' not in info.operation_support
rsp.operation_support.get_sel_allocation_info = 0
rsp.operation_support.reserve_sel = 0
rsp.operation_support.partial_add_sel_entry = 1
rsp.operation_support.delete_sel = 0
rsp.operation_support.overflow_flag = 0
info = SelInfo(rsp)
assert 'get_sel_allocation_info' not in info.operation_support
assert 'reserve_sel' not in info.operation_support
assert 'partial_add_sel_entry' in info.operation_support
assert 'delete_sel' not in info.operation_support
assert 'overflow_flag' not in info.operation_support
rsp.operation_support.get_sel_allocation_info = 0
rsp.operation_support.reserve_sel = 0
rsp.operation_support.partial_add_sel_entry = 0
rsp.operation_support.delete_sel = 1
rsp.operation_support.overflow_flag = 0
info = SelInfo(rsp)
assert 'get_sel_allocation_info' not in info.operation_support
assert 'reserve_sel' not in info.operation_support
assert 'partial_add_sel_entry' not in info.operation_support
assert 'delete_sel' in info.operation_support
assert 'overflow_flag' not in info.operation_support
rsp.operation_support.get_sel_allocation_info = 0
rsp.operation_support.reserve_sel = 0
rsp.operation_support.partial_add_sel_entry = 0
rsp.operation_support.delete_sel = 0
rsp.operation_support.overflow_flag = 1
info = SelInfo(rsp)
assert 'get_sel_allocation_info' not in info.operation_support
assert 'reserve_sel' not in info.operation_support
assert 'partial_add_sel_entry' not in info.operation_support
assert 'delete_sel' not in info.operation_support
assert 'overflow_flag' in info.operation_support
class TestSelEnty:
def test_from_data(self):
data = [0xff, 0x03, 0x02, 0xf7, 0x61, 0xef, 0x52, 0x7e,
0x00, 0x04, 0xf2, 0x09, 0x7f, 0x00, 0xff, 0xff]
entry = SelEntry(data)
assert entry.type == 2
assert entry.sensor_type == 0xf2
def test_from_data_event_direction(self):
data = [0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00]
entry = SelEntry(data)
assert entry.event_direction == 0
data = [0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00]
entry = SelEntry(data)
assert entry.event_direction == 1
def test_from_data_event_type(self):
data = [0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00]
entry = SelEntry(data)
assert entry.event_type == 0x7f
data = [0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00]
entry = SelEntry(data)
assert entry.event_type == 0x00
def test_from_data_event_data(self):
data = [0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0x11, 0x22, 0x33]
entry = SelEntry(data)
assert entry.event_data[0] == 0x11
assert entry.event_data[1] == 0x22
assert entry.event_data[2] == 0x33
def test_type_to_string(self):
assert SelEntry.type_to_string(0) is None
assert SelEntry.type_to_string(0x02) == 'System Event'
assert SelEntry.type_to_string(0xc0) == 'OEM timestamped (0xc0)'
assert SelEntry.type_to_string(0xe0) == 'OEM non-timestamped (0xe0)'