示例#1
0
 def test_task_server(self):
     # Create some stats
     t_now = datetime.utcnow()
     dm.save_object(SystemStats(
         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, t_now - timedelta(minutes=5), t_now
     ))
     # We should now have stats
     sys_stats = dm.search_system_stats(t_now - timedelta(minutes=60), t_now)
     self.assertGreater(len(sys_stats), 0)
     # Check current task list entries
     tasks = dm.list_objects(Task, order_field=Task.id)
     task_list_len = len(tasks)
     # Post a background task to purge the stats
     KEEP_SECS = 10
     task_obj = tm.add_task(
         None,
         'Purge system statistics',
         'purge_system_stats',
         {'before_time': t_now},
         Task.PRIORITY_NORMAL,
         'info', 'error',
         KEEP_SECS
     )
     self.assertIsNotNone(task_obj)
     # Check it really got added
     tasks = dm.list_objects(Task, order_field=Task.id)
     self.assertEqual(len(tasks), task_list_len + 1)
     task_list_len = len(tasks)
     # Post it again, make sure there is no dupe added
     dupe_task_obj = tm.add_task(
         None,
         'Purge system statistics',
         'purge_system_stats',
         {'before_time': t_now},
         Task.PRIORITY_NORMAL,
         'info', 'error',
         KEEP_SECS
     )
     self.assertIsNone(dupe_task_obj)
     # Check it really didn't get re-added
     tasks = dm.list_objects(Task, order_field=Task.id)
     self.assertEqual(len(tasks), task_list_len)
     task = tasks[-1]
     self.assertEqual(task.id, task_obj.id)
     # Wait for task completion
     tm.wait_for_task(task_obj.id, 20)
     # We should now have no stats
     t_now = datetime.utcnow()
     sys_stats = dm.search_system_stats(t_now - timedelta(minutes=60), t_now)
     self.assertEqual(len(sys_stats), 0)
     # The completed task should only be removed after the delay we specified
     task = dm.get_object(Task, task_obj.id)
     self.assertIsNotNone(task)
     self.assertEqual(task.status, Task.STATUS_COMPLETE)
     # Wait for keep time + task server's poll time
     time.sleep(KEEP_SECS + 10)
     # Should now be gone
     task = dm.get_object(Task, task_obj.id)
     self.assertIsNone(task)
示例#2
0
 def test_task_server(self):
     # Create some stats
     t_now = datetime.utcnow()
     dm.save_object(
         SystemStats(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                     t_now - timedelta(minutes=5), t_now))
     # We should now have stats
     sys_stats = dm.search_system_stats(t_now - timedelta(minutes=60),
                                        t_now)
     self.assertGreater(len(sys_stats), 0)
     # Check current task list entries
     tasks = dm.list_objects(Task, order_field=Task.id)
     task_list_len = len(tasks)
     # Post a background task to purge the stats
     KEEP_SECS = 10
     task_obj = tm.add_task(None, 'Purge system statistics',
                            'purge_system_stats', {'before_time': t_now},
                            Task.PRIORITY_NORMAL, 'info', 'error',
                            KEEP_SECS)
     self.assertIsNotNone(task_obj)
     # Check it really got added
     tasks = dm.list_objects(Task, order_field=Task.id)
     self.assertEqual(len(tasks), task_list_len + 1)
     task_list_len = len(tasks)
     # Post it again, make sure there is no dupe added
     dupe_task_obj = tm.add_task(None, 'Purge system statistics',
                                 'purge_system_stats',
                                 {'before_time': t_now},
                                 Task.PRIORITY_NORMAL, 'info', 'error',
                                 KEEP_SECS)
     self.assertIsNone(dupe_task_obj)
     # Check it really didn't get re-added
     tasks = dm.list_objects(Task, order_field=Task.id)
     self.assertEqual(len(tasks), task_list_len)
     task = tasks[-1]
     self.assertEqual(task.id, task_obj.id)
     # Wait for task completion
     tm.wait_for_task(task_obj.id, 10)
     # We should now have no stats
     t_now = datetime.utcnow()
     sys_stats = dm.search_system_stats(t_now - timedelta(minutes=60),
                                        t_now)
     self.assertEqual(len(sys_stats), 0)
     # The completed task should only be removed after the delay we specified
     task = dm.get_object(Task, task_obj.id)
     self.assertIsNotNone(task)
     self.assertEqual(task.status, Task.STATUS_COMPLETE)
     # Wait for keep time + task server's poll time
     time.sleep(KEEP_SECS + 10)
     # Should now be gone
     task = dm.get_object(Task, task_obj.id)
     self.assertIsNone(task)
