django_command/django_check/django_createcachetable: add return value version (#9063)

* add return value version

* add changelog frag

* reformat yaml
pull/9067/head
Alexei Znamensky 2024-10-27 21:36:38 +13:00 committed by GitHub
parent 39f3b151e8
commit 107df41d9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 104 additions and 35 deletions

View File

@ -0,0 +1,5 @@
minor_changes:
- django module utils - always retrieve version (https://github.com/ansible-collections/community.general/pull/9063).
- django_check - add return value ``version`` (https://github.com/ansible-collections/community.general/pull/9063).
- django_command - add return value ``version`` (https://github.com/ansible-collections/community.general/pull/9063).
- django_createcachetable - add return value ``version`` (https://github.com/ansible-collections/community.general/pull/9063).

View File

@ -32,6 +32,7 @@ _django_std_arg_fmts = dict(
verbosity=cmd_runner_fmt.as_opt_val("--verbosity"),
no_color=cmd_runner_fmt.as_fixed("--no-color"),
skip_checks=cmd_runner_fmt.as_bool("--skip-checks"),
version=cmd_runner_fmt.as_fixed("--version"),
)
_django_database_args = dict(
@ -60,6 +61,9 @@ class _DjangoRunner(PythonRunner):
)
return super(_DjangoRunner, self).__call__(args_order, output_process, ignore_value_none, check_mode_skip, check_mode_return, **kwargs)
def bare_context(self, *args, **kwargs):
return super(_DjangoRunner, self).__call__(*args, **kwargs)
class DjangoModuleHelper(ModuleHelper):
module = {}
@ -98,16 +102,20 @@ class DjangoModuleHelper(ModuleHelper):
arg_formats=self.arg_formats,
venv=self.vars.venv,
check_rc=True)
with runner() as ctx:
run_params = self.vars.as_dict()
if self._check_mode_arg:
run_params.update({self._check_mode_arg: self.check_mode})
rc, out, err = runner.bare_context("version").run()
self.vars.version = out.strip()
with runner() as ctx:
results = ctx.run(**run_params)
self.vars.stdout = ctx.results_out
self.vars.stderr = ctx.results_err
self.vars.cmd = ctx.cmd
if self.verbosity >= 3:
self.vars.run_info = ctx.run_info
self.vars.set("run_info", ctx.run_info, verbosity=3)
return results

View File

@ -8,16 +8,17 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
---
module: django_check
author:
- Alexei Znamensky (@russoz)
- 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).
- This module is a wrapper for the execution of C(django-admin check).
extends_documentation_fragment:
- community.general.attributes
- community.general.django
- community.general.attributes
- community.general.django
options:
database:
description:
@ -48,8 +49,8 @@ options:
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.
- 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
@ -58,6 +59,7 @@ attributes:
"""
EXAMPLES = """
---
- name: Check the entire project
community.general.django_check:
settings: myproject.settings
@ -73,10 +75,17 @@ EXAMPLES = """
"""
RETURN = """
---
run_info:
description: Command-line execution information.
type: dict
returned: success and C(verbosity) >= 3
version:
description: Version of Django.
type: str
returned: always
sample: 5.1.2
version_added: 10.0.0
"""
from ansible_collections.community.general.plugins.module_utils.django import DjangoModuleHelper

View File

@ -8,16 +8,17 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
---
module: django_command
author:
- Alexei Znamensky (@russoz)
- Alexei Znamensky (@russoz)
short_description: Run Django admin commands
version_added: 9.0.0
description:
- This module allows the execution of arbitrary Django admin commands.
- This module allows the execution of arbitrary Django admin commands.
extends_documentation_fragment:
- community.general.attributes
- community.general.django
- community.general.attributes
- community.general.django
attributes:
check_mode:
support: none
@ -37,6 +38,7 @@ options:
"""
EXAMPLES = """
---
- name: Check the project
community.general.django_command:
command: check
@ -51,10 +53,17 @@ EXAMPLES = """
"""
RETURN = """
---
run_info:
description: Command-line execution information.
type: dict
returned: success and O(verbosity) >= 3
version:
description: Version of Django.
type: str
returned: always
sample: 5.1.2
version_added: 10.0.0
"""
import shlex

View File

@ -8,17 +8,18 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
---
module: django_createcachetable
author:
- Alexei Znamensky (@russoz)
- Alexei Znamensky (@russoz)
short_description: Wrapper for C(django-admin createcachetable)
version_added: 9.1.0
description:
- This module is a wrapper for the execution of C(django-admin createcachetable).
- This module is a wrapper for the execution of C(django-admin createcachetable).
extends_documentation_fragment:
- community.general.attributes
- community.general.django
- community.general.django.database
- community.general.attributes
- community.general.django
- community.general.django.database
attributes:
check_mode:
support: full
@ -27,6 +28,7 @@ attributes:
"""
EXAMPLES = """
---
- name: Create cache table in the default database
community.general.django_createcachetable:
settings: myproject.settings
@ -40,10 +42,17 @@ EXAMPLES = """
"""
RETURN = """
---
run_info:
description: Command-line execution information.
type: dict
returned: success and O(verbosity) >= 3
version:
description: Version of Django.
type: str
returned: always
sample: 5.1.2
version_added: 10.0.0
"""
from ansible_collections.community.general.plugins.module_utils.django import DjangoModuleHelper

View File

@ -7,11 +7,18 @@
- id: success
input:
settings: whatever.settings
output:
version: "5.1.2"
mocks:
run_command:
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings]
- command: [/testbin/python, -m, django, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
rc: 0
out: "5.1.2\n"
err: ""
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings]
environ: *env-def
rc: 0
out: "whatever\n"
err: ""
- id: multiple_databases
@ -20,8 +27,15 @@
database:
- abc
- def
output:
version: "5.1.2"
mocks:
run_command:
- command: [/testbin/python, -m, django, --version]
environ: *env-def
rc: 0
out: "5.1.2\n"
err: ""
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings, --database, abc, --database, def]
environ: *env-def
rc: 0

View File

@ -15,9 +15,14 @@
settings: whatever.settings
mocks:
run_command:
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings, babaloo, yaba, daba, doo]
- command: [/testbin/python, -m, django, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
rc: 0
out: "5.1.2\n"
err: ""
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings, babaloo, yaba, daba, doo]
environ: *env-def
rc: 0
out: "whatever\n"
err: ""
- id: command_fail
@ -33,6 +38,11 @@
failed: true
mocks:
run_command:
- command: [/testbin/python, -m, django, --version]
environ: *env-def
rc: 0
out: "5.1.2\n"
err: ""
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings, babaloo, yaba, daba, doo]
environ: *env-def
rc: 1

View File

@ -9,8 +9,13 @@
settings: whatever.settings
mocks:
run_command:
- command: [/testbin/python, -m, django, --version]
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
rc: 0
out: "5.1.2\n"
err: ""
- command: [/testbin/python, -m, django, createcachetable, --no-color, --settings=whatever.settings, --noinput, --database=default]
environ: {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
environ: *env-def
rc: 0
out: "whatever\n"
err: ""