]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: change bucket owner between owners from same tenant 29485/head
authorAlfonso Martínez <almartin@redhat.com>
Tue, 20 Aug 2019 08:35:06 +0000 (10:35 +0200)
committerAlfonso Martínez <almartin@redhat.com>
Tue, 17 Sep 2019 14:03:24 +0000 (16:03 +0200)
Since https://github.com/ceph/ceph/pull/28813 is in master, the bucket operations
(with tenanted owners) behaviour has changed regarding nautilus, so this fix is
applied to nautilus directly.

Fixes: https://tracker.ceph.com/issues/41067
Signed-off-by: Alfonso Martínez <almartin@redhat.com>
qa/tasks/mgr/dashboard/test_rgw.py
src/pybind/mgr/dashboard/controllers/rgw.py
src/pybind/mgr/dashboard/tox.ini

index b4c0676b0dd6cef7741c59cffdc623b984998cde..34f337f8df37e7ae1288943dcaf85908527fc225 100644 (file)
@@ -114,16 +114,22 @@ class RgwBucketTest(RgwTestCase):
     def setUpClass(cls):
         cls.create_test_user = True
         super(RgwBucketTest, cls).setUpClass()
-        # Create a tenanted user.
+        # Create tenanted users.
         cls._radosgw_admin_cmd([
             'user', 'create', '--tenant', 'testx', '--uid', 'teuth-test-user',
             '--display-name', 'tenanted teuth-test-user'
         ])
+        cls._radosgw_admin_cmd([
+            'user', 'create', '--tenant', 'testx', '--uid', 'teuth-test-user2',
+            '--display-name', 'tenanted teuth-test-user 2'
+        ])
 
     @classmethod
     def tearDownClass(cls):
         cls._radosgw_admin_cmd(
             ['user', 'rm', '--tenant', 'testx', '--uid=teuth-test-user'])
+        cls._radosgw_admin_cmd(
+            ['user', 'rm', '--tenant', 'testx', '--uid=teuth-test-user2'])
         super(RgwBucketTest, cls).tearDownClass()
 
     def test_all(self):
@@ -232,7 +238,22 @@ class RgwBucketTest(RgwTestCase):
         self.assertEqual(data['tenant'], 'testx')
         self.assertEqual(data['bid'], 'testx/teuth-test-bucket')
 
-        # Update the bucket.
+        # Update bucket: different user from same tenant.
+        self._put(
+            '/api/rgw/bucket/{}'.format(
+                urllib.quote_plus('testx/teuth-test-bucket')),
+            params={
+                'bucket_id': data['id'],
+                'uid': 'testx$teuth-test-user2'
+            })
+        self.assertStatus(200)
+        data = self._get('/api/rgw/bucket/{}'.format(
+            urllib.quote_plus('testx/teuth-test-bucket')))
+        self.assertStatus(200)
+        self.assertIn('owner', data)
+        self.assertEqual(data['owner'], 'testx$teuth-test-user2')
+
+        # Update bucket: different user from empty tenant.
         self._put(
             '/api/rgw/bucket/{}'.format(
                 urllib.quote_plus('testx/teuth-test-bucket')),
index 871fa00fdf4eefde1c9dbed24437c62e7fbaa97f..bd7a12b7be2da850bdd91352ae7f6bcb4e33653f 100644 (file)
@@ -121,6 +121,26 @@ class RgwBucket(RgwRESTController):
                 if bucket['tenant'] else bucket['bucket']
         return bucket
 
+    @staticmethod
+    def strip_tenant_from_bucket_name(bucket_name, uid):
+        # type (str, str) => str
+        """
+        When linking a bucket to a new user belonging to same tenant
+        as the previous owner, tenant must be removed from the bucket name.
+        >>> RgwBucket.strip_tenant_from_bucket_name('tenant/bucket-name', 'tenant$user1')
+        'bucket-name'
+        >>> RgwBucket.strip_tenant_from_bucket_name('tenant/bucket-name', 'tenant2$user2')
+        'tenant/bucket-name'
+        >>> RgwBucket.strip_tenant_from_bucket_name('bucket-name', 'user1')
+        'bucket-name'
+        """
+        bucket_tenant = bucket_name[:bucket_name.find('/')] if bucket_name.find('/') >= 0 else None
+        uid_tenant = uid[:uid.find('$')] if uid.find('$') >= 0 else None
+        if bucket_tenant and uid_tenant and bucket_tenant == uid_tenant:
+            return bucket_name[bucket_name.find('/') + 1:]
+
+        return bucket_name
+
     def list(self):
         return self.proxy('GET', 'bucket')
 
@@ -137,7 +157,7 @@ class RgwBucket(RgwRESTController):
 
     def set(self, bucket, bucket_id, uid):
         result = self.proxy('PUT', 'bucket', {
-            'bucket': bucket,
+            'bucket': RgwBucket.strip_tenant_from_bucket_name(bucket, uid),
             'bucket-id': bucket_id,
             'uid': uid
         }, json_response=False)
index d404d59abe138e0b5b657b5794cfea7f2414fafe..b5daa9278e3b24a489e7f8fe77d11c69654507de 100644 (file)
@@ -20,7 +20,7 @@ commands=
     py27: pip install -r {toxinidir}/requirements-py27.txt
     py3: pip install -r {toxinidir}/requirements-py3.txt
     cov: coverage erase
-    cov: {envbindir}/py.test --cov=. --cov-report= --junitxml=junit.{envname}.xml --doctest-modules controllers/rbd.py services/ tests/ tools.py
+    cov: {envbindir}/py.test --cov=. --cov-report= --junitxml=junit.{envname}.xml --doctest-modules controllers services/ tests/ tools.py
     cov: coverage combine {toxinidir}/{env:COVERAGE_FILE}
     cov: coverage report
     cov: coverage xml