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

Add devlink_port API #238

Merged
merged 1 commit into from
Apr 6, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
- module: devlink
description: devlink-port - devlink port configuration
classes:
- name: devlink_port
desc: |
devlink [ OPTIONS ] port { COMMAND | help }
OPTIONS := { -V[ersion] | -n[no-nice-names] }

devlink port set DEV/PORT_INDEX [ type { eth | ib | auto } ]
devlink port split DEV/PORT_INDEX count COUNT
devlink port unsplit DEV/PORT_INDEX
devlink port show [ DEV/PORT_INDEX ]
devlink port health { show | recover | diagnose | dump | set }
devlink port add { DEV | DEV/PORT_INDEX } [ flavour FLAVOUR ] [
pfnum PFNUMBER ] [ sfnum SFNUMBER ] [ controller CNUM ]

devlink port del DEV/PORT_INDEX
devlink port function set DEV/PORT_INDEX [ hw_addr ADDR ] [ state
{ active | inactive } ]

devlink port function rate { show | set | add | del | help }
devlink dev param set DEV/PORT_INDEX name PARAMETER value VALUE
cmode { runtime | driverinit | permanent }

devlink dev param show [ DEV/PORT_INDEX name PARAMETER ]
devlink port help
apis: ['set', 'split', 'unsplit', 'show', 'health', 'add', 'delete', 'function', 'param']
members:
- name: dev
type: string
desc: |
dev - specifies the devlink port to operate on.
Format is:
BUS_NAME/BUS_ADDRESS/PORT_INDEX
- name: name
type: string
desc: |
Specify parameter name to set.
- name: value
type: string
desc: |
New value to set.
- name: cmode
type: string
desc: |
Configuration mode in which the new value is set.
runtime - Set new value while driver is running. This
configuration mode doesn't require any reset to apply the
new value.

driverinit - Set new value which will be applied during
driver initialization. This configuration mode requires
restart driver by devlink reload command to apply the new
value.

