mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
Final round of moving modules to new import error msg (#51852)
* Final round of moving modules to new import error msg * readd URL to jenkins install guide * fix unit tests
This commit is contained in:
parent
ffbc9d99de
commit
a39c4ad464
42 changed files with 292 additions and 150 deletions
|
@ -190,10 +190,13 @@ members:
|
|||
'''
|
||||
|
||||
import re
|
||||
import traceback
|
||||
|
||||
BEAUTIFUL_SOUP_IMP_ERR = None
|
||||
try:
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
except ImportError:
|
||||
BEAUTIFUL_SOUP_IMP_ERR = traceback.format_exc()
|
||||
HAS_BEAUTIFULSOUP = False
|
||||
else:
|
||||
HAS_BEAUTIFULSOUP = True
|
||||
|
@ -357,7 +360,7 @@ def main():
|
|||
)
|
||||
|
||||
if HAS_BEAUTIFULSOUP is False:
|
||||
module.fail_json(msg="python module 'BeautifulSoup' is required!")
|
||||
module.fail_json(msg=missing_required_lib('BeautifulSoup'), exception=BEAUTIFUL_SOUP_IMP_ERR)
|
||||
|
||||
if module.params['state'] is not None:
|
||||
states = module.params['state'].split(',')
|
||||
|
@ -435,7 +438,7 @@ def main():
|
|||
module.fail_json(msg=str(module.params['member_host']) + ' is not a member of the balancer ' + str(module.params['balancer_vhost']) + '!')
|
||||
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -95,14 +95,18 @@ EXAMPLES = """
|
|||
|
||||
import os
|
||||
import tempfile
|
||||
import traceback
|
||||
from distutils.version import LooseVersion
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
PASSLIB_IMP_ERR = None
|
||||
try:
|
||||
from passlib.apache import HtpasswdFile, htpasswd_context
|
||||
from passlib.context import CryptContext
|
||||
import passlib
|
||||
except ImportError:
|
||||
PASSLIB_IMP_ERR = traceback.format_exc()
|
||||
passlib_installed = False
|
||||
else:
|
||||
passlib_installed = True
|
||||
|
@ -218,7 +222,7 @@ def main():
|
|||
check_mode = module.check_mode
|
||||
|
||||
if not passlib_installed:
|
||||
module.fail_json(msg="This module requires the passlib Python library")
|
||||
module.fail_json(msg=missing_required_lib("passlib"), exception=PASSLIB_IMP_ERR)
|
||||
|
||||
# Check file for blank lines in effort to avoid "need more than 1 value to unpack" error.
|
||||
try:
|
||||
|
|
|
@ -148,19 +148,23 @@ url:
|
|||
|
||||
import traceback
|
||||
|
||||
JENKINS_IMP_ERR = None
|
||||
try:
|
||||
import jenkins
|
||||
python_jenkins_installed = True
|
||||
except ImportError:
|
||||
JENKINS_IMP_ERR = traceback.format_exc()
|
||||
python_jenkins_installed = False
|
||||
|
||||
LXML_IMP_ERR = None
|
||||
try:
|
||||
from lxml import etree as ET
|
||||
python_lxml_installed = True
|
||||
except ImportError:
|
||||
LXML_IMP_ERR = traceback.format_exc()
|
||||
python_lxml_installed = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
|
@ -325,12 +329,15 @@ class JenkinsJob:
|
|||
|
||||
def test_dependencies(module):
|
||||
if not python_jenkins_installed:
|
||||
module.fail_json(msg="python-jenkins required for this module. "
|
||||
"see http://python-jenkins.readthedocs.io/en/latest/install.html")
|
||||
module.fail_json(
|
||||
msg=missing_required_lib("python-jenkins",
|
||||
url="https://python-jenkins.readthedocs.io/en/latest/install.html"),
|
||||
exception=JENKINS_IMP_ERR)
|
||||
|
||||
if not python_lxml_installed:
|
||||
module.fail_json(msg="lxml required for this module. "
|
||||
"see http://lxml.de/installation.html")
|
||||
module.fail_json(
|
||||
msg=missing_required_lib("lxml", url="https://lxml.de/installation.html"),
|
||||
exception=LXML_IMP_ERR)
|
||||
|
||||
|
||||
def job_config_to_string(xml_str):
|
||||
|
|
|
@ -137,13 +137,15 @@ import ssl
|
|||
import fnmatch
|
||||
import traceback
|
||||
|
||||
JENKINS_IMP_ERR = None
|
||||
try:
|
||||
import jenkins
|
||||
HAS_JENKINS = True
|
||||
except ImportError:
|
||||
JENKINS_IMP_ERR = traceback.format_exc()
|
||||
HAS_JENKINS = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
|
@ -171,8 +173,9 @@ def get_jenkins_connection(module):
|
|||
def test_dependencies(module):
|
||||
if not HAS_JENKINS:
|
||||
module.fail_json(
|
||||
msg="python-jenkins required for this module. "
|
||||
"see http://python-jenkins.readthedocs.io/en/latest/install.html")
|
||||
msg=missing_required_lib("python-jenkins",
|
||||
url="https://python-jenkins.readthedocs.io/en/latest/install.html"),
|
||||
exception=JENKINS_IMP_ERR)
|
||||
|
||||
|
||||
def get_jobs(module):
|
||||
|
|
|
@ -105,15 +105,20 @@ EXAMPLES = '''
|
|||
'''
|
||||
|
||||
RETURN = '''# '''
|
||||
import traceback
|
||||
|
||||
from os import getenv
|
||||
from os.path import isfile
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
TAIGA_IMP_ERR = None
|
||||
try:
|
||||
from taiga import TaigaAPI
|
||||
from taiga.exceptions import TaigaException
|
||||
TAIGA_MODULE_IMPORTED = True
|
||||
except ImportError:
|
||||
TAIGA_IMP_ERR = traceback.format_exc()
|
||||
TAIGA_MODULE_IMPORTED = False
|
||||
|
||||
|
||||
|
@ -252,8 +257,8 @@ def main():
|
|||
)
|
||||
|
||||
if not TAIGA_MODULE_IMPORTED:
|
||||
msg = "This module needs python-taiga module"
|
||||
module.fail_json(msg=msg)
|
||||
module.fail_json(msg=missing_required_lib("python-taiga"),
|
||||
exception=TAIGA_IMP_ERR)
|
||||
|
||||
taiga_host = module.params['taiga_host']
|
||||
project_name = module.params['project']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue