示例#1
0
    def test_new_connection(self):
        mock_api = mock.Mock()
        mock_api.nsxlib_config = mock.Mock()
        mock_api.nsxlib_config.username = '******'
        mock_api.nsxlib_config.password = '******'
        mock_api.nsxlib_config.retries = 100
        mock_api.nsxlib_config.insecure = True
        mock_api.nsxlib_config.ca_file = None
        mock_api.nsxlib_config.http_timeout = 99
        mock_api.nsxlib_config.conn_idle_timeout = 39
        mock_api.nsxlib_config.client_cert_provider = None
        provider = cluster.NSXRequestsHTTPProvider()
        with mock.patch.object(cluster.TimeoutSession,
                               'request',
                               return_value=get_sess_create_resp()):
            session = provider.new_connection(
                mock_api,
                cluster.Provider('9.8.7.6', 'https://9.8.7.6', 'nsxuser',
                                 'nsxpassword', None))

            self.assertEqual(('nsxuser', 'nsxpassword'), session.auth)
            self.assertFalse(session.verify)
            self.assertIsNone(session.cert)
            self.assertEqual(100,
                             session.adapters['https://'].max_retries.total)
            self.assertEqual(99, session.timeout)
示例#2
0
    def test_validate_connection_method_v2(self):
        mock_cluster, mock_ep, mock_conn = self._validate_con_mocks('2.4.0')
        provider = cluster.NSXRequestsHTTPProvider()
        with mock.patch.object(client.JSONRESTClient,
                               "get",
                               return_value={'healthy': False}):
            self.assertRaises(nsxlib_exc.ResourceNotFound,
                              provider.validate_connection, mock_cluster,
                              mock_ep, mock_conn)

        with mock.patch.object(client.JSONRESTClient,
                               "get",
                               return_value={'healthy': True}):
            provider.validate_connection(mock_cluster, mock_ep, mock_conn)
示例#3
0
    def test_validate_connection_method_v1(self):
        mock_cluster, mock_ep, mock_conn = self._validate_con_mocks('2.3.0')
        provider = cluster.NSXRequestsHTTPProvider()
        with mock.patch.object(client.JSONRESTClient,
                               "get",
                               return_value={'application_status': 'DOWN'}):
            self.assertRaises(nsxlib_exc.ResourceNotFound,
                              provider.validate_connection, mock_cluster,
                              mock_ep, mock_conn)

        with mock.patch.object(client.JSONRESTClient,
                               "get",
                               return_value={'application_status': 'WORKING'}):
            provider.validate_connection(mock_cluster, mock_ep, mock_conn)
示例#4
0
    def test_validate_connection(self):
        mock_conn = mocks.MockRequestSessionApi()
        mock_conn.default_headers = {}
        mock_ep = mock.Mock()
        mock_ep.provider.url = 'https://1.2.3.4'
        mock_cluster = mock.Mock()
        mock_cluster.nsxlib_config = mock.Mock()
        mock_cluster.nsxlib_config.url_base = 'abc'
        mock_cluster.nsxlib_config.keepalive_section = 'transport-zones'
        provider = cluster.NSXRequestsHTTPProvider()
        self.assertRaises(nsxlib_exc.ResourceNotFound,
                          provider.validate_connection, mock_cluster, mock_ep,
                          mock_conn)

        with mock.patch.object(client.JSONRESTClient,
                               "get",
                               return_value={'result_count': 1}):
            provider.validate_connection(mock_cluster, mock_ep, mock_conn)
示例#5
0
    def test_new_connection_with_client_auth(self):
        mock_api = mock.Mock()
        mock_api.nsxlib_config = mock.Mock()
        mock_api.nsxlib_config.retries = 100
        mock_api.nsxlib_config.insecure = True
        mock_api.nsxlib_config.ca_file = None
        mock_api.nsxlib_config.http_timeout = 99
        mock_api.nsxlib_config.conn_idle_timeout = 39
        cert_provider_inst = client_cert.ClientCertProvider('/etc/cert.pem')
        mock_api.nsxlib_config.client_cert_provider = cert_provider_inst
        provider = cluster.NSXRequestsHTTPProvider()
        with mock.patch.object(cluster.TimeoutSession,
                               'request',
                               return_value=get_sess_create_resp()):
            session = provider.new_connection(
                mock_api,
                cluster.Provider('9.8.7.6', 'https://9.8.7.6', None, None,
                                 None))

            self.assertIsNone(session.auth)
            self.assertFalse(session.verify)
            self.assertEqual(cert_provider_inst, session.cert_provider)
            self.assertEqual(99, session.timeout)