示例#3
0
文件: views_pages.py 项目: quru/qis
def template_list():
    db_default_template = data_engine.get_object(Property,
                                                 Property.DEFAULT_TEMPLATE)
    return render_template('admin_template_list.html',
                           templates=data_engine.list_objects(
                               ImageTemplate, order_field=ImageTemplate.name),
                           system_template_key=db_default_template.key,
                           system_template_value=db_default_template.value)
示例#4
0
文件: views_pages.py 项目: quru/qis
def folder_permissions():
    folder_path = request.args.get('path', '')
    if folder_path == '':
        folder_path = os.path.sep

    group_id = request.args.get('group', '')
    if group_id == '':
        group_id = Group.ID_PUBLIC

    group = None
    folder = None
    current_perms = None
    groups = []
    err_msg = None
    db_session = data_engine.db_get_session()
    try:
        # Get folder and group info
        group = data_engine.get_group(group_id, _db_session=db_session)
        if group is None:
            raise DoesNotExistError('This group no longer exists')
        folder = data_engine.get_folder(folder_path=folder_path, _db_session=db_session)
        if folder is None or folder.status == Folder.STATUS_DELETED:
            raise DoesNotExistError('This folder no longer exists')

        # Get groups list
        groups = data_engine.list_objects(Group, Group.name, _db_session=db_session)

        # Get the current permissions for the folder+group, which can be None.
        # Note that permissions_manager might fall back to the Public group if
        # this is None, but to keep the admin manageable we're going to deal
        # only with folder inheritance, not group inheritance too.
        current_perms = data_engine.get_nearest_folder_permission(
            folder, group,
            _load_nearest_folder=True,
            _db_session=db_session
        )
    except Exception as e:
        log_security_error(e, request)
        err_msg = str(e)
    finally:
        try:
            return render_template(
                'admin_folder_permissions.html',
                group=group,
                folder=folder,
                folder_is_root=folder.is_root() if folder else False,
                current_permissions=current_perms,
                group_list=groups,
                err_msg=err_msg,
                GROUP_ID_PUBLIC=Group.ID_PUBLIC,
                GROUP_ID_EVERYONE=Group.ID_EVERYONE
            )
        finally:
            db_session.close()
示例#5
0
 def get(self, permission_id=None):
     if permission_id is None:
         # List all permissions
         fp_list = data_engine.list_objects(FolderPermission)
         return make_api_success_response(object_to_dict_list(fp_list))
     else:
         # Get permission entry
         fp = data_engine.get_object(FolderPermission, permission_id)
         if fp is None:
             raise DoesNotExistError(str(permission_id))
         return make_api_success_response(object_to_dict(fp))
示例#6
0
 def get(self, permission_id=None):
     if permission_id is None:
         # List all permissions
         fp_list = data_engine.list_objects(FolderPermission)
         return make_api_success_response(object_to_dict_list(fp_list))
     else:
         # Get permission entry
         fp = data_engine.get_object(FolderPermission, permission_id)
         if fp is None:
             raise DoesNotExistError(str(permission_id))
         return make_api_success_response(object_to_dict(fp))
