Ejemplo n.º 1
0
    def test_delete(self):
        self.ncclient.command.side_effect = [
            # list dhcp bindings to clear
            FakeNcClientResponse(fixtures.show_dhcp(1)),
            # run remove dhcp binding commands
            FakeNcClientResponse(fixtures.ok()),
            # run clear commands
            FakeNcClientResponse(fixtures.ok()),
            # save commands
            FakeNcClientResponse(fixtures.ok())
        ]

        port = base_driver.PortInfo(
            switch_host='switch1.host.com',
            switch_username='******',
            switch_password='******',
            interface='eth1/1',
            hardware_id='hardware1',
            vlan_id=1,
            ip='10.0.0.2',
            mac_address='ff:ff:ff:ff:ff:ff',
            trunked=True)

        eventlet.spawn(self.driver.delete, port).wait()

        self.assertEqual(self.ncclient.command.call_count, 4)
        show_bindings_cmd = self._get_called_commands(0)
        remove_bindings_cmd = self._get_called_commands(1)
        clear_port_cmd = self._get_called_commands(2)
        save_cmd = self._get_called_commands(3)

        show_bindings_expected = ['show running dhcp | egrep port-channel1$']

        remove_bindings_expected = [
            'configure terminal',
            'interface port-channel 1',
            ('no ip source binding 10.0.0.1 FFFF.FFFF.FFFF.FFFF '
             'vlan 1 interface port-channel1')
        ]

        clear_port_expected = [
            'configure terminal',
            'interface port-channel 1',
            'no ip verify source dhcp-snooping-vlan',
            'no interface port-channel 1',
            'configure terminal',
            'default interface ethernet 1/1',
            'configure terminal',
            'interface ethernet 1/1',
            'shutdown'
        ]

        save_expected = ['copy running-config startup-config']

        self.assertEqual(show_bindings_cmd, show_bindings_expected)
        self.assertEqual(remove_bindings_cmd, remove_bindings_expected)
        self.assertEqual(clear_port_cmd, clear_port_expected)
        self.assertEqual(save_cmd, save_expected)
Ejemplo n.º 2
0
    def test_running_config_trunked(self):
        self.ncclient.command.side_effect = [
            FakeNcClientResponse(fixtures.show_dhcp(1)),
            FakeNcClientResponse(fixtures.show_ethernet_config_trunked(1)),
            FakeNcClientResponse(fixtures.show_port_channel_config_trunked(1))
        ]

        port = base_driver.PortInfo(
            switch_host='switch1.host.com',
            switch_username='******',
            switch_password='******',
            interface='eth1/1',
            hardware_id='hardware1',
            vlan_id=1,
            ip='10.0.0.2',
            mac_address='ff:ff:ff:ff:ff:ff',
            trunked=True)

        res = self.driver.running_config(port)
        expected_res = {
            'switch': {
                'interface': 'eth1/1',
                'hostname': 'switch1.host.com'
            },
            'running-config': {
                'dhcp': [
                    ('ip source binding 10.0.0.1 FFFF.FFFF.FFFF.FFFF '
                     'vlan 1 interface port-channel1')
                ],
                'port-channel': [
                    ('description '
                     'CUST39a8365c-3b84-4169-bc1a-1efa3ab20e04-host'),
                    'switchport mode trunk',
                    'switchport trunk allowed vlan 1,2',
                    'ip verify source dhcp-snooping-vlan',
                    'spanning-tree port type edge trunk',
                    'no negotiate auto',
                    'vpc 1'
                ],
                'ethernet': [
                    ('description '
                     'CUST39a8365c-3b84-4169-bc1a-1efa3ab20e04-host'),
                    'no lldp transmit',
                    'switchport mode trunk',
                    'switchport trunk allowed vlan 1,2',
                    'spanning-tree port type edge trunk',
                    'spanning-tree bpduguard enable',
                    'channel-group 1 mode active'
                ]
            }
        }
        self.assertEqual(self.ncclient.command.call_count, 3)
        self.assertEqual(res, expected_res)
