Exemplo n.º 1
0
 def setUp(self):
     self.devices = {
         'A':
         devices.device_manager({"device_type": 'netmiko_ovs_linux'}),
         'B':
         devices.device_manager({
             "device_type": 'netmiko_cisco_ios',
             "ngs_mac_address": 'aa:bb:cc:dd:ee:ff'
         }),
     }
Exemplo n.º 2
0
    def initialize(self):
        """Perform driver initialization.

        Called after all drivers have been loaded and the database has
        been initialized. No abstract methods defined below will be
        called prior to this method being called.
        """
        LOG.info("PRUTH: GenericSwitchDriver")
        self.vfcHost = None

        gsw_devices = gsw_conf.get_devices()
        self.switches = {}
        for switch_info, device_cfg in gsw_devices.items():
            switch = devices.device_manager(device_cfg)
            if hasattr(devices, 'corsa_devices') and isinstance(
                    switch, devices.corsa_devices.corsa2100.CorsaDP2100):
                device_cfg['name'] = switch_info
            self.switches[switch_info] = switch
            if 'VFCHost' in device_cfg and device_cfg['VFCHost'] == 'True':
                self.vfcHost = switch
            if 'sharedNonByocVFC' in device_cfg:
                self.sharedNonByocVFC = device_cfg['sharedNonByocVFC']
            if 'sharedNonByocVLAN' in device_cfg:
                self.sharedNonByocVLAN = device_cfg['sharedNonByocVLAN']
            if 'sharedNonByocProvider' in device_cfg:
                self.sharedNonByocProvider = device_cfg[
                    'sharedNonByocProvider']

        LOG.info('Devices %s have been loaded', self.switches.keys())
        if not self.switches:
            LOG.error('No devices have been loaded')
 def test_driver_load_fail_load(self):
     device_cfg = {'device_type': 'fake_device'}
     device = None
     with self.assertRaises(exc.GenericSwitchEntrypointLoadError) as ex:
         device = devices.device_manager(device_cfg)
     self.assertIn("fake_device", ex.exception.msg)
     self.assertIsNone(device)
 def test_driver_ngs_config_defaults(self):
     device_cfg = {"device_type": 'netmiko_ovs_linux'}
     device = devices.device_manager(device_cfg)
     self.assertIsInstance(device, devices.GenericSwitchDevice)
     self.assertNotIn('ngs_mac_address', device.ngs_config)
     self.assertEqual(60, device.ngs_config['ngs_ssh_connect_timeout'])
     self.assertEqual(10, device.ngs_config['ngs_ssh_connect_interval'])
 def test_driver_ngs_config(self):
     device_cfg = {"device_type": 'netmiko_ovs_linux',
                   "ngs_mac_address": 'aa:bb:cc:dd:ee:ff',
                   "ngs_ssh_connect_timeout": "120",
                   "ngs_ssh_connect_interval": "20",
                   "ngs_trunk_ports": "port1,port2",
                   "ngs_physical_networks": "physnet1,physnet2",
                   "ngs_port_default_vlan": "20",
                   "ngs_disable_inactive_ports": "true"}
     device = devices.device_manager(device_cfg)
     self.assertIsInstance(device, devices.GenericSwitchDevice)
     self.assertNotIn('ngs_mac_address', device.config)
     self.assertNotIn('ngs_ssh_connect_timeout', device.config)
     self.assertNotIn('ngs_ssh_connect_interval', device.config)
     self.assertNotIn('ngs_trunk_ports', device.config)
     self.assertNotIn('ngs_physical_networks', device.config)
     self.assertNotIn('ngs_port_default_vlan', device.config)
     self.assertEqual('aa:bb:cc:dd:ee:ff',
                      device.ngs_config['ngs_mac_address'])
     self.assertEqual('120', device.ngs_config['ngs_ssh_connect_timeout'])
     self.assertEqual('20', device.ngs_config['ngs_ssh_connect_interval'])
     self.assertEqual('port1,port2', device.ngs_config['ngs_trunk_ports'])
     self.assertEqual('physnet1,physnet2',
                      device.ngs_config['ngs_physical_networks'])
     self.assertEqual('20', device.ngs_config['ngs_port_default_vlan'])
     self.assertEqual('true',
                      device.ngs_config['ngs_disable_inactive_ports'])
