Skip to content

Commit 249fd80

Browse files
committed
Add Dell Enterprise SONiC CLI driver
This patch is required urgently for Cambridge. It is unlikely that we can wait for the upstream patch to merge: https://review.opendev.org/c/openstack/networking-generic-switch/+/965373 This driver uses the `sonic-cli` rather than Linux userspace to configure the switch. This is because LLDP advertises switch ports based on the naming from the `sonic-cli`, which is not the same as Linux userspace. Note the existing Dell SONiC driver is using the Linux namespace netmiko driver, which is not suitable. Change-Id: Ia79de43a33c19f7b80bd0ef29badee464cd6fc0c Signed-off-by: Doug Szumski <[email protected]>
1 parent d6fba83 commit 249fd80

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed

doc/source/configuration.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ for the Dell OS10 device::
117117
password = password
118118
secret = secret
119119

120+
for the Dell Enterprise SONiC CLI device::
121+
122+
[genericswitch:dell-hostname]
123+
device_type = netmiko_dell_enterprise_sonic_cli
124+
ngs_mac_address = <switch mac address>
125+
ip = <switch mgmt ip address>
126+
username = admin
127+
password = password
128+
secret = secret
129+
120130
for the Dell PowerConnect device::
121131

122132
[genericswitch:dell-hostname]

networking_generic_switch/devices/netmiko_devices/dell.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,70 @@ class DellNos(netmiko_devices.NetmikoSwitch):
133133
)
134134

135135

136+
class DellEnterpriseSonicCli(netmiko_devices.NetmikoSwitch):
137+
"""Netmiko device driver for Dell Enterprise switches.
138+
139+
Developed against SONiC-OS-4.2.3-Edge_Standard.
140+
141+
This driver uses the sonic-cli rather than Linux userspace to
142+
configure the switch. This is because LLDP advertises switch
143+
ports based on the naming from the sonic-cli, which is not the
144+
same as Linux userspace.
145+
"""
146+
147+
NETMIKO_DEVICE_TYPE = "dell_sonic_ssh"
148+
149+
ADD_NETWORK = (
150+
'interface Vlan {segmentation_id}',
151+
)
152+
153+
DELETE_NETWORK = (
154+
'no interface Vlan {segmentation_id}',
155+
)
156+
157+
PLUG_PORT_TO_NETWORK = (
158+
'interface {port}',
159+
'switchport access Vlan {segmentation_id}',
160+
)
161+
162+
DELETE_PORT = (
163+
'interface {port}',
164+
'no switchport access Vlan',
165+
)
166+
167+
SAVE_CONFIGURATION = (
168+
'copy running-configuration startup-configuration',
169+
)
170+
171+
# TODO(dougszu): We need some typical failures to add here
172+
ERROR_MSG_PATTERNS = []
173+
174+
def save_configuration(self, net_connect):
175+
"""Try to save the device's configuration.
176+
177+
:param net_connect: a netmiko connection object.
178+
"""
179+
# NOTE(dougszu): We override this because the default
180+
# method tries 'copy running-config startup-config' which
181+
# is transformed by the switch to:
182+
# 'copy running-configuration startup-configuration'.
183+
for cmd in self.SAVE_CONFIGURATION:
184+
net_connect.send_command(cmd)
185+
186+
def send_config_set(self, net_connect, cmd_set):
187+
"""Send a set of configuration lines to the device.
188+
189+
:param net_connect: a netmiko connection object.
190+
:param cmd_set: a list of configuration lines to send.
191+
:returns: The output of the configuration commands.
192+
"""
193+
net_connect.enable()
194+
# NOTE(dougszu): We override this so that we wait for commands
195+
# to run before moving on.
196+
return net_connect.send_config_set(config_commands=cmd_set,
197+
cmd_verify=True)
198+
199+
136200
class DellPowerConnect(netmiko_devices.NetmikoSwitch):
137201
"""Netmiko device driver for Dell PowerConnect switches."""
138202

networking_generic_switch/tests/unit/netmiko/test_dell.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,46 @@ def test__format_commands(self):
123123
['interface vlan 33', 'no tagged 3333', 'exit'])
124124

125125

126+
class TestNetmikoDellEnterpriseSonicCli(
127+
test_netmiko_base.NetmikoSwitchTestBase):
128+
129+
def _make_switch_device(self, extra_cfg={}):
130+
device_cfg = {'device_type': 'netmiko_dell_enterprise_sonic_cli'}
131+
device_cfg.update(extra_cfg)
132+
return dell.DellEnterpriseSonicCli(device_cfg)
133+
134+
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
135+
'NetmikoSwitch.send_commands_to_device', autospec=True)
136+
def test_add_network(self, m_exec):
137+
self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
138+
m_exec.assert_called_with(
139+
self.switch,
140+
['interface Vlan 33'])
141+
142+
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
143+
'NetmikoSwitch.send_commands_to_device', autospec=True)
144+
def test_del_network(self, mock_exec):
145+
self.switch.del_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
146+
mock_exec.assert_called_with(self.switch,
147+
['no interface Vlan 33'])
148+
149+
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
150+
'NetmikoSwitch.send_commands_to_device', autospec=True)
151+
def test_plug_port_to_network(self, mock_exec):
152+
self.switch.plug_port_to_network(3333, 33)
153+
mock_exec.assert_called_with(
154+
self.switch,
155+
['interface 3333', 'switchport access Vlan 33'])
156+
157+
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
158+
'NetmikoSwitch.send_commands_to_device', autospec=True)
159+
def test_delete_port(self, mock_exec):
160+
self.switch.delete_port(3333, 33)
161+
mock_exec.assert_called_with(
162+
self.switch,
163+
['interface 3333', 'no switchport access Vlan'])
164+
165+
126166
class TestNetmikoDellOS10(test_netmiko_base.NetmikoSwitchTestBase):
127167

128168
def _make_switch_device(self, extra_cfg={}):
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
features:
3+
- |
4+
Adds Dell Enterprise SONiC CLI driver. This differs from the existing Dell
5+
SONiC driver in that it uses the `sonic-cli` to administer the switch.
6+
This ensures that the port names advertised via LLDP from the switch can
7+
be used without conversion to the different naming scheme used in the
8+
Linux userspace environment.

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ generic_switch.devices =
3838
netmiko_huawei_vrpv8 = networking_generic_switch.devices.netmiko_devices.huawei_vrpv8:Huawei
3939
netmiko_arista_eos = networking_generic_switch.devices.netmiko_devices.arista:AristaEos
4040
netmiko_dell_os10 = networking_generic_switch.devices.netmiko_devices.dell:DellOS10
41+
netmiko_dell_enterprise_sonic_cli = networking_generic_switch.devices.netmiko_devices.dell:DellEnterpriseSonicCli
4142
netmiko_dell_force10 = networking_generic_switch.devices.netmiko_devices.dell:DellNos
4243
netmiko_dell_powerconnect = networking_generic_switch.devices.netmiko_devices.dell:DellPowerConnect
4344
netmiko_brocade_fastiron = networking_generic_switch.devices.netmiko_devices.brocade:BrocadeFastIron

0 commit comments

Comments
 (0)