radosgw-admin.py: Increase test coverage to current admin feature set.

Signed-off-by: caleb miles <caleb.miles@inktank.com>
This commit is contained in:
caleb miles 2012-12-22 20:56:29 -05:00
parent 0de0772e59
commit d44fb14762

View File

@ -13,6 +13,7 @@ import boto.s3.connection
import boto.s3.acl
import time
import xml.etree.ElementTree as ET
from teuthology import misc as teuthology
@ -72,10 +73,12 @@ def task(ctx, config):
client = clients[0];
##
user='foo'
user1='foo'
user2='fud'
subuser1='foo:foo1'
subuser2='foo:foo2'
display_name='Foo'
display_name1='Foo'
display_name2='Fud'
email='foo@foo.com'
access_key='9te6NH5mcdcq0Tc5i8i1'
secret_key='Ny4IOauQoL18Gp2zM7lC1vLmoawgqcYP/YGcWfXu'
@ -89,59 +92,59 @@ def task(ctx, config):
# legend (test cases can be easily grep-ed out)
# TESTCASE 'testname','object','method','operation','assertion'
# TESTCASE 'info-nosuch','user','info','non-existent user','fails'
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user1])
assert err
# TESTCASE 'create-ok','user','create','w/all valid info','succeeds'
(err, out) = rgwadmin(ctx, client, [
'user', 'create',
'--uid', user,
'--display-name', display_name,
'--uid', user1,
'--display-name', display_name1,
'--email', email,
'--access-key', access_key,
'--secret', secret_key,
'--max-buckets', '4',
'--max-buckets', '4'
])
assert not err
# TESTCASE 'info-existing','user','info','existing user','returns correct info'
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user1])
assert not err
assert out['user_id'] == user
assert out['user_id'] == user1
assert out['email'] == email
assert out['display_name'] == display_name
assert out['display_name'] == display_name1
assert len(out['keys']) == 1
assert out['keys'][0]['access_key'] == access_key
assert out['keys'][0]['secret_key'] == secret_key
assert not out['suspended']
# TESTCASE 'suspend-ok','user','suspend','active user','succeeds'
(err, out) = rgwadmin(ctx, client, ['user', 'suspend', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'suspend', '--uid', user1])
assert not err
# TESTCASE 'suspend-suspended','user','suspend','suspended user','succeeds w/advisory'
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user1])
assert not err
assert out['suspended']
# TESTCASE 're-enable','user','enable','suspended user','succeeds'
(err, out) = rgwadmin(ctx, client, ['user', 'enable', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'enable', '--uid', user1])
assert not err
# TESTCASE 'info-re-enabled','user','info','re-enabled user','no longer suspended'
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user1])
assert not err
assert not out['suspended']
# TESTCASE 'add-keys','key','create','w/valid info','succeeds'
(err, out) = rgwadmin(ctx, client, [
'key', 'create', '--uid', user,
'key', 'create', '--uid', user1,
'--access-key', access_key2, '--secret', secret_key2,
])
assert not err
# TESTCASE 'info-new-key','user','info','after key addition','returns all keys'
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user1])
assert not err
assert len(out['keys']) == 2
assert out['keys'][0]['access_key'] == access_key2 or out['keys'][1]['access_key'] == access_key2
@ -149,7 +152,7 @@ def task(ctx, config):
# TESTCASE 'rm-key','key','rm','newly added key','succeeds, key is removed'
(err, out) = rgwadmin(ctx, client, [
'key', 'rm', '--uid', user,
'key', 'rm', '--uid', user1,
'--access-key', access_key2,
])
assert not err
@ -166,7 +169,7 @@ def task(ctx, config):
assert not err
# TESTCASE 'info-swift-key','user','info','after key addition','returns all keys'
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user1])
assert not err
assert len(out['swift_keys']) == 1
assert out['swift_keys'][0]['user'] == subuser1
@ -181,7 +184,7 @@ def task(ctx, config):
assert not err
# TESTCASE 'info-swift-subuser','user','info','after key addition','returns all sub-users/keys'
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user1])
assert not err
assert len(out['swift_keys']) == 2
assert out['swift_keys'][0]['user'] == subuser2 or out['swift_keys'][1]['user'] == subuser2
@ -212,7 +215,7 @@ def task(ctx, config):
assert len(out['subusers']) == 0
# TESTCASE 'bucket-stats','bucket','stats','no session/buckets','succeeds, empty list'
(err, out) = rgwadmin(ctx, client, ['bucket', 'stats', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['bucket', 'stats', '--uid', user1])
assert not err
assert len(out) == 0
@ -229,15 +232,15 @@ def task(ctx, config):
)
# TESTCASE 'bucket-stats2','bucket','stats','no buckets','succeeds, empty list'
(err, out) = rgwadmin(ctx, client, ['bucket', 'list', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['bucket', 'list', '--uid', user1])
assert not err
assert len(out) == 0
# creat a first bucket
# create a first bucket
bucket = connection.create_bucket(bucket_name)
# TESTCASE 'bucket-list','bucket','list','one bucket','succeeds, expected list'
(err, out) = rgwadmin(ctx, client, ['bucket', 'list', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['bucket', 'list', '--uid', user1])
assert not err
assert len(out) == 1
assert out[0] == bucket_name
@ -263,11 +266,11 @@ def task(ctx, config):
(err, out) = rgwadmin(ctx, client, [
'bucket', 'stats', '--bucket', bucket_name])
assert not err
assert out['owner'] == user
assert out['owner'] == user1
bucket_id = out['id']
# TESTCASE 'bucket-stats4','bucket','stats','new empty bucket','succeeds, expected bucket ID'
(err, out) = rgwadmin(ctx, client, ['bucket', 'stats', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['bucket', 'stats', '--uid', user1])
assert not err
assert len(out) == 1
assert out[0]['id'] == bucket_id # does it return the same ID twice in a row?
@ -287,6 +290,68 @@ def task(ctx, config):
# reclaim it
key.delete()
# TESTCASE 'bucket unlink', 'bucket', 'unlink', 'unlink bucket from user', 'fails', 'access denied error'
(err, out) = rgwadmin(ctx, client, ['bucket', 'unlink', '--uid', user1, '--bucket', bucket_name])
assert not err
# create a second user to link the bucket to
(err, out) = rgwadmin(ctx, client, [
'user', 'create',
'--uid', user2,
'--display-name', display_name2,
'--access-key', access_key2,
'--secret', secret_key2,
'--max-buckets', '1',
])
assert not err
# try creating an object with the first user before the bucket is relinked
denied = false
key = boto.s3.key.Key(bucket)
try:
key.set_contents_from_string('two')
except boto.exception.S3ResponseError:
denied = true
assert not denied
# delete the object
key.delete()
# link the bucket to another user
(err, out) = rgwadmin(ctx, client, ['bucket', 'link', '--uid', user2, '--bucket', bucket_name])
assert not err
# try creating an object with the first user which should cause an error
key = boto.s3.key.Key(bucket)
try:
key.set_contents_from_string('three')
except boto.exception.S3ResponseError:
denied = true
assert denied
# relink the bucket to the first user and delete the second user
(err, out) = rgwadmin(ctx, client, ['bucket', 'link', '--uid', user1, '--bucket', bucket_name])
assert not err
(err, out) = rgwadmin(ctx, client, ['user', 'rm', '--uid', user2])
assert not err
# TESTCASE 'object-rm', 'object', 'rm', 'remove object', 'succeeds, object is removed'
# upload an object
object_name = 'four'
key = boto.s3.key.Key(bucket)
key.set_contents_from_string(object_name)
# now delete it
(err, out) = rgwadmin(ctx, client, ['object', 'rm', '--bucket', bucket_name, '--object', object_name])
assert not err
# TESTCASE 'bucket-stats6','bucket','stats','after deleting key','succeeds, lists one no objects'
(err, out) = rgwadmin(ctx, client, [
'bucket', 'stats', '--bucket', bucket_name])
@ -307,10 +372,10 @@ def task(ctx, config):
assert len(log) > 0
assert log['bucket'].find(bucket_name) == 0
assert log['bucket'] != bucket_name or log['bucket_id'] == bucket_id
assert log['bucket_owner'] == user or log['bucket'] == bucket_name + '5'
assert log['bucket_owner'] == user1 or log['bucket'] == bucket_name + '5'
for entry in log['log_entries']:
assert entry['bucket'] == log['bucket']
assert entry['user'] == user or log['bucket'] == bucket_name + '5'
assert entry['user'] == user1 or log['bucket'] == bucket_name + '5'
# TESTCASE 'log-rm','log','rm','delete log objects','succeeds'
(err, out) = rgwadmin(ctx, client, ['log', 'rm', '--object', obj])
@ -338,57 +403,85 @@ def task(ctx, config):
assert total['successful_ops'] > 0
# TESTCASE 'usage-show2' 'usage' 'show' 'user usage' 'succeeds'
(err, out) = rgwadmin(ctx, client, ['usage', 'show', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['usage', 'show', '--uid', user1])
assert not err
assert len(out['entries']) > 0
assert len(out['summary']) > 0
user_summary = out['summary'][0]
for entry in user_summary['categories']:
assert entry['successful_ops'] > 0
assert user_summary['user'] == user
assert user_summary['user'] == user1
# TESTCASE 'usage-show3' 'usage' 'show' 'user usage categories' 'succeeds'
test_categories = ['create_bucket', 'put_obj', 'delete_obj', 'delete_bucket']
for cat in test_categories:
(err, out) = rgwadmin(ctx, client, ['usage', 'show', '--uid', user, '--categories', cat])
(err, out) = rgwadmin(ctx, client, ['usage', 'show', '--uid', user1, '--categories', cat])
assert not err
assert len(out['summary']) > 0
user_summary = out['summary'][0]
assert user_summary['user'] == user
assert user_summary['user'] == user1
assert len(user_summary['categories']) == 1
entry = user_summary['categories'][0]
assert entry['category'] == cat
assert entry['successful_ops'] > 0
# TESTCASE 'usage-trim' 'usage' 'trim' 'user usage' 'succeeds, usage removed'
(err, out) = rgwadmin(ctx, client, ['usage', 'trim', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['usage', 'trim', '--uid', user1])
assert not err
(err, out) = rgwadmin(ctx, client, ['usage', 'show', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['usage', 'show', '--uid', user1])
assert not err
assert len(out['entries']) == 0
assert len(out['summary']) == 0
# TESTCASE 'user-suspend2','user','suspend','existing user','succeeds'
(err, out) = rgwadmin(ctx, client, ['user', 'suspend', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'suspend', '--uid', user1])
assert not err
# TESTCASE 'user-suspend3','user','suspend','suspended user','cannot write objects'
try:
key = boto.s3.key.Key(bucket)
key.set_contents_from_string('two')
key.set_contents_from_string('five')
except boto.exception.S3ResponseError as e:
assert e.status == 403
# TESTCASE 'user-renable2','user','enable','suspended user','succeeds'
(err, out) = rgwadmin(ctx, client, ['user', 'enable', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'enable', '--uid', user1])
assert not err
# TESTCASE 'user-renable3','user','enable','reenabled user','can write objects'
key = boto.s3.key.Key(bucket)
key.set_contents_from_string('three')
key.set_contents_from_string('six')
# TESTCASE 'gc-list', 'gc', 'list', 'get list of objects ready for garbage collection'
# create an object large enough to be split into multiple parts
test_string = 'foo'*10000000
key = boto.s3.key.Key(bucket)
key.set_contents_from_string(test_string)
# now delete the head
key.delete()
# wait a bit to give the garbage collector time to cycle
sleep 15
(err, out) = rgwadmin(ctx, client, ['gc', 'list'])
assert len(out) > 0
# TESTCASE 'gc-process', 'gc', 'process', 'manually collect garbage'
(err, out) = rgwadmin(ctx, client, ['gc', 'process'])
assert not err
#confirm
(err, out) = rgwadmin(ctx, client, ['gc', 'list'])
assert len(out) == 0
# TESTCASE 'rm-user-buckets','user','rm','existing user','fails, still has buckets'
(err, out) = rgwadmin(ctx, client, ['user', 'rm', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'rm', '--uid', user1])
assert err
# delete should fail
@ -402,9 +495,36 @@ def task(ctx, config):
key.delete()
bucket.delete()
# TESTCASE 'rm-bucket', 'bucket', 'rm', 'bucket with objects;, 'succeeds'
# TESTCASE 'policy', 'bucket', 'policy', 'get bucket policy', 'returns S3 policy'
bucket = connection.create_bucket(bucket_name)
key_name = ['four', 'five', 'six', 'seven']
# create an object
key = boto.s3.key.Key(bucket)
key.set_contents_from_string('seven')
# should be private already but guarantee it
key.set_acl('private')
(err, out) = rgwadmin(ctx, client, ['policy', '--bucket', bucket.name, '--object', key.key])
assert out
policy = ET.fromstring(out)
assert len(policy.findall('Grantee')) == 1
# add another grantee by making the object public read
key.set_acl('public-read')
(err, out) = rgwadmin(ctx, client, ['policy', '--bucket', bucket.name, '--object', key.key])
assert out
policy = ET.fromstring(out)
assert len(policy.findall('Grantee')) == 2
# TESTCASE 'rm-bucket', 'bucket', 'rm', 'bucket with objects', 'succeeds'
bucket = connection.create_bucket(bucket_name)
key_name = ['eight', 'nine', 'ten', 'eleven']
for i in range(4):
key = boto.s3.key.Key(bucket)
key.set_contents_from_string(key_name[i])
@ -412,21 +532,51 @@ def task(ctx, config):
(err, out) = rgwadmin(ctx, client, ['bucket', 'rm', '--bucket', bucket_name, '--purge-objects'])
assert not err
# TESTCASE 'caps-add', 'caps', 'add', 'add user cap', 'succeeds'
caps='user=read'
(err, out) = rgwadmin(ctx, client, ['caps', 'add', '--uid', user1, '--caps', caps])
assert out['caps']['perm'] == 'read'
# TESTCASE 'caps-rm', 'caps', 'rm', 'remove existing cap from user', 'succeeds'
(err, out) = rgwadmin(ctx, client, ['caps', 'rm', '--uid', user1, '--caps', caps])
assert not out['caps']
# TESTCASE 'rm-user','user','rm','existing user','fails, still has buckets'
bucket = connection.create_bucket(bucket_name)
key = boto.s3.key.Key(bucket)
# TESTCASE 'rm-user','user','rm','existing user','fails, still has buckets'
(err, out) = rgwadmin(ctx, client, ['user', 'rm', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'rm', '--uid', user1])
assert err
# TESTCASE 'rm-user2', 'user', 'rm', user with data', 'succeeds'
bucket = connection.create_bucket(bucket_name)
key = boto.s3.key.Key(bucket)
key.set_contents_from_string('eight')
key.set_contents_from_string('twelve')
(err, out) = rgwadmin(ctx, client, ['user', 'rm', '--uid', user, '--purge-data' ])
(err, out) = rgwadmin(ctx, client, ['user', 'rm', '--uid', user1, '--purge-data' ])
assert not err
# TESTCASE 'rm-user3','user','rm','deleted user','fails'
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user])
(err, out) = rgwadmin(ctx, client, ['user', 'info', '--uid', user1])
assert err
# TESTCASE 'pool-rm', 'pool', 'rm', 'make default pool unavailable', 'succeeds'
default_pool='.rgw.buckets'
(err, out) = rgwadmin(ctx, client, ['pool', 'rm', '--pool', default_pool])
# now list the pools
(err, out) = rgwadmin(ctx, client, ['pools', 'list'])
assert len(out) == 0
# TESTCASE 'pool-add', 'pool', 'add', 'make default pool available', 'succeeds'
(err, out) = rgwadmin(ctx, client, ['pool', 'add', '--pool', default_pool])
assert out['name'] == default_pool_name
# TESTCASE 'cluster-info', 'cluster', 'info', 'get cluser info', 'succeeds'
(err, out) = rgwadmin(ctx, client, ['cluster', 'info'])
assert len(out) > 0