CORD-2772 report version of core
prevent synchronizers from returning core version
Change-Id: I0ba8766d32baad08faec03add7054adc44eba11f
diff --git a/lib/xos-util/xosutil/autodiscover_version.py b/lib/xos-util/xosutil/autodiscover_version.py
index d41f4b3..2e606e1 100644
--- a/lib/xos-util/xosutil/autodiscover_version.py
+++ b/lib/xos-util/xosutil/autodiscover_version.py
@@ -24,7 +24,7 @@
import inspect
import os
-def autodiscover_version(caller_filename=None, save_to=None):
+def autodiscover_version(caller_filename=None, save_to=None, max_parent_depth=None):
""" walk back along the path to the current module, searching for a VERSION file """
if not caller_filename:
caller_filename = os.path.realpath(__file__)
@@ -41,6 +41,12 @@
f.close()
return version
+ # limit_parent_depth can be used to limit how far back we search the tree for a VERSION file.
+ if (max_parent_depth is not None):
+ if (max_parent_depth <= 0):
+ return None
+ max_parent_depth -= 1
+
(cur_path, remainder) = os.path.split(cur_path)
if not remainder:
return None
diff --git a/xos/coreapi/xos_dynamicload_api.py b/xos/coreapi/xos_dynamicload_api.py
index cadfaa6..2d775dc 100644
--- a/xos/coreapi/xos_dynamicload_api.py
+++ b/xos/coreapi/xos_dynamicload_api.py
@@ -26,6 +26,7 @@
from importlib import import_module
+from xosutil.autodiscover_version import autodiscover_version_of_main
from dynamicbuild import DynamicBuilder
class DynamicLoadService(dynamicload_pb2_grpc.dynamicloadServicer):
@@ -101,6 +102,15 @@
item.state = "present"
# TODO: Might be useful to return a list of models as well
+ # the core is always onboarded, so doesn't have an explicit manifest
+ item = response.services.add()
+ item.name = "core"
+ item.version = autodiscover_version_of_main()
+ if "core" in django_apps_by_name:
+ item.state = "present"
+ else:
+ item.state = "load"
+
return response
except Exception, e:
import traceback; traceback.print_exc()
diff --git a/xos/synchronizers/new_base/modelaccessor.py b/xos/synchronizers/new_base/modelaccessor.py
index 608b4e0..f917612 100644
--- a/xos/synchronizers/new_base/modelaccessor.py
+++ b/xos/synchronizers/new_base/modelaccessor.py
@@ -164,7 +164,7 @@
# is waiting on our models.
if Config.get("models_dir"):
- version = autodiscover_version_of_main() or "unknown"
+ version = autodiscover_version_of_main(max_parent_depth=0) or "unknown"
log.info("Service version is %s" % version)
try:
ModelLoadClient(client).upload_models(Config.get("name"), Config.get("models_dir"), version=version)
diff --git a/xos/xos_client/xossh b/xos/xos_client/xossh
index 374a267..9eda018 100644
--- a/xos/xos_client/xossh
+++ b/xos/xos_client/xossh
@@ -11,6 +11,7 @@
import rlcompleter
from twisted.internet import reactor
+from xosapi.version import __version__
from xosapi.xos_grpc_client import InsecureClient, SecureClient, setup_logging, Empty
current_client = None
@@ -83,6 +84,13 @@
action='count',
help=_help)
+ _help = 'enable verbose logging'
+ parser.add_argument('-V', '--version',
+ dest='version',
+ action='store_true',
+ default=False,
+ help=_help)
+
args = parser.parse_args()
return args
@@ -256,6 +264,10 @@
setup_logging(args)
+ if args.version:
+ print __version__
+ sys.exit(0)
+
login(username=args.username, password=args.password)
reactor.run()