Ejemplo n.º 1
0
    def setUp(self):
        self.fc = fake.FakeClient(STUBS_PATH)
        self.mock_nsxapi = mock.patch(NSXAPI_NAME, autospec=True)
        instance = self.mock_nsxapi.start()
        instance.return_value.login.return_value = "the_cookie"
        # Choose 3.0, but the version is irrelevant for the aim of
        # these tests as calls are throwing up errors anyway
        fake_version = getattr(self, 'fake_version', "3.0")
        instance.return_value.get_nvp_version.return_value = (
            api_client.NVPVersion(fake_version))

        def _faulty_request(*args, **kwargs):
            raise api_client.NvpApiException

        instance.return_value.request.side_effect = _faulty_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 = api_client.NVPApiHelper(
            ('1.1.1.1', '999', True), self.fake_cluster.nsx_user,
            self.fake_cluster.nsx_password, self.fake_cluster.req_timeout,
            self.fake_cluster.http_timeout, self.fake_cluster.retries,
            self.fake_cluster.redirects)

        super(NsxlibNegativeBaseTestCase, self).setUp()
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(self.mock_nsxapi.stop)
Ejemplo n.º 2
0
    def setUp(self):
        # mock nvp api client
        self.fc = fake_nvpapiclient.FakeClient(STUBS_PATH)
        mock_nvpapi = mock.patch(NVPAPI_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_nvpapi = mock_nvpapi.start()
        patch_sync.start()
        self.mock_nvpapi.return_value.login.return_value = "the_cookie"
        # Emulate tests against NVP 3.x
        self.mock_nvpapi.return_value.get_nvp_version.return_value = (
            NvpApiClient.NVPVersion("3.1"))

        def _fake_request(*args, **kwargs):
            return self.fc.fake_request(*args, **kwargs)

        self.mock_nvpapi.return_value.request.side_effect = _fake_request
        self.fake_cluster = nsx_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 = NvpApiClient.NVPApiHelper(
            ('1.1.1.1', '999', True), self.fake_cluster.nsx_user,
            self.fake_cluster.nsx_password, self.fake_cluster.req_timeout,
            self.fake_cluster.http_timeout, self.fake_cluster.retries,
            self.fake_cluster.redirects)
        # Instantiate Neutron plugin
        # and setup needed config variables
        args = [
            '--config-file',
            get_fake_conf('neutron.conf.test'), '--config-file',
            get_fake_conf('nsx.ini.test')
        ]
        config.parse(args=args)
        cfg.CONF.set_override('allow_overlapping_ips', True)
        self._plugin = NeutronPlugin.NvpPluginV2()
        # 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(NvpSyncTestCase, self).setUp()
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(patch_sync.stop)
        self.addCleanup(mock_nvpapi.stop)
        self.addCleanup(mock_nm_get_plugin.stop)
        self.addCleanup(mock_nm_get_service_plugins.stop)
Ejemplo n.º 3
0
def create_nsx_cluster(cluster_opts, concurrent_connections, nsx_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 = NvpApiClient.NVPApiHelper(
        api_providers,
        cluster.nsx_user,
        cluster.nsx_password,
        request_timeout=cluster.req_timeout,
        http_timeout=cluster.http_timeout,
        retries=cluster.retries,
        redirects=cluster.redirects,
        concurrent_connections=concurrent_connections,
        nvp_gen_timeout=nsx_gen_timeout)
    return cluster
Ejemplo n.º 4
0
    def setUp(self):
        self.fc = fake.FakeClient(STUBS_PATH)
        self.mock_nsxapi = mock.patch(NSXAPI_NAME, autospec=True)
        instance = self.mock_nsxapi.start()
        instance.return_value.login.return_value = "the_cookie"
        fake_version = getattr(self, 'fake_version', "3.0")
        instance.return_value.get_nvp_version.return_value = (
            api_client.NVPVersion(fake_version))

        instance.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 = api_client.NVPApiHelper(
            ('1.1.1.1', '999', True), self.fake_cluster.nsx_user,
            self.fake_cluster.nsx_password, self.fake_cluster.req_timeout,
            self.fake_cluster.http_timeout, self.fake_cluster.retries,
            self.fake_cluster.redirects)

        super(NsxlibTestCase, self).setUp()
        self.addCleanup(self.fc.reset_all)
        self.addCleanup(self.mock_nsxapi.stop)
Ejemplo n.º 5
0
 def test_create_cluster_default_port(self):
     opts = self.cluster_opts.copy()
     opts['nsx_controllers'] = ['1.1.1.1']
     cluster = nsx_cluster.NSXCluster(**opts)
     for (k, v) in self.cluster_opts.iteritems():
         self.assertEqual(v, getattr(cluster, k))
Ejemplo n.º 6
0
 def test_create_cluster(self):
     cluster = nsx_cluster.NSXCluster(**self.cluster_opts)
     for (k, v) in self.cluster_opts.iteritems():
         self.assertEqual(v, getattr(cluster, k))