def setUp(self):
     super(TestCiscoNexusProvider, self).setUp()
     self._nexus_md = mech_cisco_nexus.CiscoNexusMechanismDriver()
     self._nexus_md._get_port_uuid = mock.Mock(return_value='test_uuid')
     self._func = mock.Mock()
     self.context = mock.Mock()
     self.context.current = NETWORK
    def setUp(self):
        """Sets up mock ncclient, and switch and credentials dictionaries."""
        super(TestCiscoNexusReplay, self).setUp()

        cisco_config.cfg.CONF.set_default('api_workers', 0)
        cisco_config.cfg.CONF.set_default('rpc_workers', 0)

        # Use a mock netconf client
        self.mock_ncclient = mock.Mock()
        mock.patch.object(nexus_network_driver.CiscoNexusDriver,
                          '_import_ncclient',
                          return_value=self.mock_ncclient).start()
        data_xml = {'connect.return_value.get.return_value.data_xml': ''}
        self.mock_ncclient.configure_mock(**data_xml)

        cisco_config.cfg.CONF.set_override('switch_heartbeat_time', 30,
                                           'ml2_cisco')

        def new_nexus_init(mech_instance):
            mech_instance.driver = importutils.import_object(NEXUS_DRIVER)
            mech_instance.monitor_timeout = (
                cisco_config.cfg.CONF.ml2_cisco.switch_heartbeat_time)
            mech_instance._ppid = os.getpid()

            mech_instance._switch_state = {}
            mech_instance._nexus_switches = {}
            for name, config in TestCiscoNexusReplay.test_configs.items():
                ip_addr = config.nexus_ip_addr
                host_name = config.host_name
                nexus_port = config.nexus_port
                if (ip_addr, host_name) in mech_instance._nexus_switches:
                    saved_port = (mech_instance._nexus_switches[(ip_addr,
                                                                 host_name)])
                    if saved_port != nexus_port:
                        mech_instance._nexus_switches[(ip_addr, host_name)] = (
                            saved_port + ',' + nexus_port)
                else:
                    mech_instance._nexus_switches[(ip_addr,
                                                   host_name)] = nexus_port
                mech_instance._nexus_switches[(ip_addr,
                                               'ssh_port')] = NEXUS_SSH_PORT
                mech_instance._nexus_switches[(ip_addr,
                                               constants.USERNAME)] = 'admin'
                mech_instance._nexus_switches[(
                    ip_addr, constants.PASSWORD)] = 'password'
            mech_instance.driver.nexus_switches = (
                mech_instance._nexus_switches)

        mock.patch.object(mech_cisco_nexus.CiscoNexusMechanismDriver,
                          '__init__',
                          new=new_nexus_init).start()
        self._cisco_mech_driver = (
            mech_cisco_nexus.CiscoNexusMechanismDriver())
        self._cfg_monitor = (mech_cisco_nexus.CiscoNexusCfgMonitor(
            self._cisco_mech_driver.driver, self._cisco_mech_driver))
 def setUp(self):
     super(TestCiscoNexusProviderConfiguration, self).setUp()
     mock.patch.object(rest_driver.CiscoNexusRestapiDriver,
                       '__init__', return_value=None).start()
     self._nexus_md = mech_cisco_nexus.CiscoNexusMechanismDriver()
     self._nexus_md.set_switch_ip_and_active_state = mock.Mock()
     self._nexus_md.configure_next_batch_of_vlans = mock.Mock()
     self._nexus_md.driver = rest_driver.CiscoNexusRestapiDriver()
     self._nexus_md.driver.capture_and_print_timeshot = mock.Mock()
     self._get_active_host_connections_mock = mock.patch.object(
         mech_cisco_nexus.CiscoNexusMechanismDriver,
         '_get_active_port_connections',
         return_value=[[IP_ADDR, INTF_TYPE, NEXUS_PORT, IS_NATIVE,
                        None]]).start()
     self._save_switch_vlan_range_mock = mock.patch.object(
         mech_cisco_nexus.CiscoNexusMechanismDriver,
         '_save_switch_vlan_range').start()
     self._restore_port_binding_mock = mock.patch.object(
         mech_cisco_nexus.CiscoNexusMechanismDriver,
         '_restore_port_binding').start()
     self._create_and_trunk_vlan_mock = mock.patch.object(
         rest_driver.CiscoNexusRestapiDriver,
         'create_and_trunk_vlan').start()
     self._create_vlan_mock = mock.patch.object(
         rest_driver.CiscoNexusRestapiDriver,
         'create_vlan').start()
     self._send_enable_vlan_on_trunk_int_mock = mock.patch.object(
         rest_driver.CiscoNexusRestapiDriver,
         'send_enable_vlan_on_trunk_int').start()
     self._disable_vlan_on_trunk_int_mock = mock.patch.object(
         rest_driver.CiscoNexusRestapiDriver,
         'disable_vlan_on_trunk_int').start()
     self._get_nexusvlan_binding_mock = mock.patch.object(
         nexus_db_v2, 'get_nexusvlan_binding').start()
     self._is_provider_vlan_mock = mock.patch.object(
         nexus_db_v2, 'is_provider_vlan').start()
     mock.patch.object(
         nexus_db_v2, 'get_port_vlan_switch_binding',
         side_effect=excep.NexusPortBindingNotFound).start()
     mock.patch.object(
         mech_cisco_nexus.CiscoNexusMechanismDriver,
         '_delete_port_channel_resources').start()
