diff --git a/device/accton/x86_64-accton_as7712_32x-r0/sonic_platform/chassis.py b/device/accton/x86_64-accton_as7712_32x-r0/sonic_platform/chassis.py index f19616fb1b22..fc076fa9e902 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/sonic_platform/chassis.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/sonic_platform/chassis.py @@ -30,7 +30,7 @@ PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/" REBOOT_CAUSE_FILE = "reboot-cause.txt" PREV_REBOOT_CAUSE_FILE = "previous-reboot-cause.txt" -HOST_CHK_CMD = "docker > /dev/null 2>&1" +HOST_CHK_CMD = "which systemctl > /dev/null 2>&1" SYSLED_FNODE = "/sys/class/leds/accton_as7712_32x_led::diag/brightness" SYSLED_MODES = { "0" : "STATUS_LED_COLOR_OFF", @@ -45,7 +45,6 @@ class Chassis(ChassisBase): def __init__(self): ChassisBase.__init__(self) self._api_helper = APIHelper() - self._api_helper = APIHelper() self.is_host = self._api_helper.is_host() self.config_data = {} @@ -69,7 +68,8 @@ def __initialize_sfp(self): sfp_module = Sfp(index, 'SFP') self._sfp_list.append(sfp_module) - + + self._sfpevent = SfpEvent(self._sfp_list) self.sfp_module_initialized = True def __initialize_fan(self): @@ -200,10 +200,7 @@ def get_change_event(self, timeout=0): # SFP event if not self.sfp_module_initialized: self.__initialize_sfp() - - status, sfp_event = SfpEvent(self._sfp_list).get_sfp_event(timeout) - - return status, sfp_event + return self._sfpevent.get_sfp_event(timeout) def get_sfp(self, index): """ diff --git a/device/accton/x86_64-accton_as7712_32x-r0/sonic_platform/event.py b/device/accton/x86_64-accton_as7712_32x-r0/sonic_platform/event.py index f20f8df51aa2..2d296e5137b2 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/sonic_platform/event.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/sonic_platform/event.py @@ -5,6 +5,7 @@ except ImportError as e: raise ImportError(repr(e) + " - required module not found") +POLL_INTERVAL_IN_SEC = 1 class SfpEvent: ''' Listen to insert/remove sfp events ''' @@ -13,30 +14,38 @@ def __init__(self, sfp_list): self._api_helper = APIHelper() self._sfp_list = sfp_list self._logger = Logger() + self._sfp_change_event_data = {'present': 0} - sfp_change_event_data = {'valid': 0, 'last': 0, 'present': 0} - def get_sfp_event(self, timeout=2000): - now = time.time() - port_dict = {} - change_dict = {} - change_dict['sfp'] = port_dict - - if timeout < 1000: - timeout = 1000 - timeout = timeout / float(1000) # Convert to secs - - if now < (self.sfp_change_event_data['last'] + timeout) and self.sfp_change_event_data['valid']: - return True, change_dict - + def get_presence_bitmap(self): bitmap = 0 for sfp in self._sfp_list: modpres = sfp.get_presence() i=sfp.port_num-1 if modpres: bitmap = bitmap | (1 << i) + return bitmap + + def get_sfp_event(self, timeout=2000): + port_dict = {} + change_dict = {} + change_dict['sfp'] = port_dict - changed_ports = self.sfp_change_event_data['present'] ^ bitmap - if changed_ports: + if timeout < 1000: + cd_ms = 1000 + else: + cd_ms = timeout + + while cd_ms > 0: + bitmap = self.get_presence_bitmap() + changed_ports = self._sfp_change_event_data['present'] ^ bitmap + if changed_ports != 0: + break + time.sleep(POLL_INTERVAL_IN_SEC) + # timeout=0 means wait for event forever + if timeout != 0: + cd_ms = cd_ms - POLL_INTERVAL_IN_SEC * 1000 + + if changed_ports != 0: for sfp in self._sfp_list: i=sfp.port_num-1 if (changed_ports & (1 << i)): @@ -47,9 +56,7 @@ def get_sfp_event(self, timeout=2000): # Update the cache dict - self.sfp_change_event_data['present'] = bitmap - self.sfp_change_event_data['last'] = now - self.sfp_change_event_data['valid'] = 1 + self._sfp_change_event_data['present'] = bitmap return True, change_dict else: return True, change_dict diff --git a/device/accton/x86_64-accton_as7712_32x-r0/sonic_platform/sfp.py b/device/accton/x86_64-accton_as7712_32x-r0/sonic_platform/sfp.py index 7ed41648cc80..fb8ab4fb5126 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/sonic_platform/sfp.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/sonic_platform/sfp.py @@ -268,7 +268,7 @@ class Sfp(SfpBase): # Path to sysfs PLATFORM_ROOT_PATH = "/usr/share/sonic/device" PMON_HWSKU_PATH = "/usr/share/sonic/hwsku" - HOST_CHK_CMD = "docker > /dev/null 2>&1" + HOST_CHK_CMD = "which systemctl > /dev/null 2>&1" PLATFORM = "x86_64-accton_as7712_32x-r0" HWSKU = "Accton-AS7712-32X"