-
Notifications
You must be signed in to change notification settings - Fork 851
Increase timeout and set port AutonNeg according to the links file #16647
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
82224ef
9617015
e58b945
d697a79
1ed25a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Pterosaur This file change is not needed. The link file has the AN column and the minigraph should be able to generate the configuration for the AN enabled port. @vdahiya12 can you point to that? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env python | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
import traceback | ||
import subprocess | ||
import shlex | ||
|
||
|
||
def get_port_lists(): | ||
cmd = "show interfaces description | grep Ethernet | awk '{print $1}'" | ||
ps = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
output = ps.communicate()[0].decode('utf-8') | ||
port_list = [line for line in output.split('\n') if line.strip()] | ||
return port_list | ||
|
||
|
||
def get_platform(): | ||
cmd = "redis-cli --raw -n 4 hget 'DEVICE_METADATA|localhost' 'platform'" | ||
ps = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
output = ps.communicate()[0].decode('utf-8') | ||
return output.strip() | ||
|
||
|
||
def set_autoneg(port, value): | ||
if value == "on": | ||
value = "enabled" | ||
elif value == "off": | ||
value = "disabled" | ||
else: | ||
raise Exception("Invalid autoneg value: %s" % value) | ||
cmd = "config interface autoneg %s %s" % (port, value) | ||
ps = subprocess.Popen(shlex.split(cmd), shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
(_, stderr) = ps.communicate() | ||
if ps.returncode != 0: | ||
if stderr: | ||
stderr = stderr.decode('utf-8') | ||
raise Exception("Failed to set autoneg for port %s: %s" % (port, stderr)) | ||
|
||
|
||
def apply_device_conn(module, platform, port_list, device_conn): | ||
# Apply Autoneg | ||
default_autoneg_value = None | ||
# For SP4 and SP3, the default autoneg value is "on" | ||
if "nvidia_sn5" in platform or "nvidia_sn4" in platform: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do u still need to have this ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't really need them, remove them. |
||
default_autoneg_value = "on" | ||
bingwang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for port in port_list: | ||
autoneg_value = default_autoneg_value | ||
if port in device_conn: | ||
attribute = device_conn[port] | ||
if "autoneg" in attribute: | ||
autoneg_value = attribute["autoneg"] | ||
if autoneg_value: | ||
module.warn("Set autoneg for port %s to %s" % (port, autoneg_value)) | ||
set_autoneg(port, autoneg_value) | ||
|
||
|
||
def main(): | ||
module = AnsibleModule( | ||
argument_spec=dict( | ||
hostname=dict(required=False), | ||
device_conn=dict(required=True, type=dict) | ||
) | ||
) | ||
|
||
platform = get_platform() | ||
port_list = get_port_lists() | ||
device_conn = module.params['device_conn'] | ||
|
||
apply_device_conn(module, platform, port_list, device_conn) | ||
|
||
try: | ||
pass | ||
except Exception as detail: | ||
module.fail_json(msg="ERROR: %s, TRACEBACK: %s" % | ||
(repr(detail), traceback.format_exc())) | ||
module.exit_json( | ||
ansible_facts=dict() | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this for applying sonic config?
much of the config DB config will happen via #13990
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure the AutoNeg value in minigraph will be applied into the config DB?