From c7a0d6b677506e9c74e6f92f06f09fefaea098a3 Mon Sep 17 00:00:00 2001 From: Kavin Agrawal Date: Wed, 4 Dec 2024 20:47:31 -0800 Subject: [PATCH 1/2] Fixed collection failure issuees for some ansible version --- plugins/module_utils/cohesity_auth.py | 7 +++++-- plugins/module_utils/cohesity_hints.py | 6 +++++- plugins/modules/cohesity_agent.py | 6 +++++- plugins/modules/cohesity_cancel_migration.py | 6 +++++- plugins/modules/cohesity_finalize_migration.py | 6 +++++- plugins/modules/cohesity_job.py | 6 +++++- plugins/modules/cohesity_migrate_vm.py | 6 +++++- plugins/modules/cohesity_migration_status.py | 6 +++++- plugins/modules/cohesity_oracle_job.py | 5 ++++- plugins/modules/cohesity_oracle_source.py | 6 +++++- plugins/modules/cohesity_plugin.py | 6 +++++- plugins/modules/cohesity_restore_file.py | 6 +++++- plugins/modules/cohesity_restore_vm.py | 6 +++++- plugins/modules/cohesity_restore_vmware_file.py | 6 +++++- plugins/modules/cohesity_source.py | 6 +++++- plugins/modules/cohesity_sync_objects.py | 6 +++++- plugins/modules/cohesity_uda_protection_group.py | 7 +++++-- plugins/modules/cohesity_uda_source.py | 6 +++++- 18 files changed, 89 insertions(+), 20 deletions(-) diff --git a/plugins/module_utils/cohesity_auth.py b/plugins/module_utils/cohesity_auth.py index b40ffcb..4f40843 100644 --- a/plugins/module_utils/cohesity_auth.py +++ b/plugins/module_utils/cohesity_auth.py @@ -21,8 +21,11 @@ import json -from ansible.module_utils.urls import open_url, urllib_error - +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error class ParameterViolation(Exception): pass diff --git a/plugins/module_utils/cohesity_hints.py b/plugins/module_utils/cohesity_hints.py index ece1c44..36982be 100644 --- a/plugins/module_utils/cohesity_hints.py +++ b/plugins/module_utils/cohesity_hints.py @@ -34,7 +34,11 @@ except ImportError: from urllib.parse import quote -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error from ansible.module_utils.six.moves import urllib_parse try: diff --git a/plugins/modules/cohesity_agent.py b/plugins/modules/cohesity_agent.py index 09e13ad..1f86723 100644 --- a/plugins/modules/cohesity_agent.py +++ b/plugins/modules/cohesity_agent.py @@ -130,7 +130,11 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils._text import to_bytes -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error from tempfile import mkdtemp try: diff --git a/plugins/modules/cohesity_cancel_migration.py b/plugins/modules/cohesity_cancel_migration.py index e84882d..111259a 100644 --- a/plugins/modules/cohesity_cancel_migration.py +++ b/plugins/modules/cohesity_cancel_migration.py @@ -89,7 +89,11 @@ import json from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_finalize_migration.py b/plugins/modules/cohesity_finalize_migration.py index 23e7dc9..baa7830 100644 --- a/plugins/modules/cohesity_finalize_migration.py +++ b/plugins/modules/cohesity_finalize_migration.py @@ -101,7 +101,11 @@ import json from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_job.py b/plugins/modules/cohesity_job.py index a92a052..f74296f 100644 --- a/plugins/modules/cohesity_job.py +++ b/plugins/modules/cohesity_job.py @@ -313,7 +313,11 @@ import time from collections import defaultdict from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_migrate_vm.py b/plugins/modules/cohesity_migrate_vm.py index 5715dff..c20f36e 100644 --- a/plugins/modules/cohesity_migrate_vm.py +++ b/plugins/modules/cohesity_migrate_vm.py @@ -228,7 +228,11 @@ from datetime import datetime from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_migration_status.py b/plugins/modules/cohesity_migration_status.py index 82bf335..d1c50c2 100644 --- a/plugins/modules/cohesity_migration_status.py +++ b/plugins/modules/cohesity_migration_status.py @@ -98,7 +98,11 @@ from collections import defaultdict from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_oracle_job.py b/plugins/modules/cohesity_oracle_job.py index 60447ef..e6e5d1d 100644 --- a/plugins/modules/cohesity_oracle_job.py +++ b/plugins/modules/cohesity_oracle_job.py @@ -166,11 +166,14 @@ import copy import time from ansible.module_utils.basic import AnsibleModule +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, # => the expectation is that the modules will live under ansible. - from ansible.module_utils.urls import urllib_error from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_hints import ( get_cohesity_client, ) diff --git a/plugins/modules/cohesity_oracle_source.py b/plugins/modules/cohesity_oracle_source.py index a036909..62c7a05 100644 --- a/plugins/modules/cohesity_oracle_source.py +++ b/plugins/modules/cohesity_oracle_source.py @@ -112,7 +112,11 @@ import json import time from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_plugin.py b/plugins/modules/cohesity_plugin.py index d2e9049..acd3280 100644 --- a/plugins/modules/cohesity_plugin.py +++ b/plugins/modules/cohesity_plugin.py @@ -115,7 +115,11 @@ # Ansible Imports. from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_auth import ( get__cohesity_auth__token, diff --git a/plugins/modules/cohesity_restore_file.py b/plugins/modules/cohesity_restore_file.py index cdf96c0..ea22f00 100644 --- a/plugins/modules/cohesity_restore_file.py +++ b/plugins/modules/cohesity_restore_file.py @@ -187,7 +187,11 @@ import time from datetime import datetime from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_restore_vm.py b/plugins/modules/cohesity_restore_vm.py index e033faa..aa063c6 100644 --- a/plugins/modules/cohesity_restore_vm.py +++ b/plugins/modules/cohesity_restore_vm.py @@ -245,7 +245,11 @@ except ImportError: from urllib.parse import quote from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_restore_vmware_file.py b/plugins/modules/cohesity_restore_vmware_file.py index fdd7452..e9e2a7e 100644 --- a/plugins/modules/cohesity_restore_vmware_file.py +++ b/plugins/modules/cohesity_restore_vmware_file.py @@ -146,7 +146,11 @@ import time from datetime import datetime from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_source.py b/plugins/modules/cohesity_source.py index d8b3078..148490d 100644 --- a/plugins/modules/cohesity_source.py +++ b/plugins/modules/cohesity_source.py @@ -262,7 +262,11 @@ import json import time from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_sync_objects.py b/plugins/modules/cohesity_sync_objects.py index b4a4361..525041a 100644 --- a/plugins/modules/cohesity_sync_objects.py +++ b/plugins/modules/cohesity_sync_objects.py @@ -91,7 +91,11 @@ import json from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_uda_protection_group.py b/plugins/modules/cohesity_uda_protection_group.py index 35979e3..9f0bd56 100644 --- a/plugins/modules/cohesity_uda_protection_group.py +++ b/plugins/modules/cohesity_uda_protection_group.py @@ -236,12 +236,15 @@ from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, # => the expectation is that the modules will live under ansible. - from ansible.module_utils.urls import urllib_error from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_auth import ( get__cohesity_auth__token, ) diff --git a/plugins/modules/cohesity_uda_source.py b/plugins/modules/cohesity_uda_source.py index 40918bf..7b1e0c4 100644 --- a/plugins/modules/cohesity_uda_source.py +++ b/plugins/modules/cohesity_uda_source.py @@ -149,7 +149,11 @@ import json from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url, urllib_error +from ansible.module_utils.urls import open_url +try: + from urllib import error as urllib_error +except ImportError: + import urllib2 as urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, From b7d4e731b46788fcac4224568c5e71445f6e15cc Mon Sep 17 00:00:00 2001 From: Kavin Agrawal Date: Thu, 5 Dec 2024 07:03:38 -0800 Subject: [PATCH 2/2] Fixed ansible lint issues --- plugins/module_utils/cohesity_auth.py | 3 ++- plugins/module_utils/cohesity_hints.py | 2 +- plugins/modules/cohesity_agent.py | 2 +- plugins/modules/cohesity_cancel_migration.py | 2 +- plugins/modules/cohesity_finalize_migration.py | 2 +- plugins/modules/cohesity_job.py | 2 +- plugins/modules/cohesity_migrate_vm.py | 2 +- plugins/modules/cohesity_migration_status.py | 2 +- plugins/modules/cohesity_oracle_job.py | 2 +- plugins/modules/cohesity_oracle_source.py | 2 +- plugins/modules/cohesity_plugin.py | 2 +- plugins/modules/cohesity_restore_file.py | 2 +- plugins/modules/cohesity_restore_vm.py | 2 +- plugins/modules/cohesity_restore_vmware_file.py | 2 +- plugins/modules/cohesity_source.py | 2 +- plugins/modules/cohesity_sync_objects.py | 2 +- plugins/modules/cohesity_uda_protection_group.py | 2 +- plugins/modules/cohesity_uda_source.py | 2 +- 18 files changed, 19 insertions(+), 18 deletions(-) diff --git a/plugins/module_utils/cohesity_auth.py b/plugins/module_utils/cohesity_auth.py index 4f40843..6191073 100644 --- a/plugins/module_utils/cohesity_auth.py +++ b/plugins/module_utils/cohesity_auth.py @@ -25,7 +25,8 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error + class ParameterViolation(Exception): pass diff --git a/plugins/module_utils/cohesity_hints.py b/plugins/module_utils/cohesity_hints.py index 36982be..85331f9 100644 --- a/plugins/module_utils/cohesity_hints.py +++ b/plugins/module_utils/cohesity_hints.py @@ -38,7 +38,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error from ansible.module_utils.six.moves import urllib_parse try: diff --git a/plugins/modules/cohesity_agent.py b/plugins/modules/cohesity_agent.py index 1f86723..748be6c 100644 --- a/plugins/modules/cohesity_agent.py +++ b/plugins/modules/cohesity_agent.py @@ -134,7 +134,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error from tempfile import mkdtemp try: diff --git a/plugins/modules/cohesity_cancel_migration.py b/plugins/modules/cohesity_cancel_migration.py index 111259a..87fa31e 100644 --- a/plugins/modules/cohesity_cancel_migration.py +++ b/plugins/modules/cohesity_cancel_migration.py @@ -93,7 +93,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_finalize_migration.py b/plugins/modules/cohesity_finalize_migration.py index baa7830..7f0d797 100644 --- a/plugins/modules/cohesity_finalize_migration.py +++ b/plugins/modules/cohesity_finalize_migration.py @@ -105,7 +105,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_job.py b/plugins/modules/cohesity_job.py index f74296f..ab366b8 100644 --- a/plugins/modules/cohesity_job.py +++ b/plugins/modules/cohesity_job.py @@ -317,7 +317,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_migrate_vm.py b/plugins/modules/cohesity_migrate_vm.py index c20f36e..8473bc7 100644 --- a/plugins/modules/cohesity_migrate_vm.py +++ b/plugins/modules/cohesity_migrate_vm.py @@ -232,7 +232,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_migration_status.py b/plugins/modules/cohesity_migration_status.py index d1c50c2..3138f35 100644 --- a/plugins/modules/cohesity_migration_status.py +++ b/plugins/modules/cohesity_migration_status.py @@ -102,7 +102,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_oracle_job.py b/plugins/modules/cohesity_oracle_job.py index e6e5d1d..92c1a4d 100644 --- a/plugins/modules/cohesity_oracle_job.py +++ b/plugins/modules/cohesity_oracle_job.py @@ -169,7 +169,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_oracle_source.py b/plugins/modules/cohesity_oracle_source.py index 62c7a05..79e8a75 100644 --- a/plugins/modules/cohesity_oracle_source.py +++ b/plugins/modules/cohesity_oracle_source.py @@ -116,7 +116,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_plugin.py b/plugins/modules/cohesity_plugin.py index acd3280..4ae907c 100644 --- a/plugins/modules/cohesity_plugin.py +++ b/plugins/modules/cohesity_plugin.py @@ -119,7 +119,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_auth import ( get__cohesity_auth__token, diff --git a/plugins/modules/cohesity_restore_file.py b/plugins/modules/cohesity_restore_file.py index ea22f00..9642bc0 100644 --- a/plugins/modules/cohesity_restore_file.py +++ b/plugins/modules/cohesity_restore_file.py @@ -191,7 +191,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_restore_vm.py b/plugins/modules/cohesity_restore_vm.py index aa063c6..b5bb723 100644 --- a/plugins/modules/cohesity_restore_vm.py +++ b/plugins/modules/cohesity_restore_vm.py @@ -249,7 +249,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_restore_vmware_file.py b/plugins/modules/cohesity_restore_vmware_file.py index e9e2a7e..b46b0fd 100644 --- a/plugins/modules/cohesity_restore_vmware_file.py +++ b/plugins/modules/cohesity_restore_vmware_file.py @@ -150,7 +150,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_source.py b/plugins/modules/cohesity_source.py index 148490d..2afa377 100644 --- a/plugins/modules/cohesity_source.py +++ b/plugins/modules/cohesity_source.py @@ -266,7 +266,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_sync_objects.py b/plugins/modules/cohesity_sync_objects.py index 525041a..b58fd01 100644 --- a/plugins/modules/cohesity_sync_objects.py +++ b/plugins/modules/cohesity_sync_objects.py @@ -95,7 +95,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_uda_protection_group.py b/plugins/modules/cohesity_uda_protection_group.py index 9f0bd56..f7b380e 100644 --- a/plugins/modules/cohesity_uda_protection_group.py +++ b/plugins/modules/cohesity_uda_protection_group.py @@ -240,7 +240,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible, diff --git a/plugins/modules/cohesity_uda_source.py b/plugins/modules/cohesity_uda_source.py index 7b1e0c4..290d88d 100644 --- a/plugins/modules/cohesity_uda_source.py +++ b/plugins/modules/cohesity_uda_source.py @@ -153,7 +153,7 @@ try: from urllib import error as urllib_error except ImportError: - import urllib2 as urllib_error + from ansible.module_utils.urls import urllib_error try: # => When unit testing, we need to look in the correct location however, when run via ansible,