SEBA-540 Move dynamic convenience methods dir to /var/run/xosapi/convenience
Change-Id: I9877031c22114ff91a2211a616fb2e9e755a645d
diff --git a/lib/xos-api/xosapi/orm.py b/lib/xos-api/xosapi/orm.py
index 08b73e3..fccee09 100644
--- a/lib/xos-api/xosapi/orm.py
+++ b/lib/xos-api/xosapi/orm.py
@@ -883,19 +883,28 @@
def import_convenience_methods():
+ # The ORM has several built-in convenience methods that are contained here
+ lib_dir = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+ base_convenience_dir = os.path.join(lib_dir, "convenience")
- log.info("Loading convenience methods")
+ # Service convenience methods are placed here during dynamicload
+ service_convenience_dir = "/var/run/xosapi/convenience"
- cwd = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
- api_convenience_dir = os.path.join(cwd, "convenience")
- for file in os.listdir(api_convenience_dir):
- if file.endswith(".py") and "test" not in file:
- pathname = os.path.join(api_convenience_dir, file)
- try:
- log.debug("Loading: %s" % file)
- imp.load_source(file[:-3], pathname)
- except Exception:
- log.exception(
- "Cannot import api convenience method for: %s, %s"
- % (file[:-3], pathname)
- )
+ for api_convenience_dir in [base_convenience_dir, service_convenience_dir]:
+ log.info("Loading convenience methods", api_convenience_dir=api_convenience_dir)
+
+ if not os.path.exists(api_convenience_dir):
+ log.info("No convenience methods found", api_convenience_dir=api_convenience_dir)
+ continue
+
+ for file in os.listdir(api_convenience_dir):
+ if file.endswith(".py") and "test" not in file:
+ pathname = os.path.join(api_convenience_dir, file)
+ try:
+ log.debug("Loading: %s" % file)
+ imp.load_source(file[:-3], pathname)
+ except Exception:
+ log.exception(
+ "Cannot import api convenience method for: %s, %s"
+ % (file[:-3], pathname)
+ )
diff --git a/lib/xos-api/xosapi/xos_grpc_client.py b/lib/xos-api/xosapi/xos_grpc_client.py
index fba9ce4..c376552 100644
--- a/lib/xos-api/xosapi/xos_grpc_client.py
+++ b/lib/xos-api/xosapi/xos_grpc_client.py
@@ -77,18 +77,19 @@
return self
- def load_convenience_methods(self):
+ def request_convenience_methods(self):
- convenience_methods_dir = (
- "/usr/local/lib/python2.7/dist-packages/xosapi/convenience/"
- )
+ convenience_methods_dir = "/var/run/xosapi/convenience"
+ if not os.path.exists(convenience_methods_dir):
+ log.info("Creating convenience methods directory", convenience_methods_dir=convenience_methods_dir)
+ os.makedirs(convenience_methods_dir)
try:
response = self.dynamicload.GetConvenienceMethods(Empty())
if response:
log.info(
- "Loading convenience methods",
+ "Saving convenience methods",
methods=[m.filename for m in response.convenience_methods],
)
@@ -135,7 +136,7 @@
self.xos_orm = orm.ORMStub(self.xos, self.xos_pb2, "xos")
# ask the core for the convenience methods
- self.load_convenience_methods()
+ self.request_convenience_methods()
# Load convenience methods after reconnect
orm.import_convenience_methods()