Skip to content

Commit 7edbb94

Browse files
committed
[pdu support] unify the PDU support naming convention
The device external to the DUT that supply power to PSU (on DUT) is PDU. The unit send out power is outlet. This change unifies this concept in class names, function names and variables. No functional change is supposed to happen with this change. Signed-off-by: Ying Xie <ying.xie@microsoft.com>
1 parent 451d052 commit 7edbb94

10 files changed

Lines changed: 204 additions & 206 deletions

File tree

ansible/devutils

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ from devutil.task_runner import TaskRunner
1616
import sys
1717
sys.path.append("..")
1818
from tests.common.connections import ConsoleHost
19-
from tests.common.plugins.psu_controller.snmp_psu_controllers import get_psu_controller
19+
from tests.common.plugins.pdu_controller.snmp_pdu_controllers import get_pdu_controller
2020

2121
g_inv_mgr = None
2222
g_task_runner = None
@@ -156,21 +156,21 @@ def pdu_action_on_dut(host, attrs, action):
156156
rec = { 'PDU' : p_name, 'PDU_IP' : pdu_host, 'status' : [] }
157157
ret['PDU status'].append(rec)
158158

159-
controller = get_psu_controller(pdu_host, host, pdu_info)
159+
controller = get_pdu_controller(pdu_host, host, pdu_info)
160160

161161
if not controller:
162162
ret['Summary'].append('Failed to communicate with controller {}'.format(p_name))
163163
continue
164164

165-
rec['status'] = controller.get_psu_status()
165+
rec['status'] = controller.get_outlet_status()
166166
if action == 'off':
167167
for outlet in rec['status']:
168-
controller.turn_off_psu(outlet['psu_id'])
169-
rec['status'] = controller.get_psu_status()
168+
controller.turn_off_outlet(outlet['outlet_id'])
169+
rec['status'] = controller.get_outlet_status()
170170
elif action == 'on':
171171
for outlet in rec['status']:
172-
controller.turn_on_psu(outlet['psu_id'])
173-
rec['status'] = controller.get_psu_status()
172+
controller.turn_on_outlet(outlet['outlet_id'])
173+
rec['status'] = controller.get_outlet_status()
174174
elif action != 'status':
175175
ret['Summary'].append('Unsupported action {}.'.format(action))
176176
continue

docs/tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Plugins:
1010
- [ptfadapter](/tests/common/ptfadapter/README.md)
1111
- [DUT monitor](/tests/common/dut_monitor/README.md)
1212
- [Log Analyzer](/tests/common/loganalyzer/README.md)
13-
- [PSU Controller](/tests/common/psu_controller/README.md)
13+
- [PSU Controller](/tests/common/pdu_controller/README.md)
1414
- [Sanity Check](/tests/common/sanity_check/README.md)
1515
- [Test Completeness](/tests/common/test_completeness/README.md)
1616

tests/common/plugins/psu_controller/README.md renamed to tests/common/plugins/pdu_controller/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# psu_controller fixture user guide
1+
# pdu_controller fixture user guide
22

33
PSU controller is usually a PDU device which can supply power to PSUs of SONiC switch. The PDU devices usually provide management interface like SNMP, web GUI, telnet, SSH, etc.
44

5-
This plugin defined a fixture named psu_controller. It returns a python object implements the interface of PsuControllerBase defined in controller_base.py.
5+
This plugin defined a fixture named pdu_controller. It returns a python object implements the interface of PsuControllerBase defined in controller_base.py.
66

77
## Add PDU information in inventory file
88

9-
To get a psu_controller object using the psu_controller fixture, PDU host information must be known.
9+
To get a pdu_controller object using the pdu_controller fixture, PDU host information must be known.
1010

1111
PDU information of each DUT device need to be added to the inventory file. The minimum required information information of PDU host is:
1212
* IP address of the PDU host

