Merge "Restrict backup-list on instance to tenant"

This commit is contained in:
Jenkins 2014-07-23 00:32:35 +00:00 committed by Gerrit Code Review
commit 30db8aed00
2 changed files with 18 additions and 7 deletions

View File

@ -205,8 +205,13 @@ class Backup(object):
:return:
"""
query = DBBackup.query()
query = query.filter_by(instance_id=instance_id,
deleted=False)
if context.is_admin:
query = query.filter_by(instance_id=instance_id,
deleted=False)
else:
query = query.filter_by(instance_id=instance_id,
tenant_id=context.tenant,
deleted=False)
return cls._paginate(context, query)
@classmethod

View File

@ -143,6 +143,8 @@ class RestartTaskStatusTests(MgmtInstanceBase):
user = test_config.users.find_user(Requirements(is_admin=False))
dbaas = create_dbaas_client(user)
admin = test_config.users.find_user(Requirements(is_admin=True))
admin_dbaas = create_dbaas_client(admin)
result = dbaas.instances.backups(self.db_info.id)
assert_equal(0, len(result))
@ -171,15 +173,19 @@ class RestartTaskStatusTests(MgmtInstanceBase):
instance_id=self.db_info.id,
deleted=False)
# List the backups for this instance. There ought to be three!
# List the backups for this instance.
# There ought to be three in the admin tenant, but
# none in a different user's tenant.
result = dbaas.instances.backups(self.db_info.id)
assert_equal(0, len(result))
result = admin_dbaas.instances.backups(self.db_info.id)
assert_equal(3, len(result))
self.backups_to_clear = result
# Reset the task status.
self.reset_task_status()
self._reload_db_info()
result = dbaas.instances.backups(self.db_info.id)
result = admin_dbaas.instances.backups(self.db_info.id)
assert_equal(3, len(result))
for backup in result:
if backup.name == 'forever_completed':
@ -193,7 +199,7 @@ class RestartTaskStatusTests(MgmtInstanceBase):
for backup in self.backups_to_clear:
found_backup = backup_models.DBBackup.find_by(id=backup.id)
found_backup.delete()
user = test_config.users.find_user(Requirements(is_admin=False))
dbaas = create_dbaas_client(user)
result = dbaas.instances.backups(self.db_info.id)
admin = test_config.users.find_user(Requirements(is_admin=True))
admin_dbaas = create_dbaas_client(admin)
result = admin_dbaas.instances.backups(self.db_info.id)
assert_equal(0, len(result))