From 25fb79c2225ec6d8b677d6871ffc8567489c4f38 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Thu, 30 Aug 2018 15:15:38 +0100 Subject: [PATCH] Support disabling inactive links for Juniper Adds the necessary code to the Juniper Junos device driver to support disabling inactive links. This feature is enabled by setting the per-device config flag 'ngs_disable_inactive_ports'. Change-Id: I636613d0c910d10601422ad094f835c17a606e37 Story: 2003391 Task: 24933 --- .../devices/netmiko_devices/juniper.py | 8 +++++++ .../tests/unit/netmiko/test_juniper.py | 24 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/networking_generic_switch/devices/netmiko_devices/juniper.py b/networking_generic_switch/devices/netmiko_devices/juniper.py index 9c3dde14..5ccacde5 100644 --- a/networking_generic_switch/devices/netmiko_devices/juniper.py +++ b/networking_generic_switch/devices/netmiko_devices/juniper.py @@ -55,6 +55,14 @@ class Juniper(netmiko_devices.NetmikoSwitch): 'vlan members', ) + ENABLE_PORT = ( + 'delete interface {port} disable', + ) + + DISABLE_PORT = ( + 'set interface {port} disable', + ) + PLUG_TRUNK_PORT_TO_NETWORK = ( 'set interface {port} unit 0 family ethernet-switching ' 'vlan members {segmentation_id}', diff --git a/networking_generic_switch/tests/unit/netmiko/test_juniper.py b/networking_generic_switch/tests/unit/netmiko/test_juniper.py index 2d599861..56ee092f 100644 --- a/networking_generic_switch/tests/unit/netmiko/test_juniper.py +++ b/networking_generic_switch/tests/unit/netmiko/test_juniper.py @@ -80,6 +80,19 @@ def test_plug_port_to_network(self, mock_exec): 'set interface 3333 unit 0 family ethernet-switching ' 'vlan members 33']) + @mock.patch('networking_generic_switch.devices.netmiko_devices.' + 'NetmikoSwitch.send_commands_to_device') + def test_plug_port_to_network_disable_inactive(self, m_sctd): + switch = self._make_switch_device( + {'ngs_disable_inactive_ports': 'true'}) + switch.plug_port_to_network(3333, 33) + m_sctd.assert_called_with( + ['delete interface 3333 disable', + 'delete interface 3333 unit 0 family ethernet-switching ' + 'vlan members', + 'set interface 3333 unit 0 family ethernet-switching ' + 'vlan members 33']) + @mock.patch('networking_generic_switch.devices.netmiko_devices.' 'NetmikoSwitch.send_commands_to_device') def test_delete_port(self, mock_exec): @@ -88,6 +101,17 @@ def test_delete_port(self, mock_exec): ['delete interface 3333 unit 0 family ethernet-switching ' 'vlan members']) + @mock.patch('networking_generic_switch.devices.netmiko_devices.' + 'NetmikoSwitch.send_commands_to_device') + def test_delete_port_disable_inactive(self, m_sctd): + switch = self._make_switch_device( + {'ngs_disable_inactive_ports': 'true'}) + switch.delete_port(3333, 33) + m_sctd.assert_called_with( + ['delete interface 3333 unit 0 family ethernet-switching ' + 'vlan members', + 'set interface 3333 disable']) + def test_send_config_set(self): connect_mock = mock.MagicMock(netmiko.base_connection.BaseConnection) connect_mock.send_config_set.return_value = 'fake output'