Update settings references

* PROOT
* Pendo tracking state
* ad hoc commands
* activity stream
* org admin visibility
This commit is contained in:
Matthew Jones 2015-12-15 16:44:08 -05:00
parent a4d4e6d0fb
commit 35b19bf220
8 changed files with 22 additions and 17 deletions

View File

@ -194,7 +194,7 @@ class ApiV1ConfigView(APIView):
license_reader = TaskSerializer()
license_data = license_reader.from_file(show_key=request.user.is_superuser)
pendo_state = settings.PENDO_TRACKING_STATE if settings.PENDO_TRACKING_STATE in ('off', 'anonymous', 'detailed') else 'off'
pendo_state = tower_settings.PENDO_TRACKING_STATE if tower_settings.PENDO_TRACKING_STATE in ('off', 'anonymous', 'detailed') else 'off'
data = dict(
time_zone=settings.TIME_ZONE,

View File

@ -19,6 +19,7 @@ from awx.main.utils import * # noqa
from awx.main.models import * # noqa
from awx.api.license import LicenseForbids
from awx.main.task_engine import TaskSerializer
from awx.main.conf import tower_settings
__all__ = ['get_user_queryset', 'check_user_access']
@ -196,7 +197,7 @@ class UserAccess(BaseAccess):
qs = self.model.objects.filter(is_active=True).distinct()
if self.user.is_superuser:
return qs
if settings.ORG_ADMINS_CAN_SEE_ALL_USERS and self.user.admin_of_organizations.filter(active=True).exists():
if tower_settings.ORG_ADMINS_CAN_SEE_ALL_USERS and self.user.admin_of_organizations.filter(active=True).exists():
return qs
return qs.filter(
Q(pk=self.user.pk) |

View File

@ -28,6 +28,7 @@ from awx.main.models import * # noqa
from awx.main.utils import ignore_inventory_computed_fields, check_proot_installed, wrap_args_with_proot
from awx.main.signals import disable_activity_stream
from awx.main.task_engine import TaskSerializer as LicenseReader
from awx.main.conf import tower_settings
logger = logging.getLogger('awx.main.commands.inventory_import')
@ -356,7 +357,7 @@ class ExecutableJsonLoader(BaseLoader):
data = {}
stdout, stderr = '', ''
try:
if self.is_custom and getattr(settings, 'AWX_PROOT_ENABLED', False):
if self.is_custom and getattr(tower_settings, 'AWX_PROOT_ENABLED', False):
if not check_proot_installed():
raise RuntimeError("proot is not installed but is configured for use")
kwargs = {'proot_temp_dir': self.source_dir} # TODO: Remove proot dir

View File

@ -21,6 +21,7 @@ from jsonfield import JSONField
from awx.main.models.base import * # noqa
from awx.main.models.unified_jobs import * # noqa
from awx.main.utils import decrypt_field
from awx.main.conf import tower_settings
logger = logging.getLogger('awx.main.models.ad_hoc_commands')
@ -29,8 +30,8 @@ __all__ = ['AdHocCommand', 'AdHocCommandEvent']
class AdHocCommand(UnifiedJob):
MODULE_NAME_CHOICES = [(x,x) for x in settings.AD_HOC_COMMANDS]
MODULE_NAME_DEFAULT = 'command' if 'command' in settings.AD_HOC_COMMANDS else None
MODULE_NAME_CHOICES = [(x,x) for x in tower_settings.AD_HOC_COMMANDS]
MODULE_NAME_DEFAULT = 'command' if 'command' in tower_settings.AD_HOC_COMMANDS else None
class Meta(object):
app_label = 'main'
@ -104,7 +105,7 @@ class AdHocCommand(UnifiedJob):
if type(self.module_name) not in (str, unicode):
raise ValidationError("Invalid type for ad hoc command")
module_name = self.module_name.strip() or 'command'
if module_name not in settings.AD_HOC_COMMANDS:
if module_name not in tower_settings.AD_HOC_COMMANDS:
raise ValidationError('Unsupported module for ad hoc commands.')
return module_name

View File

@ -14,7 +14,8 @@ class ActivityStreamRegistrar(object):
self.models = []
def connect(self, model):
if not getattr(settings, 'ACTIVITY_STREAM_ENABLED', True):
from awx.main.conf import tower_settings
if not getattr(tower_settings, 'ACTIVITY_STREAM_ENABLED', True):
return
from awx.main.signals import activity_stream_create, activity_stream_update, activity_stream_delete, activity_stream_associate

View File

@ -22,6 +22,7 @@ from awx.api.serializers import * # noqa
from awx.main.utils import model_instance_diff, model_to_dict, camelcase_to_underscore, emit_websocket_notification
from awx.main.utils import ignore_inventory_computed_fields, ignore_inventory_group_removal, _inventory_updates
from awx.main.tasks import update_inventory_computed_fields
from awx.main.conf import tower_settings
__all__ = []
@ -273,7 +274,7 @@ def update_host_last_job_after_job_deleted(sender, **kwargs):
class ActivityStreamEnabled(threading.local):
def __init__(self):
self.enabled = getattr(settings, 'ACTIVITY_STREAM_ENABLED', True)
self.enabled = getattr(tower_settings, 'ACTIVITY_STREAM_ENABLED', True)
def __nonzero__(self):
return bool(self.enabled)

View File

@ -349,7 +349,7 @@ class BaseTask(Task):
python_paths.insert(0, local_site_packages)
env['PYTHONPATH'] = os.pathsep.join(python_paths)
if self.should_use_proot:
env['PROOT_TMP_DIR'] = settings.AWX_PROOT_BASE_PATH
env['PROOT_TMP_DIR'] = tower_settings.AWX_PROOT_BASE_PATH
return env
def build_safe_env(self, instance, **kwargs):
@ -462,7 +462,7 @@ class BaseTask(Task):
instance = self.update_model(instance.pk)
if instance.cancel_flag:
try:
if settings.AWX_PROOT_ENABLED:
if tower_settings.AWX_PROOT_ENABLED:
# NOTE: Refactor this once we get a newer psutil across the board
if not psutil:
os.kill(child.pid, signal.SIGKILL)
@ -655,9 +655,9 @@ class RunJob(BaseTask):
'''
plugin_dir = self.get_path_to('..', 'plugins', 'callback')
plugin_dirs = [plugin_dir]
if hasattr(settings, 'AWX_ANSIBLE_CALLBACK_PLUGINS') and \
settings.AWX_ANSIBLE_CALLBACK_PLUGINS:
plugin_dirs.append(settings.AWX_ANSIBLE_CALLBACK_PLUGINS)
if hasattr(tower_settings, 'AWX_ANSIBLE_CALLBACK_PLUGINS') and \
tower_settings.AWX_ANSIBLE_CALLBACK_PLUGINS:
plugin_dirs.append(tower_settings.AWX_ANSIBLE_CALLBACK_PLUGINS)
plugin_path = ':'.join(plugin_dirs)
env = super(RunJob, self).build_env(job, **kwargs)
# Set environment variables needed for inventory and job event
@ -851,7 +851,7 @@ class RunJob(BaseTask):
'''
Return whether this task should use proot.
'''
return getattr(settings, 'AWX_PROOT_ENABLED', False)
return getattr(tower_settings, 'AWX_PROOT_ENABLED', False)
def pre_run_hook(self, job, **kwargs):
if job.job_type == PERM_INVENTORY_SCAN:
@ -1476,7 +1476,7 @@ class RunAdHocCommand(BaseTask):
'''
Return whether this task should use proot.
'''
return getattr(settings, 'AWX_PROOT_ENABLED', False)
return getattr(tower_settings, 'AWX_PROOT_ENABLED', False)
def post_run_hook(self, ad_hoc_command, **kwargs):
'''

View File

@ -326,9 +326,9 @@ class RunAdHocCommandTest(BaseAdHocCommandTest):
if not has_proot:
self.skipTest('proot is not installed')
# Enable proot for this test.
tower_settings.AWX_PROOT_ENABLED = True
settings.AWX_PROOT_ENABLED = True
# Hide local settings path.
tower_settings.AWX_PROOT_HIDE_PATHS = [os.path.join(settings.BASE_DIR, 'settings')]
settings.AWX_PROOT_HIDE_PATHS = [os.path.join(settings.BASE_DIR, 'settings')]
# Create list of paths that should not be visible to the command.
hidden_paths = [
os.path.join(tower_settings.PROJECTS_ROOT, '*'),