def test_parsing_of_single_ucsm_config(self):
        """Verifies parsing of expected single UCSM config parameters."""
        # Single UCSM config parameters.
        cfg.CONF.ml2_cisco_ucsm.ucsm_ip = "1.1.1.1"
        cfg.CONF.ml2_cisco_ucsm.ucsm_username = "******"
        cfg.CONF.ml2_cisco_ucsm.ucsm_password = "******"
        cfg.CONF.ml2_cisco_ucsm.ucsm_virtio_eth_ports = ["eth0", "eth1"]

        expected_parsed_virtio_eth_ports = ["/ether-eth0", "/ether-eth1"]

        ucsm_config = conf.UcsmConfig()

        username, password = ucsm_config.get_credentials_for_ucsm_ip(
            cfg.CONF.ml2_cisco_ucsm.ucsm_ip)

        self.assertEqual(username, cfg.CONF.ml2_cisco_ucsm.ucsm_username)
        self.assertEqual(password, cfg.CONF.ml2_cisco_ucsm.ucsm_password)

        virtio_port_list = ucsm_config.get_ucsm_eth_port_list(
            cfg.CONF.ml2_cisco_ucsm.ucsm_ip)

        self.assertEqual(expected_parsed_virtio_eth_ports, virtio_port_list)

        # Check to see that SSL certificate checking is set to True by default
        self.assertTrue(cfg.CONF.ml2_cisco_ucsm.ucsm_https_verify)
 def new_ucsm_driver_init(mech_instance):
     mech_instance.ucsmsdk = None
     mech_instance.handles = {}
     mech_instance.supported_sriov_vnic_types = SRIOV_VNIC_TYPES
     mech_instance.supported_pci_devs = SUPPORTED_PCI_DEVS
     mech_instance.ucsm_host_dict = UCSM_HOST_DICT
     mech_instance.ucsm_conf = conf.UcsmConfig()
    def test_parsing_of_single_ucsm_vnic_template_config(self):
        """Verifies parsing of single UCSM vNIC Template config."""
        # Single UCSM config parameters.
        cfg.CONF.ml2_cisco_ucsm.ucsm_ip = "1.1.1.1"
        cfg.CONF.ml2_cisco_ucsm.ucsm_username = "******"
        cfg.CONF.ml2_cisco_ucsm.ucsm_password = "******"
        cfg.CONF.ml2_cisco_ucsm.ucsm_virtio_eth_ports = ["eth0", "eth1"]
        cfg.CONF.ml2_cisco_ucsm.vnic_template_list = (
            'physnet1:top-root:Test-VNIC1 '
            'physnet2:org-root/org-Test-Sub:Test-VNIC2 '
            'physnet3::Test-VNIC3')

        # Expected values after parsing of config parametrs
        expected_vnic_template1 = ('org-root/org-Test-Sub', 'Test-VNIC2')
        expected_vnic_template2 = [('top-root', 'Test-VNIC1'),
                                   ('org-root/org-Test-Sub', 'Test-VNIC2'),
                                   ('org-root', 'Test-VNIC3')]

        ucsm_config = conf.UcsmConfig()
        ucsm_config.vnic_template_dict = {}

        # Verify parsing of VNIC Template config
        self.assertTrue(ucsm_config.is_vnic_template_configured())

        vnic_template1 = ucsm_config.get_vnic_template_for_physnet(
            cfg.CONF.ml2_cisco_ucsm.ucsm_ip, "physnet2")
        self.assertEqual(expected_vnic_template1, vnic_template1)

        vnic_template2 = ucsm_config.get_vnic_template_for_ucsm_ip(
            cfg.CONF.ml2_cisco_ucsm.ucsm_ip)
        self.assertEqual(expected_vnic_template2, vnic_template2)

        vnic_template_path, vnic_template = (
            ucsm_config.get_vnic_template_for_physnet("1.1.1.1", "physnet1"))
        vnic_templ_full_path1 = (vnic_template_path +
                                 const.VNIC_TEMPLATE_PREFIX +
                                 str(vnic_template))
        expected_vnic_templ_full_path1 = "top-root/lan-conn-templ-Test-VNIC1"
        self.assertEqual(expected_vnic_templ_full_path1, vnic_templ_full_path1)

        vnic_template_path, vnic_template = (
            ucsm_config.get_vnic_template_for_physnet("1.1.1.1", "physnet2"))
        vnic_templ_full_path1 = (vnic_template_path +
                                 const.VNIC_TEMPLATE_PREFIX +
                                 str(vnic_template))
        expected_vnic_templ_full_path1 = (
            "org-root/org-Test-Sub/lan-conn-templ-Test-VNIC2")
        self.assertEqual(expected_vnic_templ_full_path1, vnic_templ_full_path1)

        vnic_template_path, vnic_template = (
            ucsm_config.get_vnic_template_for_physnet("1.1.1.1", "physnet3"))
        vnic_templ_full_path1 = (vnic_template_path +
                                 const.VNIC_TEMPLATE_PREFIX +
                                 str(vnic_template))
        expected_vnic_templ_full_path1 = "org-root/lan-conn-templ-Test-VNIC3"
        self.assertEqual(expected_vnic_templ_full_path1, vnic_templ_full_path1)
