[enable_counters.py] Convert to Python 3 (#5789)

**- Why I did it**

As part of moving all SONiC code from Python 2 (no longer supported) to Python 3

**- How I did it**

- Convert enable_counters.py script to Python 3
- Reorganize imports per PEP8 standard
- Two blank lines precede functions per PEP8 standard
This commit is contained in:
Joe LeVeque 2020-11-06 09:00:19 -08:00 committed by GitHub
parent cea364aa77
commit 51292330e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,16 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import time
import swsssdk
import time
def enable_counter_group(db, name):
info = {}
info['FLEX_COUNTER_STATUS'] = 'enable'
db.mod_entry("FLEX_COUNTER_TABLE", name, info)
def enable_counters():
db = swsssdk.ConfigDBConnector()
db.connect()
@ -20,10 +23,12 @@ def enable_counters():
enable_counter_group(db, 'BUFFER_POOL_WATERMARK')
enable_counter_group(db, 'PORT_BUFFER_DROP')
def get_uptime():
with open('/proc/uptime') as fp:
return float(fp.read().split(' ')[0])
def main():
# If the switch was just started (uptime less than 5 minutes),
# wait for 3 minutes and enable counters
@ -35,5 +40,6 @@ def main():
time.sleep(60)
enable_counters()
if __name__ == '__main__':
main()