CORD-2773 Update to gRPC 1.9.1 and protobuf 3.5.2
Change-Id: I7a2a52ef112060f50f92fa0fcb73587629109dc0
diff --git a/containers/xos/pip_requirements.txt b/containers/xos/pip_requirements.txt
index 4e65d35..233c566 100644
--- a/containers/xos/pip_requirements.txt
+++ b/containers/xos/pip_requirements.txt
@@ -52,8 +52,8 @@
google-api-python-client==1.5.3
greenlet==0.4.10
sphinx_rtd_theme==0.1.9
-grpcio==1.0.4
-grpcio-tools==1.0.4
+grpcio==1.9.1
+grpcio-tools==1.9.1
html5lib==0.999
httplib2==0.9.2
idna==2.1
@@ -105,7 +105,7 @@
ply==3.10
positional==1.1.1
prettytable==0.7.2
-protobuf==3.2.0
+protobuf==3.5.2
psycopg2==2.6.2
pyOpenSSL==16.2.0
pyasn1==0.1.9
@@ -145,7 +145,7 @@
service_identity==17.0.0
shade==1.9.0
simplejson==3.8.2
-six==1.10.0
+six==1.11.0
stevedore==1.17.1
structlog==18.1.0
supervisor==3.0b2
@@ -165,3 +165,4 @@
redis==2.10.5
astunparse==1.5.0
plyxproto==3.0.1
+setuptools==38.5.2
diff --git a/lib/xos-config/tests/test_config.py b/lib/xos-config/tests/test_config.py
index 29635ce..1684472 100644
--- a/lib/xos-config/tests/test_config.py
+++ b/lib/xos-config/tests/test_config.py
@@ -91,7 +91,7 @@
"""
with self.assertRaises(Exception) as e:
Config.init(yaml_not_valid)
- self.assertEqual(e.exception.message, "[XOS-Config] The config format is wrong: Unable to load any data from source yaml file")
+ self.assertTrue(e.exception.message.startswith("[XOS-Config] The config format is wrong:"))
def test_invalid_format(self):
"""
diff --git a/lib/xos-genx/xosgenx/targets/grpc_api.xtarget b/lib/xos-genx/xosgenx/targets/grpc_api.xtarget
index 4d05870..dffc347 100644
--- a/lib/xos-genx/xosgenx/targets/grpc_api.xtarget
+++ b/lib/xos-genx/xosgenx/targets/grpc_api.xtarget
@@ -1,13 +1,13 @@
import base64
import time
-from protos import xos_pb2
+from protos import xos_pb2, xos_pb2_grpc
from google.protobuf.empty_pb2 import Empty
from django.contrib.auth import authenticate as django_authenticate
from xos.exceptions import *
from apihelper import XOSAPIHelperMixin, translate_exceptions
-class XosService(xos_pb2.xosServicer, XOSAPIHelperMixin):
+class XosService(xos_pb2_grpc.xosServicer, XOSAPIHelperMixin):
def __init__(self, thread_pool):
self.thread_pool = thread_pool
XOSAPIHelperMixin.__init__(self)
diff --git a/xos/coreapi/grpc_server.py b/xos/coreapi/grpc_server.py
index 64dea89..3ae2bf1 100644
--- a/xos/coreapi/grpc_server.py
+++ b/xos/coreapi/grpc_server.py
@@ -1,4 +1,3 @@
-
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,7 +33,7 @@
Config.init()
log = create_logger(Config().get('logging'))
-from protos import schema_pb2, dynamicload_pb2
+from protos import schema_pb2, dynamicload_pb2, schema_pb2_grpc, dynamicload_pb2_grpc
from xos_dynamicload_api import DynamicLoadService
from dynamicbuild import DynamicBuilder
from google.protobuf.empty_pb2 import Empty
@@ -43,7 +42,7 @@
SERVER_CERT="/opt/cord_profile/core_api_cert.pem"
SERVER_CA="/usr/local/share/ca-certificates/local_certs.crt"
-class SchemaService(schema_pb2.SchemaServiceServicer):
+class SchemaService(schema_pb2_grpc.SchemaServiceServicer):
def __init__(self, thread_pool):
self.thread_pool = thread_pool
@@ -122,31 +121,31 @@
def register_core(self):
from xos_grpc_api import XosService
- from protos import xos_pb2
+ from protos import xos_pb2, xos_pb2_grpc
- self.register("xos", xos_pb2.add_xosServicer_to_server, XosService(self.thread_pool))
+ self.register("xos", xos_pb2_grpc.add_xosServicer_to_server, XosService(self.thread_pool))
def register_utility(self):
from xos_utility_api import UtilityService
- from protos import utility_pb2
+ from protos import utility_pb2, utility_pb2_grpc
- self.register("utility", utility_pb2.add_utilityServicer_to_server, UtilityService(self.thread_pool))
+ self.register("utility", utility_pb2_grpc.add_utilityServicer_to_server, UtilityService(self.thread_pool))
def register_modeldefs(self):
from xos_modeldefs_api import ModelDefsService
- from protos import modeldefs_pb2
+ from protos import modeldefs_pb2_grpc
- self.register("modeldefs", modeldefs_pb2.add_modeldefsServicer_to_server, ModelDefsService(self.thread_pool))
+ self.register("modeldefs", modeldefs_pb2_grpc.add_modeldefsServicer_to_server, ModelDefsService(self.thread_pool))
def start(self):
log.info('Starting GRPC Server')
self.register("schema",
- schema_pb2.add_SchemaServiceServicer_to_server,
+ schema_pb2_grpc.add_SchemaServiceServicer_to_server,
SchemaService(self.thread_pool))
self.register("dynamicload",
- dynamicload_pb2.add_dynamicloadServicer_to_server,
+ dynamicload_pb2_grpc.add_dynamicloadServicer_to_server,
DynamicLoadService(self.thread_pool, self))
if (self.model_status == 0):
@@ -196,7 +195,3 @@
self.delayed_shutdown_timer.cancel()
self.delayed_shutdown_timer = threading.Timer(seconds, self.stop_and_exit)
self.delayed_shutdown_timer.start()
-
-
-
-
diff --git a/xos/coreapi/xos_dynamicload_api.py b/xos/coreapi/xos_dynamicload_api.py
index e794283..53ad93e 100644
--- a/xos/coreapi/xos_dynamicload_api.py
+++ b/xos/coreapi/xos_dynamicload_api.py
@@ -21,13 +21,14 @@
import time
import traceback
from protos import dynamicload_pb2
+from protos import dynamicload_pb2_grpc
from google.protobuf.empty_pb2 import Empty
from importlib import import_module
from dynamicbuild import DynamicBuilder
-class DynamicLoadService(dynamicload_pb2.dynamicloadServicer):
+class DynamicLoadService(dynamicload_pb2_grpc.dynamicloadServicer):
def __init__(self, thread_pool, server):
self.thread_pool = thread_pool
self.server = server
@@ -85,5 +86,3 @@
except Exception, e:
import traceback; traceback.print_exc()
raise e
-
-
diff --git a/xos/coreapi/xos_modeldefs_api.py b/xos/coreapi/xos_modeldefs_api.py
index fbed321..fb79281 100644
--- a/xos/coreapi/xos_modeldefs_api.py
+++ b/xos/coreapi/xos_modeldefs_api.py
@@ -17,7 +17,7 @@
import base64
import time
import yaml
-from protos import modeldefs_pb2
+from protos import modeldefs_pb2, modeldefs_pb2_grpc
from google.protobuf.empty_pb2 import Empty
from xos.exceptions import *
@@ -35,7 +35,7 @@
else:
setattr(grpc_parent, yaml_key, yaml_repr)
-class ModelDefsService(modeldefs_pb2.modeldefsServicer, XOSAPIHelperMixin):
+class ModelDefsService(modeldefs_pb2_grpc.modeldefsServicer, XOSAPIHelperMixin):
def __init__(self, thread_pool):
self.thread_pool = thread_pool
@@ -60,4 +60,3 @@
modeldefs = modeldefs_pb2.ModelDefs()
yaml_to_grpc(yaml_repr, modeldefs)
print modeldefs
-
diff --git a/xos/coreapi/xos_utility_api.py b/xos/coreapi/xos_utility_api.py
index 4179212..4f2d125 100644
--- a/xos/coreapi/xos_utility_api.py
+++ b/xos/coreapi/xos_utility_api.py
@@ -1,4 +1,3 @@
-
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +19,7 @@
import sys
import time
import traceback
-from protos import utility_pb2
+from protos import utility_pb2, utility_pb2_grpc
from google.protobuf.empty_pb2 import Empty
from importlib import import_module
@@ -61,7 +60,7 @@
matches.append(os.path.join(root, filename))
return matches
-class UtilityService(utility_pb2.utilityServicer, XOSAPIHelperMixin):
+class UtilityService(utility_pb2_grpc.utilityServicer, XOSAPIHelperMixin):
def __init__(self, thread_pool):
self.thread_pool = thread_pool
XOSAPIHelperMixin.__init__(self)
@@ -267,6 +266,3 @@
response.subscribed_network.append(l.subscriber_network.id)
return response
-
-
-
diff --git a/xos/xos_client/xosapi/fake_stub.py b/xos/xos_client/xosapi/fake_stub.py
index 29a8962..8cd9c53 100644
--- a/xos/xos_client/xosapi/fake_stub.py
+++ b/xos/xos_client/xosapi/fake_stub.py
@@ -326,6 +326,16 @@
k = self.make_key(classname, id)
del self.objs[k]
+class FakeCommonProtos(object):
+ def __init__(self):
+ self.ID = ID
+
+class FakeProtos(object):
+ def __init__(self):
+ for name in ["Controller", "Deployment", "Slice", "Site", "ID", "Tag", "Service", "ServiceInstance", "ONOSService", "User", "Network", "NetworkTemplate", "ControllerNetwork", "NetworkSlice"]:
+ setattr(self, name, globals()[name])
+ self.common__pb2 = FakeCommonProtos()
+
class FakeSymDb(object):
def __init__(self):
self._classes = {}
diff --git a/xos/xos_client/xosapi/orm.py b/xos/xos_client/xosapi/orm.py
index bec5e7b..efe40ff 100644
--- a/xos/xos_client/xosapi/orm.py
+++ b/xos/xos_client/xosapi/orm.py
@@ -489,9 +489,11 @@
return self.objects.new(*args, **kwargs)
class ORMStub(object):
- def __init__(self, stub, package_name, invoker=None, caller_kind="grpcapi", sym_db = None, empty = None,
+ def __init__(self, stub, protos, package_name, invoker=None, caller_kind="grpcapi", empty = None,
enable_backoff=True, restart_on_disconnect=False):
self.grpc_stub = stub
+ self.protos = protos
+ self.common_protos = protos.common__pb2
self.all_model_names = []
self.all_grpc_classes = {}
self.content_type_map = {}
@@ -501,15 +503,8 @@
self.enable_backoff = enable_backoff
self.restart_on_disconnect = restart_on_disconnect
- if not sym_db:
- from google.protobuf import symbol_database as _symbol_database
- sym_db = _symbol_database.Default()
-
- self._sym_db = sym_db
-
if not empty:
- from google.protobuf.empty_pb2 import Empty
- empty = Empty
+ empty = self.protos.google_dot_protobuf_dot_empty__pb2.Empty
self._empty = empty
for name in dir(stub):
@@ -519,7 +514,7 @@
self.all_model_names.append(model_name)
- grpc_class = self._sym_db._classes["%s.%s" % (package_name, model_name)]
+ grpc_class = getattr(self.protos, model_name)
self.all_grpc_classes[model_name] = grpc_class
ct = grpc_class.DESCRIPTOR.GetOptions().Extensions._FindExtensionByName("xos.contentTypeId")
@@ -583,13 +578,13 @@
def make_ID(self, id):
- return self._sym_db._classes["xos.ID"](id=id)
+ return getattr(self.common_protos, "ID")(id=id)
def make_empty(self):
return self._empty()
def make_Query(self):
- return self._sym_db._classes["xos.Query"]()
+ return getattr(self.common_protos, "Query")()
def listObjects(self):
return self.all_model_names
diff --git a/xos/xos_client/xosapi/test_orm.py b/xos/xos_client/xosapi/test_orm.py
index 7b46308..136f71a 100644
--- a/xos/xos_client/xosapi/test_orm.py
+++ b/xos/xos_client/xosapi/test_orm.py
@@ -39,10 +39,10 @@
def make_coreapi(self):
if USE_FAKE_STUB:
import xosapi.orm
- from fake_stub import FakeStub, FakeSymDb, FakeObj
+ from fake_stub import FakeStub, FakeProtos, FakeObj
stub = FakeStub()
- api = xosapi.orm.ORMStub(stub=stub, package_name = "xos", sym_db = FakeSymDb(), empty = FakeObj, enable_backoff = False)
+ api = xosapi.orm.ORMStub(stub=stub, package_name = "xos", protos=FakeProtos(), empty = FakeObj, enable_backoff = False)
return api
else:
return xos_grpc_client.coreapi
diff --git a/xos/xos_client/xosapi/test_wrapper.py b/xos/xos_client/xosapi/test_wrapper.py
index 0ce9e73..8bce2d6 100644
--- a/xos/xos_client/xosapi/test_wrapper.py
+++ b/xos/xos_client/xosapi/test_wrapper.py
@@ -44,10 +44,10 @@
def make_coreapi(self):
if USE_FAKE_STUB:
import xosapi.orm
- from fake_stub import FakeStub, FakeSymDb, FakeObj
+ from fake_stub import FakeStub, FakeObj, FakeProtos
stub = FakeStub()
- api = xosapi.orm.ORMStub(stub=stub, package_name = "xos", sym_db = FakeSymDb(), empty = FakeObj, enable_backoff = False)
+ api = xosapi.orm.ORMStub(stub=stub, package_name = "xos", protos=FakeProtos(), empty = FakeObj, enable_backoff = False)
return api
else:
return xos_grpc_client.coreapi
diff --git a/xos/xos_client/xosapi/xos_grpc_client.py b/xos/xos_client/xosapi/xos_grpc_client.py
index a8fa51d..8a7476e 100644
--- a/xos/xos_client/xosapi/xos_grpc_client.py
+++ b/xos/xos_client/xosapi/xos_grpc_client.py
@@ -44,7 +44,7 @@
self._password = password
def __call__(self, context, callback):
basic_auth = "Basic %s" % base64.b64encode("%s:%s" % (self._username, self._password))
- metadata = (('Authorization', basic_auth),)
+ metadata = (('authorization', basic_auth),)
callback(metadata, None)
class SessionIdCallCredentials(grpc.AuthMetadataPlugin):
@@ -87,7 +87,7 @@
print >> sys.stderr, "failed to locate api", api
if hasattr(self, "xos"):
- self.xos_orm = orm.ORMStub(self.xos, "xos")
+ self.xos_orm = orm.ORMStub(self.xos, self.xos_pb2, "xos")
if self.reconnect_callback2:
self.reconnect_callback2()