Esempio n. 1
0
def get_chassis_info():
    """
    Attempts to retrieve chassis information from CHASSIS_INFO table in STATE_DB if this table does
    not exist then we assume pmon has crashed and will attempt to call the platform API directly. If this
    call fails we simply return N/A.
    """

    keys = ["serial", "model", "revision"]

    def try_get(platform, attr, fallback):
        try:
            if platform["chassis"] is None:
                import sonic_platform
                platform["chassis"] = sonic_platform.platform.Platform().get_chassis()
            return getattr(platform["chassis"], "get_{}".format(attr))()
        except Exception:
            return 'N/A'

    chassis_info = device_info.get_chassis_info()

    if all(v is None for k, v in chassis_info.items()):
        platform_cache = {"chassis": None}
        chassis_info = {k:try_get(platform_cache, k, "N/A") for k in keys}

    return chassis_info
Esempio n. 2
0
 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
Esempio n. 3
0
def get_chassis_info():
    """
    Attempts to get the chassis info via STATE_DB and falls back to direct Platform API calls.
    """

    chassis_info = device_info.get_chassis_info()
    required_keys = ['serial', 'model', 'revision']
    failed_vals = ['', 'N/A']
    platform_chassis = None

    for k in required_keys:
        if chassis_info.get(k, '') in failed_vals:
            if platform_chassis is None:
                import sonic_platform
                platform_chassis = sonic_platform.platform.Platform(
                ).get_chassis()
            try:
                chassis_info[k] = getattr(platform_chassis, "get_".format(k))()
            except AttributeError:
                chassis_info[k] = 'N/A'

    return chassis_info