Exemplo n.º 6
0
 def test_driver_load_fail_load(self):
     device_cfg = {'device_type': 'fake_device'}
     device = None
     with self.assertRaises(exc.GenericSwitchEntrypointLoadError) as ex:
         device = devices.device_manager(device_cfg)
     self.assertIn("fake_device", ex.exception.msg)
     self.assertIsNone(device)
Exemplo n.º 7
0
 def test__disable_inactive_ports(self):
     device_cfg = {
         "device_type": 'netmiko_ovs_linux',
         "ngs_disable_inactive_ports": "true"
     }
     device = devices.device_manager(device_cfg)
     self.assertEqual(True, device._disable_inactive_ports())
Exemplo n.º 8
0
 def test_driver_load_fail_validate_network_name_format(
         self, mock_validate):
     mock_validate.side_effect = exc.GenericSwitchConfigException()
     device_cfg = {'device_type': 'netmiko_ovs_linux'}
     device = None
     with self.assertRaises(exc.GenericSwitchEntrypointLoadError):
         device = devices.device_manager(device_cfg)
     self.assertIsNone(device)
Exemplo n.º 9
0
 def test_driver_load_fail_invoke(self, switch_init_mock):
     switch_init_mock.side_effect = exc.GenericSwitchException(
         method='fake_method')
     device_cfg = {'device_type': 'netmiko_ovs_linux'}
     device = None
     with self.assertRaises(exc.GenericSwitchEntrypointLoadError) as ex:
         device = devices.device_manager(device_cfg)
     self.assertIn("fake_method", ex.exception.msg)
     self.assertIsNone(device)
 def test_driver_load_fail_invoke(self, switch_init_mock):
     switch_init_mock.side_effect = exc.GenericSwitchException(
         method='fake_method')
     device_cfg = {'device_type': 'netmiko_ovs_linux'}
     device = None
     with self.assertRaises(exc.GenericSwitchEntrypointLoadError) as ex:
         device = devices.device_manager(device_cfg)
     self.assertIn("fake_method", ex.exception.msg)
     self.assertIsNone(device)
 def test_driver_ngs_config(self):
     device_cfg = {
         "device_type": 'netmiko_ovs_linux',
         "ngs_mac_address": 'aa:bb:cc:dd:ee:ff'
     }
     device = devices.device_manager(device_cfg)
     self.assertIsInstance(device, devices.GenericSwitchDevice)
     self.assertNotIn('ngs_mac_address', device.config)
     self.assertEqual('aa:bb:cc:dd:ee:ff',
                      device.ngs_config['ngs_mac_address'])
 def test_driver_ngs_config_defaults(self):
     device_cfg = {"device_type": 'netmiko_ovs_linux'}
     device = devices.device_manager(device_cfg)
     self.assertIsInstance(device, devices.GenericSwitchDevice)
     self.assertNotIn('ngs_mac_address', device.ngs_config)
     self.assertEqual(60, device.ngs_config['ngs_ssh_connect_timeout'])
     self.assertEqual(10, device.ngs_config['ngs_ssh_connect_interval'])
     self.assertNotIn('ngs_trunk_ports', device.ngs_config)
     self.assertNotIn('ngs_physical_networks', device.ngs_config)
     self.assertNotIn('ngs_port_default_vlan', device.config)
     self.assertNotIn('ngs_disable_inactive_ports', device.config)