예제 #4
0
    def set_up_mocks(self):
        # Mock the configuration file

        args = ['--config-file', base.etcdir('neutron.conf')]
        neutron_config.init(args=args)

        # Configure the ML2 mechanism drivers and network types
        ml2_opts = {
            'mechanism_drivers': ['cisco_ucsm'],
            'tenant_network_types': ['vlan'],
        }
        for opt, val in ml2_opts.items():
            ml2_config.cfg.CONF.set_override(opt, val, 'ml2')

        # Configure the Cisco UCS Manager mechanism driver
        ucsm_test_config = {
            'ml2_cisco_ucsm_ip: 1.1.1.1': {
                'ucsm_username': [UCSM_USERNAME_1],
                'ucsm_password': [UCSM_PASSWORD_1],
                'ucsm_virtio_eth_ports': UCSM_VIRTIO_ETH_PORTS_1,
                'vnic_template_list': ['test-physnet:org-root:Test-VNIC'],
            },
            'ml2_cisco_ucsm_ip: 2.2.2.2': {
                'ucsm_username': [UCSM_USERNAME_2],
                'ucsm_password': [UCSM_PASSWORD_2],
                'ucsm_virtio_eth_ports': UCSM_VIRTIO_ETH_PORTS_2,
                'vnic_template_list': ['physnet2:org-root/org-Test-Sub:Test']
            },
        }
        expected_ucsm_dict = {
            '1.1.1.1': [UCSM_PASSWORD_1, UCSM_USERNAME_1],
            '2.2.2.2': [UCSM_PASSWORD_2, UCSM_USERNAME_2],
        }

        expected_ucsm_port_dict = {
            '1.1.1.1': [const.ETH_PREFIX + 'eth0', const.ETH_PREFIX + 'eth1'],
            '2.2.2.2': [const.ETH_PREFIX + 'eth2', const.ETH_PREFIX + 'eth3'],
        }

        expected_vnic_template_dict = {
            ('1.1.1.1', 'test-physnet'): ('org-root', 'Test-VNIC'),
            ('2.2.2.2', 'physnet2'): ('org-root/org-Test-Sub', 'Test'),
        }

        self.mocked_parser = mock.patch.object(cfg,
            'MultiConfigParser').start()
        self.mocked_parser.return_value.read.return_value = [ucsm_test_config]
        self.mocked_parser.return_value.parsed = [ucsm_test_config]
        ucsm_config.UcsmConfig()
        self.assertEqual(expected_ucsm_dict,
                         ucsm_config.UcsmConfig.ucsm_dict)
        self.assertEqual(expected_ucsm_port_dict,
                         ucsm_config.UcsmConfig.ucsm_port_dict)
        self.assertEqual(expected_vnic_template_dict,
                         ucsm_config.UcsmConfig.vnic_template_dict)
예제 #5
0
 def __init__(self):
     LOG.debug("UCS Manager Network driver found")
     self.ucsmsdk = None
     self.supported_sriov_vnic_types = [
         portbindings.VNIC_DIRECT, portbindings.VNIC_MACVTAP
     ]
     self.supported_pci_devs = config.parse_pci_vendor_config()
     self.ucsm_conf = config.UcsmConfig()
     self.ucsm_host_dict = {}
     self.ucsm_sp_dict = {}
     self._create_host_and_sp_dicts_from_config()
