Tolerate spaces in extra capability values

The intent behind limiting the split of the query string at all appears
to be supporting values with spaces, but it's off-by-one, limiting the
number of splits to 3 (4 parts max) rather than 3 parts max.

This commit also generates new random values for variables id and
computehost_id during each call to _get_fake_host_extra_capabilities()
rather than just once, which is necessary to avoid a failing test due to
duplicate id values.

Closes-Bug: #1732787
Change-Id: I8dc56aa983ca27763a63325810753148cb8d8ecd
This commit is contained in:
Nick Timkovich 2017-11-16 15:20:29 -06:00 committed by Pierre Riteau
parent 9a08d37e5c
commit 7d1b3b7002
2 changed files with 19 additions and 5 deletions
blazar
db/sqlalchemy
tests/db/sqlalchemy

View File

@ -628,7 +628,7 @@ def host_get_all_by_queries(queries):
hosts = [] hosts = []
for query in queries: for query in queries:
try: try:
key, op, value = query.split(' ', 3) key, op, value = query.split(' ', 2)
except ValueError: except ValueError:
raise db_exc.BlazarDBInvalidFilter(query_filter=query) raise db_exc.BlazarDBInvalidFilter(query_filter=query)

View File

@ -168,12 +168,18 @@ def _get_fake_host_values(id=_get_fake_random_uuid(), mem=8192, disk=10):
} }
def _get_fake_host_extra_capabilities(id=_get_fake_random_uuid(), def _get_fake_host_extra_capabilities(id=None,
computehost_id=_get_fake_random_uuid()): computehost_id=None,
name='vgpu',
value='2'):
if id is None:
id = _get_fake_random_uuid()
if computehost_id is None:
computehost_id = _get_fake_random_uuid()
return {'id': id, return {'id': id,
'computehost_id': computehost_id, 'computehost_id': computehost_id,
'capability_name': 'vgpu', 'capability_name': name,
'capability_value': '2'} 'capability_value': value}
def is_result_sorted_correctly(results, sort_key, sort_dir='asc'): def is_result_sorted_correctly(results, sort_key, sort_dir='asc'):
@ -488,6 +494,11 @@ class SQLAlchemyDBApiTestCase(tests.DBTestCase):
db_api.host_create(_get_fake_host_values(id=1)) db_api.host_create(_get_fake_host_values(id=1))
db_api.host_extra_capability_create( db_api.host_extra_capability_create(
_get_fake_host_extra_capabilities(computehost_id=1)) _get_fake_host_extra_capabilities(computehost_id=1))
db_api.host_extra_capability_create(_get_fake_host_extra_capabilities(
computehost_id=1,
name='nic_model',
value='ACME Model A',
))
# We create a second host, without any extra capabilities # We create a second host, without any extra capabilities
db_api.host_create(_get_fake_host_values(id=2)) db_api.host_create(_get_fake_host_values(id=2))
@ -503,6 +514,9 @@ class SQLAlchemyDBApiTestCase(tests.DBTestCase):
'vgpu == 2']))) 'vgpu == 2'])))
self.assertRaises(db_exceptions.BlazarDBNotFound, self.assertRaises(db_exceptions.BlazarDBNotFound,
db_api.host_get_all_by_queries, ['apples < 2048']) db_api.host_get_all_by_queries, ['apples < 2048'])
self.assertEqual(1, len(
db_api.host_get_all_by_queries(['nic_model == ACME Model A'])
))
def test_search_for_hosts_by_composed_queries(self): def test_search_for_hosts_by_composed_queries(self):
"""Create one host and test composed queries.""" """Create one host and test composed queries."""