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,
            },
            'ml2_cisco_ucsm_ip: 2.2.2.2': {
                'ucsm_username': UCSM_USERNAME_2,
                'ucsm_password': UCSM_PASSWORD_2,
            },
        }
        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]
    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"],
                "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],
        }

        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)
Exemple #3
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)
 def test_bgp_dragent_main_agent_manager(self):
     logging_str = 'neutron.agent.common.config.setup_logging'
     launcher_str = 'oslo_service.service.ServiceLauncher'
     with mock.patch(logging_str):
         with mock.patch.object(sys, 'argv') as sys_argv:
             with mock.patch(launcher_str) as launcher:
                 sys_argv.return_value = ['bgp_dragent', '--config-file',
                                          base.etcdir('neutron.conf')]
                 entry.main()
                 launcher.assert_has_calls(
                     [mock.call(cfg.CONF),
                      mock.call().launch_service(mock.ANY),
                      mock.call().wait()])
Exemple #5
0
 def test_bgp_dragent_main_agent_manager(self):
     logging_str = 'neutron.agent.common.config.setup_logging'
     launcher_str = 'oslo_service.service.ServiceLauncher'
     with mock.patch(logging_str):
         with mock.patch.object(sys, 'argv') as sys_argv:
             with mock.patch(launcher_str) as launcher:
                 sys_argv.return_value = ['bgp_dragent', '--config-file',
                                          base.etcdir('neutron.conf')]
                 entry.main()
                 launcher.assert_has_calls(
                     [mock.call(cfg.CONF),
                      mock.call().launch_service(mock.ANY),
                      mock.call().wait()])
Exemple #6
0
    def setup_config(self):
        # Copied from neutron's test_db_base_plugin_v2 because they
        # don't allow to specify args

        # Create the default configurations
        args = ['--config-file', n_base.etcdir('neutron.conf')]
        # If test_config specifies some config-file, use it, as well
        for config_file in test_lib.test_config.get('config_files', []):
            args.extend(['--config-file', config_file])

        # our own stuff
        dirpath = os.path.join(os.path.dirname(__file__),
                               'etc/neutron/policy.d')
        args.extend(['--config-dir', dirpath])
        self.config_parse(args=args)
Exemple #7
0
    def set_up_mocks(self):
        # Mock the configuration file
        CONF.reset()

        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
        ucsm_config.load_single_ucsm_config()
Exemple #8
0
    def set_up_mocks(self):
        # Mock the configuration file
        args = ['--config-file', base.etcdir('neutron.conf.test')]
        neutron_config.parse(args=args)

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

        # Configure the Cisco APIC mechanism driver
        apic_test_config = {
            'apic_host': APIC_HOST,
            'apic_username': APIC_USR,
            'apic_password': APIC_PWD,
            'apic_port': APIC_PORT,
            'apic_vmm_domain': APIC_DOMAIN,
            'apic_vlan_ns_name': APIC_VLAN_NAME,
            'apic_vlan_range': '%d:%d' % (APIC_VLANID_FROM, APIC_VLANID_TO),
            'apic_node_profile': APIC_NODE_PROF,
            'apic_entity_profile': APIC_ATT_ENT_PROF,
            'apic_function_profile': APIC_FUNC_PROF,
        }
        for opt, val in apic_test_config.items():
            cfg.CONF.set_override(opt, val, 'ml2_cisco_apic')

        apic_switch_cfg = {
            'apic_switch:east01': {
                'ubuntu1,ubuntu2': ['3/11']
            },
            'apic_switch:east02': {
                'rhel01,rhel02': ['4/21'],
                'rhel03': ['4/22']
            },
        }
        self.mocked_parser = mock.patch.object(cfg,
                                               'MultiConfigParser').start()
        self.mocked_parser.return_value.read.return_value = [apic_switch_cfg]
        self.mocked_parser.return_value.parsed = [apic_switch_cfg]
    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 = {
            "ucsm_ip": UCSM_IP_ADDRESS,
            "ucsm_username": UCSM_USERNAME,
            "ucsm_password": UCSM_PASSWORD,
            "ucsm_host_list": HOST_CONFIG1,
        }

        for opt, val in ucsm_test_config.items():
            config.cfg.CONF.set_override(opt, val, "ml2_cisco_ucsm")
 def test_bgp_dragent_manager(self):
     state_rpc_str = 'neutron.agent.rpc.PluginReportStateAPI'
     # sync_state is needed for this test
     with mock.patch.object(bgp_dragent.BgpDrAgentWithStateReport,
                            'sync_state',
                            autospec=True) as mock_sync_state:
         with mock.patch(state_rpc_str) as state_rpc:
             with mock.patch.object(sys, 'argv') as sys_argv:
                 sys_argv.return_value = [
                     'bgp_dragent', '--config-file',
                     base.etcdir('neutron.conf')]
                 common_config.init(sys.argv[1:])
                 agent_mgr = bgp_dragent.BgpDrAgentWithStateReport(
                     'testhost')
                 eventlet.greenthread.sleep(1)
                 agent_mgr.after_start()
                 self.assertIsNotNone(len(mock_sync_state.mock_calls))
                 state_rpc.assert_has_calls(
                     [mock.call(mock.ANY),
                      mock.call().report_state(mock.ANY, mock.ANY,
                                               mock.ANY)])
