api.rest.neutron: Ensure dict is passed to api.neutron args
Some functions in api/neutron use @memoized decorator, but @memoized decorator cannot handle request.GET (an instance of QueryDict) because a weakref to WSGIRequest is not hashable. (Note that @memoized decorator can handle a dict itself) What we actually need is the content of request.GET. By using .dict() method we can ensure arguments which @memoized can handle are passed to api.neutron functions. This pattern is used only in api.rest.neutron and not used in other codes. Closes-Bug: #1706348 Change-Id: Ibb38ad1d95af1cd90a1fedd834602f444010c151
This commit is contained in:
parent
53dd2dbd39
commit
0c1e179b3c
@ -85,7 +85,7 @@ class Subnets(generic.View):
|
||||
a subnet.
|
||||
|
||||
"""
|
||||
result = api.neutron.subnet_list(request, **request.GET)
|
||||
result = api.neutron.subnet_list(request, **request.GET.dict())
|
||||
return{'items': [n.to_dict() for n in result]}
|
||||
|
||||
@rest_utils.ajax(data_required=True)
|
||||
@ -133,7 +133,7 @@ class Ports(generic.View):
|
||||
"""
|
||||
# see
|
||||
# https://github.com/openstack/neutron/blob/master/neutron/api/v2/attributes.py
|
||||
result = api.neutron.port_list(request, **request.GET)
|
||||
result = api.neutron.port_list(request, **request.GET.dict())
|
||||
return{'items': [n.to_dict() for n in result]}
|
||||
|
||||
|
||||
@ -165,7 +165,7 @@ class Trunks(generic.View):
|
||||
The listing result is an object with property "items".
|
||||
Each item is a trunk.
|
||||
"""
|
||||
result = api.neutron.trunk_list(request, **request.GET)
|
||||
result = api.neutron.trunk_list(request, **request.GET.dict())
|
||||
return {'items': [n.to_dict() for n in result]}
|
||||
|
||||
|
||||
@ -179,7 +179,7 @@ class Services(generic.View):
|
||||
"""Get a list of agents"""
|
||||
if api.base.is_service_enabled(request, 'network') and \
|
||||
api.neutron.is_extension_supported(request, 'agent'):
|
||||
result = api.neutron.agent_list(request, **request.GET)
|
||||
result = api.neutron.agent_list(request, **request.GET.dict())
|
||||
return {'items': [n.to_dict() for n in result]}
|
||||
else:
|
||||
raise rest_utils.AjaxError(501, '')
|
||||
|
@ -13,6 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from django.http import request as django_request
|
||||
import mock
|
||||
|
||||
from openstack_dashboard import api
|
||||
@ -75,8 +76,8 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
@test.create_stubs({api.neutron: ('is_extension_supported',)})
|
||||
@mock.patch.object(neutron.api, 'neutron')
|
||||
def test_services_get(self, client):
|
||||
request = self.mock_rest_request(
|
||||
GET={"network_id": "the_network"})
|
||||
params = django_request.QueryDict('network_id=the_network')
|
||||
request = self.mock_rest_request(GET=params)
|
||||
|
||||
api.base.is_service_enabled(request, 'network').AndReturn(True)
|
||||
api.neutron.is_extension_supported(request, 'agent').AndReturn(True)
|
||||
@ -117,8 +118,9 @@ class NeutronSubnetsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch.object(neutron.api, 'neutron')
|
||||
def test_get(self, client):
|
||||
request = self.mock_rest_request(
|
||||
GET={"network_id": self._networks[0].id})
|
||||
params = django_request.QueryDict('network_id=%s' %
|
||||
self._networks[0].id)
|
||||
request = self.mock_rest_request(GET=params)
|
||||
client.subnet_list.return_value = [self._subnets[0]]
|
||||
response = neutron.Subnets().get(request)
|
||||
self.assertStatusCode(response, 200)
|
||||
@ -150,8 +152,9 @@ class NeutronPortsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch.object(neutron.api, 'neutron')
|
||||
def test_get(self, client):
|
||||
request = self.mock_rest_request(
|
||||
GET={"network_id": self._networks[0].id})
|
||||
params = django_request.QueryDict('network_id=%s' %
|
||||
self._networks[0].id)
|
||||
request = self.mock_rest_request(GET=params)
|
||||
client.port_list.return_value = [self._ports[0]]
|
||||
response = neutron.Ports().get(request)
|
||||
self.assertStatusCode(response, 200)
|
||||
@ -182,7 +185,7 @@ class NeutronTrunksTestCase(test.TestCase):
|
||||
|
||||
@mock.patch.object(neutron.api, 'neutron')
|
||||
def test_trunks_get(self, client):
|
||||
request = self.mock_rest_request(GET={})
|
||||
request = self.mock_rest_request(GET=django_request.QueryDict())
|
||||
client.trunk_list.return_value = self.trunks.list()
|
||||
response = neutron.Trunks().get(request)
|
||||
self.assertStatusCode(response, 200)
|
||||
|
Loading…
x
Reference in New Issue
Block a user