tests/common/plugins/psu_controller/__init__.py renamed to tests/common/plugins/pdu_controller/__init__.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,34 @@
33
import pytest
44

55

6-
def psu_controller_factory(controller_ip, controller_protocol, dut_hostname, pdu):
6+
def pdu_controller_factory(controller_ip, controller_protocol, dut_hostname, pdu):
77
"""
8-
@summary: Factory function for creating PSU controller according to different management protocol.
9-
@param controller_ip: IP address of the PSU controller host.
10-
@param controller_protocol: Management protocol supported by the PSU controller host.
11-
@param dut_hostname: Hostname of the DUT to be controlled by the PSU controller.
8+
@summary: Factory function for creating PDU controller according to different management protocol.
9+
@param controller_ip: IP address of the PDU controller host.
10+
@param controller_protocol: Management protocol supported by the PDU controller host.
11+
@param dut_hostname: Hostname of the DUT to be controlled by the PDU controller.
1212
"""
13-
logging.info("Creating psu controller object")
13+
logging.info("Creating pdu controller object")
1414
if controller_protocol == "snmp":
15-
import snmp_psu_controllers
16-
return snmp_psu_controllers.get_psu_controller(controller_ip, dut_hostname, pdu)
15+
import snmp_pdu_controllers
16+
return snmp_pdu_controllers.get_pdu_controller(controller_ip, dut_hostname, pdu)
1717

1818

1919
@pytest.fixture(scope="module")
20-
def psu_controller(duthosts, rand_one_dut_hostname, pdu):
20+
def pdu_controller(duthosts, rand_one_dut_hostname, pdu):
2121
"""
2222
@summary: Fixture for controlling power supply to PSUs of DUT
2323
@param duthost: Fixture duthost defined in sonic-mgmt/tests/conftest.py
24-
@returns: Returns a psu controller object implementing the BasePsuController interface defined in
24+
@returns: Returns a pdu controller object implementing the BasePduController interface defined in
2525
controller_base.py.
2626
"""
2727
duthost = duthosts[rand_one_dut_hostname]
2828

