Unverified Commit 985bd6fc authored by 老广's avatar 老广 Committed by GitHub

Bugfix2 (#2183)

* [Bugfix] 修复错误

* [Bugfix] 修复一些bug
parent 374039d2
...@@ -141,11 +141,11 @@ def update_assets_hardware_info_period(): ...@@ -141,11 +141,11 @@ def update_assets_hardware_info_period():
logger.debug("Period task disabled, update assets hardware info pass") logger.debug("Period task disabled, update assets hardware info pass")
return return
from ops.utils import update_or_create_ansible_task # from ops.utils import update_or_create_ansible_task
from orgs.models import Organization # from orgs.models import Organization
orgs = Organization.objects.all().values_list('id', flat=True) # orgs = Organization.objects.all().values_list('id', flat=True)
orgs.append('') # orgs.append('')
task_name = _("Update assets hardware info period") # task_name = _("Update assets hardware info period")
# for org_id in orgs: # for org_id in orgs:
# org_id = str(org_id) # org_id = str(org_id)
# hostname_list = [ # hostname_list = [
...@@ -354,11 +354,12 @@ def test_system_user_connectability_period(): ...@@ -354,11 +354,12 @@ def test_system_user_connectability_period():
if PERIOD_TASK != "on": if PERIOD_TASK != "on":
logger.debug("Period task disabled, test system user connectability pass") logger.debug("Period task disabled, test system user connectability pass")
return return
system_users = SystemUser.objects.all() # Todo: 暂时禁用定期测试
for system_user in system_users: # system_users = SystemUser.objects.all()
task_name = _("Test system user connectability period: {}").format(system_user) # for system_user in system_users:
# task_name = _("定期测试系统用户可连接性: {}".format(system_user)) # task_name = _("Test system user connectability period: {}").format(system_user)
test_system_user_connectability_util(system_user, task_name) # # task_name = _("定期测试系统用户可连接性: {}".format(system_user))
# test_system_user_connectability_util(system_user, task_name)
#### Push system user tasks #### #### Push system user tasks ####
......
...@@ -45,6 +45,8 @@ class Setting(models.Model): ...@@ -45,6 +45,8 @@ class Setting(models.Model):
def cleaned_value(self): def cleaned_value(self):
try: try:
value = self.value value = self.value
if not isinstance(value, (str, bytes)):
return value
if self.encrypted: if self.encrypted:
value = signer.unsign(value) value = signer.unsign(value)
value = json.loads(value) value = json.loads(value)
......
...@@ -53,7 +53,7 @@ class AdHocRunHistorySerializer(serializers.ModelSerializer): ...@@ -53,7 +53,7 @@ class AdHocRunHistorySerializer(serializers.ModelSerializer):
@staticmethod @staticmethod
def get_stat(obj): def get_stat(obj):
return { return {
"total": len(obj.adhoc.hosts), "total": obj.adhoc.hosts.count(),
"success": len(obj.summary.get("contacted", [])), "success": len(obj.summary.get("contacted", [])),
"failed": len(obj.summary.get("dark", [])), "failed": len(obj.summary.get("dark", [])),
} }
......
...@@ -11,6 +11,7 @@ app_name = "ops" ...@@ -11,6 +11,7 @@ app_name = "ops"
router = DefaultRouter() router = DefaultRouter()
router.register(r'tasks', api.TaskViewSet, 'task') router.register(r'tasks', api.TaskViewSet, 'task')
router.register(r'adhoc', api.AdHocViewSet, 'adhoc') router.register(r'adhoc', api.AdHocViewSet, 'adhoc')
router.register(r'history', api.AdHocRunHistoryViewSet, 'history')
router.register(r'command-executions', api.CommandExecutionViewSet, 'command-execution') router.register(r'command-executions', api.CommandExecutionViewSet, 'command-execution')
urlpatterns = [ urlpatterns = [
......
...@@ -27,7 +27,7 @@ class TaskListView(AdminUserRequiredMixin, DatetimeSearchMixin, ListView): ...@@ -27,7 +27,7 @@ class TaskListView(AdminUserRequiredMixin, DatetimeSearchMixin, ListView):
def get_queryset(self): def get_queryset(self):
queryset = super().get_queryset() queryset = super().get_queryset()
if current_org.is_real(): if current_org:
queryset = queryset.filter(created_by=current_org.id) queryset = queryset.filter(created_by=current_org.id)
else: else:
queryset = queryset.filter(created_by='') queryset = queryset.filter(created_by='')
...@@ -62,8 +62,11 @@ class TaskDetailView(AdminUserRequiredMixin, DetailView): ...@@ -62,8 +62,11 @@ class TaskDetailView(AdminUserRequiredMixin, DetailView):
def get_queryset(self): def get_queryset(self):
queryset = super().get_queryset() queryset = super().get_queryset()
if current_org: # Todo: 需要整理默认组织等东西
if current_org.is_real():
queryset = queryset.filter(created_by=current_org.id) queryset = queryset.filter(created_by=current_org.id)
else:
queryset = queryset.filter(created_by='')
return queryset return queryset
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
......
...@@ -26,8 +26,8 @@ LOG_DIR = os.path.join(BASE_DIR, 'logs') ...@@ -26,8 +26,8 @@ LOG_DIR = os.path.join(BASE_DIR, 'logs')
TMP_DIR = os.path.join(BASE_DIR, 'tmp') TMP_DIR = os.path.join(BASE_DIR, 'tmp')
HTTP_HOST = CONFIG.HTTP_BIND_HOST or '127.0.0.1' HTTP_HOST = CONFIG.HTTP_BIND_HOST or '127.0.0.1'
HTTP_PORT = CONFIG.HTTP_LISTEN_PORT or 8080 HTTP_PORT = CONFIG.HTTP_LISTEN_PORT or 8080
DEBUG = CONFIG.DEBUG DEBUG = CONFIG.DEBUG or False
LOG_LEVEL = CONFIG.LOG_LEVEL LOG_LEVEL = CONFIG.LOG_LEVEL or 'INFO'
START_TIMEOUT = 40 START_TIMEOUT = 40
WORKERS = 4 WORKERS = 4
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment