Exemplo n.º 1
0
    def test_attach(self):
        self.ncclient.command.side_effect = [
            # run attach 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.attach, port).wait()

        self.assertEqual(self.ncclient.command.call_count, 2)
        attach_cmd = self._get_called_commands(0)
        save_cmd = self._get_called_commands(1)

        attach_expected = [
            'configure terminal', 'interface port-channel 1',
            'switchport trunk allowed vlan add 1', 'configure terminal',
            ('ip source binding 10.0.0.2 ff:ff:ff:ff:ff:ff '
             'vlan 1 interface port-channel1')
        ]

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

        self.assertEqual(attach_cmd, attach_expected)
        self.assertEqual(save_cmd, save_expected)
Exemplo 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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
    def _make_port_info(self,
                        switch_port,
                        neutron_port=None,
                        neutron_network=None):
        info = base_driver.PortInfo(
            switch_host=switch_port.switch.host,
            switch_username=switch_port.switch.username,
            switch_password=switch_port.switch.password,
            interface=switch_port["port"])

        if neutron_port:
            info.hardware_id = neutron_port["switch:hardware_id"]
            info.ip = self._get_ip(neutron_port)
            info.mac_address = neutron_port["mac_address"]
            info.trunked = neutron_port["trunked"]

        if neutron_network:
            info.vlan_id = neutron_network["provider:segmentation_id"]

        return info
Exemplo n.º 5
0
    def test_interface_status(self):
        self.ncclient.command.side_effect = [
            FakeNcClientResponse(fixtures.show_ethernet_status(1)),
            FakeNcClientResponse(fixtures.show_port_channel_status(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.interface_status(port)
        expected_res = {
            'switch': {
                'interface': 'eth1/1',
                'hostname': 'switch1.host.com'
            },
            'interface-status': {
                'ethernet': {
                    'interface': 'ethernet1/1',
                    'state': 'up'
                },
                'port-channel': {
                    'interface': 'port-channel1',
                    'state': 'up',
                    'vpc_status': 'vPC Status: Up, vPC number: 1'
                }
            }
        }
        self.assertEqual(self.ncclient.command.call_count, 2)
        self.assertEqual(res, expected_res)
Exemplo n.º 6
0

def add_vlan(port, driver):
    driver.attach(port)


def remove_vlan(port, driver):
    driver.detach(port)


def show(port, driver):
    driver.show(port)


def clear(port, driver):
    driver.clear(port)


d = cisco_driver.CiscoDriver(dry_run=True)
p = base.PortInfo(switch_host='host',
                  switch_username='******',
                  switch_password='******',
                  hardware_id='hardware_id',
                  interface='Eth1/20',
                  vlan_id='101',
                  ip='10.0.0.1',
                  mac_address='aa:bb:cc:dd:ee',
                  trunked=True)

clear(p, d)
Exemplo n.º 7
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)