Skip to content
This repository has been archived by the owner on Mar 20, 2018. It is now read-only.

Remove references to grpc.beta #127

Merged
merged 2 commits into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/gax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import collections


__version__ = '0.12.5'
__version__ = '0.12.6'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd feel more comfortable calling this 0.13.0, unless you have strong reason to believe that there's nothing breaking in this change to gRPC 1.0.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Good catch -- this is definitely breaking, since we no longer support the beta entry point to the gRPC stub, which is required by older gRPC autogen.



INITIAL_PAGE = object()
Expand Down
15 changes: 7 additions & 8 deletions google/gax/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"""Adapts the grpc surface."""

from __future__ import absolute_import
from grpc.beta import implementations
from grpc.beta.interfaces import StatusCode
import grpc
from grpc import StatusCode
from grpc.framework.interfaces.face import face
from . import auth

Expand Down Expand Up @@ -82,8 +82,8 @@ def grpc_auth(dummy_context, callback):
def _make_channel_creds(auth_func, ssl_creds):
"""Converts the auth func into the composite creds expected by grpc."""
grpc_auth_func = _make_grpc_auth_func(auth_func)
call_creds = implementations.metadata_call_credentials(grpc_auth_func)
return implementations.composite_channel_credentials(ssl_creds, call_creds)
call_creds = grpc.metadata_call_credentials(grpc_auth_func)
return grpc.composite_channel_credentials(ssl_creds, call_creds)


