From 0e98491dac9c165fa584abb819cef335609ec06d Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Thu, 17 Dec 2015 11:22:45 -0500 Subject: [PATCH] Remove PROJECTS_ROOT and JOBOUTPUT_ROOT from stngs --- awx/api/views.py | 2 +- awx/main/models/projects.py | 9 +++++---- awx/main/tasks.py | 8 ++++---- awx/main/tests/ad_hoc.py | 4 ++-- awx/main/tests/base.py | 6 +++--- awx/main/tests/projects.py | 4 ++-- awx/main/tests/tasks.py | 4 ++-- awx/main/utils.py | 5 +++-- awx/settings/defaults.py | 14 -------------- 9 files changed, 22 insertions(+), 34 deletions(-) diff --git a/awx/api/views.py b/awx/api/views.py index a87957b0e9..5efb16bbda 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -216,7 +216,7 @@ class ApiV1ConfigView(APIView): if request.user.is_superuser or request.user.admin_of_organizations.filter(active=True).count(): data.update(dict( - project_base_dir = tower_settings.PROJECTS_ROOT, + project_base_dir = settings.PROJECTS_ROOT, project_local_paths = Project.get_local_path_choices(), )) diff --git a/awx/main/models/projects.py b/awx/main/models/projects.py index c266f33971..f494a958f9 100644 --- a/awx/main/models/projects.py +++ b/awx/main/models/projects.py @@ -8,6 +8,7 @@ import re import urlparse # Django +from django.conf import settings from django.db import models from django.utils.translation import ugettext_lazy as _ from django.utils.encoding import smart_str @@ -45,9 +46,9 @@ class ProjectOptions(models.Model): @classmethod def get_local_path_choices(cls): - if os.path.exists(tower_settings.PROJECTS_ROOT): - paths = [x.decode('utf-8') for x in os.listdir(tower_settings.PROJECTS_ROOT) - if (os.path.isdir(os.path.join(tower_settings.PROJECTS_ROOT, x)) and + if os.path.exists(settings.PROJECTS_ROOT): + paths = [x.decode('utf-8') for x in os.listdir(settings.PROJECTS_ROOT) + if (os.path.isdir(os.path.join(settings.PROJECTS_ROOT, x)) and not x.startswith('.') and not x.startswith('_'))] qs = Project.objects.filter(active=True) used_paths = qs.values_list('local_path', flat=True) @@ -143,7 +144,7 @@ class ProjectOptions(models.Model): def get_project_path(self, check_if_exists=True): local_path = os.path.basename(self.local_path) if local_path and not local_path.startswith('.'): - proj_path = os.path.join(tower_settings.PROJECTS_ROOT, local_path) + proj_path = os.path.join(settings.PROJECTS_ROOT, local_path) if not check_if_exists or os.path.exists(smart_str(proj_path)): return proj_path diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 5c888033ad..622c533333 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -537,9 +537,9 @@ class BaseTask(Task): cwd = self.build_cwd(instance, **kwargs) env = self.build_env(instance, **kwargs) safe_env = self.build_safe_env(instance, **kwargs) - if not os.path.exists(tower_settings.JOBOUTPUT_ROOT): - os.makedirs(tower_settings.JOBOUTPUT_ROOT) - stdout_filename = os.path.join(tower_settings.JOBOUTPUT_ROOT, "%d-%s.out" % (pk, str(uuid.uuid1()))) + if not os.path.exists(settings.JOBOUTPUT_ROOT): + os.makedirs(settings.JOBOUTPUT_ROOT) + stdout_filename = os.path.join(settings.JOBOUTPUT_ROOT, "%d-%s.out" % (pk, str(uuid.uuid1()))) stdout_handle = codecs.open(stdout_filename, 'w', encoding='utf-8') if self.should_use_proot(instance, **kwargs): if not check_proot_installed(): @@ -814,7 +814,7 @@ class RunJob(BaseTask): return self.get_path_to('..', 'playbooks') cwd = job.project.get_project_path() if not cwd: - root = tower_settings.PROJECTS_ROOT + root = settings.PROJECTS_ROOT raise RuntimeError('project local_path %s cannot be found in %s' % (job.project.local_path, root)) return cwd diff --git a/awx/main/tests/ad_hoc.py b/awx/main/tests/ad_hoc.py index 095085f039..1e08d83635 100644 --- a/awx/main/tests/ad_hoc.py +++ b/awx/main/tests/ad_hoc.py @@ -331,8 +331,8 @@ class RunAdHocCommandTest(BaseAdHocCommandTest): 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, '*'), - os.path.join(tower_settings.JOBOUTPUT_ROOT, '*'), + os.path.join(settings.PROJECTS_ROOT, '*'), + os.path.join(settings.JOBOUTPUT_ROOT, '*'), ] # Create a temp directory that should not be visible to the command. temp_path = tempfile.mkdtemp() diff --git a/awx/main/tests/base.py b/awx/main/tests/base.py index 027b19e850..cc675aecf4 100644 --- a/awx/main/tests/base.py +++ b/awx/main/tests/base.py @@ -264,14 +264,14 @@ class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin): if not name: name = self.unique_name('Project') - if not os.path.exists(tower_settings.PROJECTS_ROOT): - os.makedirs(tower_settings.PROJECTS_ROOT) + if not os.path.exists(settings.PROJECTS_ROOT): + os.makedirs(settings.PROJECTS_ROOT) # Create temp project directory. if unicode_prefix: tmp_prefix = u'\u2620tmp' else: tmp_prefix = 'tmp' - project_dir = tempfile.mkdtemp(prefix=tmp_prefix, dir=tower_settings.PROJECTS_ROOT) + project_dir = tempfile.mkdtemp(prefix=tmp_prefix, dir=settings.PROJECTS_ROOT) self._temp_paths.append(project_dir) # Create temp playbook in project (if playbook content is given). if playbook_content: diff --git a/awx/main/tests/projects.py b/awx/main/tests/projects.py index e0cab8f03c..5cebd3fe4a 100644 --- a/awx/main/tests/projects.py +++ b/awx/main/tests/projects.py @@ -151,7 +151,7 @@ class ProjectsTest(BaseTransactionTest): url = reverse('api:api_v1_config_view') response = self.get(url, expect=200, auth=self.get_super_credentials()) self.assertTrue('project_base_dir' in response) - self.assertEqual(response['project_base_dir'], tower_settings.PROJECTS_ROOT) + self.assertEqual(response['project_base_dir'], settings.PROJECTS_ROOT) self.assertTrue('project_local_paths' in response) self.assertEqual(set(response['project_local_paths']), set(Project.get_local_path_choices())) @@ -219,7 +219,7 @@ class ProjectsTest(BaseTransactionTest): self.assertEquals(results['count'], 0) # can add projects (super user) - project_dir = tempfile.mkdtemp(dir=tower_settings.PROJECTS_ROOT) + project_dir = tempfile.mkdtemp(dir=settings.PROJECTS_ROOT) self._temp_paths.append(project_dir) project_data = { 'name': 'My Test Project', diff --git a/awx/main/tests/tasks.py b/awx/main/tests/tasks.py index 81ee968b21..90e4ca75ba 100644 --- a/awx/main/tests/tasks.py +++ b/awx/main/tests/tasks.py @@ -1413,8 +1413,8 @@ class RunJobTest(BaseJobExecutionTest): project_path = self.project.local_path job_template = self.create_test_job_template() extra_vars = { - 'projects_root': tower_settings.PROJECTS_ROOT, - 'joboutput_root': tower_settings.JOBOUTPUT_ROOT, + 'projects_root': settings.PROJECTS_ROOT, + 'joboutput_root': settings.JOBOUTPUT_ROOT, 'project_path': project_path, 'other_project_path': other_project_path, 'temp_path': temp_path, diff --git a/awx/main/utils.py b/awx/main/utils.py index de95460201..546c26e3e9 100644 --- a/awx/main/utils.py +++ b/awx/main/utils.py @@ -17,6 +17,7 @@ import contextlib import tempfile # Django REST Framework +from django.conf import settings from rest_framework.exceptions import ParseError, PermissionDenied from django.utils.encoding import smart_str from django.core.urlresolvers import reverse @@ -467,8 +468,8 @@ def wrap_args_with_proot(args, cwd, **kwargs): new_args = [getattr(settings, 'AWX_PROOT_CMD', 'proot'), '-v', str(getattr(settings, 'AWX_PROOT_VERBOSITY', '0')), '-r', '/'] hide_paths = ['/etc/tower', '/var/lib/awx', '/var/log', - tempfile.gettempdir(), tower_settings.PROJECTS_ROOT, - tower_settings.JOBOUTPUT_ROOT] + tempfile.gettempdir(), settings.PROJECTS_ROOT, + settings.JOBOUTPUT_ROOT] hide_paths.extend(getattr(tower_settings, 'AWX_PROOT_HIDE_PATHS', None) or []) for path in sorted(set(hide_paths)): if not os.path.exists(path): diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 2e35c848f7..bf650f40e5 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -682,20 +682,6 @@ FACT_CACHE_PORT = 6564 ORG_ADMINS_CAN_SEE_ALL_USERS = True TOWER_SETTINGS_MANIFEST = { - "PROJECTS_ROOT": { - "name": "Projects Root Directory", - "description": "Directory to store synced projects in and to look for manual projects", - "default": PROJECTS_ROOT, - "type": "string", - "category": "jobs", - }, - "JOBOUTPUT_ROOT": { - "name": "Job Standard Output Directory", - "description": "Directory to store job standard output files", - "default": JOBOUTPUT_ROOT, - "type": "string", - "category": "jobs", - }, "SCHEDULE_MAX_JOBS": { "name": "Maximum Scheduled Jobs", "description": "Maximum number of the same job template that can be waiting to run when launching from a schedule before no more are created",