예제 #6
0
 def __init__(self):
     LOG.debug("UCS Manager Network driver found")
     self.ucsmsdk = None
     self.supported_sriov_vnic_types = [
         portbindings.VNIC_DIRECT, portbindings.VNIC_MACVTAP
     ]
     self.supported_pci_devs = config.parse_pci_vendor_config()
     self.ucsm_conf = config.UcsmConfig()
     self.ucsm_host_dict = {}
     self.ucsm_sp_dict = {}
     # Check if Service Profile to Hostname mapping config has been provided
     if cfg.CONF.ml2_cisco_ucsm.ucsm_host_list:
         self.ucsm_host_dict = config.parse_ucsm_host_config()
     else:
         self._create_ucsm_host_to_service_profile_mapping()
    def __init__(self):
        LOG.debug("UCS Manager Network driver found")
        self.ucsmsdk = None
        self.supported_sriov_vnic_types = [bc.portbindings.VNIC_DIRECT,
                                           bc.portbindings.VNIC_MACVTAP]
        self.supported_pci_devs = config.parse_pci_vendor_config()
        self.ucsm_conf = config.UcsmConfig()
        self.ucsm_db = ucsm_db.UcsmDbModel()
        self.ucsm_host_dict = {}
        self.ucsm_sp_dict = {}
        self._disable_ssl_cert_check()
        self._create_host_and_sp_dicts_from_config()

        Timer(const.DEFAULT_PP_DELETE_TIME,
            self._delayed_delete_port_profile, ()).start()
        LOG.debug('Starting periodic Port Profile delete timer for %d',
            const.DEFAULT_PP_DELETE_TIME)
예제 #8
0
    def initialize(self):
        self.vif_type = const.VIF_TYPE_802_QBH
        self.vif_details = {bc.portbindings.CAP_PORT_FILTER: False}
        self.ucsm_db = ucsm_db.UcsmDbModel()

        if importutils.try_import('ucsmsdk'):
            self.driver = ucsm_network_driver.CiscoUcsmDriver()
        elif importutils.try_import('UcsSdk'):
            warnings.warn("Cannot find ucsmsdk package, falling back to "
                    "using UcsSdk which is now deprecated. For new "
                    "features please run with ucsmsdk installed.",
                    DeprecationWarning)
            self.driver = deprecated_network_driver.CiscoUcsmDriver()
        else:
            LOG.error('Could not import ucsm sdk.')

        self.ucsm_conf = config.UcsmConfig()
    def test_parsing_of_single_ucsm_sp_template_config(self):
        """Verifies parsing of single UCSM SP Template config."""

        # Single UCSM config parameters.
        cfg.CONF.ml2_cisco_ucsm.ucsm_ip = "1.1.1.1"
        cfg.CONF.ml2_cisco_ucsm.ucsm_username = "******"
        cfg.CONF.ml2_cisco_ucsm.ucsm_password = "******"
        cfg.CONF.ml2_cisco_ucsm.ucsm_virtio_eth_ports = ["eth0", "eth1"]
        cfg.CONF.ml2_cisco_ucsm.sp_template_list = (
            'SP_Template1_path:SP_Template1:Host11,Host12 '
            'SP_Template2_path:SP_Template2:Host21,Host22')

        ucsm_config = conf.UcsmConfig()

        # Verify parsing of SP Template config
        self.assertTrue(ucsm_config.is_service_profile_template_configured())

        # Test all the utility methods to glean information
        # from sp_template_dict
        expected_sp_template_path = "SP_Template1_path"
        sp_template_path = ucsm_config.get_sp_template_path_for_host("Host11")
        self.assertEqual(expected_sp_template_path, sp_template_path)

        expected_sp_template = "SP_Template1"
        sp_template = ucsm_config.get_sp_template_for_host("Host12")
        self.assertEqual(expected_sp_template, sp_template)

        expected_ucsm_ip = "1.1.1.1"
        ucsm_ip = ucsm_config.get_ucsm_ip_for_sp_template_host("Host21")
        self.assertEqual(expected_ucsm_ip, ucsm_ip)

        expected_sp_template_list = [
            ('1.1.1.1', 'SP_Template2_path', 'SP_Template2'),
            ('1.1.1.1', 'SP_Template1_path', 'SP_Template1'),
        ]
        sp_template_list = ucsm_config.get_sp_template_list_for_ucsm("1.1.1.1")
        for entry in expected_sp_template_list:
            self.assertIn(entry, sp_template_list)

        expected_sp_template_list = []
        sp_template_list = ucsm_config.get_sp_template_list_for_ucsm("2.2.2.2")
        self.assertEqual(expected_sp_template_list, sp_template_list)
    def test_parsing_of_single_ucsm_config(self):
        cfg.CONF.ml2_cisco_ucsm.ucsm_ip = "1.1.1.1"
        cfg.CONF.ml2_cisco_ucsm.ucsm_username = "******"
        cfg.CONF.ml2_cisco_ucsm.ucsm_password = "******"
        cfg.CONF.ml2_cisco_ucsm.ucsm_virtio_eth_ports = ["eth0", "eth1"]
        expected_parsed_virtio_eth_ports = ["/ether-eth0", "/ether-eth1"]

        ucsm_config = conf.UcsmConfig()

        ucsm_config._create_single_ucsm_dicts()

        username, password = ucsm_config.get_credentials_for_ucsm_ip(
            cfg.CONF.ml2_cisco_ucsm.ucsm_ip)

        self.assertEqual(username, cfg.CONF.ml2_cisco_ucsm.ucsm_username)
        self.assertEqual(password, cfg.CONF.ml2_cisco_ucsm.ucsm_password)

        virtio_port_list = ucsm_config.get_ucsm_eth_port_list(
            cfg.CONF.ml2_cisco_ucsm.ucsm_ip)

        self.assertEqual(expected_parsed_virtio_eth_ports, virtio_port_list)
    def setUp(self):
        """Sets up mock Ucs Sdk."""
        super(TestCiscoUcsmMechDriver, self).setUp()
        self.set_up_mocks()

        def new_ucsm_driver_init(mech_instance):
            mech_instance.ucsmsdk = None
            mech_instance.handles = {}
            mech_instance.supported_sriov_vnic_types = SRIOV_VNIC_TYPES
            mech_instance.supported_pci_devs = SUPPORTED_PCI_DEVS
            mech_instance.ucsm_host_dict = UCSM_HOST_DICT

        mock.patch.object(ucsm_network_driver.CiscoUcsmDriver,
                          '__init__',
                          new=new_ucsm_driver_init).start()

        self.mech_driver = md.CiscoUcsmMechanismDriver()
        self.mech_driver.initialize()
        self.vif_type = const.VIF_TYPE_802_QBH
        self.db = ucsm_db.UcsmDbModel()
        self.ucsm_driver = ucsm_network_driver.CiscoUcsmDriver()
        self.ucsm_config = conf.UcsmConfig()
