Skip to content

Commit

Permalink
Chore: Update data structure of xfs_quota to fix taking too long to r…
Browse files Browse the repository at this point in the history
…un (#3989)

* Chore: Update data structure of xfs_quota to fix taking too long to run

Signed-off-by: xintli <[email protected]>

* UPdate doc string

Signed-off-by: xintli <[email protected]>
(cherry picked from commit d3d6cfc)
  • Loading branch information
TZ3070 authored and xiangce committed Jan 11, 2024
1 parent a012992 commit b0f469e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
19 changes: 10 additions & 9 deletions insights/parsers/xfs_quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Parser contains in this module is:
XFSQuotaState - command ``/sbin/xfs_quota -x -c 'state -gu'``
--------------------------------------------------------------
-------------------------------------------------------------
"""

from insights.core import CommandParser
Expand All @@ -21,8 +21,8 @@ class XFSQuotaState(CommandParser):
xfs quota devices.
Attributes:
group_quota (list): List of information for each group quota
user_quota (list): List of information for each user quota
group_quota (dict): Dictionary of information for each group quota
user_quota (dict): Dictionary of information for each user quota
Sample directory list collected::
Expand Down Expand Up @@ -68,14 +68,15 @@ class XFSQuotaState(CommandParser):
<class 'insights.parsers.xfs_quota.XFSQuotaState'>
>>> len(quota_state.user_quota)
3
>>> quota_state.user_quota[0] == {'device': '/dev/sdd', 'accounting': 'ON', 'enforcement': 'ON', 'inode': '#131 (1 blocks, 1 extents)', 'blocks_grace_time': '7 days', 'blocks_max_warnings': '5', 'inodes_grace_time': '7 days', 'inodes_max_warnings': '5', 'realtime_blocks_grace_time': '7 days'}
>>> quota_state.user_quota['/dev/sdd'] == {'device': '/dev/sdd', 'accounting': 'ON', 'enforcement': 'ON', 'inode': '#131 (1 blocks, 1 extents)', 'blocks_grace_time': '7 days', 'blocks_max_warnings': '5', 'inodes_grace_time': '7 days', 'inodes_max_warnings': '5', 'realtime_blocks_grace_time': '7 days'}
True
"""

def parse_content(self, content):
self.user_quota = []
self.group_quota = []
self.user_quota = {}
self.group_quota = {}
data = None
device = None
for line in content:
if not line.strip():
continue
Expand All @@ -85,11 +86,11 @@ def parse_content(self, content):
data = self.group_quota
if 'User ' in line:
data = self.user_quota
data.append({'device': device})
data[device] = data.get(device, dict(device=device))

elif ': ' in line:
elif ': ' in line and device:
key, value = line.split(':', 1)
data[-1]['_'.join(key.strip().lower().split())] = value.strip().lstrip('[').rstrip(']') if '-' not in value else None
data[device]['_'.join(key.strip().lower().split())] = value.strip().lstrip('[').rstrip(']') if '-' not in value else None

if not self.user_quota and not self.group_quota:
raise SkipComponent("Empty result")
10 changes: 5 additions & 5 deletions insights/tests/parsers/test_xfs_quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@
def test_repquota():
results = XFSQuotaState(context_wrap(XFSQUOTASTATE))
assert len(results.group_quota) == 3
assert results.group_quota[0]['device'] == '/dev/sdd'
assert results.group_quota[0]['accounting'] == 'OFF'
assert results.group_quota[0]['blocks_grace_time'] is None
assert results.group_quota['/dev/sdd']['device'] == '/dev/sdd'
assert results.group_quota['/dev/sdd']['accounting'] == 'OFF'
assert results.group_quota['/dev/sdd']['blocks_grace_time'] is None
assert len(results.user_quota) == 3
assert results.group_quota[-1]['accounting'] == 'ON'
assert results.user_quota[-1] == {'device': '/dev/sdc', 'accounting': 'ON', 'enforcement': 'ON', 'inode': '#131 (2 blocks, 2 extents)', 'blocks_grace_time': '7 days', 'blocks_max_warnings': '20', 'inodes_grace_time': '7 days', 'inodes_max_warnings': '5', 'realtime_blocks_grace_time': '7 days'}
assert results.group_quota['/dev/sdc']['accounting'] == 'ON'
assert results.user_quota['/dev/sdc'] == {'device': '/dev/sdc', 'accounting': 'ON', 'enforcement': 'ON', 'inode': '#131 (2 blocks, 2 extents)', 'blocks_grace_time': '7 days', 'blocks_max_warnings': '20', 'inodes_grace_time': '7 days', 'inodes_max_warnings': '5', 'realtime_blocks_grace_time': '7 days'}


def test_repquota_err():
Expand Down

0 comments on commit b0f469e

Please sign in to comment.