Beispiel #4
0
    def setUp(self):
        """Sets up mock ncclient, and switch and credentials dictionaries."""
        super(TestCiscoNexusDevice, self).setUp()

        # Use a mock netconf client
        self.mock_ncclient = mock.Mock()
        mock.patch.object(nexus_network_driver.CiscoNexusDriver,
                          '_import_ncclient',
                          return_value=self.mock_ncclient).start()
        data_xml = {'connect.return_value.get.return_value.data_xml': ''}
        self.mock_ncclient.configure_mock(**data_xml)

        def new_nexus_init(mech_instance):
            mech_instance.driver = importutils.import_object(NEXUS_DRIVER)
            mech_instance.monitor_timeout = (
                cisco_config.cfg.CONF.ml2_cisco.switch_heartbeat_time)

            mech_instance._nexus_switches = {}
            for name, config in TestCiscoNexusDevice.test_configs.items():
                ip_addr = config.nexus_ip_addr
                host_name = config.host_name
                nexus_port = config.nexus_port
                mech_instance._nexus_switches[(ip_addr,
                                               host_name)] = nexus_port
                mech_instance._nexus_switches[(ip_addr,
                                               'ssh_port')] = NEXUS_SSH_PORT
                mech_instance._nexus_switches[(ip_addr,
                                               constants.USERNAME)] = 'admin'
                mech_instance._nexus_switches[(
                    ip_addr, constants.PASSWORD)] = 'password'
            mech_instance.driver.nexus_switches = (
                mech_instance._nexus_switches)

        mock.patch.object(mech_cisco_nexus.CiscoNexusMechanismDriver,
                          '__init__',
                          new=new_nexus_init).start()
        self._cisco_mech_driver = (
            mech_cisco_nexus.CiscoNexusMechanismDriver())
    def setUp(self):
        """Sets up mock client, switch, and credentials dictionaries."""

        #Clear all configuration parsing
        nexus_config.ML2MechCiscoConfig.nexus_dict = collections.OrderedDict()
        cfg.CONF.clear()

        super(TestCiscoNexusBase, self).setUp()

        cfg.CONF.import_opt('api_workers', 'neutron.service')
        cfg.CONF.set_default('api_workers', 0)
        cfg.CONF.import_opt('rpc_workers', 'neutron.service')
        cfg.CONF.set_default('rpc_workers', 0)

        # Use a mock netconf or REST API client
        self.mock_ncclient = mock.Mock()
        if cfg.CONF.ml2_cisco.nexus_driver == 'restapi':
            mock.patch.object(
                nexus_restapi_network_driver.CiscoNexusRestapiDriver,
                '_import_client',
                return_value=self.mock_ncclient).start()
            self.mock_nxapi_client = mock.Mock()
            mock.patch.object(
                nexus_restapi_network_driver.CiscoNexusRestapiDriver,
                '_get_nxapi_client',
                return_value=self.mock_nxapi_client).start()
            self._verify_results = self._verify_restapi_results
        else:
            mock.patch.object(nexus_network_driver.CiscoNexusSshDriver,
                              '_import_client',
                              return_value=self.mock_ncclient).start()
            self._verify_results = self._verify_ssh_results

        original_get_switch_ips = (
            mech_cisco_nexus.CiscoNexusMechanismDriver.get_switch_ips)

        original_get_switch_host_mappings = (
            nexus_db_v2.get_switch_host_mappings)

        original_get_host_mappings = (nexus_db_v2.get_host_mappings)

        def new_get_switch_ips(self):
            switch_ips = original_get_switch_ips(self)
            switch_ips.sort()
            return switch_ips

        def new_get_switch_host_mappings(switch_ip):
            map = original_get_switch_host_mappings(switch_ip)
            map = sorted(map, key=attrgetter('if_id'))
            return map

        def new_get_host_mappings(host_id):
            map = original_get_host_mappings(host_id)
            map = sorted(map, key=attrgetter('switch_ip', 'if_id'))
            return map

        mock.patch.object(nexus_db_v2,
                          'get_switch_host_mappings',
                          new=new_get_switch_host_mappings).start()
        mock.patch.object(nexus_db_v2,
                          'get_host_mappings',
                          new=new_get_host_mappings).start()
        mock.patch.object(mech_cisco_nexus.CiscoNexusMechanismDriver,
                          'get_switch_ips',
                          new=new_get_switch_ips).start()
        test_config_parts = {}
        for name, config in self.test_configs.items():
            host_name = config.host_name
            nexus_port = config.nexus_port
            if not config.nexus_ip_addr:
                if not config.profile:
                    continue
                all_link_info = config.profile['local_link_information']
                for link_info in all_link_info:
                    ip_addr = link_info['switch_info']['switch_ip']
                    self._config_switch_cred(test_config_parts, ip_addr)
            else:
                ip_addr = config.nexus_ip_addr
                self._config_switch_cred(test_config_parts, ip_addr)

            if (host_name is not HOST_NAME_UNUSED
                    and HOST_NAME_Baremetal not in host_name):
                if host_name in test_config_parts[ip_addr]:
                    test_config_parts[ip_addr][host_name].add(nexus_port)
                else:
                    test_config_parts[ip_addr][host_name] = set([nexus_port])
        test_config_file = ""
        for ip, subparts in test_config_parts.items():
            switch_config = subparts['main']
            for name, subpart in subparts.items():
                if name == "main":
                    continue
                switch_config += "%s=%s\n" % (name, ','.join(subpart))
            test_config_file += switch_config
        nc_base.load_config_file(test_config_file)

        self.mock_continue_binding = mock.patch.object(
            FakePortContext, 'continue_binding').start()

        self.mock_get_dynamic_segment = mock.patch.object(
            bc.segments_db,
            'get_dynamic_segment',
            return_value={
                'testkey': 'testvalue'
            }).start()

        mock.patch.object(trunk.NexusMDTrunkHandler,
                          'is_trunk_subport_baremetal',
                          return_value=False).start()

        if cfg.CONF.ml2_cisco.nexus_driver == 'restapi':
            self.restapi_mock_init()
        else:
            self.mock_init()
        self._cisco_mech_driver = mech_cisco_nexus.CiscoNexusMechanismDriver()
        self._cisco_mech_driver.initialize()
        self._cfg_monitor = self._cisco_mech_driver.monitor
        self._cisco_mech_driver.driver.nexus_switches = (
            self._cisco_mech_driver._nexus_switches)
        self.addCleanup(self._clear_port_dbs)
