def test_jsonrpc_init_without_ca(self, mock_warning): self.rpc = jsonrpc.JsonRpc("https://foo.bar/", ('fakeuser', 'fakepwd'), None) mock_warning.assert_called_once_with( "Will not verify the server certificate of the API service" " because the CA certificate is not available.")
def test_https_call_verify(self, mock_req_get): fake_ca_file = tempfile.TemporaryFile() self.rpc = jsonrpc.JsonRpc(url="https://test", user_credentials=("me", "team"), ca_file=fake_ca_file) result = self.rpc.call('method', {'param': 'value'}) mock_req_get.assert_called_once_with( url=self.rpc._url, json=mock.ANY, # not checking here as of undefined order in dict auth=self.rpc._credentials, verify=fake_ca_file) self.assertEqual("Sweet gorilla of Manila", result)
def do_setup(self, context): """Prepares the backend.""" self.rpc = jsonrpc.JsonRpc( url=self.configuration.quobyte_api_url, ca_file=self.configuration.quobyte_api_ca, user_credentials=(self.configuration.quobyte_api_username, self.configuration.quobyte_api_password)) try: self.rpc.call('getInformation', {}) except Exception as exc: LOG.error("Could not connect to API: %s", exc) raise exception.QBException( _('Could not connect to API: %s') % exc)
def test_jsonrpc_init_with_ca(self): foofile = tempfile.TemporaryFile() fake_url = "https://foo.bar/" fake_credentials = ('fakeuser', 'fakepwd') fake_cert_file = tempfile.TemporaryFile() fake_key_file = tempfile.TemporaryFile() self.rpc = jsonrpc.JsonRpc(url=fake_url, user_credentials=fake_credentials, ca_file=foofile, key_file=fake_key_file, cert_file=fake_cert_file) self.assertEqual("https", self.rpc._url_scheme) self.assertEqual(fake_url, self.rpc._url) self.assertEqual(foofile, self.rpc._ca_file) self.assertEqual(fake_cert_file, self.rpc._cert_file) self.assertEqual(fake_key_file, self.rpc._key_file)
def test_jsonrpc_init_no_ssl(self): self.rpc = jsonrpc.JsonRpc("http://foo.bar/", ('fakeuser', 'fakepwd')) self.assertEqual("http", self.rpc._url_scheme)
def setUp(self): super(QuobyteJsonRpcTestCase, self).setUp() self.rpc = jsonrpc.JsonRpc(url="http://test", user_credentials=("me", "team")) self.mock_object(time, 'sleep')
def test_jsonrpc_init_no_ssl(self, mock_init): self.rpc = jsonrpc.JsonRpc("http://foo.bar/", ('fakeuser', 'fakepwd')) mock_init.assert_called_once_with("foo.bar")
def test_jsonrpc_init_with_ca(self, mock_init): foofile = tempfile.TemporaryFile() self.rpc = jsonrpc.JsonRpc("https://foo.bar/", ('fakeuser', 'fakepwd'), foofile) mock_init.assert_called_once_with("foo.bar", ca_file=foofile.name)
def setUp(self): super(QuobyteJsonRpcTestCase, self).setUp() self.rpc = jsonrpc.JsonRpc(url="http://test", user_credentials=("me", "team")) self.rpc._connection = mock.Mock() self.rpc._connection.request = mock.Mock()