- 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>
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]
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)])
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]
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)
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(
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,
'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):
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
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