29-
logging.info("Creating psu_controller fixture")
29+
logging.info("Creating pdu_controller fixture")
3030
inv_mgr = duthost.host.options["inventory_manager"]
3131
pdu_host = inv_mgr.get_host(duthost.hostname).get_vars().get("pdu_host")
3232
if not pdu_host:
33-
logging.info("No 'pdu_host' is defined in inventory file for '%s'. Unable to create psu_controller" %
33+
logging.info("No 'pdu_host' is defined in inventory file for '%s'. Unable to create pdu_controller" %
3434
duthost.hostname)
3535
yield None
3636
return
@@ -40,7 +40,7 @@ def psu_controller(duthosts, rand_one_dut_hostname, pdu):
4040
controller_ip = controller_vars.get("ansible_host")
4141
if not controller_ip:
4242
logging.info("No 'ansible_host' is defined in inventory file for '%s'" % pdu_host)
43-
logging.info("Unable to create psu_controller for %s" % duthost.hostname)
43+
logging.info("Unable to create pdu_controller for %s" % duthost.hostname)
4444
yield None
4545
return
4646

@@ -49,15 +49,15 @@ def psu_controller(duthosts, rand_one_dut_hostname, pdu):
4949
logging.info("No protocol is defined in inventory file for '%s'. Try to use default 'snmp'" % pdu_host)
5050
controller_protocol = "snmp"
5151

52-
controller = psu_controller_factory(controller_ip, controller_protocol, duthost.hostname, pdu)
52+
controller = pdu_controller_factory(controller_ip, controller_protocol, duthost.hostname, pdu)
5353

5454
yield controller
5555

56-
logging.info("psu_controller fixture teardown, ensure that all PSUs are turned on after test")
56+
logging.info("pdu_controller fixture teardown, ensure that all PDU outlets are turned on after test")
5757
if controller:
58-
psu_status = controller.get_psu_status()
59-
if psu_status:
60-
for psu in psu_status:
61-
if not psu["psu_on"]:
62-
controller.turn_on_psu(psu["psu_id"])
58+
outlet_status = controller.get_outlet_status()
59+
if outlet_status:
60+
for outlet in outlet_status:
61+
if not outlet["outlet_on"]:
62+
controller.turn_on_outlet(outlet["outlet_id"])
6363
controller.close()

tests/common/plugins/psu_controller/controller_base.py renamed to tests/common/plugins/pdu_controller/controller_base.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,54 @@
11
"""
2-
Base class for controlling PSUs of DUT
2+
Base class for controlling PDU(s) connected to DUT power supplies
33
4-
This file defines the base class for controlling PSUs of DUT. The base class defined the basic interface of
5-
PSU controllers.
4+
This file defines the base class for controlling PDU outlets. The base class defined the basic interface of
5+
PDU controllers.
66
7-
The PSU controller for actually controlling PSUs must be a subclass of the PsuControllerBase class and must
7+
The PDU controller for PDUs must be a subclass of the PduControllerBase class and must
88
implement the methods defined in the base class.
99
"""
10-
import os
11-
import sys
1210
import subprocess
1311

1412

15-
class PsuControllerBase():
13+
class PduControllerBase():
1614
"""
17-
@summary: Base class for PSU controller
15+
@summary: Base class for PDU controller
1816
19-
This base class defines the basic interface to be provided by PSU controller.
17+
This base class defines the basic interface to be provided by PDU controller.
2018
21-
The PSU controller for actually controlling PSUs must be a subclass of the PsuControllerBase class and must
19+
The PDU controller for PDUs must be a subclass of the PduControllerBase class and must
2220
implement the methods defined in the base class.
2321
"""
2422
def __init__(self):
2523
pass
2624

27-
def turn_on_psu(self, psu_id):
25+
def turn_on_outlet(self, outlet):
2826
"""
29-
@summary: Turn on power for specified PSU.
27+
@summary: Turn on power for specified PDU.
3028
31-
@param psu_id: PSU ID, it could be integer of string digit. For example: 0 or '1'
29+
@param outlet: PDU ID, it could be integer of string digit. For example: 0 or '1'
3230
@return: Returns True if operation is successful. Otherwise, returns False
3331
"""
3432
raise NotImplementedError
3533

36-
def turn_off_psu(self, psu_id):
34+
def turn_off_outlet(self, outlet):
3735
"""
38-
@summary: Turn off power for specified PSU.
36+
@summary: Turn off power for specified PDU.
3937
40-
@param psu_id: PSU ID, it could be integer of string digit. For example: 0 or '1'
38+
@param outlet: PDU ID, it could be integer of string digit. For example: 0 or '1'
4139
@return: Returns True if operation is successful. Otherwise, returns False
4240
"""
4341
raise NotImplementedError
4442

45-
def get_psu_status(self, psu_id=None):
43+
def get_outlet_status(self, outlet=None):
4644
"""
47-
@summary: Get current power status of PSUs
45+
@summary: Get current power status of PDU outlets
4846
49-
@param psu_id: Optional PSU ID, it could be integer or string digit. If no psu_id is specified, power status of
50-
all PSUs should be returned
47+
@param outlet: Optional outlet ID, it could be integer or string digit. If no outlet is specified, power status of
48+
all PDU outlets should be returned
5149
@return: Returns a list of dictionaries. For example:
52-
[{"psu_id": 0, "psu_on": True}, {"psu_id": 1, "psu_on": True}]
53-
If getting PSU status failed, an empty list should be returned.
50+
[{"outlet_id": 0, "outlet_on": True}, {"outlet_id": 1, "outlet_on": True}]
51+
If getting outlet(s) status failed, an empty list should be returned.
5452
"""
5553
raise NotImplementedError
5654

0 commit comments

Comments
 (0)