sonic-buildimage/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py
Joe LeVeque 7f4ab8fbd8
[sonic-utilities] Update submodule; Build and install as a Python 3 wheel (#5926)
Submodule updates include the following commits:

* src/sonic-utilities 9dc58ea...f9eb739 (18):
  > Remove unnecessary calls to str.encode() now that the package is Python 3; Fix deprecation warning (#1260)
  > [generate_dump] Ignoring file/directory not found Errors (#1201)
  > Fixed porstat rate and util issues (#1140)
  > fix error: interface counters is mismatch after warm-reboot (#1099)
  > Remove unnecessary calls to str.decode() now that the package is Python 3 (#1255)
  > [acl-loader] Make list sorting compliant with Python 3 (#1257)
  > Replace hard-coded fast-reboot with variable. And some typo corrections (#1254)
  > [configlet][portconfig] Remove calls to dict.has_key() which is not available in Python 3 (#1247)
  > Remove unnecessary conversions to list() and calls to dict.keys() (#1243)
  > Clean up LGTM alerts (#1239)
  > Add 'requests' as install dependency in setup.py (#1240)
  > Convert to Python 3 (#1128)
  > Fix mock SonicV2Connector in python3: use decode_responses mode so caller code will be the same as python2 (#1238)
  > [tests] Do not trim from PATH if we did not append to it; Clean up/fix shebangs in scripts (#1233)
  > Updates to bgp config and show commands with BGP_INTERNAL_NEIGHBOR table (#1224)
  > [cli]: NAT show commands newline issue after migrated to Python3 (#1204)
  > [doc]: Update Command-Reference.md (#1231)
  > Added 'import sys' in feature.py file (#1232)

* src/sonic-py-swsssdk 9d9f0c6...1664be9 (2):
  > Fix: no need to decode() after redis client scan, so it will work for both python2 and python3 (#96)
  > FieldValueMap `contains`(`in`)  will also work when migrated to libswsscommon(C++ with SWIG wrapper) (#94)

- Also fix Python 3-related issues:
    - Use integer (floor) division in config_samples.py (sonic-config-engine)
    - Replace print statement with print function in eeprom.py plugin for x86_64-kvm_x86_64-r0 platform
    - Update all platform plugins to be compatible with both Python 2 and Python 3
    - Remove shebangs from plugins files which are not intended to be executable
    - Replace tabs with spaces in Python plugin files and fix alignment, because Python 3 is more strict
    - Remove trailing whitespace from plugins files
2020-11-25 10:28:36 -08:00

105 lines
3.5 KiB
Python

#!/usr/bin/env python3
#
# Name: juniper_sfp_init.py version: 1.0
#
# Description: Platform-specific SFP Transceiver Initialization for Juniper QFX5200
#
# Copyright (c) 2020, Juniper Networks, Inc.
# All rights reserved.
#
# Notice and Disclaimer: This code is licensed to you under the GNU General
# Public License as published by the Free Software Foundation, version 3 or
# any later version. This code is not an official Juniper product. You can
# obtain a copy of the License at <https://www.gnu.org/licenses/>
#
# OSS License:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Third-Party Code: This code may depend on other components under separate
# copyright notice and license terms. Your use of the source code for those
# components is subject to the terms and conditions of the respective license
# as noted in the Third-Party source code file.
import time
import os.path
import sfputil as jnpr_sfp
from sonic_py_common.logger import Logger
from pprint import pprint
SYSLOG_IDENTIFIER = "sfputil"
# Global logger class instance
logger = Logger(SYSLOG_IDENTIFIER)
DEBUG = False
def i2c_eeprom_dev_update(port, create_eeprom):
eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom"
i2c_path = "/sys/class/i2c-adapter/i2c-{0}"
i2c_port = port + jnpr_sfp.SFP_I2C_OFFSET
port_eeprom_path = eeprom_path.format(i2c_port)
port_i2c_path = i2c_path.format(i2c_port)
if create_eeprom:
if not os.path.exists(port_eeprom_path):
try:
i2c_file = open(port_i2c_path + "/new_device", "w")
i2c_file.write("optoe2 0x50")
except IOError as e:
print("Error: unable to write to i2c file: %s" % str(e))
return
else:
if os.path.exists(port_eeprom_path):
try:
i2c_file = open(port_i2c_path + "/delete_device", "w")
i2c_file.write("0x50")
except IOError as e:
print("Error: unable to write to i2c file: %s" % str(e))
return
def gpio_sfp_init():
jnpr_sfp.gpio_sfp_base_init()
time.sleep(2)
# Reset all ports
for port in range(jnpr_sfp.GPIO_PORT_START, jnpr_sfp.GPIO_PORT_END + 1):
logger.log_debug("GPIO SFP port {}".format(port))
jnpr_sfp.gpio_sfp_reset_set(port, 0)
i2c_eeprom_dev_update(port, True)
time.sleep(1)
# Enable optics for all ports which have XCVRs present
for port in range(jnpr_sfp.GPIO_PORT_START, jnpr_sfp.GPIO_PORT_END + 1):
jnpr_sfp.gpio_sfp_lpmode_set(port, 1)
if __name__ == '__main__':
if DEBUG == True:
print("Initializing Juniper SFP module")
gpio_sfp_init()
if DEBUG == True:
print("Juniper GPIO presence pin mapping:")
pprint(jnpr_sfp.gpio_sfp_presence)
print("Juniper GPIO reset pin mapping:")
pprint(jnpr_sfp.gpio_sfp_reset)
print("Juniper GPIO lpmode pin mapping:")
pprint(jnpr_sfp.gpio_sfp_lpmode)