Hide Datastores In List With No Active Versions
in a datastore-list operation, for non-admin, filters out datastores that either have no versions or have no active versions for non-admin users. admins continue to see all datastores, active or inactive, in a datastore-list operation. Change-Id: Iccaf9ae59469fd0f4cb346ee258d3132eed83660 Co-Authored-By: Andrey Shestakov <ashestakov@mirantis.com> Closes-Bug: #1290617
This commit is contained in:
parent
a767623967
commit
63d62f084e
@ -78,7 +78,7 @@ def datastore_init():
|
|||||||
name=CONFIG.dbaas_datastore,
|
name=CONFIG.dbaas_datastore,
|
||||||
default_version_id=
|
default_version_id=
|
||||||
CONFIG.dbaas_datastore_version_id)
|
CONFIG.dbaas_datastore_version_id)
|
||||||
models.DBDatastore.create(id="e00000e0-00e0-0e00-00e0-000e000000ee",
|
models.DBDatastore.create(id=CONFIG.dbaas_datastore_id_no_versions,
|
||||||
name='Test_Datastore_1',
|
name='Test_Datastore_1',
|
||||||
default_version_id=None)
|
default_version_id=None)
|
||||||
|
|
||||||
|
@ -81,8 +81,12 @@ class Datastores(object):
|
|||||||
self.db_info = db_info
|
self.db_info = db_info
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls):
|
def load(cls, only_active=True):
|
||||||
return cls(DBDatastore.find_all())
|
datastores = DBDatastore.find_all()
|
||||||
|
if only_active:
|
||||||
|
datastores = datastores.join(DBDatastoreVersion).filter(
|
||||||
|
DBDatastoreVersion.active == 1)
|
||||||
|
return cls(datastores)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for item in self.db_info:
|
for item in self.db_info:
|
||||||
@ -137,7 +141,7 @@ class DatastoreVersion(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def active(self):
|
def active(self):
|
||||||
return self.db_info.active
|
return (True if self.db_info.active else False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def manager(self):
|
def manager(self):
|
||||||
|
@ -28,7 +28,11 @@ class DatastoreController(wsgi.Controller):
|
|||||||
DatastoreView(datastore, req).data(), 200)
|
DatastoreView(datastore, req).data(), 200)
|
||||||
|
|
||||||
def index(self, req, tenant_id):
|
def index(self, req, tenant_id):
|
||||||
datastores = models.Datastores.load()
|
context = req.environ[wsgi.CONTEXT_KEY]
|
||||||
|
only_active = True
|
||||||
|
if context.is_admin:
|
||||||
|
only_active = False
|
||||||
|
datastores = models.Datastores.load(only_active)
|
||||||
return wsgi.Result(views.
|
return wsgi.Result(views.
|
||||||
DatastoresView(datastores, req).data(),
|
DatastoresView(datastores, req).data(),
|
||||||
200)
|
200)
|
||||||
|
@ -53,6 +53,9 @@ class Query(object):
|
|||||||
return self.db_api.first(self._query_func, self._model,
|
return self.db_api.first(self._query_func, self._model,
|
||||||
**self._conditions)
|
**self._conditions)
|
||||||
|
|
||||||
|
def join(self, *args):
|
||||||
|
return self.db_api.join(self._query_func, self._model, *args)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self.all())
|
return iter(self.all())
|
||||||
|
|
||||||
|
@ -32,6 +32,10 @@ def first(query, *args, **kwargs):
|
|||||||
return query(*args, **kwargs).first()
|
return query(*args, **kwargs).first()
|
||||||
|
|
||||||
|
|
||||||
|
def join(query, model, *args):
|
||||||
|
return query(model).join(*args)
|
||||||
|
|
||||||
|
|
||||||
def find_all(model, **conditions):
|
def find_all(model, **conditions):
|
||||||
return _query_by(model, **conditions)
|
return _query_by(model, **conditions)
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ from troveclient.compat import exceptions
|
|||||||
from proboscis import before_class
|
from proboscis import before_class
|
||||||
from proboscis import test
|
from proboscis import test
|
||||||
from proboscis.asserts import assert_raises
|
from proboscis.asserts import assert_raises
|
||||||
|
from proboscis.asserts import assert_true
|
||||||
|
|
||||||
from trove import tests
|
from trove import tests
|
||||||
from trove.tests.util import create_dbaas_client
|
from trove.tests.util import create_dbaas_client
|
||||||
@ -39,7 +40,10 @@ class Datastores(object):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
rd_user = test_config.users.find_user(
|
rd_user = test_config.users.find_user(
|
||||||
Requirements(is_admin=False, services=["trove"]))
|
Requirements(is_admin=False, services=["trove"]))
|
||||||
|
rd_admin = test_config.users.find_user(
|
||||||
|
Requirements(is_admin=True, services=["trove"]))
|
||||||
self.rd_client = create_dbaas_client(rd_user)
|
self.rd_client = create_dbaas_client(rd_user)
|
||||||
|
self.rd_admin = create_dbaas_client(rd_admin)
|
||||||
|
|
||||||
@test
|
@test
|
||||||
def test_datastore_list_attrs(self):
|
def test_datastore_list_attrs(self):
|
||||||
@ -152,3 +156,17 @@ class Datastores(object):
|
|||||||
assert_equal(e.message,
|
assert_equal(e.message,
|
||||||
"Datastore version '%s' cannot be found." %
|
"Datastore version '%s' cannot be found." %
|
||||||
test_config.dbaas_datastore_version)
|
test_config.dbaas_datastore_version)
|
||||||
|
|
||||||
|
@test
|
||||||
|
def test_datastore_with_no_active_versions_is_hidden(self):
|
||||||
|
datastores = self.rd_client.datastores.list()
|
||||||
|
id_list = [datastore.id for datastore in datastores]
|
||||||
|
id_no_versions = test_config.dbaas_datastore_id_no_versions
|
||||||
|
assert_true(id_no_versions not in id_list)
|
||||||
|
|
||||||
|
@test
|
||||||
|
def test_datastore_with_no_active_versions_is_visible_for_admin(self):
|
||||||
|
datastores = self.rd_admin.datastores.list()
|
||||||
|
id_list = [datastore.id for datastore in datastores]
|
||||||
|
id_no_versions = test_config.dbaas_datastore_id_no_versions
|
||||||
|
assert_true(id_no_versions in id_list)
|
||||||
|
@ -72,6 +72,8 @@ class TestConfig(object):
|
|||||||
'nova_url': "http://localhost:8774/v1.1",
|
'nova_url': "http://localhost:8774/v1.1",
|
||||||
'dbaas_datastore': "mysql",
|
'dbaas_datastore': "mysql",
|
||||||
'dbaas_datastore_id': "a00000a0-00a0-0a00-00a0-000a000000aa",
|
'dbaas_datastore_id': "a00000a0-00a0-0a00-00a0-000a000000aa",
|
||||||
|
'dbaas_datastore_id_no_versions': "e00000e0-00e0-0e00-00e0-"
|
||||||
|
"000e000000ee",
|
||||||
'dbaas_datastore_version': "mysql-5.5",
|
'dbaas_datastore_version': "mysql-5.5",
|
||||||
'dbaas_datastore_version_id': "b00000b0-00b0-0b00-00b0-"
|
'dbaas_datastore_version_id': "b00000b0-00b0-0b00-00b0-"
|
||||||
"000b000000bb",
|
"000b000000bb",
|
||||||
|
Loading…
Reference in New Issue
Block a user