예제 #12
0
 def initialize(self):
     self.vif_type = const.VIF_TYPE_802_QBH
     self.vif_details = {bc.portbindings.CAP_PORT_FILTER: False}
     self.ucsm_db = ucsm_db.UcsmDbModel()
     self.driver = ucsm_network_driver.CiscoUcsmDriver()
     self.ucsm_conf = config.UcsmConfig()
예제 #13
0
    def set_up_mocks(self):
        # Mock the configuration file

        args = ['--config-file', base.etcdir('neutron.conf')]
        neutron_config.init(args=args)

        # Configure the ML2 mechanism drivers and network types
        ml2_opts = {
            'mechanism_drivers': ['cisco_ucsm'],
            'tenant_network_types': ['vlan'],
        }
        for opt, val in ml2_opts.items():
            ml2_config.cfg.CONF.set_override(opt, val, 'ml2')

        # Configure the Cisco UCS Manager mechanism driver
        ucsm_test_config = {
            'ml2_cisco_ucsm_ip: 1.1.1.1': {
                'ucsm_username': [UCSM_USERNAME_1],
                'ucsm_password': [UCSM_PASSWORD_1],
                'ucsm_host_list': UCSM_HOST_LIST_1,
                'ucsm_virtio_eth_ports': UCSM_VIRTIO_ETH_PORTS_1,
                'vnic_template_list': ['test-physnet:org-root:Test-VNIC'],
                'sriov_qos_policy': ['Test']
            },
            'ml2_cisco_ucsm_ip: 2.2.2.2': {
                'ucsm_username': [UCSM_USERNAME_2],
                'ucsm_password': [UCSM_PASSWORD_2],
                'ucsm_virtio_eth_ports': UCSM_VIRTIO_ETH_PORTS_2,
                'vnic_template_list': ['physnet2:org-root/org-Test-Sub:Test']
            },
            'sriov_multivlan_trunk': {
                'test_network1': ['5, 7 - 9'],
                'test_network2': ['500 - 509, 700'],
            },
        }
        expected_ucsm_dict = {
            '1.1.1.1': (UCSM_USERNAME_1, UCSM_PASSWORD_1),
            '2.2.2.2': (UCSM_USERNAME_2, UCSM_PASSWORD_2),
        }

        expected_ucsm_port_dict = {
            '1.1.1.1': [const.ETH_PREFIX + 'eth0', const.ETH_PREFIX + 'eth1'],
            '2.2.2.2': [const.ETH_PREFIX + 'eth2', const.ETH_PREFIX + 'eth3'],
        }

        expected_vnic_template_dict = {
            ('1.1.1.1', 'test-physnet'): ('org-root', 'Test-VNIC'),
            ('2.2.2.2', 'physnet2'): ('org-root/org-Test-Sub', 'Test'),
        }

        expected_sriov_qos_policy = {
            '1.1.1.1': 'Test',
        }

        expected_multivlan_trunk_dict = {
            'test_network1': [5, 7, 8, 9],
            'test_network2':
            [500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 700]
        }

        expected_sp_dict = {
            ('1.1.1.1', 'UCS-1'): ('org-root/ls-UCS-1-SP'),
            ('1.1.1.1', 'UCS-2'): ('org-root/test/ls-UCS-2-SP'),
        }

        self.mocked_parser = mock.patch.object(cfg,
                                               'MultiConfigParser').start()
        self.mocked_parser.return_value.read.return_value = [ucsm_test_config]
        self.mocked_parser.return_value.parsed = [ucsm_test_config]
        ucsm_config.UcsmConfig()
        self.assertEqual(expected_ucsm_dict, ucsm_config.UcsmConfig.ucsm_dict)
        self.assertEqual(expected_ucsm_port_dict,
                         ucsm_config.UcsmConfig.ucsm_port_dict)
        self.assertEqual(expected_vnic_template_dict,
                         ucsm_config.UcsmConfig.vnic_template_dict)
        self.assertEqual(expected_sriov_qos_policy,
                         ucsm_config.UcsmConfig.sriov_qos_policy)
        self.assertEqual(expected_multivlan_trunk_dict,
                         ucsm_config.UcsmConfig.multivlan_trunk_dict)
        self.assertEqual(expected_sp_dict, ucsm_config.UcsmConfig.ucsm_sp_dict)
