[SEBA-497]
Change to using alpine-grpc-base
Fix issue with nested exceptions causing an error in structlog
Reformat and python3 fixes, v3.5 mock support
Record execution times in the loader
Change-Id: I6d7923818d57012fca32ce44668820de422206d6
diff --git a/src/tosca/generator.py b/src/tosca/generator.py
index 1c2dccb..fbaf4e5 100644
--- a/src/tosca/generator.py
+++ b/src/tosca/generator.py
@@ -1,4 +1,3 @@
-
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,24 +12,30 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from xosconfig import Config
-from multistructlog import create_logger
-log = create_logger(Config().get('logging'))
+from __future__ import absolute_import
import os
-from default import TOSCA_DEFS_DIR, TOSCA_KEYS_DIR
-from xosgenx.generator import XOSProcessor, XOSProcessorArgs
+
from xosapi.xos_grpc_client import Empty
+from xosgenx.generator import XOSProcessor, XOSProcessorArgs
+
+from multistructlog import create_logger
+from xosconfig import Config
+
+from .default import TOSCA_DEFS_DIR, TOSCA_KEYS_DIR
+
+log = create_logger(Config().get("logging"))
+
current_dir = os.path.dirname(os.path.realpath(__file__))
-class TOSCA_Generator:
+class TOSCA_Generator:
def clean(self, dir=TOSCA_DEFS_DIR):
filesToRemove = [f for f in os.listdir(dir)]
for f in filesToRemove:
- if not f.startswith('.'):
- os.remove(dir + '/' + f)
+ if not f.startswith("."):
+ os.remove(dir + "/" + f)
def clean_keys(self, dir=TOSCA_KEYS_DIR):
keys_fn = os.path.join(dir, "KEYS.py")
@@ -42,23 +47,27 @@
try:
xproto = client.utility.GetXproto(Empty())
- args = XOSProcessorArgs(output = TOSCA_DEFS_DIR,
- inputs = str(xproto.xproto),
- target = os.path.join(current_dir, 'xtarget/tosca.xtarget'),
- write_to_file = 'target')
+ args = XOSProcessorArgs(
+ output=TOSCA_DEFS_DIR,
+ inputs=str(xproto.xproto),
+ target=os.path.join(current_dir, "xtarget/tosca.xtarget"),
+ write_to_file="target",
+ )
XOSProcessor.process(args)
log.info("[XOS-TOSCA] Recipes generated in %s" % args.output)
- except Exception as e:
+ except Exception:
log.exception("[XOS-TOSCA] Failed to generate TOSCA")
try:
xproto = client.utility.GetXproto(Empty())
- args = XOSProcessorArgs(output = TOSCA_KEYS_DIR,
- inputs = str(xproto.xproto),
- target = os.path.join(current_dir, 'xtarget/tosca_keys.xtarget'),
- write_to_file = 'single',
- dest_file = 'KEYS.py')
+ args = XOSProcessorArgs(
+ output=TOSCA_KEYS_DIR,
+ inputs=str(xproto.xproto),
+ target=os.path.join(current_dir, "xtarget/tosca_keys.xtarget"),
+ write_to_file="single",
+ dest_file="KEYS.py",
+ )
XOSProcessor.process(args)
log.info("[XOS-TOSCA] TOSCA Keys generated in %s" % args.output)
- except Exception as e:
+ except Exception:
log.exception("[XOS-TOSCA] Failed to generate TOSCA Keys")