mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 18:37:36 -02:30
Merge branch 'devel' into topology-rbac
This commit is contained in:
@@ -2190,7 +2190,7 @@ class BulkHostCreateSerializer(serializers.Serializer):
|
|||||||
host_data = []
|
host_data = []
|
||||||
for r in result:
|
for r in result:
|
||||||
item = {k: getattr(r, k) for k in return_keys}
|
item = {k: getattr(r, k) for k in return_keys}
|
||||||
if not settings.IS_TESTING_MODE:
|
if settings.DATABASES and ('sqlite3' not in settings.DATABASES.get('default', {}).get('ENGINE')):
|
||||||
# sqlite acts different with bulk_create -- it doesn't return the id of the objects
|
# sqlite acts different with bulk_create -- it doesn't return the id of the objects
|
||||||
# to get it, you have to do an additional query, which is not useful for our tests
|
# to get it, you have to do an additional query, which is not useful for our tests
|
||||||
item['url'] = reverse('api:host_detail', kwargs={'pk': r.id})
|
item['url'] = reverse('api:host_detail', kwargs={'pk': r.id})
|
||||||
|
|||||||
@@ -1479,8 +1479,6 @@ class PluginFileInjector(object):
|
|||||||
def build_env(self, inventory_update, env, private_data_dir, private_data_files):
|
def build_env(self, inventory_update, env, private_data_dir, private_data_files):
|
||||||
injector_env = self.get_plugin_env(inventory_update, private_data_dir, private_data_files)
|
injector_env = self.get_plugin_env(inventory_update, private_data_dir, private_data_files)
|
||||||
env.update(injector_env)
|
env.update(injector_env)
|
||||||
# Preserves current behavior for Ansible change in default planned for 2.10
|
|
||||||
env['ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS'] = 'never'
|
|
||||||
# All CLOUD_PROVIDERS sources implement as inventory plugin from collection
|
# All CLOUD_PROVIDERS sources implement as inventory plugin from collection
|
||||||
env['ANSIBLE_INVENTORY_ENABLED'] = 'auto'
|
env['ANSIBLE_INVENTORY_ENABLED'] = 'auto'
|
||||||
return env
|
return env
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"ANSIBLE_JINJA2_NATIVE": "True",
|
"ANSIBLE_JINJA2_NATIVE": "True",
|
||||||
"ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS": "never",
|
|
||||||
"AZURE_CLIENT_ID": "fooo",
|
"AZURE_CLIENT_ID": "fooo",
|
||||||
"AZURE_CLOUD_ENVIRONMENT": "fooo",
|
"AZURE_CLOUD_ENVIRONMENT": "fooo",
|
||||||
"AZURE_SECRET": "fooo",
|
"AZURE_SECRET": "fooo",
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS": "never",
|
|
||||||
"TOWER_HOST": "https://foo.invalid",
|
"TOWER_HOST": "https://foo.invalid",
|
||||||
"TOWER_PASSWORD": "fooo",
|
"TOWER_PASSWORD": "fooo",
|
||||||
"TOWER_USERNAME": "fooo",
|
"TOWER_USERNAME": "fooo",
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"ANSIBLE_JINJA2_NATIVE": "True",
|
"ANSIBLE_JINJA2_NATIVE": "True",
|
||||||
"ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS": "never",
|
|
||||||
"AWS_ACCESS_KEY_ID": "fooo",
|
"AWS_ACCESS_KEY_ID": "fooo",
|
||||||
"AWS_SECRET_ACCESS_KEY": "fooo",
|
"AWS_SECRET_ACCESS_KEY": "fooo",
|
||||||
"AWS_SECURITY_TOKEN": "fooo",
|
"AWS_SECURITY_TOKEN": "fooo",
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"ANSIBLE_JINJA2_NATIVE": "True",
|
"ANSIBLE_JINJA2_NATIVE": "True",
|
||||||
"ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS": "never",
|
|
||||||
"GCE_CREDENTIALS_FILE_PATH": "{{ file_reference }}",
|
"GCE_CREDENTIALS_FILE_PATH": "{{ file_reference }}",
|
||||||
"GOOGLE_APPLICATION_CREDENTIALS": "{{ file_reference }}",
|
"GOOGLE_APPLICATION_CREDENTIALS": "{{ file_reference }}",
|
||||||
"GCP_AUTH_KIND": "serviceaccount",
|
"GCP_AUTH_KIND": "serviceaccount",
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS": "never",
|
|
||||||
"INSIGHTS_USER": "fooo",
|
"INSIGHTS_USER": "fooo",
|
||||||
"INSIGHTS_PASSWORD": "fooo"
|
"INSIGHTS_PASSWORD": "fooo"
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
{
|
{
|
||||||
"ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS": "never",
|
|
||||||
"OS_CLIENT_CONFIG_FILE": "{{ file_reference }}"
|
"OS_CLIENT_CONFIG_FILE": "{{ file_reference }}"
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS": "never",
|
|
||||||
"OVIRT_INI_PATH": "{{ file_reference }}",
|
"OVIRT_INI_PATH": "{{ file_reference }}",
|
||||||
"OVIRT_PASSWORD": "fooo",
|
"OVIRT_PASSWORD": "fooo",
|
||||||
"OVIRT_URL": "https://foo.invalid",
|
"OVIRT_URL": "https://foo.invalid",
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS": "never",
|
|
||||||
"FOREMAN_PASSWORD": "fooo",
|
"FOREMAN_PASSWORD": "fooo",
|
||||||
"FOREMAN_SERVER": "https://foo.invalid",
|
"FOREMAN_SERVER": "https://foo.invalid",
|
||||||
"FOREMAN_USER": "fooo"
|
"FOREMAN_USER": "fooo"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS": "never",
|
|
||||||
"VMWARE_HOST": "https://foo.invalid",
|
"VMWARE_HOST": "https://foo.invalid",
|
||||||
"VMWARE_PASSWORD": "fooo",
|
"VMWARE_PASSWORD": "fooo",
|
||||||
"VMWARE_USER": "fooo",
|
"VMWARE_USER": "fooo",
|
||||||
|
|||||||
28
awx/main/tests/settings_for_test.py
Normal file
28
awx/main/tests/settings_for_test.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Python
|
||||||
|
from unittest import mock
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
# patch python-ldap
|
||||||
|
with mock.patch('__main__.__builtins__.dir', return_value=[]):
|
||||||
|
import ldap # NOQA
|
||||||
|
|
||||||
|
# Load development settings for base variables.
|
||||||
|
from awx.settings.development import * # NOQA
|
||||||
|
|
||||||
|
# Some things make decisions based on settings.SETTINGS_MODULE, so this is done for that
|
||||||
|
SETTINGS_MODULE = 'awx.settings.development'
|
||||||
|
|
||||||
|
# Use SQLite for unit tests instead of PostgreSQL. If the lines below are
|
||||||
|
# commented out, Django will create the test_awx-dev database in PostgreSQL to
|
||||||
|
# run unit tests.
|
||||||
|
CACHES = {'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'LOCATION': 'unique-{}'.format(str(uuid.uuid4()))}}
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
|
'NAME': os.path.join(BASE_DIR, 'awx.sqlite3'), # noqa
|
||||||
|
'TEST': {
|
||||||
|
# Test database cannot be :memory: for inventory tests.
|
||||||
|
'NAME': os.path.join(BASE_DIR, 'awx_test.sqlite3') # noqa
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ LOCAL_SETTINGS = (
|
|||||||
'BROADCAST_WEBSOCKET_PROTOCOL',
|
'BROADCAST_WEBSOCKET_PROTOCOL',
|
||||||
'BROADCAST_WEBSOCKET_SECRET',
|
'BROADCAST_WEBSOCKET_SECRET',
|
||||||
'DATABASES',
|
'DATABASES',
|
||||||
|
'CACHES',
|
||||||
'DEBUG',
|
'DEBUG',
|
||||||
'NAMED_URL_GRAPH',
|
'NAMED_URL_GRAPH',
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,24 +1,16 @@
|
|||||||
# Copyright (c) 2015 Ansible, Inc.
|
# Copyright (c) 2015 Ansible, Inc.
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
|
|
||||||
|
# Python
|
||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
import re # noqa
|
import re # noqa
|
||||||
import sys
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import socket
|
import socket
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
# python-ldap
|
||||||
if "pytest" in sys.modules:
|
import ldap
|
||||||
IS_TESTING_MODE = True
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
with mock.patch('__main__.__builtins__.dir', return_value=[]):
|
|
||||||
import ldap
|
|
||||||
else:
|
|
||||||
IS_TESTING_MODE = False
|
|
||||||
import ldap
|
|
||||||
|
|
||||||
|
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import socket
|
|||||||
import copy
|
import copy
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
import uuid
|
|
||||||
|
|
||||||
# Centos-7 doesn't include the svg mime type
|
# Centos-7 doesn't include the svg mime type
|
||||||
# /usr/lib64/python/mimetypes.py
|
# /usr/lib64/python/mimetypes.py
|
||||||
@@ -65,22 +64,6 @@ INSTALL_UUID = '00000000-0000-0000-0000-000000000000'
|
|||||||
BASE_VENV_PATH = "/var/lib/awx/venv/"
|
BASE_VENV_PATH = "/var/lib/awx/venv/"
|
||||||
AWX_VENV_PATH = os.path.join(BASE_VENV_PATH, "awx")
|
AWX_VENV_PATH = os.path.join(BASE_VENV_PATH, "awx")
|
||||||
|
|
||||||
# Use SQLite for unit tests instead of PostgreSQL. If the lines below are
|
|
||||||
# commented out, Django will create the test_awx-dev database in PostgreSQL to
|
|
||||||
# run unit tests.
|
|
||||||
if "pytest" in sys.modules:
|
|
||||||
CACHES = {'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'LOCATION': 'unique-{}'.format(str(uuid.uuid4()))}}
|
|
||||||
DATABASES = {
|
|
||||||
'default': {
|
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
|
||||||
'NAME': os.path.join(BASE_DIR, 'awx.sqlite3'), # noqa
|
|
||||||
'TEST': {
|
|
||||||
# Test database cannot be :memory: for inventory tests.
|
|
||||||
'NAME': os.path.join(BASE_DIR, 'awx_test.sqlite3') # noqa
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CLUSTER_HOST_ID = socket.gethostname()
|
CLUSTER_HOST_ID = socket.gethostname()
|
||||||
|
|
||||||
AWX_CALLBACK_PROFILE = True
|
AWX_CALLBACK_PROFILE = True
|
||||||
@@ -132,6 +115,6 @@ except ImportError:
|
|||||||
# because conf.d files will define DATABASES and this should modify that
|
# because conf.d files will define DATABASES and this should modify that
|
||||||
from .application_name import set_application_name
|
from .application_name import set_application_name
|
||||||
|
|
||||||
set_application_name(DATABASES, CLUSTER_HOST_ID)
|
set_application_name(DATABASES, CLUSTER_HOST_ID) # NOQA
|
||||||
|
|
||||||
del set_application_name
|
del set_application_name
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from awx.main.models import WorkflowJob
|
|||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_bulk_job_launch(run_module, admin_user, job_template):
|
def test_bulk_job_launch(run_module, admin_user, job_template):
|
||||||
jobs = [dict(unified_job_template=job_template.id)]
|
jobs = [dict(unified_job_template=job_template.id)]
|
||||||
run_module(
|
result = run_module(
|
||||||
'bulk_job_launch',
|
'bulk_job_launch',
|
||||||
{
|
{
|
||||||
'name': "foo-bulk-job",
|
'name': "foo-bulk-job",
|
||||||
@@ -21,6 +21,8 @@ def test_bulk_job_launch(run_module, admin_user, job_template):
|
|||||||
},
|
},
|
||||||
admin_user,
|
admin_user,
|
||||||
)
|
)
|
||||||
|
assert not result.get('failed', False), result.get('msg', result)
|
||||||
|
assert result.get('changed'), result
|
||||||
|
|
||||||
bulk_job = WorkflowJob.objects.get(name="foo-bulk-job")
|
bulk_job = WorkflowJob.objects.get(name="foo-bulk-job")
|
||||||
assert bulk_job.extra_vars == '{"animal": "owl"}'
|
assert bulk_job.extra_vars == '{"animal": "owl"}'
|
||||||
@@ -30,7 +32,7 @@ def test_bulk_job_launch(run_module, admin_user, job_template):
|
|||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_bulk_host_create(run_module, admin_user, inventory):
|
def test_bulk_host_create(run_module, admin_user, inventory):
|
||||||
hosts = [dict(name="127.0.0.1"), dict(name="foo.dns.org")]
|
hosts = [dict(name="127.0.0.1"), dict(name="foo.dns.org")]
|
||||||
run_module(
|
result = run_module(
|
||||||
'bulk_host_create',
|
'bulk_host_create',
|
||||||
{
|
{
|
||||||
'inventory': inventory.name,
|
'inventory': inventory.name,
|
||||||
@@ -38,6 +40,8 @@ def test_bulk_host_create(run_module, admin_user, inventory):
|
|||||||
},
|
},
|
||||||
admin_user,
|
admin_user,
|
||||||
)
|
)
|
||||||
|
assert not result.get('failed', False), result.get('msg', result)
|
||||||
|
assert result.get('changed'), result
|
||||||
resp_hosts = inventory.hosts.all().values_list('name', flat=True)
|
resp_hosts = inventory.hosts.all().values_list('name', flat=True)
|
||||||
for h in hosts:
|
for h in hosts:
|
||||||
assert h['name'] in resp_hosts
|
assert h['name'] in resp_hosts
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[pytest]
|
[pytest]
|
||||||
DJANGO_SETTINGS_MODULE = awx.settings.development
|
DJANGO_SETTINGS_MODULE = awx.main.tests.settings_for_test
|
||||||
python_paths = /var/lib/awx/venv/tower/lib/python3.8/site-packages
|
python_paths = /var/lib/awx/venv/tower/lib/python3.8/site-packages
|
||||||
site_dirs = /var/lib/awx/venv/tower/lib/python3.8/site-packages
|
site_dirs = /var/lib/awx/venv/tower/lib/python3.8/site-packages
|
||||||
python_files = *.py
|
python_files = *.py
|
||||||
|
|||||||
Reference in New Issue
Block a user