-
Notifications
You must be signed in to change notification settings - Fork 1k
[pdu manager] introduce pdu manager #3013
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,63 +1,33 @@ | ||
| import logging | ||
|
|
||
| import pytest | ||
| from pdu_manager import pdu_manager_factory | ||
|
|
||
|
|
||
| def pdu_controller_factory(controller_ip, controller_protocol, dut_hostname, pdu): | ||
| """ | ||
| @summary: Factory function for creating PDU controller according to different management protocol. | ||
| @param controller_ip: IP address of the PDU controller host. | ||
| @param controller_protocol: Management protocol supported by the PDU controller host. | ||
| @param dut_hostname: Hostname of the DUT to be controlled by the PDU controller. | ||
| """ | ||
| logging.info("Creating pdu controller object") | ||
| if controller_protocol == "snmp": | ||
| import snmp_pdu_controllers | ||
| return snmp_pdu_controllers.get_pdu_controller(controller_ip, dut_hostname, pdu) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def pdu_controller(duthosts, rand_one_dut_hostname, pdu): | ||
| def pdu_controller(duthosts, rand_one_dut_hostname, conn_graph_facts, pdu): | ||
| """ | ||
| @summary: Fixture for controlling power supply to PSUs of DUT | ||
| @param duthost: Fixture duthost defined in sonic-mgmt/tests/conftest.py | ||
| @returns: Returns a pdu controller object implementing the BasePduController interface defined in | ||
| controller_base.py. | ||
| """ | ||
| duthost = duthosts[rand_one_dut_hostname] | ||
|
|
||
| logging.info("Creating pdu_controller fixture") | ||
| inv_mgr = duthost.host.options["inventory_manager"] | ||
| pdu_host = inv_mgr.get_host(duthost.hostname).get_vars().get("pdu_host") | ||
| if not pdu_host: | ||
| logging.info("No 'pdu_host' is defined in inventory file for '%s'. Unable to create pdu_controller" % | ||
| duthost.hostname) | ||
| yield None | ||
| return | ||
|
|
||
| controller_vars = inv_mgr.get_host(pdu_host).get_vars() | ||
|
|
||
| controller_ip = controller_vars.get("ansible_host") | ||
| if not controller_ip: | ||
| logging.info("No 'ansible_host' is defined in inventory file for '%s'" % pdu_host) | ||
| logging.info("Unable to create pdu_controller for %s" % duthost.hostname) | ||
| yield None | ||
| return | ||
|
|
||
| controller_protocol = controller_vars.get("protocol") | ||
| if not controller_protocol: | ||
| logging.info("No protocol is defined in inventory file for '%s'. Try to use default 'snmp'" % pdu_host) | ||
| controller_protocol = "snmp" | ||
| pdu_host_list = inv_mgr.get_host(duthost.hostname).get_vars().get("pdu_host") | ||
| pdu_hosts = {} | ||
| for ph in pdu_host_list.split(','): | ||
| var_list = inv_mgr.get_host(ph).get_vars() | ||
| pdu_hosts[ph] = var_list | ||
|
|
||
| controller = pdu_controller_factory(controller_ip, controller_protocol, duthost.hostname, pdu) | ||
| controller = pdu_manager_factory(duthost.hostname, pdu_hosts, conn_graph_facts, pdu) | ||
|
|
||
| yield controller | ||
|
|
||
| logging.info("pdu_controller fixture teardown, ensure that all PDU outlets are turned on after test") | ||
| logger.info("pdu_controller fixture teardown, ensure that all PDU outlets are turned on after test") | ||
| if controller: | ||
| outlet_status = controller.get_outlet_status() | ||
| if outlet_status: | ||
| for outlet in outlet_status: | ||
| if not outlet["outlet_on"]: | ||
| controller.turn_on_outlet(outlet["outlet_id"]) | ||
| controller.turn_on_outlet() | ||
| controller.close() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.