Martin Blanchard pushed to branch master at BuildGrid / buildgrid
Commits:
-
15d44d3b
by Martin Blanchard at 2019-01-24T08:57:04Z
-
4a600cfc
by Martin Blanchard at 2019-01-24T08:57:04Z
-
89f2b765
by Martin Blanchard at 2019-01-24T08:57:04Z
-
02692ded
by Martin Blanchard at 2019-01-24T08:57:04Z
3 changed files:
Changes:
| ... | ... | @@ -24,6 +24,7 @@ import sys |
| 24 | 24 |
|
| 25 | 25 |
import click
|
| 26 | 26 |
|
| 27 |
+from buildgrid._exceptions import PermissionDeniedError
|
|
| 27 | 28 |
from buildgrid.server._authentication import AuthMetadataMethod, AuthMetadataAlgorithm
|
| 28 | 29 |
from buildgrid.server.instance import BuildGridServer
|
| 29 | 30 |
from buildgrid.server._monitoring import MonitoringOutputType, MonitoringOutputFormat
|
| ... | ... | @@ -120,8 +121,13 @@ def _create_server_from_config(configuration): |
| 120 | 121 |
|
| 121 | 122 |
server = BuildGridServer(**kargs)
|
| 122 | 123 |
|
| 123 |
- for channel in network:
|
|
| 124 |
- server.add_port(channel.address, channel.credentials)
|
|
| 124 |
+ try:
|
|
| 125 |
+ for channel in network:
|
|
| 126 |
+ server.add_port(channel.address, channel.credentials)
|
|
| 127 |
+ |
|
| 128 |
+ except PermissionDeniedError as e:
|
|
| 129 |
+ click.echo("Error: {}.".format(e), err=True)
|
|
| 130 |
+ sys.exit(-1)
|
|
| 125 | 131 |
|
| 126 | 132 |
for instance in instances:
|
| 127 | 133 |
instance_name = instance['name']
|
| ... | ... | @@ -89,3 +89,9 @@ class FailedPreconditionError(BgdError): |
| 89 | 89 |
able to fix the errors and retry."""
|
| 90 | 90 |
def __init__(self, message, detail=None, reason=None):
|
| 91 | 91 |
super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason)
|
| 92 |
+ |
|
| 93 |
+ |
|
| 94 |
+class PermissionDeniedError(BgdError):
|
|
| 95 |
+ """The caller does not have permission to execute the specified operation."""
|
|
| 96 |
+ def __init__(self, message, detail=None, reason=None):
|
|
| 97 |
+ super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason)
|
| ... | ... | @@ -27,6 +27,7 @@ import grpc |
| 27 | 27 |
import janus
|
| 28 | 28 |
|
| 29 | 29 |
from buildgrid._enums import BotStatus, LogRecordLevel, MetricRecordDomain, MetricRecordType
|
| 30 |
+from buildgrid._exceptions import PermissionDeniedError
|
|
| 30 | 31 |
from buildgrid._protos.buildgrid.v2 import monitoring_pb2
|
| 31 | 32 |
from buildgrid.server.actioncache.service import ActionCacheService
|
| 32 | 33 |
from buildgrid.server._authentication import AuthMetadataMethod, AuthMetadataAlgorithm
|
| ... | ... | @@ -87,7 +88,8 @@ class BuildGridServer: |
| 87 | 88 |
AuthContext.interceptor = self.__grpc_auth_interceptor
|
| 88 | 89 |
|
| 89 | 90 |
self.__grpc_executor = futures.ThreadPoolExecutor(max_workers)
|
| 90 |
- self.__grpc_server = grpc.server(self.__grpc_executor)
|
|
| 91 |
+ self.__grpc_server = grpc.server(self.__grpc_executor,
|
|
| 92 |
+ options=(('grpc.so_reuseport', 0),))
|
|
| 91 | 93 |
|
| 92 | 94 |
self.__main_loop = asyncio.get_event_loop()
|
| 93 | 95 |
|
| ... | ... | @@ -205,6 +207,9 @@ class BuildGridServer: |
| 205 | 207 |
|
| 206 | 208 |
Returns:
|
| 207 | 209 |
int: Number of the bound port.
|
| 210 |
+ |
|
| 211 |
+ Raises:
|
|
| 212 |
+ PermissionDeniedError: If socket binding fails.
|
|
| 208 | 213 |
"""
|
| 209 | 214 |
if credentials is not None:
|
| 210 | 215 |
self.__logger.info("Adding secure connection on: [%s]", address)
|
| ... | ... | @@ -214,6 +219,9 @@ class BuildGridServer: |
| 214 | 219 |
self.__logger.info("Adding insecure connection on [%s]", address)
|
| 215 | 220 |
port_number = self.__grpc_server.add_insecure_port(address)
|
| 216 | 221 |
|
| 222 |
+ if not port_number:
|
|
| 223 |
+ raise PermissionDeniedError("Unable to configure socket")
|
|
| 224 |
+ |
|
| 217 | 225 |
return port_number
|
| 218 | 226 |
|
| 219 | 227 |
def add_execution_instance(self, instance, instance_name):
|