示例#7
0
文件: views_pages.py 项目: quru/qis
def folder_permissions():
    folder_path = request.args.get('path', '')
    if folder_path == '':
        folder_path = os.path.sep

    group_id = request.args.get('group', '')
    if group_id == '':
        group_id = Group.ID_PUBLIC

    group = None
    folder = None
    current_perms = None
    groups = []
    err_msg = None
    db_session = data_engine.db_get_session()
    try:
        # Get folder and group info
        group = data_engine.get_group(group_id, _db_session=db_session)
        if group is None:
            raise DoesNotExistError('This group no longer exists')
        folder = data_engine.get_folder(folder_path=folder_path,
                                        _db_session=db_session)
        if folder is None or folder.status == Folder.STATUS_DELETED:
            raise DoesNotExistError('This folder no longer exists')

        # Get groups list
        groups = data_engine.list_objects(Group,
                                          Group.name,
                                          _db_session=db_session)

        # Get the current permissions for the folder+group, which can be None.
        # Note that permissions_manager might fall back to the Public group if
        # this is None, but to keep the admin manageable we're going to deal
        # only with folder inheritance, not group inheritance too.
        current_perms = data_engine.get_nearest_folder_permission(
            folder, group, _load_nearest_folder=True, _db_session=db_session)
    except Exception as e:
        log_security_error(e, request)
        err_msg = safe_error_str(e)
    finally:
        try:
            return render_template(
                'admin_folder_permissions.html',
                group=group,
                folder=folder,
                folder_is_root=folder.is_root() if folder else False,
                current_permissions=current_perms,
                group_list=groups,
                err_msg=err_msg,
                GROUP_ID_PUBLIC=Group.ID_PUBLIC,
                GROUP_ID_EVERYONE=Group.ID_EVERYONE)
        finally:
            db_session.close()
示例#8
0
 def get(self, group_id=None):
     if group_id is None:
         # List groups
         return make_api_success_response(
             object_to_dict_list(data_engine.list_objects(
                 Group, Group.name)))
     else:
         # Get single group
         group = data_engine.get_group(group_id=group_id, load_users=True)
         if group is None:
             raise DoesNotExistError(str(group_id))
         return make_api_success_response(object_to_dict(group))
示例#9
0
 def get(self, template_id=None):
     if template_id is None:
         # List templates
         tlist = data_engine.list_objects(ImageTemplate, ImageTemplate.name)
         tdictlist = object_to_dict_list(tlist)
         for tdict in tdictlist:
             self._del_keys(tdict['template'], TemplateAPI.HIDE_FIELDS)
         return make_api_success_response(tdictlist)
     else:
         # Get single template
         template_info = data_engine.get_image_template(template_id)
         if template_info is None:
             raise DoesNotExistError(str(template_id))
         tdict = object_to_dict(template_info)
         self._del_keys(tdict['template'], TemplateAPI.HIDE_FIELDS)
         return make_api_success_response(tdict)
示例#10
0
 def get(self, group_id=None):
     if group_id is None:
         # List groups
         return make_api_success_response(
             object_to_dict_list(data_engine.list_objects(Group, Group.name))
         )
     else:
         # Get single group
         group = data_engine.get_group(group_id=group_id, load_users=True)
         if group is None:
             raise DoesNotExistError(str(group_id))
         # Do not give out anything password related
         gdict = object_to_dict(group)
         for udict in gdict['users']:
             del udict['password']
         return make_api_success_response(gdict)
示例#11
0
文件: views_pages.py 项目: quru/qis
def group_list():
    return render_template('admin_group_list.html',
                           groups=data_engine.list_objects(Group, Group.name),
                           GROUP_TYPE_SYSTEM=Group.GROUP_TYPE_SYSTEM)
示例#12
0
文件: views_pages.py 项目: quru/qis
def group_list():
    return render_template(
        'admin_group_list.html',
        groups=data_engine.list_objects(Group, Group.name),
        GROUP_TYPE_SYSTEM=Group.GROUP_TYPE_SYSTEM
    )