diff --git a/awx/api/views.py b/awx/api/views.py index b1c65f2f23..1677bb37be 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -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, diff --git a/awx/main/access.py b/awx/main/access.py index c043855873..a786920b24 100644 --- a/awx/main/access.py +++ b/awx/main/access.py @@ -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) | diff --git a/awx/main/management/commands/inventory_import.py b/awx/main/management/commands/inventory_import.py index 97d5937533..ae5eeb8a25 100644 --- a/awx/main/management/commands/inventory_import.py +++ b/awx/main/management/commands/inventory_import.py @@ -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 diff --git a/awx/main/models/ad_hoc_commands.py b/awx/main/models/ad_hoc_commands.py index 80520cdb1e..e47328844c 100644 --- a/awx/main/models/ad_hoc_commands.py +++ b/awx/main/models/ad_hoc_commands.py @@ -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 diff --git a/awx/main/registrar.py b/awx/main/registrar.py index 6d01ec8d2d..20783745ad 100644 --- a/awx/main/registrar.py +++ b/awx/main/registrar.py @@ -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 diff --git a/awx/main/signals.py b/awx/main/signals.py index 6eb9745830..483626a7c7 100644 --- a/awx/main/signals.py +++ b/awx/main/signals.py @@ -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) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 3c6e18ba0f..5c888033ad 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -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): ''' diff --git a/awx/main/tests/ad_hoc.py b/awx/main/tests/ad_hoc.py index b5ca386c1b..095085f039 100644 --- a/awx/main/tests/ad_hoc.py +++ b/awx/main/tests/ad_hoc.py @@ -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, '*'),