Exemplo n.º 13
0
    def initialize(self):
        """Perform driver initialization.

        Called after all drivers have been loaded and the database has
        been initialized. No abstract methods defined below will be
        called prior to this method being called.
        """

        gsw_devices = gsw_conf.get_devices()
        self.switches = {}
        for switch_info, device_cfg in gsw_devices.items():
            switch = devices.device_manager(device_cfg)
            self.switches[switch_info] = switch
        LOG.info(_LI('Devices %s have been loaded'), self.switches.keys())
    def initialize(self):
        """Perform driver initialization.

        Called after all drivers have been loaded and the database has
        been initialized. No abstract methods defined below will be
        called prior to this method being called.
        """

        gsw_devices = gsw_conf.get_devices()
        self.switches = {}
        for switch_info, device_cfg in gsw_devices.items():
            switch = devices.device_manager(device_cfg)
            self.switches[switch_info] = switch
        LOG.info(_LI('Devices %s have been loaded'), self.switches.keys())
 def test_driver_ngs_config(self):
     device_cfg = {
         "device_type": 'netmiko_ovs_linux',
         "ngs_mac_address": 'aa:bb:cc:dd:ee:ff',
         "ngs_ssh_connect_timeout": "120",
         "ngs_ssh_connect_interval": "20"
     }
     device = devices.device_manager(device_cfg)
     self.assertIsInstance(device, devices.GenericSwitchDevice)
     self.assertNotIn('ngs_mac_address', device.config)
     self.assertNotIn('ngs_ssh_connect_timeout', device.config)
     self.assertNotIn('ngs_ssh_connect_interval', device.config)
     self.assertEqual('aa:bb:cc:dd:ee:ff',
                      device.ngs_config['ngs_mac_address'])
     self.assertEqual('120', device.ngs_config['ngs_ssh_connect_timeout'])
     self.assertEqual('20', device.ngs_config['ngs_ssh_connect_interval'])
    def delete_network_postcommit(self, context):
        """Delete a network.

        :param context: NetworkContext instance describing the current
        state of the network, prior to the call to delete it.

        Called after the transaction commits. Call can block, though
        will block the entire process so care should be taken to not
        drastically affect performance. Runtime errors are not
        expected, and will not prevent the resource from being
        deleted.
        """
        network = context.current
        provider_type = network['provider:network_type']
        segmentation_id = network['provider:segmentation_id']

        if provider_type == 'vlan' and segmentation_id:
            # Delete vlan on all switches from this driver
            gsw_devices = gsw_conf.get_devices()
            for device_cfg in gsw_devices.values():
                switch = devices.device_manager(device_cfg)
                switch.del_network(segmentation_id)
Exemplo n.º 17
0
    def delete_network_postcommit(self, context):
        """Delete a network.

        :param context: NetworkContext instance describing the current
        state of the network, prior to the call to delete it.

        Called after the transaction commits. Call can block, though
        will block the entire process so care should be taken to not
        drastically affect performance. Runtime errors are not
        expected, and will not prevent the resource from being
        deleted.
        """
        network = context.current
        provider_type = network['provider:network_type']
        segmentation_id = network['provider:segmentation_id']

        if provider_type == 'vlan' and segmentation_id:
            # Delete vlan on all switches from this driver
            gsw_devices = gsw_conf.get_devices()
            for device_cfg in gsw_devices.values():
                switch = devices.device_manager(device_cfg)
                switch.del_network(segmentation_id)
Exemplo n.º 18
0
    def create_network_postcommit(self, context):
        """Create a network.

        :param context: NetworkContext instance describing the new
        network.

        Called after the transaction commits. Call can block, though
        will block the entire process so care should be taken to not
        drastically affect performance. Raising an exception will
        cause the deletion of the resource.
        """

        network = context.current
        network_id = network['id']
        provider_type = network['provider:network_type']
        segmentation_id = network['provider:segmentation_id']

        if provider_type == 'vlan' and segmentation_id:
            # Create vlan on all switches from this driver
            gsw_devices = gsw_conf.get_devices()
            for device_cfg in gsw_devices.values():
                switch = devices.device_manager(device_cfg)
                switch.add_network(segmentation_id, network_id)
