Clean up imports to prevent issues with mutable data being used in modules (#35112)
* Clean up imports to prevent issues with mutable data being used in modules * Remove un-needed mock
This commit is contained in:
parent
bf1580a333
commit
f9c2c9570d
2 changed files with 9 additions and 37 deletions
|
@ -214,7 +214,6 @@ lib/ansible/modules/clustering/openshift/openshift_raw.py E321
|
|||
lib/ansible/modules/clustering/openshift/openshift_scale.py E321
|
||||
lib/ansible/modules/commands/command.py E322
|
||||
lib/ansible/modules/commands/command.py E323
|
||||
lib/ansible/modules/database/influxdb/influxdb_user.py E322
|
||||
lib/ansible/modules/database/mongodb/mongodb_parameter.py E317
|
||||
lib/ansible/modules/database/mongodb/mongodb_parameter.py E323
|
||||
lib/ansible/modules/database/mongodb/mongodb_user.py E322
|
||||
|
@ -377,14 +376,7 @@ lib/ansible/modules/network/dellos9/dellos9_command.py E322
|
|||
lib/ansible/modules/network/enos/enos_command.py E323
|
||||
lib/ansible/modules/network/enos/enos_config.py E323
|
||||
lib/ansible/modules/network/enos/enos_facts.py E323
|
||||
lib/ansible/modules/network/eos/eos_interface.py E322
|
||||
lib/ansible/modules/network/eos/eos_l3_interface.py E322
|
||||
lib/ansible/modules/network/eos/eos_linkagg.py E322
|
||||
lib/ansible/modules/network/eos/eos_lldp.py E322
|
||||
lib/ansible/modules/network/eos/eos_logging.py E322
|
||||
lib/ansible/modules/network/eos/eos_static_route.py E322
|
||||
lib/ansible/modules/network/eos/eos_vlan.py E322
|
||||
lib/ansible/modules/network/eos/eos_vrf.py E322
|
||||
lib/ansible/modules/network/f5/bigip_asm_policy.py E322
|
||||
lib/ansible/modules/network/f5/bigip_asm_policy.py E323
|
||||
lib/ansible/modules/network/f5/bigip_command.py E322
|
||||
|
@ -511,31 +503,15 @@ lib/ansible/modules/network/f5/bigiq_regkey_pool.py E323
|
|||
lib/ansible/modules/network/illumos/dladm_linkprop.py E317
|
||||
lib/ansible/modules/network/illumos/ipadm_addrprop.py E317
|
||||
lib/ansible/modules/network/illumos/ipadm_ifprop.py E317
|
||||
lib/ansible/modules/network/ios/ios_interface.py E322
|
||||
lib/ansible/modules/network/ios/ios_l3_interface.py E322
|
||||
lib/ansible/modules/network/ios/ios_linkagg.py E322
|
||||
lib/ansible/modules/network/ios/ios_lldp.py E322
|
||||
lib/ansible/modules/network/ios/ios_logging.py E322
|
||||
lib/ansible/modules/network/ios/ios_static_route.py E322
|
||||
lib/ansible/modules/network/ios/ios_user.py E322
|
||||
lib/ansible/modules/network/ios/ios_vlan.py E322
|
||||
lib/ansible/modules/network/iosxr/iosxr_command.py E322
|
||||
lib/ansible/modules/network/iosxr/iosxr_logging.py E322
|
||||
lib/ansible/modules/network/iosxr/iosxr_netconf.py E322
|
||||
lib/ansible/modules/network/ironware/ironware_command.py E323
|
||||
lib/ansible/modules/network/ironware/ironware_config.py E323
|
||||
lib/ansible/modules/network/ironware/ironware_facts.py E323
|
||||
lib/ansible/modules/network/junos/junos_banner.py E322
|
||||
lib/ansible/modules/network/junos/junos_interface.py E322
|
||||
lib/ansible/modules/network/junos/junos_l3_interface.py E322
|
||||
lib/ansible/modules/network/junos/junos_linkagg.py E322
|
||||
lib/ansible/modules/network/junos/junos_lldp.py E322
|
||||
lib/ansible/modules/network/junos/junos_lldp_interface.py E322
|
||||
lib/ansible/modules/network/junos/junos_logging.py E322
|
||||
lib/ansible/modules/network/junos/junos_static_route.py E322
|
||||
lib/ansible/modules/network/junos/junos_system.py E322
|
||||
lib/ansible/modules/network/junos/junos_vlan.py E322
|
||||
lib/ansible/modules/network/junos/junos_vrf.py E322
|
||||
lib/ansible/modules/network/netscaler/netscaler_cs_action.py E323
|
||||
lib/ansible/modules/network/netscaler/netscaler_cs_vserver.py E322
|
||||
lib/ansible/modules/network/netscaler/netscaler_cs_vserver.py E323
|
||||
|
@ -630,17 +606,8 @@ lib/ansible/modules/network/radware/vdirect_commit.py E321
|
|||
lib/ansible/modules/network/radware/vdirect_file.py E321
|
||||
lib/ansible/modules/network/radware/vdirect_runnable.py E321
|
||||
lib/ansible/modules/network/sros/sros_config.py E323
|
||||
lib/ansible/modules/network/vyos/vyos_banner.py E322
|
||||
lib/ansible/modules/network/vyos/vyos_interface.py E322
|
||||
lib/ansible/modules/network/vyos/vyos_l3_interface.py E322
|
||||
lib/ansible/modules/network/vyos/vyos_linkagg.py E322
|
||||
lib/ansible/modules/network/vyos/vyos_lldp.py E322
|
||||
lib/ansible/modules/network/vyos/vyos_lldp_interface.py E322
|
||||
lib/ansible/modules/network/vyos/vyos_logging.py E322
|
||||
lib/ansible/modules/network/vyos/vyos_static_route.py E322
|
||||
lib/ansible/modules/network/vyos/vyos_system.py E322
|
||||
lib/ansible/modules/network/vyos/vyos_user.py E322
|
||||
lib/ansible/modules/network/vyos/vyos_vlan.py E322
|
||||
lib/ansible/modules/notification/cisco_spark.py E322
|
||||
lib/ansible/modules/notification/hipchat.py E322
|
||||
lib/ansible/modules/notification/irc.py E322
|
||||
|
@ -689,9 +656,7 @@ lib/ansible/modules/remote_management/oneview/oneview_san_manager.py E322
|
|||
lib/ansible/modules/remote_management/oneview/oneview_san_manager_facts.py E322
|
||||
lib/ansible/modules/remote_management/stacki/stacki_host.py E317
|
||||
lib/ansible/modules/remote_management/stacki/stacki_host.py E322
|
||||
lib/ansible/modules/remote_management/ucs/ucs_ip_pool.py E322
|
||||
lib/ansible/modules/remote_management/ucs/ucs_ip_pool.py E323
|
||||
lib/ansible/modules/remote_management/ucs/ucs_mac_pool.py E322
|
||||
lib/ansible/modules/remote_management/ucs/ucs_mac_pool.py E323
|
||||
lib/ansible/modules/remote_management/ucs/ucs_san_connectivity.py E322
|
||||
lib/ansible/modules/remote_management/ucs/ucs_san_connectivity.py E323
|
||||
|
|
|
@ -41,8 +41,8 @@ class AnsibleModuleImportError(ImportError):
|
|||
|
||||
@contextmanager
|
||||
def add_mocks(filename):
|
||||
gp = mock.patch('ansible.module_utils.basic.get_platform').start()
|
||||
gp.return_value = 'linux'
|
||||
# Used to clean up imports later
|
||||
pre_sys_modules = list(sys.modules.keys())
|
||||
|
||||
module_mock = mock.MagicMock()
|
||||
mocks = []
|
||||
|
@ -62,6 +62,13 @@ def add_mocks(filename):
|
|||
for m in mocks:
|
||||
m.stop()
|
||||
|
||||
# Clean up imports to prevent issues with mutable data being used in modules
|
||||
for k in list(sys.modules.keys()):
|
||||
# It's faster if we limit to items in ansible.module_utils
|
||||
# But if this causes problems later, we should remove it
|
||||
if k not in pre_sys_modules and k.startswith('ansible.module_utils.'):
|
||||
del sys.modules[k]
|
||||
|
||||
|
||||
def get_argument_spec(filename):
|
||||
with add_mocks(filename) as module_mock:
|
||||
|
|
Loading…
Reference in a new issue