Fix to docker import issues and swagger error

This is actually two fixes in one change:
1. Fixing the import issues in the docker containers, also cleaning
   it up.
2. Avoiding the creation of multiple swagger.json files by specifying
   which of the proto files represent the top-level service.

Change-Id: I9fec5cf48df127725673ba53f0e91d2ed2e275ad
diff --git a/grpc_client/grpc_client.py b/grpc_client/grpc_client.py
index 9a95330..36618be 100644
--- a/grpc_client/grpc_client.py
+++ b/grpc_client/grpc_client.py
@@ -34,6 +34,7 @@
 from werkzeug.exceptions import ServiceUnavailable
 
 from common.utils.asleep import asleep
+from chameleon.protos import third_party
 from chameleon.protos.schema_pb2 import SchemaServiceStub
 from google.protobuf.empty_pb2 import Empty
 
@@ -101,8 +102,8 @@
             log.info('connecting', endpoint=_endpoint)
             self.channel = grpc.insecure_channel(_endpoint)
 
-            self._retrieve_schema()
-            self._compile_proto_files()
+            swagger_from = self._retrieve_schema()
+            self._compile_proto_files(swagger_from)
             self._clear_backoff()
 
             self.connected = True
@@ -192,8 +193,9 @@
                       length=len(desc_content))
             with open(os.path.join(self.work_dir, desc_fname), 'wb') as f:
                 f.write(desc_content)
+        return schemas.swagger_from
 
-    def _compile_proto_files(self):
+    def _compile_proto_files(self, swagger_from):
         """
         For each *.proto file in the work directory, compile the proto
         file into the respective *_pb2.py file as well as generate the
@@ -211,7 +213,8 @@
         for fname in [f for f in os.listdir(self.work_dir)
                       if f.endswith('.proto')]:
 
-            log.debug('compiling', file=fname)
+            need_swagger = fname == swagger_from
+            log.debug('compiling', file=fname, need_swagger=need_swagger)
             cmd = (
                 'cd %s && '
                 'env PATH=%s PYTHONPATH=%s '
@@ -223,7 +226,7 @@
                 '--plugin=protoc-gen-gw=%s/gw_gen.py '
                 '--gw_out=. '
                 '--plugin=protoc-gen-swagger=%s/swagger_gen.py '
-                '--swagger_out=. '
+                '%s'
                 '%s' % (
                     self.work_dir,
                     ':'.join([os.environ['PATH'], self.plugin_dir]),
@@ -231,6 +234,7 @@
                     google_api_dir,
                     self.plugin_dir,
                     self.plugin_dir,
+                    '--swagger_out=. ' if need_swagger else '',
                     fname)
             )
             log.debug('executing', cmd=cmd, file=fname)
diff --git a/protos/schema.proto b/protos/schema.proto
index 0c06feb..764f53f 100644
--- a/protos/schema.proto
+++ b/protos/schema.proto
@@ -17,6 +17,9 @@
     // Proto files
     repeated ProtoFile protos = 1;
 
+    // Name of proto file to generae swagger.json from
+    string swagger_from = 2;
+
 }
 
 // Schema services
diff --git a/protos/schema_pb2.py b/protos/schema_pb2.py
index 537ba02..6f45cc6 100644
--- a/protos/schema_pb2.py
+++ b/protos/schema_pb2.py
@@ -20,7 +20,7 @@
   name='schema.proto',
   package='schema',
   syntax='proto3',
-  serialized_pb=_b('\n\x0cschema.proto\x12\x06schema\x1a\x1bgoogle/protobuf/empty.proto\"A\n\tProtoFile\x12\x11\n\tfile_name\x18\x01 \x01(\t\x12\r\n\x05proto\x18\x02 \x01(\t\x12\x12\n\ndescriptor\x18\x03 \x01(\x0c\",\n\x07Schemas\x12!\n\x06protos\x18\x01 \x03(\x0b\x32\x11.schema.ProtoFile2G\n\rSchemaService\x12\x36\n\tGetSchema\x12\x16.google.protobuf.Empty\x1a\x0f.schema.Schemas\"\x00\x62\x06proto3')
+  serialized_pb=_b('\n\x0cschema.proto\x12\x06schema\x1a\x1bgoogle/protobuf/empty.proto\"A\n\tProtoFile\x12\x11\n\tfile_name\x18\x01 \x01(\t\x12\r\n\x05proto\x18\x02 \x01(\t\x12\x12\n\ndescriptor\x18\x03 \x01(\x0c\"B\n\x07Schemas\x12!\n\x06protos\x18\x01 \x03(\x0b\x32\x11.schema.ProtoFile\x12\x14\n\x0cswagger_from\x18\x02 \x01(\t2G\n\rSchemaService\x12\x36\n\tGetSchema\x12\x16.google.protobuf.Empty\x1a\x0f.schema.Schemas\"\x00\x62\x06proto3')
   ,
   dependencies=[google_dot_protobuf_dot_empty__pb2.DESCRIPTOR,])
 _sym_db.RegisterFileDescriptor(DESCRIPTOR)
@@ -87,6 +87,13 @@
       message_type=None, enum_type=None, containing_type=None,
       is_extension=False, extension_scope=None,
       options=None),
+    _descriptor.FieldDescriptor(
+      name='swagger_from', full_name='schema.Schemas.swagger_from', index=1,
+      number=2, type=9, cpp_type=9, label=1,
+      has_default_value=False, default_value=_b("").decode('utf-8'),
+      message_type=None, enum_type=None, containing_type=None,
+      is_extension=False, extension_scope=None,
+      options=None),
   ],
   extensions=[
   ],
@@ -100,7 +107,7 @@
   oneofs=[
   ],
   serialized_start=120,
-  serialized_end=164,
+  serialized_end=186,
 )
 
 _SCHEMAS.fields_by_name['protos'].message_type = _PROTOFILE
@@ -172,6 +179,11 @@
 
 
 class BetaSchemaServiceServicer(object):
+  """The Beta API is deprecated for 0.15.0 and later.
+
+  It is recommended to use the GA API (classes and functions in this
+  file not marked beta) for all further purposes. This class was generated
+  only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0."""
   """Schema services
   """
   def GetSchema(self, request, context):
@@ -181,6 +193,11 @@
 
 
 class BetaSchemaServiceStub(object):
+  """The Beta API is deprecated for 0.15.0 and later.
+
+  It is recommended to use the GA API (classes and functions in this
+  file not marked beta) for all further purposes. This class was generated
+  only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0."""
   """Schema services
   """
   def GetSchema(self, request, timeout, metadata=None, with_call=False, protocol_options=None):
@@ -191,6 +208,11 @@
 
 
 def beta_create_SchemaService_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None):
+  """The Beta API is deprecated for 0.15.0 and later.
+
+  It is recommended to use the GA API (classes and functions in this
+  file not marked beta) for all further purposes. This function was
+  generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0"""
   request_deserializers = {
     ('schema.SchemaService', 'GetSchema'): google_dot_protobuf_dot_empty__pb2.Empty.FromString,
   }
@@ -205,6 +227,11 @@
 
 
 def beta_create_SchemaService_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None):
+  """The Beta API is deprecated for 0.15.0 and later.
+
+  It is recommended to use the GA API (classes and functions in this
+  file not marked beta) for all further purposes. This function was
+  generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0"""
   request_serializers = {
     ('schema.SchemaService', 'GetSchema'): google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
   }