예제 #14
0
    def set_up_mocks(self):
        # Mock the configuration file

        args = ['--config-file', base.etcdir('neutron.conf')]
        neutron_config.init(args=args)

        nc_base.load_config_file(ucsm_test_config_file)

        # Configure the ML2 mechanism drivers and network types
        ml2_opts = {
            'mechanism_drivers': ['cisco_ucsm'],
            'tenant_network_types': ['vlan'],
        }
        for opt, val in ml2_opts.items():
            ml2_config.cfg.CONF.set_override(opt, val, 'ml2')

        # Configure and test the Cisco UCS Manager mechanism driver
        config = ucsm_config.UcsmConfig()

        self.assertEqual(config.get_credentials_for_ucsm_ip("1.1.1.1"),
                         (UCSM_USERNAME_1, UCSM_PASSWORD_1))

        self.assertEqual(config.get_credentials_for_ucsm_ip("2.2.2.2"),
                         (UCSM_USERNAME_2, UCSM_PASSWORD_2))

        expected_sp_dict = {
            ('1.1.1.1', 'UCS-1'): ('org-root/ls-UCS-1-SP'),
            ('1.1.1.1', 'UCS-2'): ('org-root/test/ls-UCS-2-SP'),
        }
        self.assertEqual(expected_sp_dict, config.ucsm_sp_dict)

        self.assertEqual(config.get_vnic_template_for_ucsm_ip("1.1.1.1"),
                         [('org-root', 'Test-VNIC,vnic2')])

        self.assertEqual(
            config.get_vnic_template_for_physnet("1.1.1.1", "test-physnet"),
            ('org-root', 'Test-VNIC,vnic2'))

        self.assertEqual(
            config.get_vnic_template_for_physnet("2.2.2.2", "physnet2"),
            ('org-root/org-Test-Sub', 'Test'))

        self.assertTrue(config.is_vnic_template_configured())

        self.assertEqual(
            config.get_ucsm_eth_port_list('1.1.1.1'),
            [const.ETH_PREFIX + 'eth0', const.ETH_PREFIX + 'eth1'])

        self.assertEqual(
            config.get_ucsm_eth_port_list('2.2.2.2'),
            [const.ETH_PREFIX + 'eth2', const.ETH_PREFIX + 'eth3'])

        self.assertEqual(config.get_sriov_qos_policy('1.1.1.1'), 'Test')

        self.assertEqual(
            config.get_sriov_multivlan_trunk_config("test_network1"),
            [5, 7, 8, 9])

        self.assertEqual(
            config.get_sriov_multivlan_trunk_config("test_network2"),
            [500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 700])