From 985bd6fc8260349b79d07ca0c323a9986fe8be8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E5=B9=BF?= Date: Mon, 17 Dec 2018 11:44:43 +0800 Subject: [PATCH] Bugfix2 (#2183) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Bugfix] 修复错误 * [Bugfix] 修复一些bug --- apps/assets/tasks.py | 21 +++++++++++---------- apps/common/models.py | 2 ++ apps/ops/serializers.py | 2 +- apps/ops/urls/api_urls.py | 1 + apps/ops/views/adhoc.py | 7 +++++-- jms | 4 ++-- 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/apps/assets/tasks.py b/apps/assets/tasks.py index 4b4ec2867..846964d94 100644 --- a/apps/assets/tasks.py +++ b/apps/assets/tasks.py @@ -141,11 +141,11 @@ def update_assets_hardware_info_period(): logger.debug("Period task disabled, update assets hardware info pass") return - from ops.utils import update_or_create_ansible_task - from orgs.models import Organization - orgs = Organization.objects.all().values_list('id', flat=True) - orgs.append('') - task_name = _("Update assets hardware info period") + # from ops.utils import update_or_create_ansible_task + # from orgs.models import Organization + # orgs = Organization.objects.all().values_list('id', flat=True) + # orgs.append('') + # task_name = _("Update assets hardware info period") # for org_id in orgs: # org_id = str(org_id) # hostname_list = [ @@ -354,11 +354,12 @@ def test_system_user_connectability_period(): if PERIOD_TASK != "on": logger.debug("Period task disabled, test system user connectability pass") return - system_users = SystemUser.objects.all() - for system_user in system_users: - task_name = _("Test system user connectability period: {}").format(system_user) - # task_name = _("定期测试系统用户可连接性: {}".format(system_user)) - test_system_user_connectability_util(system_user, task_name) + # Todo: 暂时禁用定期测试 + # system_users = SystemUser.objects.all() + # for system_user in system_users: + # task_name = _("Test system user connectability period: {}").format(system_user) + # # task_name = _("定期测试系统用户可连接性: {}".format(system_user)) + # test_system_user_connectability_util(system_user, task_name) #### Push system user tasks #### diff --git a/apps/common/models.py b/apps/common/models.py index cc5ba8fc5..cb97b8988 100644 --- a/apps/common/models.py +++ b/apps/common/models.py @@ -45,6 +45,8 @@ class Setting(models.Model): def cleaned_value(self): try: value = self.value + if not isinstance(value, (str, bytes)): + return value if self.encrypted: value = signer.unsign(value) value = json.loads(value) diff --git a/apps/ops/serializers.py b/apps/ops/serializers.py index 13423486f..5eb16c5a8 100644 --- a/apps/ops/serializers.py +++ b/apps/ops/serializers.py @@ -53,7 +53,7 @@ class AdHocRunHistorySerializer(serializers.ModelSerializer): @staticmethod def get_stat(obj): return { - "total": len(obj.adhoc.hosts), + "total": obj.adhoc.hosts.count(), "success": len(obj.summary.get("contacted", [])), "failed": len(obj.summary.get("dark", [])), } diff --git a/apps/ops/urls/api_urls.py b/apps/ops/urls/api_urls.py index 615f53a8b..5f955540d 100644 --- a/apps/ops/urls/api_urls.py +++ b/apps/ops/urls/api_urls.py @@ -11,6 +11,7 @@ app_name = "ops" router = DefaultRouter() router.register(r'tasks', api.TaskViewSet, 'task') router.register(r'adhoc', api.AdHocViewSet, 'adhoc') +router.register(r'history', api.AdHocRunHistoryViewSet, 'history') router.register(r'command-executions', api.CommandExecutionViewSet, 'command-execution') urlpatterns = [ diff --git a/apps/ops/views/adhoc.py b/apps/ops/views/adhoc.py index 737047290..f3efbcc70 100644 --- a/apps/ops/views/adhoc.py +++ b/apps/ops/views/adhoc.py @@ -27,7 +27,7 @@ class TaskListView(AdminUserRequiredMixin, DatetimeSearchMixin, ListView): def get_queryset(self): queryset = super().get_queryset() - if current_org.is_real(): + if current_org: queryset = queryset.filter(created_by=current_org.id) else: queryset = queryset.filter(created_by='') @@ -62,8 +62,11 @@ class TaskDetailView(AdminUserRequiredMixin, DetailView): def get_queryset(self): queryset = super().get_queryset() - if current_org: + # Todo: 需要整理默认组织等东西 + if current_org.is_real(): queryset = queryset.filter(created_by=current_org.id) + else: + queryset = queryset.filter(created_by='') return queryset def get_context_data(self, **kwargs): diff --git a/jms b/jms index 1bb6bb56c..613de2fe3 100755 --- a/jms +++ b/jms @@ -26,8 +26,8 @@ LOG_DIR = os.path.join(BASE_DIR, 'logs') TMP_DIR = os.path.join(BASE_DIR, 'tmp') HTTP_HOST = CONFIG.HTTP_BIND_HOST or '127.0.0.1' HTTP_PORT = CONFIG.HTTP_LISTEN_PORT or 8080 -DEBUG = CONFIG.DEBUG -LOG_LEVEL = CONFIG.LOG_LEVEL +DEBUG = CONFIG.DEBUG or False +LOG_LEVEL = CONFIG.LOG_LEVEL or 'INFO' START_TIMEOUT = 40 WORKERS = 4