Browse Source

add support for huawei VRPV8 switch.

detail:
    Huawei switch like CE6850EI needs to execute the command 'commit'
    after configuring the port or network. And also add the unit test for
    this type of switch.
    All newest huawei devices use VRP v8 as the next network OS now. For
    VRP v8 platform, the command 'commit' is used to avoid making some
    mistakes in a ssh connection.

Change-Id: I962398b18dcfb4b42f5a557bbdbc28be94107a0d
Close-bug: #1697676
changes/00/473800/11
fumeng2005 4 years ago
parent
commit
3dbc82a984
5 changed files with 123 additions and 11 deletions
  1. +11
    -1
      README.rst
  2. +11
    -10
      networking_generic_switch/devices/netmiko_devices/huawei.py
  3. +34
    -0
      networking_generic_switch/devices/netmiko_devices/huawei_vrpv8.py
  4. +66
    -0
      networking_generic_switch/tests/unit/netmiko/test_huawei_vrpv8.py
  5. +1
    -0
      setup.cfg

+ 11
- 1
README.rst View File

@ -71,7 +71,7 @@ for the Cisco IOS device::
secret = secret
ip = <switch mgmt ip address>
for the Huawei device::
for the Huawei VRPV3 or VRPV5 device::
[genericswitch:sw-hostname]
device_type = netmiko_huawei
@ -81,6 +81,16 @@ for the Huawei device::
secret = secret
ip = <switch mgmt ip address>
for the Huawei VRPV8 device::
[genericswitch:sw-hostname]
device_type = netmiko_huawei_vrpv8
username = admin
password = password
port = 8222
secret = secret
ip = <switch mgmt ip address>
for the Arista EOS device::
[genericswitch:arista-hostname]


+ 11
- 10
networking_generic_switch/devices/netmiko_devices/huawei.py View File

@ -16,15 +16,16 @@ from networking_generic_switch.devices import netmiko_devices
class Huawei(netmiko_devices.NetmikoSwitch):
ADD_NETWORK = (
'vlan {segmentation_id}',
)
"""For Huawei Network Operating System VRP V3 and V5."""
ADD_NETWORK = (
'vlan {segmentation_id}',
)
DELETE_NETWORK = (
'undo vlan {segmentation_id}',
)
DELETE_NETWORK = (
'undo vlan {segmentation_id}',
)
PLUG_PORT_TO_NETWORK = (
'interface {port}',
'port default vlan {segmentation_id}',
)
PLUG_PORT_TO_NETWORK = (
'interface {port}',
'port default vlan {segmentation_id}',
)

+ 34
- 0
networking_generic_switch/devices/netmiko_devices/huawei_vrpv8.py View File

@ -0,0 +1,34 @@
# Copyright 2016 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from networking_generic_switch.devices import netmiko_devices
class Huawei(netmiko_devices.NetmikoSwitch):
"""For Huawei Next-Generation Network Operating System VRP V8."""
ADD_NETWORK = (
'vlan {segmentation_id}',
'commit',
)
DELETE_NETWORK = (
'undo vlan {segmentation_id}',
'commit',
)
PLUG_PORT_TO_NETWORK = (
'interface {port}',
'port default vlan {segmentation_id}',
'commit',
)

+ 66
- 0
networking_generic_switch/tests/unit/netmiko/test_huawei_vrpv8.py View File

@ -0,0 +1,66 @@
# Copyright 2016 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from networking_generic_switch.devices.netmiko_devices import huawei_vrpv8
from networking_generic_switch.tests.unit.netmiko import test_netmiko_base
class TestNetmikoHuawei_vrpv8(test_netmiko_base.NetmikoSwitchTestBase):
def _make_switch_device(self):
device_cfg = {'device_type': 'netmiko_huawei'}
return huawei_vrpv8.Huawei(device_cfg)
def test_constants(self):
self.assertIsNone(self.switch.SAVE_CONFIGURATION)
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
'NetmikoSwitch.send_commands_to_device')
def test_add_network(self, m_exec):
self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
m_exec.assert_called_with(['vlan 33', 'commit'])
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
'NetmikoSwitch.send_commands_to_device')
def test_del_network(self, mock_exec):
self.switch.del_network(33)
mock_exec.assert_called_with(['undo vlan 33', 'commit'])
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
'NetmikoSwitch.send_commands_to_device')
def test_plug_port_to_network(self, mock_exec):
self.switch.plug_port_to_network(3333, 33)
mock_exec.assert_called_with(
['interface 3333', 'port default vlan 33', 'commit'])
def test__format_commands(self):
cmd_set = self.switch._format_commands(
huawei_vrpv8.Huawei.ADD_NETWORK,
segmentation_id=22,
network_id=22)
self.assertEqual(cmd_set, ['vlan 22', 'commit'])
cmd_set = self.switch._format_commands(
huawei_vrpv8.Huawei.DELETE_NETWORK,
segmentation_id=22)
self.assertEqual(cmd_set, ['undo vlan 22', 'commit'])
cmd_set = self.switch._format_commands(
huawei_vrpv8.Huawei.PLUG_PORT_TO_NETWORK,
port=3333,
segmentation_id=33)
self.assertEqual(cmd_set,
['interface 3333', 'port default vlan 33', 'commit'])

+ 1
- 0
setup.cfg View File

@ -21,6 +21,7 @@ generic_switch.devices =
netmiko_ovs_linux = networking_generic_switch.devices.netmiko_devices.ovs:OvsLinux
netmiko_cisco_ios = networking_generic_switch.devices.netmiko_devices.cisco:CiscoIos
netmiko_huawei = networking_generic_switch.devices.netmiko_devices.huawei:Huawei
netmiko_huawei_vrpv8 = networking_generic_switch.devices.netmiko_devices.huawei_vrpv8:Huawei
netmiko_arista_eos = networking_generic_switch.devices.netmiko_devices.arista:AristaEos
netmiko_dell_force10 = networking_generic_switch.devices.netmiko_devices.dell:DellNos
netmiko_brocade_fastiron = networking_generic_switch.devices.netmiko_devices.brocade:BrocadeFastIron


Loading…
Cancel
Save