def create_stub(generated_create_stub, service_path, port, ssl_creds=None,
Expand All @@ -108,15 +108,14 @@ def create_stub(generated_create_stub, service_path, port, ssl_creds=None,
"""
if channel is None:
if ssl_creds is None:
ssl_creds = implementations.ssl_channel_credentials(
None, None, None)
ssl_creds = grpc.ssl_channel_credentials(None, None, None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are keyword arguments that default to None: https://github.com/grpc/grpc/blob/01da196879cb69b3c56b3bdcff6f0194ab5a190d/src/python/grpcio/grpc/__init__.py#L1029

Best to not pass anything at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if metadata_transformer is None:
if scopes is None:
scopes = []
metadata_transformer = auth.make_auth_func(scopes)

channel_creds = _make_channel_creds(metadata_transformer, ssl_creds)
channel = implementations.secure_channel(
service_path, port, channel_creds)
target = '{}:{}'.format(service_path, port)
channel = grpc.secure_channel(target, channel_creds)

return generated_create_stub(channel)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

install_requires = [
'future>=0.15.2',
'grpcio>=1.0rc1',
'grpcio>=1.0.0',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to regenerate the auto-gen code with 1.0.0 to ensure everything still works correctly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, let's update test-requirements.txt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to regenerate the auto-gen code with 1.0.0 to ensure everything still works correctly?

Yes. GAX 0.13.0 will not work with older auto-gen code, since those have only beta entry points into the gRPC stub.

Also, let's update test-requirements.txt.

Done

'ply==3.8',
'protobuf>=3.0.0b3',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to 3.0.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

'oauth2client>=1.5.2',
Expand Down
49 changes: 26 additions & 23 deletions test/test_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,24 @@ class TestCreateStub(unittest2.TestCase):
FAKE_SERVICE_PATH = 'service_path'
FAKE_PORT = 10101

@mock.patch('grpc.beta.implementations.composite_channel_credentials')
@mock.patch('grpc.beta.implementations.ssl_channel_credentials')
@mock.patch('grpc.beta.implementations.secure_channel')
@mock.patch('grpc.composite_channel_credentials')
@mock.patch('grpc.ssl_channel_credentials')
@mock.patch('grpc.secure_channel')
@mock.patch('google.gax.auth.make_auth_func')
def test_creates_a_stub_ok_with_no_scopes(
self, auth, chan, chan_creds, comp):
got_channel = grpc.create_stub(
_fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT)
chan_creds.assert_called_once_with(None, None, None)
chan.assert_called_once_with(self.FAKE_SERVICE_PATH, self.FAKE_PORT,
comp.return_value)
chan.assert_called_once_with(
'{}:{}'.format(self.FAKE_SERVICE_PATH, self.FAKE_PORT),
comp.return_value)
auth.assert_called_once_with([])
self.assertEqual(got_channel, chan.return_value)

@mock.patch('grpc.beta.implementations.composite_channel_credentials')
@mock.patch('grpc.beta.implementations.ssl_channel_credentials')
@mock.patch('grpc.beta.implementations.secure_channel')
@mock.patch('grpc.composite_channel_credentials')
@mock.patch('grpc.ssl_channel_credentials')
@mock.patch('grpc.secure_channel')
@mock.patch('google.gax.auth.make_auth_func')
def test_creates_a_stub_ok_with_scopes(
self, auth, chan, chan_creds, comp):
Expand All @@ -71,14 +72,15 @@ def test_creates_a_stub_ok_with_scopes(
_fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT,
scopes=fake_scopes)
chan_creds.assert_called_once_with(None, None, None)
chan.assert_called_once_with(self.FAKE_SERVICE_PATH, self.FAKE_PORT,
comp.return_value)
chan.assert_called_once_with(
'{}:{}'.format(self.FAKE_SERVICE_PATH, self.FAKE_PORT),
comp.return_value)
auth.assert_called_once_with(fake_scopes)

@mock.patch('grpc.beta.implementations.metadata_call_credentials')
@mock.patch('grpc.beta.implementations.composite_channel_credentials')
@mock.patch('grpc.beta.implementations.ssl_channel_credentials')
@mock.patch('grpc.beta.implementations.secure_channel')
@mock.patch('grpc.metadata_call_credentials')
@mock.patch('grpc.composite_channel_credentials')
@mock.patch('grpc.ssl_channel_credentials')
@mock.patch('grpc.secure_channel')
@mock.patch('google.gax.auth.make_auth_func')
def test_creates_a_stub_with_given_channel(
self, auth, chan, chan_creds, comp, md):
Expand All @@ -93,29 +95,30 @@ def test_creates_a_stub_with_given_channel(
self.assertFalse(comp.called)
self.assertFalse(md.called)

@mock.patch('grpc.beta.implementations.metadata_call_credentials')
@mock.patch('grpc.beta.implementations.composite_channel_credentials')
@mock.patch('grpc.beta.implementations.ssl_channel_credentials')
@mock.patch('grpc.beta.implementations.secure_channel')
@mock.patch('grpc.metadata_call_credentials')
@mock.patch('grpc.composite_channel_credentials')
@mock.patch('grpc.ssl_channel_credentials')
@mock.patch('grpc.secure_channel')
@mock.patch('google.gax.auth.make_auth_func')
def test_creates_a_stub_ok_with_given_creds(self, auth, chan, chan_creds,
comp, md):
fake_creds = object()
got_channel = grpc.create_stub(
_fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT,
ssl_creds=fake_creds)
chan.assert_called_once_with(self.FAKE_SERVICE_PATH, self.FAKE_PORT,
comp.return_value)
chan.assert_called_once_with(
'{}:{}'.format(self.FAKE_SERVICE_PATH, self.FAKE_PORT),
comp.return_value)
auth.assert_called_once_with([])
self.assertTrue(chan.called)
self.assertFalse(chan_creds.called)
self.assertTrue(comp.called)
self.assertTrue(md.called)
self.assertEqual(got_channel, chan.return_value)

@mock.patch('grpc.beta.implementations.composite_channel_credentials')
@mock.patch('grpc.beta.implementations.ssl_channel_credentials')
@mock.patch('grpc.beta.implementations.secure_channel')
@mock.patch('grpc.composite_channel_credentials')
@mock.patch('grpc.ssl_channel_credentials')
@mock.patch('grpc.secure_channel')
@mock.patch('google.gax.auth.make_auth_func')
def test_creates_a_stub_ok_with_given_auth_func(self, auth, dummy_chan,
dummy_chan_creds, dummy_md):
Expand Down