Bug #54254
closedwhen the remove-all parameter of rgw admin operation trim usage interface is set false, the usage is trimmed.
0%
Description
when the remove-all parameter of rgw admin operation trim usage interface is set false, the usage is trimmed. i use the python3 rgwadmin package, the test code and output is following:
-------------------------------- the test code ----------------------------------
def test_trim_usage_without_uid_remove_all_false(self):
tmp_user = 'test_trim_usage_without_uid_remove_all_false'
tmp_bucket = 'test_trim_usage_without_uid_remove_all_false'
self.rgw.trim_usage(remove_all=True)
user_info = {
'uid': tmp_user,
'display_name': tmp_user,
'access_key': tmp_user,
'secret_key': tmp_user,
'suspended': False
}
self.rgw.create_user(**user_info)
session = Session(
aws_access_key_id=user_info['access_key'],
aws_secret_access_key=user_info['secret_key']
)
s3_client = session.client(
's3',
endpoint_url='http://'+AdminConfig.host+':'+AdminConfig.port,
config=Config(signature_version='s3v4')
)
s3_client.create_bucket(Bucket=tmp_bucket)
# 造一个大小10M的文件
if platform.system() == 'Windows':
tmp_file = open('./tmp.txt', 'w')
tmp_file.seek(1024 * 1024 * 10 - 1)
tmp_file.write('\x00')
tmp_file.close()
elif platform.system() == 'Linux':
os.system('dd if=/dev/zero of=./tmp.txt bs=1M count=10')
with open('tmp.txt', 'rb') as test_file:
content = test_file.read()
s3_client.put_object(
Bucket=tmp_bucket,
Body=content,
Key='tmp.txt'
)
os.remove('tmp.txt')
time.sleep(60)
res_before_trim = self.rgw.get_usage(show_entries=True, show_summary=True)
print(res_before_trim)
print('--------------')
self.rgw.trim_usage()
print('--------------')
time.sleep(120)
res_after_trim = self.rgw.get_usage(show_entries=True, show_summary=True)
print(res_after_trim)
---------------------------------- output is following -------------------------
{'entries': [{'user': 'test_trim_usage_without_uid_remove_all_false', 'buckets': [{'bucket': 'test_trim_usage_without_uid_remove_all_false', 'time': '2022-02-11 02:00:00.000000Z', 'epoch': 1644544800, 'owner': 'test_trim_usage_without_uid_remove_all_false', 'categories': [{'category': 'create_bucket', 'bytes_sent': 0, 'bytes_received': 0, 'ops': 1, 'successful_ops': 1}, {'category': 'put_obj', 'bytes_sent': 0, 'bytes_received': 10485760, 'ops': 1, 'successful_ops': 1}]}]}], 'summary': [{'user': 'test_trim_usage_without_uid_remove_all_false', 'categories': [{'category': 'create_bucket', 'bytes_sent': 0, 'bytes_received': 0, 'ops': 1, 'successful_ops': 1}, {'category': 'put_obj', 'bytes_sent': 0, 'bytes_received': 10485760, 'ops': 1, 'successful_ops': 1}], 'total': {'bytes_sent': 0, 'bytes_received': 10485760, 'ops': 2, 'successful_ops': 2}}]}
--------------
--------------
{'entries': [], 'summary': []}
Updated by Casey Bodley over 1 year ago
- Status changed from New to Fix Under Review
- Tags set to adminapi usage
- Pull request ID set to 49402
Updated by Casey Bodley over 1 year ago
- Status changed from Fix Under Review to Resolved