]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
radosgw_user: support account feature main
authorSteffen Bohr <steffen.bohr@github.execve.de>
Thu, 9 Jul 2026 11:51:26 +0000 (11:51 +0000)
committerSeena Fallah <seenafallah@gmail.com>
Thu, 23 Jul 2026 21:43:35 +0000 (23:43 +0200)
Add support to add rgw users to an rgw account. Update tests
accordingly

Signed-off-by: Steffen Bohr <steffen.bohr@github.execve.de>
library/radosgw_user.py
tests/library/test_radosgw_user.py

index 1142eb0e1cf67e588ef320acd8326dcef9aae4e3..fe63f0ffd0b686f01055c91bc894c9c5e7492828 100644 (file)
@@ -102,6 +102,16 @@ options:
             - set the admin flag on the user.
         required: false
         default: false
             - set the admin flag on the user.
         required: false
         default: false
+    account_id:
+        description:
+            - account-id the user is associated with.
+        required: false
+        default: None
+    account_root:
+        description:
+            - set the account-root flag of the user.
+        required: false
+        default: false
 
 author:
     - Dimitri Savineau <dsavinea@redhat.com>
 
 author:
     - Dimitri Savineau <dsavinea@redhat.com>
@@ -242,6 +252,8 @@ def create_user(module, container_image=None):
     system = module.params.get('system', False)
     admin = module.params.get('admin', False)
     caps = module.params.get('caps')
     system = module.params.get('system', False)
     admin = module.params.get('admin', False)
     caps = module.params.get('caps')
+    account_id = module.params.get('account_id')
+    account_root = module.params.get('account_root')
 
     args = ['create', '--uid=' + name, '--display_name=' + display_name]
 
 
     args = ['create', '--uid=' + name, '--display_name=' + display_name]
 
@@ -269,6 +281,12 @@ def create_user(module, container_image=None):
     if admin:
         args.append('--admin')
 
     if admin:
         args.append('--admin')
 
+    if account_id:
+        args.extend(['--account-id=' + account_id])
+
+    if account_root:
+        args.append('--account-root')
+
     if caps:
         caps_args = [f"{cap['type']}={cap['perm']}" for cap in caps]
         args.extend(['--caps=' + ';'.join(caps_args)])
     if caps:
         caps_args = [f"{cap['type']}={cap['perm']}" for cap in caps]
         args.extend(['--caps=' + ';'.join(caps_args)])
@@ -360,6 +378,8 @@ def modify_user(module, container_image=None):
     zone = module.params.get('zone', None)
     system = module.params.get('system', False)
     admin = module.params.get('admin', False)
     zone = module.params.get('zone', None)
     system = module.params.get('system', False)
     admin = module.params.get('admin', False)
+    account_id = module.params.get('account_id')
+    account_root = module.params.get('account_root')
 
     args = ['modify', '--uid=' + name]
 
 
     args = ['modify', '--uid=' + name]
 
@@ -390,6 +410,12 @@ def modify_user(module, container_image=None):
     if admin:
         args.append('--admin')
 
     if admin:
         args.append('--admin')
 
+    if account_id:
+        args.extend(['--account-id=' + account_id])
+
+    if account_root:
+        args.append('--account-root')
+
     cmd = generate_radosgw_cmd(cluster=cluster,
                                args=args,
                                container_image=container_image)
     cmd = generate_radosgw_cmd(cluster=cluster,
                                args=args,
                                container_image=container_image)
@@ -487,6 +513,8 @@ def run_module():
         system=dict(type='bool', required=False, default=False),
         admin=dict(type='bool', required=False, default=False),
         caps=dict(type='list', required=False),
         system=dict(type='bool', required=False, default=False),
         admin=dict(type='bool', required=False, default=False),
         caps=dict(type='list', required=False),