Exemple #11
0
 def test_bgp_dragent_manager(self):
     state_rpc_str = 'neutron.agent.rpc.PluginReportStateAPI'
     # sync_state is needed for this test
     with mock.patch.object(bgp_dragent.BgpDrAgentWithStateReport,
                            'sync_state',
                            autospec=True) as mock_sync_state:
         with mock.patch(state_rpc_str) as state_rpc:
             with mock.patch.object(sys, 'argv') as sys_argv:
                 sys_argv.return_value = [
                     'bgp_dragent', '--config-file',
                     base.etcdir('neutron.conf')]
                 common_config.init(sys.argv[1:])
                 agent_mgr = bgp_dragent.BgpDrAgentWithStateReport(
                     'testhost')
                 eventlet.greenthread.sleep(1)
                 agent_mgr.after_start()
                 self.assertIsNotNone(len(mock_sync_state.mock_calls))
                 state_rpc.assert_has_calls(
                     [mock.call(mock.ANY),
                      mock.call().report_state(mock.ANY, mock.ANY,
                                               mock.ANY)])
    def set_up_mocks(self):
        # Mock the configuration file
        args = ['--config-file', base.etcdir('neutron.conf.test')]
        neutron_config.parse(args=args)

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

        # Configure the Cisco APIC mechanism driver
        apic_test_config = {
            'apic_host': APIC_HOST,
            'apic_username': APIC_USR,
            'apic_password': APIC_PWD,
            'apic_port': APIC_PORT,
            'apic_vmm_domain': APIC_DOMAIN,
            'apic_vlan_ns_name': APIC_VLAN_NAME,
            'apic_vlan_range': '%d:%d' % (APIC_VLANID_FROM, APIC_VLANID_TO),
            'apic_node_profile': APIC_NODE_PROF,
            'apic_entity_profile': APIC_ATT_ENT_PROF,
            'apic_function_profile': APIC_FUNC_PROF,
        }
        for opt, val in apic_test_config.items():
            cfg.CONF.set_override(opt, val, 'ml2_cisco_apic')

        apic_switch_cfg = {
            'apic_switch:east01': {'ubuntu1,ubuntu2': ['3/11']},
            'apic_switch:east02': {'rhel01,rhel02': ['4/21'],
                                   'rhel03': ['4/22']},
        }
        self.mocked_parser = mock.patch.object(cfg,
                                               'MultiConfigParser').start()
        self.mocked_parser.return_value.read.return_value = [apic_switch_cfg]
        self.mocked_parser.return_value.parsed = [apic_switch_cfg]
    def set_up_mocks(self):
        # Mock the configuration file

        args = ['--config-file', base.etcdir('neutron.conf.test')]
        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 = {
            'ucsm_ip': UCSM_IP_ADDRESS,
            'ucsm_username': UCSM_USERNAME,
            'ucsm_password': UCSM_PASSWORD,
            'ucsm_host_list': HOST_CONFIG1,
        }

        for opt, val in ucsm_test_config.items():
            config.cfg.CONF.set_override(opt, val, 'ml2_cisco_ucsm')
    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 = {
            'ucsm_ip': UCSM_IP_ADDRESS,
            'ucsm_username': UCSM_USERNAME,
            'ucsm_password': UCSM_PASSWORD,
            'ucsm_host_list': HOST_CONFIG1,
        }

        for opt, val in ucsm_test_config.items():
            config.cfg.CONF.set_override(opt, val, 'ml2_cisco_ucsm')
Exemple #15
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)
Exemple #16
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])