Ejemplo n.º 3
0
    def test_running_config_trunked(self):
        self.ncclient.command.side_effect = [
            FakeNcClientResponse(fixtures.show_dhcp(1)),
            FakeNcClientResponse(fixtures.show_ethernet_config_trunked(1)),
            FakeNcClientResponse(fixtures.show_port_channel_config_trunked(1))
        ]

        port = base_driver.PortInfo(switch_host='switch1.host.com',
                                    switch_username='******',
                                    switch_password='******',
                                    interface='eth1/1',
                                    hardware_id='hardware1',
                                    vlan_id=1,
                                    ip='10.0.0.2',
                                    mac_address='ff:ff:ff:ff:ff:ff',
                                    trunked=True)

        res = self.driver.running_config(port)
        expected_res = {
            'switch': {
                'interface': 'eth1/1',
                'hostname': 'switch1.host.com'
            },
            'running-config': {
                'dhcp': [('ip source binding 10.0.0.1 FFFF.FFFF.FFFF.FFFF '
                          'vlan 1 interface port-channel1')],
                'port-channel':
                [('description '
                  'CUST39a8365c-3b84-4169-bc1a-1efa3ab20e04-host'),
                 'switchport mode trunk', 'switchport trunk allowed vlan 1,2',
                 'ip verify source dhcp-snooping-vlan',
                 'spanning-tree port type edge trunk', 'no negotiate auto',
                 'vpc 1'],
                'ethernet': [('description '
                              'CUST39a8365c-3b84-4169-bc1a-1efa3ab20e04-host'),
                             'no lldp transmit', 'switchport mode trunk',
                             'switchport trunk allowed vlan 1,2',
                             'spanning-tree port type edge trunk',
                             'spanning-tree bpduguard enable',
                             'channel-group 1 mode active']
            }
        }
        self.assertEqual(self.ncclient.command.call_count, 3)
        self.assertEqual(res, expected_res)
Ejemplo n.º 4
0
    def test_delete(self):
        self.ncclient.command.side_effect = [
            # list dhcp bindings to clear
            FakeNcClientResponse(fixtures.show_dhcp(1)),
            # run clear commands
            FakeNcClientResponse(fixtures.ok())
        ]

        port = base_driver.PortInfo(switch_host='switch1.host.com',
                                    switch_username='******',
                                    switch_password='******',
                                    interface='eth1/1',
                                    hardware_id='hardware1',
                                    vlan_id=1,
                                    ip='10.0.0.2',
                                    mac_address='ff:ff:ff:ff:ff:ff',
                                    trunked=True)

        eventlet.spawn(self.driver.delete, port).wait()

        self.assertEqual(self.ncclient.command.call_count, 3)
        remove_bindings_cmd = self._get_called_commands(0)
        clear_port_cmd = self._get_called_commands(1)
        save_cmd = self._get_called_commands(2)

        remove_bindings_expected = ['show running dhcp | egrep port-channel1$']

        clear_port_expected = [
            'configure terminal', 'interface port-channel 1',
            ('no ip source binding 10.0.0.1 FFFF.FFFF.FFFF.FFFF '
             'vlan 1 interface port-channel1'), 'configure terminal',
            'interface port-channel 1',
            'no ip verify source dhcp-snooping-vlan',
            'no interface port-channel 1', 'configure terminal',
            'default interface ethernet 1/1', 'configure terminal',
            'interface ethernet 1/1', 'shutdown'
        ]

        save_expected = ['copy running-config startup-config']

        self.assertEqual(remove_bindings_cmd, remove_bindings_expected)
        self.assertEqual(clear_port_cmd, clear_port_expected)
        self.assertEqual(save_cmd, save_expected)
