-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
python_runner/django_command: bugfixes (#8944)
* python_runner/django_command: bugfixes * fix indentation * join path_prefix with : when concatenating with PATH * add changelog frag
- Loading branch information
Showing
12 changed files
with
349 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bugfixes: | ||
- python_runner module utils - parameter ``path_prefix`` was being handled as string when it should be a list (https://github.com/ansible-collections/community.general/pull/8944). | ||
- django_command - option ``command`` is now split lexically before passed to underlying PythonRunner (https://github.com/ansible-collections/community.general/pull/8944). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (c) Ansible Project | ||
# 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 | ||
|
||
azp/posix/2 | ||
skip/python2 | ||
skip/freebsd | ||
skip/macos | ||
skip/osx | ||
skip/rhel8.2 | ||
skip/rhel8.3 | ||
skip/rhel8.4 | ||
skip/rhel8.5 | ||
skip/rhel8.6 | ||
skip/rhel8.7 | ||
skip/rhel8.8 | ||
skip/rhel9.0 | ||
skip/rhel9.1 | ||
skip/rhel9.2 | ||
skip/rhel9.3 | ||
skip/rhel9.4 |
6 changes: 6 additions & 0 deletions
6
...jango_command/files/base_test/1045-single-app-project/single_app_project/core/settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Copyright (c) Ansible Project | ||
# 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 | ||
|
||
# single_app_project/core/settings.py | ||
SECRET_KEY = 'testtesttesttesttest' |
21 changes: 21 additions & 0 deletions
21
...rgets/django_command/files/base_test/1045-single-app-project/single_app_project/manage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
# Copyright (c) Ansible Project | ||
# 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 | ||
|
||
# single_app_project/manage.py | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'single_app_project.core.settings') | ||
from django.core.management import execute_from_command_line | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
29 changes: 29 additions & 0 deletions
29
tests/integration/targets/django_command/files/base_test/simple_project/p1/manage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python | ||
# Copyright (c) Ansible Project | ||
# 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 | ||
|
||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
"""Run administrative tasks.""" | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'p1.settings') | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
133 changes: 133 additions & 0 deletions
133
tests/integration/targets/django_command/files/base_test/simple_project/p1/p1/settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) Ansible Project | ||
# 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 | ||
|
||
""" | ||
Django settings for p1 project. | ||
Generated by 'django-admin startproj' using Django 3.1.5. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/3.1/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/3.1/ref/settings/ | ||
""" | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
# Build paths inside the project like this: BASE_DIR / 'subdir'. | ||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = '%g@gyhl*q@@g(_ab@t^76dao^#b9-v8mw^50)x_bv6wpl+mukj' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
ALLOWED_HOSTS = [] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
|
||
ROOT_URLCONF = 'p1.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = 'p1.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': BASE_DIR / 'db.sqlite3', | ||
} | ||
} | ||
|
||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators | ||
|
||
AUTH_PASSWORD_VALIDATORS = [ | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', | ||
}, | ||
] | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/3.1/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/3.1/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
STATIC_ROOT = '/tmp/django-static' | ||
|
||
if "DJANGO_ANSIBLE_RAISE" in os.environ: | ||
raise ValueError("DJANGO_ANSIBLE_RAISE={0}".format(os.environ["DJANGO_ANSIBLE_RAISE"])) |
28 changes: 28 additions & 0 deletions
28
tests/integration/targets/django_command/files/base_test/simple_project/p1/p1/urls.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (c) Ansible Project | ||
# 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 | ||
|
||
"""p1 URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/2.2/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: path('', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Import the include() function: from django.urls import include, path | ||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | ||
""" | ||
from django.contrib import admin | ||
from django.urls import path | ||
|
||
urlpatterns = [ | ||
path('admin/', admin.site.urls), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
# Copyright (c) Ansible Project | ||
# 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 | ||
|
||
dependencies: | ||
- setup_pkg_mgr | ||
- setup_os_pkg_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Test code for django_command module | ||
# | ||
# Copyright (c) 2020, Alexei Znamensky <[email protected]> | ||
# 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 | ||
- name: Create temporary test directory | ||
tempfile: | ||
state: directory | ||
suffix: .django_command | ||
register: tmp_django_root | ||
|
||
- name: Install OS package virtualenv | ||
package: | ||
name: "{{ os_package_name.virtualenv }}" | ||
state: present | ||
|
||
- name: Ensure virtualenv is created | ||
command: >- | ||
virtualenv {{ tmp_django_root.path }}/venv | ||
- name: Update python package pip | ||
pip: | ||
name: pip | ||
state: latest | ||
virtualenv: "{{ tmp_django_root.path }}/venv" | ||
|
||
- name: Install python package django | ||
pip: | ||
name: django | ||
state: present | ||
virtualenv: "{{ tmp_django_root.path }}/venv" | ||
|
||
- name: Copy files | ||
copy: | ||
src: base_test/ | ||
dest: "{{ tmp_django_root.path }}" | ||
mode: preserve | ||
|
||
- name: Create project | ||
command: | ||
chdir: "{{ tmp_django_root.path }}/startproj" | ||
cmd: "{{ tmp_django_root.path }}/venv/bin/django-admin startproject test_django_command_1" | ||
|
||
- name: Create app | ||
command: | ||
chdir: "{{ tmp_django_root.path }}/startproj" | ||
cmd: "{{ tmp_django_root.path }}/venv/bin/django-admin startapp app1" | ||
|
||
- name: Check | ||
community.general.django_command: | ||
pythonpath: "{{ tmp_django_root.path }}/startproj/test_django_command_1" | ||
settings: test_django_command_1.settings | ||
command: check | ||
venv: "{{ tmp_django_root.path }}/venv" | ||
|
||
- name: Check simple_project | ||
community.general.django_command: | ||
pythonpath: "{{ tmp_django_root.path }}/simple_project/p1" | ||
settings: p1.settings | ||
command: check | ||
venv: "{{ tmp_django_root.path }}/venv" | ||
|
||
- name: Check custom project | ||
community.general.django_command: | ||
pythonpath: "{{ tmp_django_root.path }}/1045-single-app-project/single_app_project" | ||
settings: core.settings | ||
command: check | ||
venv: "{{ tmp_django_root.path }}/venv" | ||
|
||
- name: Run collectstatic --noinput on simple project | ||
community.general.django_command: | ||
pythonpath: "{{ tmp_django_root.path }}/simple_project/p1" | ||
settings: p1.settings | ||
command: collectstatic --noinput | ||
venv: "{{ tmp_django_root.path }}/venv" | ||
|
||
- name: Trigger exception with environment variable | ||
community.general.django_command: | ||
pythonpath: "{{ tmp_django_root.path }}/simple_project/p1" | ||
settings: p1.settings | ||
command: collectstatic --noinput | ||
venv: "{{ tmp_django_root.path }}/venv" | ||
environment: | ||
DJANGO_ANSIBLE_RAISE: blah | ||
ignore_errors: true | ||
register: env_raise | ||
|
||
- name: Check env variable reached manage.py | ||
ansible.builtin.assert: | ||
that: | ||
- "'ValueError: DJANGO_ANSIBLE_RAISE=blah' in env_raise.msg" |