Skip to content

Commit

Permalink
[fanshow] Display other fan status, such as Updating (sonic-net#1014)
Browse files Browse the repository at this point in the history
The original fan status can be one of "OK", "Not OK", "N/A". This PR allows a new fan status "Updating".
If fan status is not "true" or "false", display the status field value in CLI output.
  • Loading branch information
Junchao-Mellanox authored Aug 25, 2020
1 parent 3e52604 commit 8934479
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 5 deletions.
23 changes: 18 additions & 5 deletions scripts/fanshow
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@
"""
from __future__ import print_function

import os
import sys
from tabulate import tabulate
from swsssdk import SonicV2Connector
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


header = ['Drawer', 'LED', 'FAN', 'Speed', 'Direction', 'Presence', 'Status', 'Timestamp']

Expand Down Expand Up @@ -52,13 +65,13 @@ class FanShow(object):

presence = data_dict[PRESENCE_FIELD_NAME].lower()
presence = 'Present' if presence == 'true' else 'Not Present'
status = data_dict[STATUS_FIELD_NAME].lower()
if status == 'true':

status = data_dict[STATUS_FIELD_NAME]
status_lower = status.lower()
if status_lower == 'true':
status = 'OK'
elif status == 'false':
elif status_lower == 'false':
status = 'Not OK'
else:
status = 'N/A'

table.append((data_dict[DRAWER_FIELD_NAME], data_dict[LED_STATUS_FIELD_NAME], name, speed, data_dict[DIRECTION_FIELD_NAME], presence, status,
data_dict[TIMESTAMP_FIELD_NAME]))
Expand Down
38 changes: 38 additions & 0 deletions tests/fan_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys
import os
from click.testing import CliRunner

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)

import show.main as show

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_fan(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["platform"].commands["fan"])
print(result.output)
expected = """\
Drawer LED FAN Speed Direction Presence Status Timestamp
-------- ----- ----- ------- ----------- ---------- -------- -----------------
drawer1 red fan1 30% intake Present OK 20200813 01:32:30
drawer2 green fan2 50% intake Present Not OK 20200813 01:32:30
drawer3 green fan3 50% intake Present Updating 20200813 01:32:30
"""

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"

39 changes: 39 additions & 0 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,44 @@
"runner.fast_rate": "false",
"setup.kernel_team_mode_name": "loadbalance",
"runner.active": "true"
},
"FAN_INFO|fan1": {
"drawer_name": "drawer1",
"presence": "True",
"model": "N/A",
"serial": "N/A",
"status": "True",
"direction": "intake",
"speed": "30",
"speed_tolerance": "50",
"speed_target": "20",
"led_status": "red",
"timestamp": "20200813 01:32:30"
},
"FAN_INFO|fan2": {
"drawer_name": "drawer2",
"presence": "True",
"model": "N/A",
"serial": "N/A",
"status": "False",
"direction": "intake",
"speed": "50",
"speed_tolerance": "50",
"speed_target": "50",
"led_status": "green",
"timestamp": "20200813 01:32:30"
},
"FAN_INFO|fan3": {
"drawer_name": "drawer3",
"presence": "True",
"model": "N/A",
"serial": "N/A",
"status": "Updating",
"direction": "intake",
"speed": "50",
"speed_tolerance": "50",
"speed_target": "50",
"led_status": "green",
"timestamp": "20200813 01:32:30"
}
}

0 comments on commit 8934479

Please sign in to comment.