From: Steffen Bohr Date: Thu, 9 Jul 2026 11:51:26 +0000 (+0000) Subject: radosgw_user: support account feature X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;p=ceph-ansible.git radosgw_user: support account feature Add support to add rgw users to an rgw account. Update tests accordingly Signed-off-by: Steffen Bohr --- diff --git a/library/radosgw_user.py b/library/radosgw_user.py index 1142eb0e1..fe63f0ffd 100644 --- a/library/radosgw_user.py +++ b/library/radosgw_user.py @@ -102,6 +102,16 @@ options: - 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 @@ -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') + account_id = module.params.get('account_id') + account_root = module.params.get('account_root') 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 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)]) @@ -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) + account_id = module.params.get('account_id') + account_root = module.params.get('account_root') args = ['modify', '--uid=' + name] @@ -390,6 +410,12 @@ def modify_user(module, container_image=None): 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) @@ -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), + account_id=dict(type='str', required=False), + account_root=dict(type='bool', required=False, default=False) ) module = AnsibleModule( diff --git a/tests/library/test_radosgw_user.py b/tests/library/test_radosgw_user.py index 374c51219..272c09436 100644 --- a/tests/library/test_radosgw_user.py +++ b/tests/library/test_radosgw_user.py @@ -25,6 +25,7 @@ fake_user = 'foo' 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, @@ -36,6 +37,9 @@ fake_params = {'cluster': fake_cluster, '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): @@ -98,6 +102,53 @@ class TestRadosgwUserModule(object): 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 @@ -119,6 +170,53 @@ class TestRadosgwUserModule(object): 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