|
52 | 52 | 'onie_kernel_version': '4.10.11'
|
53 | 53 | }
|
54 | 54 |
|
| 55 | +SONIC_VERISON_YML = """\ |
| 56 | +--- |
| 57 | +build_version: 'test_branch.1-a8fbac59d' |
| 58 | +debian_version: '11.4' |
| 59 | +kernel_version: '5.10.0-12-2-amd64' |
| 60 | +asic_type: mellanox |
| 61 | +asic_subtype: 'mellanox' |
| 62 | +commit_id: 'a8fbac59d' |
| 63 | +branch: 'test_branch' |
| 64 | +release: 'master' |
| 65 | +libswsscommon: 1.0.0 |
| 66 | +sonic_utilities: 1.2""" |
| 67 | + |
| 68 | +SONIC_VERISON_YML_RESULT = { |
| 69 | + 'build_version': 'test_branch.1-a8fbac59d', |
| 70 | + 'debian_version': '11.4', |
| 71 | + 'kernel_version': '5.10.0-12-2-amd64', |
| 72 | + 'asic_type': 'mellanox', |
| 73 | + 'asic_subtype': 'mellanox', |
| 74 | + 'commit_id': 'a8fbac59d', |
| 75 | + 'branch': 'test_branch', |
| 76 | + 'release': 'master', |
| 77 | + 'libswsscommon': '1.0.0', |
| 78 | + 'sonic_utilities': 1.2 |
| 79 | +} |
| 80 | + |
55 | 81 | class TestDeviceInfo(object):
|
56 | 82 | @pytest.fixture(scope="class", autouse=True)
|
57 | 83 | def sanitize_environment(self):
|
@@ -83,6 +109,38 @@ def test_get_chassis_info(self):
|
83 | 109 | "revision": SonicV2Connector.TEST_REV}
|
84 | 110 | assert result == truth
|
85 | 111 |
|
| 112 | + @mock.patch("os.path.isfile") |
| 113 | + def test_get_sonic_version(self, mock_isfile): |
| 114 | + mock_isfile.return_value = True |
| 115 | + open_mocked = mock.mock_open(read_data=SONIC_VERISON_YML) |
| 116 | + with mock.patch("{}.open".format(BUILTINS), open_mocked): |
| 117 | + for _ in range(0,5): |
| 118 | + assert device_info.get_sonic_version_info() == SONIC_VERISON_YML_RESULT |
| 119 | + # Assert the file was read only once |
| 120 | + open_mocked.assert_called_once_with(device_info.SONIC_VERSION_YAML_PATH) |
| 121 | + |
| 122 | + @mock.patch("sonic_py_common.device_info.get_platform_info") |
| 123 | + def test_is_chassis(self, mock_platform_info): |
| 124 | + mock_platform_info.return_value = {"switch_type": "npu"} |
| 125 | + assert device_info.is_chassis() == False |
| 126 | + assert device_info.is_voq_chassis() == False |
| 127 | + assert device_info.is_packet_chassis() == False |
| 128 | + |
| 129 | + mock_platform_info.return_value = {"switch_type": "voq"} |
| 130 | + assert device_info.is_voq_chassis() == True |
| 131 | + assert device_info.is_packet_chassis() == False |
| 132 | + assert device_info.is_chassis() == True |
| 133 | + |
| 134 | + mock_platform_info.return_value = {"switch_type": "chassis-packet"} |
| 135 | + assert device_info.is_voq_chassis() == False |
| 136 | + assert device_info.is_packet_chassis() == True |
| 137 | + assert device_info.is_chassis() == True |
| 138 | + |
| 139 | + mock_platform_info.return_value = {} |
| 140 | + assert device_info.is_voq_chassis() == False |
| 141 | + assert device_info.is_packet_chassis() == False |
| 142 | + assert device_info.is_chassis() == False |
| 143 | + |
86 | 144 | @classmethod
|
87 | 145 | def teardown_class(cls):
|
88 | 146 | print("TEARDOWN")
|
0 commit comments