mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
django_check: new module (#8454)
* django_check: new module * sanity fix * working version * remove unused import * add note about the module output * add note on module failing when rc!=0
This commit is contained in:
parent
1ae6c82558
commit
c31499a411
4 changed files with 159 additions and 4 deletions
10
.github/BOTMETA.yml
vendored
10
.github/BOTMETA.yml
vendored
|
@ -506,13 +506,15 @@ files:
|
||||||
maintainers: tintoy
|
maintainers: tintoy
|
||||||
$modules/discord.py:
|
$modules/discord.py:
|
||||||
maintainers: cwollinger
|
maintainers: cwollinger
|
||||||
$modules/django_manage.py:
|
$modules/django_check.py:
|
||||||
ignore: scottanderson42 tastychutney
|
maintainers: russoz
|
||||||
labels: django_manage
|
$modules/django_command.py:
|
||||||
maintainers: russoz
|
maintainers: russoz
|
||||||
$modules/django_createcachetable.py:
|
$modules/django_createcachetable.py:
|
||||||
maintainers: russoz
|
maintainers: russoz
|
||||||
$modules/django_command.py:
|
$modules/django_manage.py:
|
||||||
|
ignore: scottanderson42 tastychutney
|
||||||
|
labels: django_manage
|
||||||
maintainers: russoz
|
maintainers: russoz
|
||||||
$modules/dnf_versionlock.py:
|
$modules/dnf_versionlock.py:
|
||||||
maintainers: moreda
|
maintainers: moreda
|
||||||
|
|
113
plugins/modules/django_check.py
Normal file
113
plugins/modules/django_check.py
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2024, Alexei Znamensky <russoz@gmail.com>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
DOCUMENTATION = """
|
||||||
|
module: django_check
|
||||||
|
author:
|
||||||
|
- Alexei Znamensky (@russoz)
|
||||||
|
short_description: Wrapper for C(django-admin check)
|
||||||
|
version_added: 9.1.0
|
||||||
|
description:
|
||||||
|
- This module is a wrapper for the execution of C(django-admin check).
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- community.general.attributes
|
||||||
|
- community.general.django
|
||||||
|
options:
|
||||||
|
database:
|
||||||
|
description:
|
||||||
|
- Specify databases to run checks against.
|
||||||
|
- If not specified, Django will not run database tests.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
deploy:
|
||||||
|
description:
|
||||||
|
- Include additional checks relevant in a deployment setting.
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
fail_level:
|
||||||
|
description:
|
||||||
|
- Message level that will trigger failure.
|
||||||
|
- Default is the Django default value. Check the documentation for the version being used.
|
||||||
|
type: str
|
||||||
|
choices: [CRITICAL, ERROR, WARNING, INFO, DEBUG]
|
||||||
|
tags:
|
||||||
|
description:
|
||||||
|
- Restrict checks to specific tags.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
apps:
|
||||||
|
description:
|
||||||
|
- Restrict checks to specific applications.
|
||||||
|
- Default is to check all applications.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
notes:
|
||||||
|
- The outcome of the module is found in the common return values RV(ignore:stdout), RV(ignore:stderr), RV(ignore:rc).
|
||||||
|
- The module will fail if RV(ignore:rc) is not zero.
|
||||||
|
attributes:
|
||||||
|
check_mode:
|
||||||
|
support: full
|
||||||
|
diff_mode:
|
||||||
|
support: none
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = """
|
||||||
|
- name: Check the entire project
|
||||||
|
community.general.django_check:
|
||||||
|
settings: myproject.settings
|
||||||
|
|
||||||
|
- name: Create the project using specific databases
|
||||||
|
community.general.django_check:
|
||||||
|
database:
|
||||||
|
- somedb
|
||||||
|
- myotherdb
|
||||||
|
settings: fancysite.settings
|
||||||
|
pythonpath: /home/joedoe/project/fancysite
|
||||||
|
venv: /home/joedoe/project/fancysite/venv
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = """
|
||||||
|
run_info:
|
||||||
|
description: Command-line execution information.
|
||||||
|
type: dict
|
||||||
|
returned: success and C(verbosity) >= 3
|
||||||
|
"""
|
||||||
|
|
||||||
|
from ansible_collections.community.general.plugins.module_utils.django import DjangoModuleHelper
|
||||||
|
from ansible_collections.community.general.plugins.module_utils.cmd_runner import cmd_runner_fmt
|
||||||
|
|
||||||
|
|
||||||
|
class DjangoCheck(DjangoModuleHelper):
|
||||||
|
module = dict(
|
||||||
|
argument_spec=dict(
|
||||||
|
database=dict(type="list", elements="str"),
|
||||||
|
deploy=dict(type="bool", default=False),
|
||||||
|
fail_level=dict(type="str", choices=["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]),
|
||||||
|
tags=dict(type="list", elements="str"),
|
||||||
|
apps=dict(type="list", elements="str"),
|
||||||
|
),
|
||||||
|
supports_check_mode=True,
|
||||||
|
)
|
||||||
|
arg_formats = dict(
|
||||||
|
database=cmd_runner_fmt.stack(cmd_runner_fmt.as_opt_val)("--database"),
|
||||||
|
deploy=cmd_runner_fmt.as_bool("--deploy"),
|
||||||
|
fail_level=cmd_runner_fmt.as_opt_val("--fail-level"),
|
||||||
|
tags=cmd_runner_fmt.stack(cmd_runner_fmt.as_opt_val)("--tag"),
|
||||||
|
apps=cmd_runner_fmt.as_list(),
|
||||||
|
)
|
||||||
|
django_admin_cmd = "check"
|
||||||
|
django_admin_arg_order = "database deploy fail_level tags apps"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
DjangoCheck.execute()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
13
tests/unit/plugins/modules/test_django_check.py
Normal file
13
tests/unit/plugins/modules/test_django_check.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Copyright (c) Alexei Znamensky (russoz@gmail.com)
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
|
from ansible_collections.community.general.plugins.modules import django_check
|
||||||
|
from .helper import Helper
|
||||||
|
|
||||||
|
|
||||||
|
Helper.from_module(django_check, __name__)
|
27
tests/unit/plugins/modules/test_django_check.yaml
Normal file
27
tests/unit/plugins/modules/test_django_check.yaml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) Alexei Znamensky (russoz@gmail.com)
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
---
|
||||||
|
- id: success
|
||||||
|
input:
|
||||||
|
settings: whatever.settings
|
||||||
|
run_command_calls:
|
||||||
|
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings]
|
||||||
|
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
|
||||||
|
rc: 0
|
||||||
|
out: "whatever\n"
|
||||||
|
err: ""
|
||||||
|
- id: multiple_databases
|
||||||
|
input:
|
||||||
|
settings: whatever.settings
|
||||||
|
database:
|
||||||
|
- abc
|
||||||
|
- def
|
||||||
|
run_command_calls:
|
||||||
|
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings, --database, abc, --database, def]
|
||||||
|
environ: *env-def
|
||||||
|
rc: 0
|
||||||
|
out: "whatever\n"
|
||||||
|
err: ""
|
Loading…
Reference in a new issue