From cacce05f7cce9a765d539a84b1c9f008f0e1a876 Mon Sep 17 00:00:00 2001 From: shirady <57721533+shirady@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:11:40 +0300 Subject: [PATCH] NC | NSFS | Head object on tagged object does not return x-amz-tagging-count header 1. In namespace_fs return tag_count which is the sum of all the extended attribute that has the prefix `user.noobaa.tag.`. 2. Rename XATTR_NOOBAA_CUSTOM_PREFIX to XATTR_TAG and move the variable declaration to a lower place in the variable declaration list. Signed-off-by: shirady <57721533+shirady@users.noreply.github.com> --- src/sdk/namespace_fs.js | 19 ++++++++++++------- .../nsfs_s3_tests_pending_list.txt | 1 - 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/sdk/namespace_fs.js b/src/sdk/namespace_fs.js index e5ea08253c..f876307cce 100644 --- a/src/sdk/namespace_fs.js +++ b/src/sdk/namespace_fs.js @@ -52,7 +52,6 @@ const multi_buffer_pool = new buffer_utils.MultiSizeBuffersPool({ const XATTR_USER_PREFIX = 'user.'; const XATTR_NOOBAA_INTERNAL_PREFIX = XATTR_USER_PREFIX + 'noobaa.'; -const XATTR_NOOBAA_CUSTOM_PREFIX = XATTR_NOOBAA_INTERNAL_PREFIX + 'tag.'; // TODO: In order to verify validity add content_md5_mtime as well const XATTR_MD5_KEY = XATTR_USER_PREFIX + 'content_md5'; const XATTR_CONTENT_TYPE = XATTR_NOOBAA_INTERNAL_PREFIX + 'content_type'; @@ -63,6 +62,7 @@ const XATTR_VERSION_ID = XATTR_NOOBAA_INTERNAL_PREFIX + 'version_id'; const XATTR_PREV_VERSION_ID = XATTR_NOOBAA_INTERNAL_PREFIX + 'prev_version_id'; const XATTR_DELETE_MARKER = XATTR_NOOBAA_INTERNAL_PREFIX + 'delete_marker'; const XATTR_DIR_CONTENT = XATTR_NOOBAA_INTERNAL_PREFIX + 'dir_content'; +const XATTR_TAG = XATTR_NOOBAA_INTERNAL_PREFIX + 'tag.'; const HIDDEN_VERSIONS_PATH = '.versions'; const NULL_VERSION_ID = 'null'; const NULL_VERSION_SUFFIX = '_' + NULL_VERSION_ID; @@ -1967,9 +1967,9 @@ class NamespaceFS { const stat = await file.stat(fs_context); if (stat.xattr) { for (const [xattr_key, xattr_value] of Object.entries(stat.xattr)) { - if (xattr_key.includes(XATTR_NOOBAA_CUSTOM_PREFIX)) { + if (xattr_key.includes(XATTR_TAG)) { tag_set.push({ - key: xattr_key.replace(XATTR_NOOBAA_CUSTOM_PREFIX, ''), + key: xattr_key.replace(XATTR_TAG, ''), value: xattr_value, }); } @@ -1993,7 +1993,7 @@ class NamespaceFS { } const fs_context = this.prepare_fs_context(object_sdk); try { - await this._clear_user_xattr(fs_context, file_path, XATTR_NOOBAA_CUSTOM_PREFIX); + await this._clear_user_xattr(fs_context, file_path, XATTR_TAG); } catch (err) { dbg.error(`NamespaceFS.delete_object_tagging: failed in dir ${file_path} with error: `, err); throw native_fs_utils.translate_error_codes(err, native_fs_utils.entity_enum.OBJECT); @@ -2005,7 +2005,7 @@ class NamespaceFS { const fs_xattr = {}; const tagging = params.tagging && Object.fromEntries(params.tagging.map(tag => ([tag.key, tag.value]))); for (const [xattr_key, xattr_value] of Object.entries(tagging)) { - fs_xattr[XATTR_NOOBAA_CUSTOM_PREFIX + xattr_key] = xattr_value; + fs_xattr[XATTR_TAG + xattr_key] = xattr_value; } let file_path; if (params.version_id && this._is_versioning_enabled()) { @@ -2017,7 +2017,7 @@ class NamespaceFS { dbg.log0('NamespaceFS.put_object_tagging: fs_xattr ', fs_xattr, 'file_path :', file_path); try { // remove existng tag before putting new tags - await this._clear_user_xattr(fs_context, file_path, XATTR_NOOBAA_CUSTOM_PREFIX); + await this._clear_user_xattr(fs_context, file_path, XATTR_TAG); await this.set_fs_xattr_op(fs_context, file_path, fs_xattr, undefined); } catch (err) { dbg.error(`NamespaceFS.put_object_tagging: failed in dir ${file_path} with error: `, err); @@ -2316,6 +2316,10 @@ class NamespaceFS { return xattr[XATTR_MD5_KEY]; } + _number_of_tags_fs_xttr(xattr) { + return Object.keys(xattr).filter(xattr_key => xattr_key.includes(XATTR_TAG)).length; + } + /** * @param {string} bucket * @param {string} key @@ -2336,6 +2340,7 @@ class NamespaceFS { mime.getType(key) || 'application/octet-stream'; const storage_class = s3_utils.parse_storage_class(stat.xattr?.[XATTR_STORAGE_CLASS_KEY]); const size = Number(stat.xattr?.[XATTR_DIR_CONTENT] || stat.size); + const tag_count = stat.xattr ? this._number_of_tags_fs_xttr(stat.xattr) : 0; return { obj_id: etag, @@ -2352,9 +2357,9 @@ class NamespaceFS { storage_class, restore_status: GlacierBackend.get_restore_status(stat.xattr, new Date(), this._get_file_path({key})), xattr: to_xattr(stat.xattr), + tag_count, // temp: - tag_count: 0, lock_settings: undefined, md5_b64: undefined, num_parts: undefined, diff --git a/src/test/system_tests/ceph_s3_tests/s3-tests-lists/nsfs_s3_tests_pending_list.txt b/src/test/system_tests/ceph_s3_tests/s3-tests-lists/nsfs_s3_tests_pending_list.txt index 785cc24750..0407bb7923 100644 --- a/src/test/system_tests/ceph_s3_tests/s3-tests-lists/nsfs_s3_tests_pending_list.txt +++ b/src/test/system_tests/ceph_s3_tests/s3-tests-lists/nsfs_s3_tests_pending_list.txt @@ -177,7 +177,6 @@ s3tests_boto3/functional/test_s3.py::test_bucketv2_policy s3tests_boto3/functional/test_s3.py::test_bucket_policy_another_bucket s3tests_boto3/functional/test_s3.py::test_bucketv2_policy_another_bucket s3tests_boto3/functional/test_s3.py::test_get_obj_tagging -s3tests_boto3/functional/test_s3.py::test_get_obj_head_tagging s3tests_boto3/functional/test_s3.py::test_put_max_tags s3tests_boto3/functional/test_s3.py::test_bucket_policy_put_obj_s3_noenc s3tests_boto3/functional/test_s3.py::test_copy_object_ifmatch_failed