diff options
Diffstat (limited to 'iceci/decorator')
-rw-r--r-- | iceci/decorator/__init__.py | 38 | ||||
-rw-r--r-- | iceci/decorator/__init__.pyc | bin | 0 -> 147 bytes | |||
-rw-r--r-- | iceci/decorator/__pycache__/__init__.cpython-36.pyc | bin | 0 -> 143 bytes | |||
-rw-r--r-- | iceci/decorator/__pycache__/exception_decor.cpython-36.pyc | bin | 0 -> 995 bytes | |||
-rw-r--r-- | iceci/decorator/__pycache__/logFuncEntry.cpython-36.pyc | bin | 0 -> 1402 bytes | |||
-rw-r--r-- | iceci/decorator/exception_decor.py | 70 | ||||
-rw-r--r-- | iceci/decorator/logFuncEntry.py | 75 | ||||
-rw-r--r-- | iceci/decorator/logFuncEntry.pyc | bin | 0 -> 1760 bytes | |||
-rw-r--r-- | iceci/decorator/repeat.py | 49 |
9 files changed, 232 insertions, 0 deletions
diff --git a/iceci/decorator/__init__.py b/iceci/decorator/__init__.py new file mode 100644 index 0000000..30d7152 --- /dev/null +++ b/iceci/decorator/__init__.py @@ -0,0 +1,38 @@ + +# ============LICENSE_START========================================== +# org.onap.vvp/test-engine +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the “License”); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. diff --git a/iceci/decorator/__init__.pyc b/iceci/decorator/__init__.pyc Binary files differnew file mode 100644 index 0000000..46251cd --- /dev/null +++ b/iceci/decorator/__init__.pyc diff --git a/iceci/decorator/__pycache__/__init__.cpython-36.pyc b/iceci/decorator/__pycache__/__init__.cpython-36.pyc Binary files differnew file mode 100644 index 0000000..1c87097 --- /dev/null +++ b/iceci/decorator/__pycache__/__init__.cpython-36.pyc diff --git a/iceci/decorator/__pycache__/exception_decor.cpython-36.pyc b/iceci/decorator/__pycache__/exception_decor.cpython-36.pyc Binary files differnew file mode 100644 index 0000000..582fb86 --- /dev/null +++ b/iceci/decorator/__pycache__/exception_decor.cpython-36.pyc diff --git a/iceci/decorator/__pycache__/logFuncEntry.cpython-36.pyc b/iceci/decorator/__pycache__/logFuncEntry.cpython-36.pyc Binary files differnew file mode 100644 index 0000000..ce3d14f --- /dev/null +++ b/iceci/decorator/__pycache__/logFuncEntry.cpython-36.pyc diff --git a/iceci/decorator/exception_decor.py b/iceci/decorator/exception_decor.py new file mode 100644 index 0000000..467f2ce --- /dev/null +++ b/iceci/decorator/exception_decor.py @@ -0,0 +1,70 @@ + +# ============LICENSE_START========================================== +# org.onap.vvp/test-engine +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the “License”); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +import logging +import traceback + +from services.logging_service import LoggingServiceFactory +from services.session import session + + +logger = LoggingServiceFactory.get_logger() + + +def exception(): + """ + A decorator that wraps the passed in function and logs + exceptions should one occur + + @param logger: The logging object + """ + + def decorator(func): + + def wrapper(*args, **kwargs): + try: + return func(*args, **kwargs) + except: + err = "There was an exception in %s" % func.__name__ + logger.error(err) + session.errorCounter += 1 + session.errorList = traceback.format_exc() + raise + + return wrapper + return decorator diff --git a/iceci/decorator/logFuncEntry.py b/iceci/decorator/logFuncEntry.py new file mode 100644 index 0000000..0995f3b --- /dev/null +++ b/iceci/decorator/logFuncEntry.py @@ -0,0 +1,75 @@ + +# ============LICENSE_START========================================== +# org.onap.vvp/test-engine +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the “License”); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +from services.logging_service import LoggingServiceFactory +logger = LoggingServiceFactory.get_logger() + +def _aop(decorator): + '''This decorator can be used to turn simple functions + into well-behaved decorators, so long as the decorators + are fairly simple. If a decorator expects a function and + returns a function (no descriptors), and if it doesn't + modify function attributes or docstring, then it is + eligible to use this. Simply apply @_aop to + your decorator and it will automatically preserve the + docstring and function attributes of functions to which + it is applied.''' + def new_decorator(f): + g = decorator(f) + g.__name__ = f.__name__ + g.__doc__ = f.__doc__ + g.__dict__.update(f.__dict__) + return g + + # Now a few lines needed to make _aop itself + # be a well-behaved decorator. + new_decorator.__name__ = decorator.__name__ + new_decorator.__doc__ = decorator.__doc__ + new_decorator.__dict__.update(decorator.__dict__) + return new_decorator + +# +# Sample Use: +# +@_aop +def logFuncEntry(func): + def foo(*args, **kwargs): + logger.debug('calling {}'.format(func.__name__)+" | "+str(args)+" | "+str(kwargs)) + return func(*args, **kwargs) + return foo + diff --git a/iceci/decorator/logFuncEntry.pyc b/iceci/decorator/logFuncEntry.pyc Binary files differnew file mode 100644 index 0000000..541fede --- /dev/null +++ b/iceci/decorator/logFuncEntry.pyc diff --git a/iceci/decorator/repeat.py b/iceci/decorator/repeat.py new file mode 100644 index 0000000..38eac03 --- /dev/null +++ b/iceci/decorator/repeat.py @@ -0,0 +1,49 @@ + +# ============LICENSE_START========================================== +# org.onap.vvp/test-engine +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the “License”); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +import unittest,time +def repeat(times): + def repeatHelper(f): + def callHelper(*args): + for i in range(0, times): + f(*args) + time.sleep(3) + return callHelper + time.sleep(3) + return repeatHelper + |