Beispiel #6
0
    def setUp(self):
        """Sets up mock client, switch, and credentials dictionaries."""

        super(TestCiscoNexusBase, self).setUp()

        cfg.CONF.import_opt('api_workers', 'neutron.service')
        cfg.CONF.set_default('api_workers', 0)
        cfg.CONF.import_opt('rpc_workers', 'neutron.service')
        cfg.CONF.set_default('rpc_workers', 0)

        # Use a mock netconf or REST API client
        self.mock_ncclient = mock.Mock()
        if cfg.CONF.ml2_cisco.nexus_driver == 'restapi':
            mock.patch.object(
                nexus_restapi_network_driver.CiscoNexusRestapiDriver,
                '_import_client',
                return_value=self.mock_ncclient).start()
            self._verify_results = self._verify_restapi_results
        else:
            mock.patch.object(nexus_network_driver.CiscoNexusSshDriver,
                              '_import_client',
                              return_value=self.mock_ncclient).start()
            self._verify_results = self._verify_ssh_results

        self.mock_continue_binding = mock.patch.object(
            FakePortContext, 'continue_binding').start()

        if cfg.CONF.ml2_cisco.nexus_driver == 'restapi':
            self.restapi_mock_init()
        else:
            self.mock_init()

        def new_nexus_init(mech_instance):
            mech_instance.driver = mech_instance._load_nexus_cfg_driver()
            mech_instance.monitor_timeout = (
                cfg.CONF.ml2_cisco.switch_heartbeat_time)
            mech_instance._ppid = os.getpid()

            mech_instance._switch_state = {}
            mech_instance._nexus_switches = collections.OrderedDict()
            for name, config in self.test_configs.items():
                ip_addr = config.nexus_ip_addr
                host_name = config.host_name
                nexus_ports = config.nexus_port
                # baremetal config done differently
                if not ip_addr:
                    continue
                # if VNIC_TYPE is baremetal
                # VMs that reference this baremetal
                # do not configure an entry in the host mapping db
                # since code learns this information.
                if (host_name is not HOST_NAME_UNUSED
                        and HOST_NAME_Baremetal not in host_name):
                    for nexus_port in nexus_ports.split(','):
                        try:
                            nexus_db_v2.get_switch_if_host_mappings(
                                ip_addr, nexus_port)
                        except exceptions.NexusHostMappingNotFound:
                            nexus_db_v2.add_host_mapping(
                                host_name, ip_addr, nexus_port, 0, True)
                mech_instance._nexus_switches[(ip_addr,
                                               'ssh_port')] = NEXUS_SSH_PORT
                mech_instance._nexus_switches[(ip_addr,
                                               constants.USERNAME)] = 'admin'
                mech_instance._nexus_switches[(
                    ip_addr, constants.PASSWORD)] = 'password'
                mech_instance._nexus_switches[(ip_addr,
                                               const.PHYSNET)] = PHYSNET
            mech_instance.driver.nexus_switches = (
                mech_instance._nexus_switches)
            mech_instance.context = bc.get_context()

        mock.patch.object(mech_cisco_nexus.CiscoNexusMechanismDriver,
                          '__init__',
                          new=new_nexus_init).start()
        self._cisco_mech_driver = (
            mech_cisco_nexus.CiscoNexusMechanismDriver())
        self._cfg_monitor = (mech_cisco_nexus.CiscoNexusCfgMonitor(
            self._cisco_mech_driver.driver, self._cisco_mech_driver))
        self.addCleanup(self._clear_port_dbs)
