Fix access_ip_v4/6 filters params for servers filter
While adding the json schema for servers filter query, we added 'accessIPv4' and 'accessIPv6' as allowed params but they do not match with what DB has. It is 'access_ip_v4' and 'access_ip_v6' in DB. This makes 'access_ip_v4' and 'access_ip_v6' filter stop working. The schema should be fixed accordingly to allow the 'access_ip_v4' and 'access_ip_v6' as valid filter. 'accessIPv4' and 'accessIPv6' are something the API accepts and returns and internally API layer translate those param to their respective field('access_ip_v4' and 'access_ip_v6') present in DB. So user does not know anything about 'access_ip_v4' and 'access_ip_v6'. They are not in API representation actually. Later list filter and sort param should be same as field return in GET or accepted in POST/PUT which are 'accessIPv4' and 'accessIPv6'. But that is something new attribute support in filter and can be done later after more discussion. Change-Id: Idc12de0062d298259e25c8b4c0dde889054a9ae5 Closes-Bug: #1661195
This commit is contained in:
parent
d92e56a99d
commit
cd29a4e6c5
|
@ -340,8 +340,8 @@ query_params_v21 = {
|
|||
'uuid': common_param,
|
||||
'root_device_name': common_regex_param,
|
||||
'config_drive': common_regex_param,
|
||||
'accessIPv4': common_regex_param,
|
||||
'accessIPv6': common_regex_param,
|
||||
'access_ip_v4': common_regex_param,
|
||||
'access_ip_v6': common_regex_param,
|
||||
'auto_disk_config': common_regex_param,
|
||||
'progress': common_regex_param,
|
||||
'sort_key': multi_params(VALID_SORT_KEYS),
|
||||
|
|
|
@ -1272,6 +1272,54 @@ class ServersControllerTest(ControllerTest):
|
|||
self.assertEqual(len(servers), 1)
|
||||
self.assertEqual(servers[0]['id'], server_uuid)
|
||||
|
||||
def test_get_servers_admin_allows_access_ip_v4(self):
|
||||
"""Test getting servers by access_ip_v4 with admin_api enabled and
|
||||
admin context
|
||||
"""
|
||||
server_uuid = uuids.fake
|
||||
|
||||
def fake_get_all(compute_self, context, search_opts=None,
|
||||
limit=None, marker=None,
|
||||
expected_attrs=None, sort_keys=None, sort_dirs=None):
|
||||
self.assertIsNotNone(search_opts)
|
||||
self.assertIn('access_ip_v4', search_opts)
|
||||
self.assertEqual(search_opts['access_ip_v4'], 'ffff.*')
|
||||
return objects.InstanceList(
|
||||
objects=[fakes.stub_instance_obj(100, uuid=server_uuid)])
|
||||
|
||||
self.stubs.Set(compute_api.API, 'get_all', fake_get_all)
|
||||
|
||||
req = self.req('/fake/servers?access_ip_v4=ffff.*',
|
||||
use_admin_context=True)
|
||||
servers = self.controller.index(req)['servers']
|
||||
|
||||
self.assertEqual(1, len(servers))
|
||||
self.assertEqual(server_uuid, servers[0]['id'])
|
||||
|
||||
def test_get_servers_admin_allows_access_ip_v6(self):
|
||||
"""Test getting servers by access_ip_v6 with admin_api enabled and
|
||||
admin context
|
||||
"""
|
||||
server_uuid = uuids.fake
|
||||
|
||||
def fake_get_all(compute_self, context, search_opts=None,
|
||||
limit=None, marker=None,
|
||||
expected_attrs=None, sort_keys=None, sort_dirs=None):
|
||||
self.assertIsNotNone(search_opts)
|
||||
self.assertIn('access_ip_v6', search_opts)
|
||||
self.assertEqual(search_opts['access_ip_v6'], 'ffff.*')
|
||||
return objects.InstanceList(
|
||||
objects=[fakes.stub_instance_obj(100, uuid=server_uuid)])
|
||||
|
||||
self.stubs.Set(compute_api.API, 'get_all', fake_get_all)
|
||||
|
||||
req = self.req('/fake/servers?access_ip_v6=ffff.*',
|
||||
use_admin_context=True)
|
||||
servers = self.controller.index(req)['servers']
|
||||
|
||||
self.assertEqual(1, len(servers))
|
||||
self.assertEqual(server_uuid, servers[0]['id'])
|
||||
|
||||
def test_get_all_server_details(self):
|
||||
expected_flavor = {
|
||||
"id": "2",
|
||||
|
|
Loading…
Reference in New Issue