From 37abdd9968ad19fc29abde5783e6e07c9a4637cb Mon Sep 17 00:00:00 2001 From: Satyanarayana Patibandla Date: Sat, 27 Apr 2013 14:44:23 -0400 Subject: Added attribute 'ip' to server search options. Allows all tenants to use attribute 'ip' in server search options. For this fix, added attribute 'ip' to server search options. Modified the existing test case to verify 'ip' search for all tenants. Implements: blueprint add-attribute-ip-in-server-search-options Change-Id: Ic24ee67d729f77d56c4fe3e1d4110865550c2154 --- nova/api/openstack/compute/servers.py | 2 +- nova/tests/api/openstack/compute/test_servers.py | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 2df16c886..166c8b10e 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -1392,7 +1392,7 @@ class Controller(wsgi.Controller): def _get_server_search_options(self): """Return server search options allowed by non-admin.""" return ('reservation_id', 'name', 'status', 'image', 'flavor', - 'changes-since', 'all_tenants') + 'ip', 'changes-since', 'all_tenants') def create_resource(ext_mgr): diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index 5d2118564..22aecf020 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -935,10 +935,10 @@ class ServersControllerTest(test.TestCase): self.assertNotEqual(search_opts, None) # Allowed by user self.assertTrue('name' in search_opts) + self.assertTrue('ip' in search_opts) # OSAPI converts status to vm_state self.assertTrue('vm_state' in search_opts) # Allowed only by admins with admin API on - self.assertFalse('ip' in search_opts) self.assertFalse('unknown_option' in search_opts) return [fakes.stub_instance(100, uuid=server_uuid)] @@ -981,10 +981,8 @@ class ServersControllerTest(test.TestCase): self.assertEqual(len(servers), 1) self.assertEqual(servers[0]['id'], server_uuid) - def test_get_servers_admin_allows_ip(self): - """Test getting servers by ip with admin_api enabled and - admin context - """ + def test_get_servers_allows_ip(self): + """Test getting servers by ip.""" server_uuid = str(uuid.uuid4()) def fake_get_all(compute_self, context, search_opts=None, @@ -997,8 +995,7 @@ class ServersControllerTest(test.TestCase): self.stubs.Set(compute_api.API, 'get_all', fake_get_all) - req = fakes.HTTPRequest.blank('/v2/fake/servers?ip=10\..*', - use_admin_context=True) + req = fakes.HTTPRequest.blank('/v2/fake/servers?ip=10\..*') servers = self.controller.index(req)['servers'] self.assertEqual(len(servers), 1) -- cgit