Beispiel #7
0
    def setUp(self):
        """Sets up mock ncclient, and switch and credentials dictionaries."""
        super(TestCiscoNexusBase, self).setUp()

        cfg.CONF.import_opt('api_workers', 'neutron.service')
        cfg.CONF.set_default('api_workers', 0)
        cfg.CONF.import_opt('rpc_workers', 'neutron.service')
        cfg.CONF.set_default('rpc_workers', 0)

        # Use a mock netconf client
        self.mock_ncclient = mock.Mock()
        mock.patch.object(nexus_network_driver.CiscoNexusDriver,
                          '_import_ncclient',
                          return_value=self.mock_ncclient).start()
        # this is to prevent interface initialization from occurring
        # which adds unnecessary noise to the results.
        data_xml = {
            'connect.return_value.get.return_value.data_xml':
            'switchport trunk allowed vlan none'
        }
        self.mock_ncclient.configure_mock(**data_xml)

        def new_nexus_init(mech_instance):
            mech_instance.driver = importutils.import_object(NEXUS_DRIVER)
            mech_instance.monitor_timeout = (
                cfg.CONF.ml2_cisco.switch_heartbeat_time)
            mech_instance._ppid = os.getpid()

            mech_instance._switch_state = {}
            mech_instance._nexus_switches = collections.OrderedDict()
            for name, config in self.test_configs.items():
                ip_addr = config.nexus_ip_addr
                host_name = config.host_name
                nexus_port = config.nexus_port
                # baremetal config done differently
                if not ip_addr:
                    continue
                if host_name is not HOST_NAME_UNUSED:
                    if (ip_addr, host_name) in mech_instance._nexus_switches:
                        saved_port = (mech_instance._nexus_switches[(
                            ip_addr, host_name)])
                        if saved_port != nexus_port:
                            mech_instance._nexus_switches[(
                                ip_addr,
                                host_name)] = (saved_port + ',' + nexus_port)
                    else:
                        mech_instance._nexus_switches[(ip_addr,
                                                       host_name)] = nexus_port
                mech_instance._nexus_switches[(ip_addr,
                                               'ssh_port')] = NEXUS_SSH_PORT
                mech_instance._nexus_switches[(ip_addr,
                                               constants.USERNAME)] = 'admin'
                mech_instance._nexus_switches[(
                    ip_addr, constants.PASSWORD)] = 'password'
            mech_instance.driver.nexus_switches = (
                mech_instance._nexus_switches)

        mock.patch.object(mech_cisco_nexus.CiscoNexusMechanismDriver,
                          '__init__',
                          new=new_nexus_init).start()
        self._cisco_mech_driver = (
            mech_cisco_nexus.CiscoNexusMechanismDriver())
        self._cfg_monitor = (mech_cisco_nexus.CiscoNexusCfgMonitor(
            self._cisco_mech_driver.driver, self._cisco_mech_driver))