Ejemplo n.º 5
0
    def test_create(self):

        self.ncclient.command.side_effect = [
            # list dhcp bindings to clear
            FakeNcClientResponse(fixtures.show_dhcp(1)),
            # run clear commands
            FakeNcClientResponse(fixtures.ok()),
            # run create commands
            FakeNcClientResponse(fixtures.ok())
        ]

        port = base_driver.PortInfo(switch_host='switch1.host.com',
                                    switch_username='******',
                                    switch_password='******',
                                    interface='eth1/1',
                                    hardware_id='hardware1',
                                    vlan_id=1,
                                    ip='10.0.0.2',
                                    mac_address='ff:ff:ff:ff:ff:ff',
                                    trunked=True)

        eventlet.spawn(self.driver.create, port).wait()

        self.assertEqual(self.ncclient.command.call_count, 4)
        remove_bindings_cmd = self._get_called_commands(0)
        clear_port_cmd = self._get_called_commands(1)
        create_port_cmd = self._get_called_commands(2)
        save_cmd = self._get_called_commands(3)

        remove_bindings_expected = ['show running dhcp | egrep port-channel1$']

        clear_port_expected = [
            'configure terminal', 'interface port-channel 1',
            ('no ip source binding 10.0.0.1 FFFF.FFFF.FFFF.FFFF '
             'vlan 1 interface port-channel1'), 'configure terminal',
            'interface port-channel 1',
            'no ip verify source dhcp-snooping-vlan',
            'no interface port-channel 1', 'configure terminal',
            'default interface ethernet 1/1', 'configure terminal',
            'interface ethernet 1/1', 'shutdown'
        ]

        create_port_expected = [
            'configure terminal', 'interface port-channel 1',
            'description CUSThardware1-host', 'switchport mode trunk',
            'switchport trunk allowed vlan 1',
            'spanning-tree port type edge trunk', 'vpc 1',
            'ip verify source dhcp-snooping-vlan', 'no shutdown',
            'configure terminal',
            ('ip source binding 10.0.0.2 ff:ff:ff:ff:ff:ff '
             'vlan 1 interface port-channel1'), 'configure terminal',
            'interface ethernet 1/1', 'description CUSThardware1-host',
            'switchport mode trunk', 'switchport trunk allowed vlan 1',
            'spanning-tree port type edge trunk',
            'spanning-tree bpduguard enable', 'channel-group 1 mode active',
            'no lldp transmit', 'no cdp enable', 'no shutdown'
        ]

        save_expected = ['copy running-config startup-config']

        self.assertEqual(remove_bindings_cmd, remove_bindings_expected)
        self.assertEqual(clear_port_cmd, clear_port_expected)
        self.assertEqual(create_port_cmd, create_port_expected)
        self.assertEqual(save_cmd, save_expected)
Ejemplo n.º 6
0
    def test_create_access(self):

        self.ncclient.command.side_effect = [
            # list dhcp bindings to clear
            FakeNcClientResponse(fixtures.show_dhcp(1)),
            # run dhcp binding delete commands
            FakeNcClientResponse(fixtures.ok()),
            # run clear commands
            FakeNcClientResponse(fixtures.ok()),
            # run create commands
            FakeNcClientResponse(fixtures.ok()),
            # run save commands
            FakeNcClientResponse(fixtures.ok()),
        ]

        port = base_driver.PortInfo(
            switch_host='switch1.host.com',
            switch_username='******',
            switch_password='******',
            interface='eth1/1',
            hardware_id='hardware1',
            vlan_id=1,
            ip='10.0.0.2',
            mac_address='ff:ff:ff:ff:ff:ff',
            trunked=False)

        eventlet.spawn(self.driver.create, port).wait()

        self.assertEqual(self.ncclient.command.call_count, 5)
        show_bindings_cmd = self._get_called_commands(0)
        remove_bindings_cmd = self._get_called_commands(1)
        clear_port_cmd = self._get_called_commands(2)
        create_port_cmd = self._get_called_commands(3)
        save_cmd = self._get_called_commands(4)

        show_bindings_expected = ['show running dhcp | egrep port-channel1$']

        remove_bindings_expected = [
            'configure terminal',
            'interface port-channel 1',
            ('no ip source binding 10.0.0.1 FFFF.FFFF.FFFF.FFFF '
             'vlan 1 interface port-channel1'),
        ]

        clear_port_expected = [
            'configure terminal',
            'interface port-channel 1',
            'no ip verify source dhcp-snooping-vlan',
            'no interface port-channel 1',
            'configure terminal',
            'default interface ethernet 1/1',
            'configure terminal',
            'interface ethernet 1/1',
            'shutdown'
        ]

        create_port_expected = [
            'configure terminal',
            'interface ethernet 1/1',
            'description CUSThardware1-host',
            'switchport mode access',
            'switchport access vlan 1',
            'spanning-tree port type edge',
            'spanning-tree bpduguard enable',
            'lldp transmit',
            'cdp enable',
            'ip verify source dhcp-snooping-vlan',
            'no ip verify source dhcp-snooping-vlan',
            'no shutdown'
        ]

        save_expected = ['copy running-config startup-config']

        self.assertEqual(show_bindings_cmd, show_bindings_expected)
        self.assertEqual(remove_bindings_cmd, remove_bindings_expected)
        self.assertEqual(clear_port_cmd, clear_port_expected)
        self.assertEqual(create_port_cmd, create_port_expected)
        self.assertEqual(save_cmd, save_expected)