permanent - New value is written to device's non-volatile
memory. This configuration mode requires hard reset to
apply the new value.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- module: devlink
description: devlink - Devlink tool
classes:
- name: devlink_port
desc: |
devlink [ OPTIONS ] {dev|port|monitor|sb|resource|region|health|trap } {COMMAND | help }
devlink [ -force ] -batch filename
implements: 'dent:devlink:devlink_port'
platforms: ['dentos']
commands:
- name: set
apis: ['set']
cmd: ['devlink port param']
params: ['dev', 'name', 'value', 'cmode']
desc: |
devlink port param set DEV/PORT_INDEX name PARAMETER value VALUE
cmode { runtime | driverinit | permanent }
- name: show
apis: ['show']
cmd: ['devlink port param']
params: ['dev', 'name']
desc: |
devlink port param show [ DEV/PORT_INDEX name PARAMETER ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# generated using file ./gen/model/dent/network/devlink/devlink.yaml
#
# DONOT EDIT - generated by diligent bots

import pytest
from dent_os_testbed.lib.test_lib_object import TestLibObject
from dent_os_testbed.lib.devlink.linux.devlink_port_impl import DevlinkPortImpl
class DevlinkPort(TestLibObject):
"""
devlink [ OPTIONS ] port { COMMAND | help }
OPTIONS := { -V[ersion] | -n[no-nice-names] }

devlink port set DEV/PORT_INDEX [ type { eth | ib | auto } ]
devlink port split DEV/PORT_INDEX count COUNT
devlink port unsplit DEV/PORT_INDEX
devlink port show [ DEV/PORT_INDEX ]
devlink port health { show | recover | diagnose | dump | set }
devlink port add { DEV | DEV/PORT_INDEX } [ flavour FLAVOUR ] [
pfnum PFNUMBER ] [ sfnum SFNUMBER ] [ controller CNUM ]

devlink port del DEV/PORT_INDEX
devlink port function set DEV/PORT_INDEX [ hw_addr ADDR ] [ state
{ active | inactive } ]

devlink port function rate { show | set | add | del | help }
devlink dev param set DEV/PORT_INDEX name PARAMETER value VALUE
cmode { runtime | driverinit | permanent }

devlink dev param show [ DEV/PORT_INDEX name PARAMETER ]
devlink port help

"""
async def _run_command(api, *argv, **kwarg):
devices = kwarg['input_data']
result = list()
for device in devices:
for device_name in device:
device_result = {
device_name : dict()
}
# device lookup
if 'device_obj' in kwarg:
device_obj = kwarg.get('device_obj', None)[device_name]
else:
if device_name not in pytest.testbed.devices_dict:
device_result[device_name] = "No matching device "+ device_name
result.append(device_result)
return result
device_obj = pytest.testbed.devices_dict[device_name]
commands = ""
if device_obj.os in ['dentos']:
impl_obj = DevlinkPortImpl()
for command in device[device_name]:
commands += impl_obj.format_command(command=api, params=command)
commands += '&& '
commands = commands[:-3]

else:
device_result[device_name]['rc'] = -1
device_result[device_name]['result'] = "No matching device OS "+ device_obj.os
result.append(device_result)
return result
device_result[device_name]['command'] = commands
try:
rc, output = await device_obj.run_cmd(("sudo " if device_obj.ssh_conn_params.pssh else "") + commands)
device_result[device_name]['rc'] = rc
device_result[device_name]['result'] = output
if 'parse_output' in kwarg:
parse_output = impl_obj.parse_output(command=api, output=output, commands=commands)
device_result[device_name]['parsed_output'] = parse_output
except Exception as e:
device_result[device_name]['rc'] = -1
device_result[device_name]['result'] = str(e)
result.append(device_result)
return result

async def set(*argv, **kwarg):
"""
Platforms: ['dentos']
Usage:
DevlinkPort.set(
input_data = [{
# device 1
'dev1' : [{
# command 1
'dev':'string',
'name':'string',
'value':'string',
'cmode':'string',
}],
}],
)
Description:
devlink port param set DEV/PORT_INDEX name PARAMETER value VALUE
cmode { runtime | driverinit | permanent }

"""
return await DevlinkPort._run_command("set", *argv, **kwarg)

async def split(*argv, **kwarg):
"""
Platforms: ['dentos']
Usage:
DevlinkPort.split(
input_data = [{
# device 1
'dev1' : [{
# command 1

}],
}],
)
Description:

"""
return await DevlinkPort._run_command("split", *argv, **kwarg)

async def unsplit(*argv, **kwarg):
"""
Platforms: ['dentos']
Usage:
DevlinkPort.unsplit(
input_data = [{
# device 1
'dev1' : [{
# command 1

}],
}],
)
Description:

"""
return await DevlinkPort._run_command("unsplit", *argv, **kwarg)

async def show(*argv, **kwarg):
"""
Platforms: ['dentos']
Usage:
DevlinkPort.show(
input_data = [{
# device 1
'dev1' : [{
# command 1
'dev':'string',
'name':'string',
}],
}],
)
Description:
devlink port param show [ DEV/PORT_INDEX name PARAMETER ]
"""
return await DevlinkPort._run_command("show", *argv, **kwarg)

async def health(*argv, **kwarg):
"""
Platforms: ['dentos']
Usage:
DevlinkPort.health(
input_data = [{
# device 1
'dev1' : [{
# command 1

}],
}],
)
Description:

"""
return await DevlinkPort._run_command("health", *argv, **kwarg)

async def add(*argv, **kwarg):
"""
Platforms: ['dentos']
Usage:
DevlinkPort.add(
input_data = [{
# device 1
'dev1' : [{
# command 1

}],
}],
)
Description:

"""
return await DevlinkPort._run_command("add", *argv, **kwarg)

async def delete(*argv, **kwarg):
"""
Platforms: ['dentos']
Usage:
DevlinkPort.delete(
input_data = [{
# device 1
'dev1' : [{
# command 1

}],
}],
)
Description:

"""
return await DevlinkPort._run_command("delete", *argv, **kwarg)

async def function(*argv, **kwarg):
"""
Platforms: ['dentos']
Usage:
DevlinkPort.function(
input_data = [{
# device 1
'dev1' : [{
# command 1

}],
}],
)
Description:

"""
return await DevlinkPort._run_command("function", *argv, **kwarg)

async def param(*argv, **kwarg):
"""
Platforms: ['dentos']
Usage:
DevlinkPort.param(
input_data = [{
# device 1
'dev1' : [{
# command 1

}],
}],
)
Description:

"""
return await DevlinkPort._run_command("param", *argv, **kwarg)

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# generated using file ./gen/model/linux/network/devlink/devlink.yaml
#
# DONOT EDIT - generated by diligent bots

from dent_os_testbed.lib.test_lib_object import TestLibObject
class DevlinkPort(TestLibObject):
"""
devlink [ OPTIONS ] {dev|port|monitor|sb|resource|region|health|trap } {COMMAND | help }
devlink [ -force ] -batch filename

"""
def format_set(self, command, *argv, **kwarg):
raise NotImplementedError

def parse_set(self, command, output, *argv, **kwarg):
raise NotImplementedError

def format_show(self, command, *argv, **kwarg):
raise NotImplementedError

def parse_show(self, command, output, *argv, **kwarg):
raise NotImplementedError

def format_command(self, command, *argv, **kwarg):
if command in ['set']:
return self.format_set(command, *argv, **kwarg)

if command in ['show']:
return self.format_show(command, *argv, **kwarg)


raise NameError("Cannot find command "+command)

def parse_output(self, command, output, *argv, **kwarg):
if command in ['set']:
return self.parse_set(command, output, *argv, **kwarg)

if command in ['show']:
return self.parse_show(command, output, *argv, **kwarg)


raise NameError("Cannot find command "+command)

Loading