-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathdevice_info_test.py
More file actions
83 lines (72 loc) · 2.69 KB
/
device_info_test.py
File metadata and controls
83 lines (72 loc) · 2.69 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
import os
import sys
# TODO: Remove this if/else block once we no longer support Python 2
if sys.version_info.major == 3:
from unittest import mock
else:
# Expect the 'mock' package for python 2
# https://pypi.python.org/pypi/mock
import mock
from sonic_py_common import device_info
from .mock_swsssdk import SonicV2Connector
# TODO: Remove this if/else block once we no longer support Python 2
if sys.version_info.major == 3:
BUILTINS = "builtins"
else:
BUILTINS = "__builtin__"
MACHINE_CONF_CONTENTS = """\
onie_version=2016.11-5.1.0008-9600
onie_vendor_id=33049
onie_machine_rev=0
onie_arch=x86_64
onie_config_version=1
onie_build_date="2017-04-26T11:01+0300"
onie_partition_type=gpt
onie_kernel_version=4.10.11
onie_firmware=auto
onie_switch_asic=mlnx
onie_skip_ethmgmt_macs=yes
onie_machine=mlnx_msn2700
onie_platform=x86_64-mlnx_msn2700-r0"""
EXPECTED_GET_MACHINE_INFO_RESULT = {
'onie_arch': 'x86_64',
'onie_skip_ethmgmt_macs': 'yes',
'onie_platform': 'x86_64-mlnx_msn2700-r0',
'onie_machine_rev': '0',
'onie_version': '2016.11-5.1.0008-9600',
'onie_machine': 'mlnx_msn2700',
'onie_config_version': '1',
'onie_partition_type': 'gpt',
'onie_build_date': '"2017-04-26T11:01+0300"',
'onie_switch_asic': 'mlnx',
'onie_vendor_id': '33049',
'onie_firmware': 'auto',
'onie_kernel_version': '4.10.11'
}
class TestDeviceInfo(object):
@classmethod
def setup_class(cls):
print("SETUP")
def test_get_machine_info(self):
with mock.patch("os.path.isfile") as mock_isfile:
mock_isfile.return_value = True
open_mocked = mock.mock_open(read_data=MACHINE_CONF_CONTENTS)
with mock.patch("{}.open".format(BUILTINS), open_mocked):
result = device_info.get_machine_info()
assert result == EXPECTED_GET_MACHINE_INFO_RESULT
open_mocked.assert_called_once_with("/host/machine.conf")
def test_get_platform(self):
with mock.patch("sonic_py_common.device_info.get_machine_info") as get_machine_info_mocked:
get_machine_info_mocked.return_value = EXPECTED_GET_MACHINE_INFO_RESULT
result = device_info.get_platform()
assert result == "x86_64-mlnx_msn2700-r0"
def test_get_chassis_info(self):
with mock.patch("sonic_py_common.device_info.SonicV2Connector", new=SonicV2Connector):
result = device_info.get_chassis_info()
truth = {"serial": SonicV2Connector.TEST_SERIAL,
"model": SonicV2Connector.TEST_MODEL,
"revision": SonicV2Connector.TEST_REV}
assert result == truth
@classmethod
def teardown_class(cls):
print("TEARDOWN")