From 8db7f496b26d49729755a10e9773e6af330bf1f4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 19 Jan 2018 09:08:03 +0100 Subject: [PATCH] library: don't create AnsibleUtil.module lazily Now, that we only create the AnsibleUtil instance when we already know that we run under ansible (not from unit tests), we can avoid initializing the AnsibleModule lazily. --- library/network_connections.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/library/network_connections.py b/library/network_connections.py index bf24dc3..82286c4 100755 --- a/library/network_connections.py +++ b/library/network_connections.py @@ -2004,21 +2004,15 @@ class AnsibleUtil(RunEnvironment): def __init__(self): RunEnvironment.__init__(self) - self._module = None self._run_results = [] self._log_idx = 0 - @property - def module(self): - module = self._module - if module is None: - from ansible.module_utils.basic import AnsibleModule - module = AnsibleModule( - argument_spec = self.ARGS, - supports_check_mode = True, - ) - self._module = module - return module + from ansible.module_utils.basic import AnsibleModule + module = AnsibleModule( + argument_spec = self.ARGS, + supports_check_mode = True, + ) + self.module = module def run_command(self, argv, encoding = None): return self.module.run_command(argv, encoding = encoding) @@ -2681,9 +2675,9 @@ class Cmd_initscripts(Cmd): ############################################################################### if __name__ == '__main__': - ansible_util = AnsibleUtil() connections = None cmd = None + ansible_util = AnsibleUtil() try: params = ansible_util.module.params cmd = Cmd.create(params['provider'],