Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions scripts/leakageshow
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python3

"""
Script to show leakage status.
"""

import os
import sys
from tabulate import tabulate
from natsort import natsorted

# mock the redis for unit test purposes #
try:
if os.environ["UTILITIES_UNIT_TESTING"] == "1":
modules_path = os.path.join(os.path.dirname(__file__), "..")
test_path = os.path.join(modules_path, "tests")
sys.path.insert(0, modules_path)
sys.path.insert(0, test_path)
import mock_tables.dbconnector
except KeyError:
pass

from swsscommon.swsscommon import SonicV2Connector

header = ['Name', 'Leak']

LIQUID_COOLING_TABLE_NAME = 'LIQUID_COOLING_INFO'
STATUS_FIELD_NAME = 'leak_status'

class LeakageShow(object):
def __init__(self):
self.db = SonicV2Connector(host="127.0.0.1")
self.db.connect(self.db.STATE_DB)

def show(self):
keys = self.db.keys(self.db.STATE_DB, LIQUID_COOLING_TABLE_NAME + '*')
if not keys:
print('Leakage sensor Not detected\n')
return

table = []
for key in natsorted(keys):
key_list = key.split('|')
if len(key_list) != 2: # error data in DB, log it and ignore
print('Warn: Invalid key in table LIQUID_COOLING_INFO: {}'.format(key))
continue

name = key_list[1]
data_dict = self.db.get_all(self.db.STATE_DB, key)
status = data_dict[STATUS_FIELD_NAME]

table.append((name, status))

if table:
print(tabulate(table, header, tablefmt='simple', stralign='right'))
else:
print('No leakage status data available\n')


if __name__ == "__main__":
leakageShow = LeakageShow()
leakageShow.show()
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
'scripts/intfstat',
'scripts/ipintutil',
'scripts/lag_keepalive.py',
'scripts/leakageshow',
'scripts/lldpshow',
'scripts/log_ssd_health',
'scripts/mellanox_buffer_migrator.py',
Expand Down
14 changes: 14 additions & 0 deletions show/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,17 @@ def firmware(args):
subprocess.check_call(cmd)
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)


# 'leakage' subcommand ("show platform leakage status")
@platform.group()
def leakage():
"""Show platform leakage information"""
pass


@leakage.command()
def status():
"""Show platform leakage status"""
cmd = ["leakageshow"]
clicommon.run_command(cmd)
37 changes: 37 additions & 0 deletions tests/leakage_status_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys
import os
from click.testing import CliRunner
import show.main as show

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
scripts_path = os.path.join(modules_path, "scripts")
sys.path.insert(0, modules_path)


class TestFan(object):
@classmethod
def setup_class(cls):
print("SETUP")
os.environ["PATH"] += os.pathsep + scripts_path
os.environ["UTILITIES_UNIT_TESTING"] = "1"

def test_show_platform_leakage_status(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["platform"].commands["leakage"].commands["status"])
print(result.output)
expected = """\
Name Leak
-------- ------
leakage1 No
leakage2 No
leakage3 Yes
"""

assert result.output == expected

@classmethod
def teardown_class(cls):
print("TEARDOWN")
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
os.environ["UTILITIES_UNIT_TESTING"] = "0"
9 changes: 9 additions & 0 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,15 @@
"14": "200:200:200:200::5@Vlan1000",
"15": "200:200:200:200::5@Vlan1000"
},
"LIQUID_COOLING_INFO|leakage1": {
"leak_status": "No"
},
"LIQUID_COOLING_INFO|leakage2": {
"leak_status": "No"
},
"LIQUID_COOLING_INFO|leakage3": {
"leak_status": "Yes"
},
"FG_ROUTE_TABLE|100.50.25.12/32": {
"0": "200.200.200.4@Vlan1000",
"1": "200.200.200.4@Vlan1000",
Expand Down
Loading