Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pdu controller] refactoring snmp pdu controller #3041

Merged
merged 4 commits into from
Mar 2, 2021
Merged
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
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