Exemplo n.º 19
0
    def initialize(self):
        """Perform driver initialization.

        Called after all drivers have been loaded and the database has
        been initialized. No abstract methods defined below will be
        called prior to this method being called.
        """

        gsw_devices = gsw_conf.get_devices()
        self.switches = {}
        for switch_info, device_cfg in gsw_devices.items():
            switch = devices.device_manager(device_cfg)
            self.switches[switch_info] = switch
        LOG.info('Devices %s have been loaded', self.switches.keys())
        if not self.switches:
            LOG.error('No devices have been loaded')
        self.warned_del_network = False

        registry.subscribe(self.add_subports_to_trunk, constants.SUBPORTS,
                           events.PRECOMMIT_CREATE)

        registry.subscribe(self.remove_subports_from_trunk, constants.SUBPORTS,
                           events.PRECOMMIT_DELETE)
    def create_network_postcommit(self, context):
        """Create a network.

        :param context: NetworkContext instance describing the new
        network.

        Called after the transaction commits. Call can block, though
        will block the entire process so care should be taken to not
        drastically affect performance. Raising an exception will
        cause the deletion of the resource.
        """

        network = context.current
        network_id = network['id']
        provider_type = network['provider:network_type']
        segmentation_id = network['provider:segmentation_id']

        if provider_type == 'vlan' and segmentation_id:
            # Create vlan on all switches from this driver
            gsw_devices = gsw_conf.get_devices()
            for device_cfg in gsw_devices.values():
                switch = devices.device_manager(device_cfg)
                switch.add_network(segmentation_id, network_id)
    def bind_port(self, context):
        """Attempt to bind a port.

        :param context: PortContext instance describing the port

        This method is called outside any transaction to attempt to
        establish a port binding using this mechanism driver. Bindings
        may be created at each of multiple levels of a hierarchical
        network, and are established from the top level downward. At
        each level, the mechanism driver determines whether it can
        bind to any of the network segments in the
        context.segments_to_bind property, based on the value of the
        context.host property, any relevant port or network
        attributes, and its own knowledge of the network topology. At
        the top level, context.segments_to_bind contains the static
        segments of the port's network. At each lower level of
        binding, it contains static or dynamic segments supplied by
        the driver that bound at the level above. If the driver is
        able to complete the binding of the port to any segment in
        context.segments_to_bind, it must call context.set_binding
        with the binding details. If it can partially bind the port,
        it must call context.continue_binding with the network
        segments to be used to bind at the next lower level.

        If the binding results are committed after bind_port returns,
        they will be seen by all mechanism drivers as
        update_port_precommit and update_port_postcommit calls. But if
        some other thread or process concurrently binds or updates the
        port, these binding results will not be committed, and
        update_port_precommit and update_port_postcommit will not be
        called on the mechanism drivers with these results. Because
        binding results can be discarded rather than committed,
        drivers should avoid making persistent state changes in
        bind_port, or else must ensure that such state changes are
        eventually cleaned up.

        Implementing this method explicitly declares the mechanism
        driver as having the intention to bind ports. This is inspected
        by the QoS service to identify the available QoS rules you
        can use with ports.
        """

        port = context.current
        binding_profile = port['binding:profile']
        local_link_information = binding_profile.get('local_link_information',
                                                     False)
        vnic_type = port['binding:vnic_type']
        if vnic_type == 'baremetal' and local_link_information:
            gsw_devices = gsw_conf.get_devices()
            switch_info = local_link_information[0].get('switch_info')
            if switch_info not in gsw_devices:
                raise exc.GenericSwitchConfigError(switch=switch_info)
            port_id = local_link_information[0].get('port_id')
            segments = context.segments_to_bind
            segmentation_id = segments[0]['segmentation_id']
            # If segmentation ID is None, set vlan 1
            if not segmentation_id:
                segmentation_id = '1'
            LOG.debug("Putting port {port} on {switch_info} to vlan: "
                      "{segmentation_id}".format(
                          port=port_id,
                          switch_info=switch_info,
                          segmentation_id=segmentation_id))
            switch = devices.device_manager(gsw_devices[switch_info])
            # Move port to network
            switch.plug_port_to_network(port_id, segmentation_id)
            context.set_binding(segments[0][driver_api.ID],
                                portbindings.VIF_TYPE_OTHER, {},
                                status=const.PORT_STATUS_ACTIVE)