+        account_id=dict(type='str', required=False),
+        account_root=dict(type='bool', required=False, default=False)
     )
 
     module = AnsibleModule(
     )
 
     module = AnsibleModule(
index 374c5121919debce4300b32c43bc21fdc2917e97..272c094364b168f0ea62ad33c9a34b308d437074 100644 (file)
@@ -25,6 +25,7 @@ fake_user = 'foo'
 fake_realm = 'canada'
 fake_zonegroup = 'quebec'
 fake_zone = 'montreal'
 fake_realm = 'canada'
 fake_zonegroup = 'quebec'
 fake_zone = 'montreal'
+fake_account_id = 'RGW93485238593854'
 fake_params = {'cluster': fake_cluster,
                'name': fake_user,
                'display_name': fake_user,
 fake_params = {'cluster': fake_cluster,
                'name': fake_user,
                'display_name': fake_user,
@@ -36,6 +37,9 @@ fake_params = {'cluster': fake_cluster,
                'zone': fake_zone,
                'system': True,
                'admin': True}
                'zone': fake_zone,
                'system': True,
                'admin': True}
+fake_params_with_account = dict(fake_params,
+                                account_id=fake_account_id,
+                                account_root=True)
 
 
 class TestRadosgwUserModule(object):
 
 
 class TestRadosgwUserModule(object):
@@ -98,6 +102,53 @@ class TestRadosgwUserModule(object):
 
         assert radosgw_user.create_user(fake_module) == expected_cmd
 
 
         assert radosgw_user.create_user(fake_module) == expected_cmd
 
+    def test_create_user_with_account_id(self):
+        fake_module = MagicMock()
+        fake_module.params = fake_params_with_account
+        expected_cmd = [
+            fake_binary,
+            '--cluster', fake_cluster,
+            'user', 'create',
+            '--uid=' + fake_user,
+            '--display_name=' + fake_user,
+            '--email=' + fake_user,
+            '--access-key=PC7NPg87QWhOzXTkXIhX',
+            '--secret-key=jV64v39lVTjEx1ZJN6ocopnhvwMp1mXCD4kzBiPz',
+            '--rgw-realm=' + fake_realm,
+            '--rgw-zonegroup=' + fake_zonegroup,
+            '--rgw-zone=' + fake_zone,
+            '--system',
+            '--admin',
+            '--account-id=' + fake_account_id,
+            '--account-root'
+        ]
+
+        assert radosgw_user.create_user(fake_module) == expected_cmd
+
+    def test_create_user_with_account_id_only(self):
+        fake_module = MagicMock()
+        fake_module.params = dict(fake_params,
+                                  account_id=fake_account_id,
+                                  account_root=False)
+        expected_cmd = [
+            fake_binary,
+            '--cluster', fake_cluster,
+            'user', 'create',
+            '--uid=' + fake_user,
+            '--display_name=' + fake_user,
+            '--email=' + fake_user,
+            '--access-key=PC7NPg87QWhOzXTkXIhX',
+            '--secret-key=jV64v39lVTjEx1ZJN6ocopnhvwMp1mXCD4kzBiPz',
+            '--rgw-realm=' + fake_realm,
+            '--rgw-zonegroup=' + fake_zonegroup,
+            '--rgw-zone=' + fake_zone,
+            '--system',
+            '--admin',
+            '--account-id=' + fake_account_id
+        ]
+
+        assert radosgw_user.create_user(fake_module) == expected_cmd
+
     def test_modify_user(self):
         fake_module = MagicMock()
         fake_module.params = fake_params
     def test_modify_user(self):
         fake_module = MagicMock()
         fake_module.params = fake_params
@@ -119,6 +170,53 @@ class TestRadosgwUserModule(object):
 
         assert radosgw_user.modify_user(fake_module) == expected_cmd
 
 
         assert radosgw_user.modify_user(fake_module) == expected_cmd
 
+    def test_modify_user_with_account_id(self):
+        fake_module = MagicMock()
+        fake_module.params = fake_params_with_account
+        expected_cmd = [
+            fake_binary,
+            '--cluster', fake_cluster,
+            'user', 'modify',
+            '--uid=' + fake_user,
+            '--display_name=' + fake_user,
+            '--email=' + fake_user,
+            '--access-key=PC7NPg87QWhOzXTkXIhX',
+            '--secret-key=jV64v39lVTjEx1ZJN6ocopnhvwMp1mXCD4kzBiPz',
+            '--rgw-realm=' + fake_realm,
+            '--rgw-zonegroup=' + fake_zonegroup,
+            '--rgw-zone=' + fake_zone,
+            '--system',
+            '--admin',
+            '--account-id=' + fake_account_id,
+            '--account-root'
+        ]
+
+        assert radosgw_user.modify_user(fake_module) == expected_cmd
+
+    def test_modify_user_with_account_id_only(self):
+        fake_module = MagicMock()
+        fake_module.params = dict(fake_params,
+                                  account_id=fake_account_id,
+                                  account_root=False)
+        expected_cmd = [
+            fake_binary,
+            '--cluster', fake_cluster,
+            'user', 'modify',
+            '--uid=' + fake_user,
+            '--display_name=' + fake_user,
+            '--email=' + fake_user,
+            '--access-key=PC7NPg87QWhOzXTkXIhX',
+            '--secret-key=jV64v39lVTjEx1ZJN6ocopnhvwMp1mXCD4kzBiPz',
+            '--rgw-realm=' + fake_realm,
+            '--rgw-zonegroup=' + fake_zonegroup,
+            '--rgw-zone=' + fake_zone,
+            '--system',
+            '--admin',
+            '--account-id=' + fake_account_id
+        ]
+
+        assert radosgw_user.modify_user(fake_module) == expected_cmd
+
     def test_get_user(self):
         fake_module = MagicMock()
         fake_module.params = fake_params
     def test_get_user(self):
         fake_module = MagicMock()
         fake_module.params = fake_params