Skip to content

Commit

Permalink
[pdu controller] refactoring snmp pdu controller (#3041)
Browse files Browse the repository at this point in the history
Description of PR
Refactoring the SNMP PDU controller code.

Summary:
Approach
What is the motivation for this PR?
Clean up the SNMP PDU control code to be a generic SNMP controller controls the whole PDU.

How did you do it?
Making PDU controller more generic. It should manage the whole PDU controller instead of just for a single DUT.

For PDU models that know has lane concept. Make lane ID part of the outlet ID. And outlet ID is the portion of OID that can
uniquely identify an outlet on the particular PDU.

Label match is still supported by a passed in hostname.

Add support to query output power wattage

Signed-off-by: Ying Xie ying.xie@microsoft.com

How did you verify/test it?
Ran all test cases invoked pdu controller and tested with devutils
  • Loading branch information
yxieca authored Mar 2, 2021
1 parent de9c33f commit 724e05f
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 114 deletions.
5 changes: 3 additions & 2 deletions tests/common/plugins/pdu_controller/controller_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ def turn_off_outlet(self, outlet):
"""
raise NotImplementedError

def get_outlet_status(self, outlet=None):
def get_outlet_status(self, outlet=None, hostname=None):
"""
@summary: Get current power status of PDU outlets
@param outlet: Optional outlet ID, it could be integer or string digit. If no outlet is specified, power status of
all PDU outlets should be returned
@param hostname: Optional hostname used to partial match any label
@return: Returns a list of dictionaries. For example:
[{"outlet_id": 0, "outlet_on": True}, {"outlet_id": 1, "outlet_on": True}]
[{"outlet_id": "0.0.1", "outlet_on": True}, {"outlet_id": "0.0.2", "outlet_on": True}]
If getting outlet(s) status failed, an empty list should be returned.
"""
raise NotImplementedError
Expand Down
8 changes: 4 additions & 4 deletions tests/common/plugins/pdu_controller/pdu_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def add_controller(self, psu_name, psu_peer, pdu_vars):
next_index = len(self.controllers)
self.controllers.append(pdu)
if not shared_pdu:
controller = get_pdu_controller(pdu_ip, self.dut_hostname, pdu_vars)
controller = get_pdu_controller(pdu_ip, pdu_vars)
if not controller:
logger.warning('Failed creating pdu controller: {}'.format(psu_peer))
return
outlets = controller.get_outlet_status()
outlets = controller.get_outlet_status(hostname=self.dut_hostname)
self._update_outlets(outlets, next_index)
pdu['outlets'] = outlets
pdu['controller'] = controller
Expand Down Expand Up @@ -158,14 +158,14 @@ def get_outlet_status(self, outlet=None):
if outlet is not None:
pdu_index = outlet['pdu_index']
controller = self._get_pdu_controller(pdu_index)
outlets = controller.get_outlet_status(outlet['outlet_id'])
outlets = controller.get_outlet_status(outlet=outlet['outlet_id'])
self._update_outlets(outlets, pdu_index)
status = status + outlets
else:
# collect all status
for pdu_index, controller in enumerate(self.controllers):
if len(controller['outlets']) > 0:
outlets = controller['controller'].get_outlet_status()
outlets = controller['controller'].get_outlet_status(hostname=self.dut_hostname)
self._update_outlets(outlets, pdu_index)
status = status + outlets

Expand Down
Loading

0 comments on commit 724e05f

Please sign in to comment.