Пример #1
0
    def setUp(self):
        # mock api client
        self.fc = fake.FakeClient(vmware.STUBS_PATH)
        mock_api = mock.patch(vmware.NSXAPI_NAME, autospec=True)
        # Avoid runs of the synchronizer looping call
        # These unit tests will excplicitly invoke synchronization
        patch_sync = mock.patch.object(sync, '_start_loopingcall')
        self.mock_api = mock_api.start()
        patch_sync.start()
        self.mock_api.return_value.login.return_value = "the_cookie"
        # Emulate tests against NSX 3.x
        self.mock_api.return_value.get_version.return_value = (
            version.Version("3.1"))

        self.mock_api.return_value.request.side_effect = self.fc.fake_request
        self.fake_cluster = cluster.NSXCluster(name='fake-cluster',
                                               nsx_controllers=['1.1.1.1:999'],
                                               default_tz_uuid=_uuid(),
                                               nsx_user='******',
                                               nsx_password='******')
        self.fake_cluster.api_client = client.NsxApiClient(
            ('1.1.1.1', '999', True),
            self.fake_cluster.nsx_user,
            self.fake_cluster.nsx_password,
            http_timeout=self.fake_cluster.http_timeout,
            retries=self.fake_cluster.retries,
            redirects=self.fake_cluster.redirects)
        # Instantiate Neutron plugin
        # and setup needed config variables
        args = [
            '--config-file',
            vmware.get_fake_conf('neutron.conf.test'), '--config-file',
            vmware.get_fake_conf('nsx.ini.test')
        ]
        self.config_parse(args=args)
        cfg.CONF.set_override('allow_overlapping_ips', True)
        self._plugin = plugin.NsxPlugin()
        # Mock neutron manager plugin load functions to speed up tests
        mock_nm_get_plugin = mock.patch('neutron.manager.NeutronManager.'
                                        'get_plugin')
        mock_nm_get_service_plugins = mock.patch(
            'neutron.manager.NeutronManager.get_service_plugins')
        self.mock_nm_get_plugin = mock_nm_get_plugin.start()
        self.mock_nm_get_plugin.return_value = self._plugin
        mock_nm_get_service_plugins.start()
        super(SyncTestCase, self).setUp()
        self.addCleanup(self.fc.reset_all)
Пример #2
0
def create_nsx_cluster(cluster_opts, concurrent_connections, gen_timeout):
    cluster = nsx_cluster.NSXCluster(**cluster_opts)

    def _ctrl_split(x, y):
        return (x, int(y), True)

    api_providers = [
        _ctrl_split(*ctrl.split(':')) for ctrl in cluster.nsx_controllers
    ]
    cluster.api_client = client.NsxApiClient(
        api_providers,
        cluster.nsx_user,
        cluster.nsx_password,
        http_timeout=cluster.http_timeout,
        retries=cluster.retries,
        redirects=cluster.redirects,
        concurrent_connections=concurrent_connections,
        gen_timeout=gen_timeout)
    return cluster