Exemplo n.º 22
0
 def test_driver_load(self):
     device_cfg = {"device_type": 'netmiko_ovs_linux'}
     device = devices.device_manager(device_cfg)
     self.assertIsInstance(device, devices.GenericSwitchDevice)
     self.assertEqual(device.config, device_cfg)
Exemplo n.º 23
0
    def bind_port(self, context):
        """Attempt to bind a port.

        :param context: PortContext instance describing the port

        This method is called outside any transaction to attempt to
        establish a port binding using this mechanism driver. Bindings
        may be created at each of multiple levels of a hierarchical
        network, and are established from the top level downward. At
        each level, the mechanism driver determines whether it can
        bind to any of the network segments in the
        context.segments_to_bind property, based on the value of the
        context.host property, any relevant port or network
        attributes, and its own knowledge of the network topology. At
        the top level, context.segments_to_bind contains the static
        segments of the port's network. At each lower level of
        binding, it contains static or dynamic segments supplied by
        the driver that bound at the level above. If the driver is
        able to complete the binding of the port to any segment in
        context.segments_to_bind, it must call context.set_binding
        with the binding details. If it can partially bind the port,
        it must call context.continue_binding with the network
        segments to be used to bind at the next lower level.

        If the binding results are committed after bind_port returns,
        they will be seen by all mechanism drivers as
        update_port_precommit and update_port_postcommit calls. But if
        some other thread or process concurrently binds or updates the
        port, these binding results will not be committed, and
        update_port_precommit and update_port_postcommit will not be
        called on the mechanism drivers with these results. Because
        binding results can be discarded rather than committed,
        drivers should avoid making persistent state changes in
        bind_port, or else must ensure that such state changes are
        eventually cleaned up.

        Implementing this method explicitly declares the mechanism
        driver as having the intention to bind ports. This is inspected
        by the QoS service to identify the available QoS rules you
        can use with ports.
        """

        port = context.current
        binding_profile = port['binding:profile']
        local_link_information = binding_profile.get('local_link_information',
                                                     False)
        vnic_type = port['binding:vnic_type']
        if vnic_type == 'baremetal' and local_link_information:
            gsw_devices = gsw_conf.get_devices()
            switch_info = local_link_information[0].get('switch_info')
            if switch_info not in gsw_devices:
                raise exc.GenericSwitchConfigError(switch=switch_info)
            port_id = local_link_information[0].get('port_id')
            segments = context.segments_to_bind
            segmentation_id = segments[0]['segmentation_id']
            # If segmentation ID is None, set vlan 1
            if not segmentation_id:
                segmentation_id = '1'
            LOG.debug("Putting port {port} on {switch_info} to vlan: "
                      "{segmentation_id}".format(
                          port=port_id,
                          switch_info=switch_info,
                          segmentation_id=segmentation_id))
            switch = devices.device_manager(gsw_devices[switch_info])
            # Move port to network
            switch.plug_port_to_network(port_id, segmentation_id)
            context.set_binding(segments[0][driver_api.ID],
                                portbindings.VIF_TYPE_OTHER, {},
                                status=const.PORT_STATUS_ACTIVE)
 def test_driver_load(self):
     device_cfg = {"device_type": 'netmiko_ovs_linux'}
     device = devices.device_manager(device_cfg)
     self.assertIsInstance(device, devices.GenericSwitchDevice)
     self.assertEqual(device.config, device_cfg)