Use jsonutils instead of stdlib json
jsonutils provides multiple benefits in comparison to pure stdlib json (like using simplejson on Python 2.6). Similar patch was already merged before [1], but since it lacked hacking rule to enforce jsonutils usage, new occurrences of stdlib json module usage were introduced. This patch switches all the code to using jsonutils and adds a hacking rule to enforce the rule. The hacking rule requires that jsonutils module does not mimic as 'json' thru using import renames, so the code was updated not to rename the module when doing import. The hacking rule was shamelessly copied from the corresponding nova review [2]. [1]: https://review.openstack.org/#/c/99760/ [2]: https://review.openstack.org/111296/ Change-Id: Ie7a5bb76445e15cde9fbf9ff3d2101a014637b37
This commit is contained in:
parent
3c5ce011f2
commit
4a36519393
@ -9,6 +9,7 @@ Neutron Specific Commandments
|
|||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
- [N320] Validate that LOG messages, except debug ones, have translations
|
- [N320] Validate that LOG messages, except debug ones, have translations
|
||||||
|
- [N321] Validate that jsonutils module is used instead of json
|
||||||
|
|
||||||
Creating Unit Tests
|
Creating Unit Tests
|
||||||
-------------------
|
-------------------
|
||||||
|
@ -46,5 +46,27 @@ def validate_log_translations(logical_line, physical_line, filename):
|
|||||||
yield (0, msg)
|
yield (0, msg)
|
||||||
|
|
||||||
|
|
||||||
|
def use_jsonutils(logical_line, filename):
|
||||||
|
msg = "N321: jsonutils.%(fun)s must be used instead of json.%(fun)s"
|
||||||
|
|
||||||
|
# Some files in the tree are not meant to be run from inside Neutron
|
||||||
|
# itself, so we should not complain about them not using jsonutils
|
||||||
|
json_check_skipped_patterns = [
|
||||||
|
"neutron/plugins/openvswitch/agent/xenapi/etc/xapi.d/plugins/netwrap",
|
||||||
|
]
|
||||||
|
|
||||||
|
for pattern in json_check_skipped_patterns:
|
||||||
|
if pattern in filename:
|
||||||
|
return
|
||||||
|
|
||||||
|
if "json." in logical_line:
|
||||||
|
json_funcs = ['dumps(', 'dump(', 'loads(', 'load(']
|
||||||
|
for f in json_funcs:
|
||||||
|
pos = logical_line.find('json.%s' % f)
|
||||||
|
if pos != -1:
|
||||||
|
yield (pos, msg % {'fun': f[:-1]})
|
||||||
|
|
||||||
|
|
||||||
def factory(register):
|
def factory(register):
|
||||||
register(validate_log_translations)
|
register(validate_log_translations)
|
||||||
|
register(use_jsonutils)
|
||||||
|
@ -44,7 +44,7 @@ from oslo.config import cfg
|
|||||||
from neutron.common import exceptions
|
from neutron.common import exceptions
|
||||||
from neutron.common import utils
|
from neutron.common import utils
|
||||||
from neutron.openstack.common import excutils
|
from neutron.openstack.common import excutils
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
from neutron.plugins.bigswitch.db import consistency_db as cdb
|
from neutron.plugins.bigswitch.db import consistency_db as cdb
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ class ServerProxy(object):
|
|||||||
def get_capabilities(self):
|
def get_capabilities(self):
|
||||||
try:
|
try:
|
||||||
body = self.rest_call('GET', CAPABILITIES_PATH)[2]
|
body = self.rest_call('GET', CAPABILITIES_PATH)[2]
|
||||||
self.capabilities = json.loads(body)
|
self.capabilities = jsonutils.loads(body)
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.exception(_("Couldn't retrieve capabilities. "
|
LOG.exception(_("Couldn't retrieve capabilities. "
|
||||||
"Newer API calls won't be supported."))
|
"Newer API calls won't be supported."))
|
||||||
@ -124,7 +124,7 @@ class ServerProxy(object):
|
|||||||
def rest_call(self, action, resource, data='', headers={}, timeout=False,
|
def rest_call(self, action, resource, data='', headers={}, timeout=False,
|
||||||
reconnect=False, hash_handler=None):
|
reconnect=False, hash_handler=None):
|
||||||
uri = self.base_uri + resource
|
uri = self.base_uri + resource
|
||||||
body = json.dumps(data)
|
body = jsonutils.dumps(data)
|
||||||
if not headers:
|
if not headers:
|
||||||
headers = {}
|
headers = {}
|
||||||
headers['Content-type'] = 'application/json'
|
headers['Content-type'] = 'application/json'
|
||||||
@ -192,7 +192,7 @@ class ServerProxy(object):
|
|||||||
if hash_value is not None:
|
if hash_value is not None:
|
||||||
hash_handler.put_hash(hash_value)
|
hash_handler.put_hash(hash_value)
|
||||||
try:
|
try:
|
||||||
respdata = json.loads(respstr)
|
respdata = jsonutils.loads(respstr)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# response was not JSON, ignore the exception
|
# response was not JSON, ignore the exception
|
||||||
pass
|
pass
|
||||||
|
@ -27,7 +27,7 @@ import re
|
|||||||
from six import moves
|
from six import moves
|
||||||
from wsgiref import simple_server
|
from wsgiref import simple_server
|
||||||
|
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
|
|
||||||
|
|
||||||
class TestNetworkCtrl(object):
|
class TestNetworkCtrl(object):
|
||||||
@ -123,7 +123,7 @@ class TestNetworkCtrl(object):
|
|||||||
request_data = environ.get('wsgi.input').read(content_len)
|
request_data = environ.get('wsgi.input').read(content_len)
|
||||||
if request_data:
|
if request_data:
|
||||||
try:
|
try:
|
||||||
request_data = json.loads(request_data)
|
request_data = jsonutils.loads(request_data)
|
||||||
except Exception:
|
except Exception:
|
||||||
# OK for it not to be json! Ignore it
|
# OK for it not to be json! Ignore it
|
||||||
pass
|
pass
|
||||||
@ -138,13 +138,14 @@ class TestNetworkCtrl(object):
|
|||||||
print('%s %s' % (method, uri))
|
print('%s %s' % (method, uri))
|
||||||
if request_data:
|
if request_data:
|
||||||
print('%s' %
|
print('%s' %
|
||||||
json.dumps(request_data, sort_keys=True, indent=4))
|
jsonutils.dumps(
|
||||||
|
request_data, sort_keys=True, indent=4))
|
||||||
|
|
||||||
status, body = self.request_handler(method, uri, None)
|
status, body = self.request_handler(method, uri, None)
|
||||||
body_data = None
|
body_data = None
|
||||||
if body:
|
if body:
|
||||||
try:
|
try:
|
||||||
body_data = json.loads(body)
|
body_data = jsonutils.loads(body)
|
||||||
except Exception:
|
except Exception:
|
||||||
# OK for it not to be json! Ignore it
|
# OK for it not to be json! Ignore it
|
||||||
pass
|
pass
|
||||||
@ -153,7 +154,8 @@ class TestNetworkCtrl(object):
|
|||||||
if self.debug:
|
if self.debug:
|
||||||
if self.debug_env:
|
if self.debug_env:
|
||||||
print('%s: %s' % ('Response',
|
print('%s: %s' % ('Response',
|
||||||
json.dumps(body_data, sort_keys=True, indent=4)))
|
jsonutils.dumps(
|
||||||
|
body_data, sort_keys=True, indent=4)))
|
||||||
return body
|
return body
|
||||||
return simple_server.make_server(self.host, self.port, app)
|
return simple_server.make_server(self.host, self.port, app)
|
||||||
|
|
||||||
|
@ -14,9 +14,9 @@
|
|||||||
#
|
#
|
||||||
# @author: Hareesh Puthalath, Cisco Systems, Inc.
|
# @author: Hareesh Puthalath, Cisco Systems, Inc.
|
||||||
|
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.plugins.cisco.cfg_agent.device_drivers import devicedriver_api
|
from neutron.plugins.cisco.cfg_agent.device_drivers import devicedriver_api
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -33,7 +33,7 @@ class DummyRoutingDriver(devicedriver_api.RoutingDriverBase):
|
|||||||
# Datetime values causes json decoding errors. So removing it locally
|
# Datetime values causes json decoding errors. So removing it locally
|
||||||
if my_device_params.get('created_at'):
|
if my_device_params.get('created_at'):
|
||||||
del my_device_params['created_at']
|
del my_device_params['created_at']
|
||||||
LOG.debug(json.dumps(my_device_params, sort_keys=True, indent=4))
|
LOG.debug(jsonutils.dumps(my_device_params, sort_keys=True, indent=4))
|
||||||
|
|
||||||
###### Public Functions ########
|
###### Public Functions ########
|
||||||
def router_added(self, ri):
|
def router_added(self, ri):
|
||||||
@ -44,7 +44,7 @@ class DummyRoutingDriver(devicedriver_api.RoutingDriverBase):
|
|||||||
|
|
||||||
def internal_network_added(self, ri, port):
|
def internal_network_added(self, ri, port):
|
||||||
LOG.debug("DummyDriver internal_network_added() called.")
|
LOG.debug("DummyDriver internal_network_added() called.")
|
||||||
LOG.debug("Int port data: " + json.dumps(port, sort_keys=True,
|
LOG.debug("Int port data: " + jsonutils.dumps(port, sort_keys=True,
|
||||||
indent=4))
|
indent=4))
|
||||||
|
|
||||||
def internal_network_removed(self, ri, port):
|
def internal_network_removed(self, ri, port):
|
||||||
@ -52,8 +52,9 @@ class DummyRoutingDriver(devicedriver_api.RoutingDriverBase):
|
|||||||
|
|
||||||
def external_gateway_added(self, ri, ex_gw_port):
|
def external_gateway_added(self, ri, ex_gw_port):
|
||||||
LOG.debug("DummyDriver external_gateway_added() called.")
|
LOG.debug("DummyDriver external_gateway_added() called.")
|
||||||
LOG.debug("Ext port data: " + json.dumps(ex_gw_port, sort_keys=True,
|
LOG.debug("Ext port data: " + jsonutils.dumps(ex_gw_port,
|
||||||
indent=4))
|
sort_keys=True,
|
||||||
|
indent=4))
|
||||||
|
|
||||||
def external_gateway_removed(self, ri, ex_gw_port):
|
def external_gateway_removed(self, ri, ex_gw_port):
|
||||||
LOG.debug("DummyDriver external_gateway_removed() called.")
|
LOG.debug("DummyDriver external_gateway_removed() called.")
|
||||||
|
@ -21,7 +21,7 @@ import time
|
|||||||
import requests
|
import requests
|
||||||
import requests.exceptions
|
import requests.exceptions
|
||||||
|
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
from neutron.plugins.ml2.drivers.cisco.apic import exceptions as cexc
|
from neutron.plugins.ml2.drivers.cisco.apic import exceptions as cexc
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ class ApicSession(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _make_data(key, **attrs):
|
def _make_data(key, **attrs):
|
||||||
"""Build the body for a msg out of a key and some attributes."""
|
"""Build the body for a msg out of a key and some attributes."""
|
||||||
return json.dumps({key: {'attributes': attrs}})
|
return jsonutils.dumps({key: {'attributes': attrs}})
|
||||||
|
|
||||||
def _api_url(self, api):
|
def _api_url(self, api):
|
||||||
"""Create the URL for a generic API."""
|
"""Create the URL for a generic API."""
|
||||||
|
@ -18,7 +18,7 @@ import time
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from neutron.openstack.common import excutils
|
from neutron.openstack.common import excutils
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
from neutron.plugins.nec.common import config
|
from neutron.plugins.nec.common import config
|
||||||
from neutron.plugins.nec.common import exceptions as nexc
|
from neutron.plugins.nec.common import exceptions as nexc
|
||||||
@ -80,7 +80,7 @@ class OFCClient(object):
|
|||||||
{'host': self.host, 'port': self.port,
|
{'host': self.host, 'port': self.port,
|
||||||
'method': method, 'action': action, 'body': body})
|
'method': method, 'action': action, 'body': body})
|
||||||
if type(body) is dict:
|
if type(body) is dict:
|
||||||
body = json.dumps(body)
|
body = jsonutils.dumps(body)
|
||||||
try:
|
try:
|
||||||
res = self._get_response(method, action, body)
|
res = self._get_response(method, action, body)
|
||||||
data = res.text
|
data = res.text
|
||||||
@ -90,7 +90,7 @@ class OFCClient(object):
|
|||||||
|
|
||||||
# Try to decode JSON data if possible.
|
# Try to decode JSON data if possible.
|
||||||
try:
|
try:
|
||||||
data = json.loads(data)
|
data = jsonutils.loads(data)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
"""Intermidiate NVSD Library."""
|
"""Intermidiate NVSD Library."""
|
||||||
|
|
||||||
from neutron.openstack.common import excutils
|
from neutron.openstack.common import excutils
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
import neutron.plugins.oneconvergence.lib.exception as nvsdexception
|
import neutron.plugins.oneconvergence.lib.exception as nvsdexception
|
||||||
from neutron.plugins.oneconvergence.lib import plugin_helper
|
from neutron.plugins.oneconvergence.lib import plugin_helper
|
||||||
@ -101,7 +101,8 @@ class NVSDApi(object):
|
|||||||
|
|
||||||
uri = NETWORKS_URI % tenant_id
|
uri = NETWORKS_URI % tenant_id
|
||||||
|
|
||||||
response = self.send_request("POST", uri, body=json.dumps(network_obj),
|
response = self.send_request("POST", uri,
|
||||||
|
body=jsonutils.dumps(network_obj),
|
||||||
resource='network', tenant_id=tenant_id)
|
resource='network', tenant_id=tenant_id)
|
||||||
|
|
||||||
nvsd_net = response.json()
|
nvsd_net = response.json()
|
||||||
@ -119,7 +120,7 @@ class NVSDApi(object):
|
|||||||
uri = NETWORK_URI % (tenant_id, network_id)
|
uri = NETWORK_URI % (tenant_id, network_id)
|
||||||
|
|
||||||
self.send_request("PUT", uri,
|
self.send_request("PUT", uri,
|
||||||
body=json.dumps(network_update),
|
body=jsonutils.dumps(network_update),
|
||||||
resource='network', tenant_id=tenant_id,
|
resource='network', tenant_id=tenant_id,
|
||||||
resource_id=network_id)
|
resource_id=network_id)
|
||||||
|
|
||||||
@ -154,7 +155,7 @@ class NVSDApi(object):
|
|||||||
|
|
||||||
uri = SUBNETS_URI % (tenant_id, network_id)
|
uri = SUBNETS_URI % (tenant_id, network_id)
|
||||||
|
|
||||||
self.send_request("POST", uri, body=json.dumps(subnet),
|
self.send_request("POST", uri, body=jsonutils.dumps(subnet),
|
||||||
resource='subnet', tenant_id=tenant_id)
|
resource='subnet', tenant_id=tenant_id)
|
||||||
|
|
||||||
LOG.debug(_("Subnet %(id)s created under tenant %(tenant_id)s"),
|
LOG.debug(_("Subnet %(id)s created under tenant %(tenant_id)s"),
|
||||||
@ -183,7 +184,7 @@ class NVSDApi(object):
|
|||||||
uri = SUBNET_URI % (tenant_id, network_id, subnet_id)
|
uri = SUBNET_URI % (tenant_id, network_id, subnet_id)
|
||||||
|
|
||||||
self.send_request("PUT", uri,
|
self.send_request("PUT", uri,
|
||||||
body=json.dumps(subnet_update),
|
body=jsonutils.dumps(subnet_update),
|
||||||
resource='subnet', tenant_id=tenant_id,
|
resource='subnet', tenant_id=tenant_id,
|
||||||
resource_id=subnet_id)
|
resource_id=subnet_id)
|
||||||
|
|
||||||
@ -216,7 +217,7 @@ class NVSDApi(object):
|
|||||||
|
|
||||||
path = PORTS_URI % (tenant_id, network_id)
|
path = PORTS_URI % (tenant_id, network_id)
|
||||||
|
|
||||||
self.send_request("POST", path, body=json.dumps(lport),
|
self.send_request("POST", path, body=jsonutils.dumps(lport),
|
||||||
resource='port', tenant_id=tenant_id)
|
resource='port', tenant_id=tenant_id)
|
||||||
|
|
||||||
LOG.debug(_("Port %(id)s created under tenant %(tenant_id)s"),
|
LOG.debug(_("Port %(id)s created under tenant %(tenant_id)s"),
|
||||||
@ -239,7 +240,7 @@ class NVSDApi(object):
|
|||||||
|
|
||||||
uri = PORT_URI % (tenant_id, network_id, port_id)
|
uri = PORT_URI % (tenant_id, network_id, port_id)
|
||||||
|
|
||||||
self.send_request("PUT", uri, body=json.dumps(lport),
|
self.send_request("PUT", uri, body=jsonutils.dumps(lport),
|
||||||
resource='port', tenant_id=tenant_id,
|
resource='port', tenant_id=tenant_id,
|
||||||
resource_id=port_id)
|
resource_id=port_id)
|
||||||
|
|
||||||
@ -274,7 +275,7 @@ class NVSDApi(object):
|
|||||||
|
|
||||||
uri = FLOATING_IPS_URI % tenant_id
|
uri = FLOATING_IPS_URI % tenant_id
|
||||||
|
|
||||||
self.send_request("POST", uri, body=json.dumps(floating_ip),
|
self.send_request("POST", uri, body=jsonutils.dumps(floating_ip),
|
||||||
resource='floating_ip',
|
resource='floating_ip',
|
||||||
tenant_id=tenant_id)
|
tenant_id=tenant_id)
|
||||||
|
|
||||||
@ -290,7 +291,8 @@ class NVSDApi(object):
|
|||||||
uri = FLOATING_IP_URI % (tenant_id, floating_ip_id)
|
uri = FLOATING_IP_URI % (tenant_id, floating_ip_id)
|
||||||
|
|
||||||
self.send_request("PUT", uri,
|
self.send_request("PUT", uri,
|
||||||
body=json.dumps(floating_ip_update['floatingip']),
|
body=jsonutils.dumps(
|
||||||
|
floating_ip_update['floatingip']),
|
||||||
resource='floating_ip',
|
resource='floating_ip',
|
||||||
tenant_id=tenant_id,
|
tenant_id=tenant_id,
|
||||||
resource_id=floating_ip_id)
|
resource_id=floating_ip_id)
|
||||||
@ -318,7 +320,7 @@ class NVSDApi(object):
|
|||||||
|
|
||||||
uri = ROUTERS_URI % tenant_id
|
uri = ROUTERS_URI % tenant_id
|
||||||
|
|
||||||
self.send_request("POST", uri, body=json.dumps(router),
|
self.send_request("POST", uri, body=jsonutils.dumps(router),
|
||||||
resource='router',
|
resource='router',
|
||||||
tenant_id=tenant_id)
|
tenant_id=tenant_id)
|
||||||
|
|
||||||
@ -334,7 +336,7 @@ class NVSDApi(object):
|
|||||||
uri = ROUTER_URI % (tenant_id, router_id)
|
uri = ROUTER_URI % (tenant_id, router_id)
|
||||||
|
|
||||||
self.send_request("PUT", uri,
|
self.send_request("PUT", uri,
|
||||||
body=json.dumps(router),
|
body=jsonutils.dumps(router),
|
||||||
resource='router', tenant_id=tenant_id,
|
resource='router', tenant_id=tenant_id,
|
||||||
resource_id=router_id)
|
resource_id=router_id)
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ from oslo.config import cfg
|
|||||||
import requests
|
import requests
|
||||||
from six.moves.urllib import parse
|
from six.moves.urllib import parse
|
||||||
|
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
import neutron.plugins.oneconvergence.lib.exception as exception
|
import neutron.plugins.oneconvergence.lib.exception as exception
|
||||||
|
|
||||||
@ -68,7 +68,8 @@ class NVSDController(object):
|
|||||||
login_url = parse.urljoin(self.api_url,
|
login_url = parse.urljoin(self.api_url,
|
||||||
"/pluginhandler/ocplugin/authmgmt/login")
|
"/pluginhandler/ocplugin/authmgmt/login")
|
||||||
|
|
||||||
data = json.dumps({"user_name": self._user, "passwd": self._password})
|
data = jsonutils.dumps({"user_name": self._user,
|
||||||
|
"passwd": self._password})
|
||||||
|
|
||||||
attempts = 0
|
attempts = 0
|
||||||
|
|
||||||
@ -98,7 +99,7 @@ class NVSDController(object):
|
|||||||
LOG.debug(_("Login Successful %(uri)s "
|
LOG.debug(_("Login Successful %(uri)s "
|
||||||
"%(status)s"), {'uri': self.api_url,
|
"%(status)s"), {'uri': self.api_url,
|
||||||
'status': response.status_code})
|
'status': response.status_code})
|
||||||
self.auth_token = json.loads(response.content)["session_uuid"]
|
self.auth_token = jsonutils.loads(response.content)["session_uuid"]
|
||||||
LOG.debug(_("AuthToken = %s"), self.auth_token)
|
LOG.debug(_("AuthToken = %s"), self.auth_token)
|
||||||
else:
|
else:
|
||||||
LOG.error(_("login failed"))
|
LOG.error(_("login failed"))
|
||||||
|
@ -18,7 +18,7 @@ import eventlet
|
|||||||
import httplib
|
import httplib
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
from neutron.plugins.vmware.api_client import request
|
from neutron.plugins.vmware.api_client import request
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ class GetApiProvidersRequestEventlet(EventletApiRequest):
|
|||||||
try:
|
try:
|
||||||
if self.successful():
|
if self.successful():
|
||||||
ret = []
|
ret = []
|
||||||
body = json.loads(self.value.body)
|
body = jsonutils.loads(self.value.body)
|
||||||
for node in body.get('results', []):
|
for node in body.get('results', []):
|
||||||
for role in node.get('roles', []):
|
for role in node.get('roles', []):
|
||||||
if role.get('role') == 'api_provider':
|
if role.get('role') == 'api_provider':
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from neutron.common import exceptions as exception
|
from neutron.common import exceptions as exception
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log
|
from neutron.openstack.common import log
|
||||||
from neutron.plugins.vmware.api_client import exception as api_exc
|
from neutron.plugins.vmware.api_client import exception as api_exc
|
||||||
from neutron.plugins.vmware.common import exceptions as nsx_exc
|
from neutron.plugins.vmware.common import exceptions as nsx_exc
|
||||||
@ -97,7 +97,7 @@ def do_request(*args, **kwargs):
|
|||||||
try:
|
try:
|
||||||
res = cluster.api_client.request(*args)
|
res = cluster.api_client.request(*args)
|
||||||
if res:
|
if res:
|
||||||
return json.loads(res)
|
return jsonutils.loads(res)
|
||||||
except api_exc.ResourceNotFound:
|
except api_exc.ResourceNotFound:
|
||||||
raise exception.NotFound()
|
raise exception.NotFound()
|
||||||
except api_exc.ReadOnlyMode:
|
except api_exc.ReadOnlyMode:
|
||||||
@ -141,4 +141,4 @@ def mk_body(**kwargs):
|
|||||||
:param kwargs: the key/value pirs to be dumped into a json string.
|
:param kwargs: the key/value pirs to be dumped into a json string.
|
||||||
:returns: a json string.
|
:returns: a json string.
|
||||||
"""
|
"""
|
||||||
return json.dumps(kwargs, ensure_ascii=False)
|
return jsonutils.dumps(kwargs, ensure_ascii=False)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log
|
from neutron.openstack.common import log
|
||||||
from neutron.plugins.vmware.api_client import exception as api_exc
|
from neutron.plugins.vmware.api_client import exception as api_exc
|
||||||
from neutron.plugins.vmware.common import exceptions as nsx_exc
|
from neutron.plugins.vmware.common import exceptions as nsx_exc
|
||||||
@ -59,7 +59,7 @@ def create_l2_gw_service(cluster, tenant_id, display_name, devices):
|
|||||||
}
|
}
|
||||||
return nsxlib.do_request(
|
return nsxlib.do_request(
|
||||||
HTTP_POST, nsxlib._build_uri_path(GWSERVICE_RESOURCE),
|
HTTP_POST, nsxlib._build_uri_path(GWSERVICE_RESOURCE),
|
||||||
json.dumps(gwservice_obj), cluster=cluster)
|
jsonutils.dumps(gwservice_obj), cluster=cluster)
|
||||||
|
|
||||||
|
|
||||||
def plug_l2_gw_service(cluster, lswitch_id, lport_id,
|
def plug_l2_gw_service(cluster, lswitch_id, lport_id,
|
||||||
@ -101,7 +101,7 @@ def update_l2_gw_service(cluster, gateway_id, display_name):
|
|||||||
return nsxlib.do_request(HTTP_PUT,
|
return nsxlib.do_request(HTTP_PUT,
|
||||||
nsxlib._build_uri_path(GWSERVICE_RESOURCE,
|
nsxlib._build_uri_path(GWSERVICE_RESOURCE,
|
||||||
resource_id=gateway_id),
|
resource_id=gateway_id),
|
||||||
json.dumps(gwservice_obj), cluster=cluster)
|
jsonutils.dumps(gwservice_obj), cluster=cluster)
|
||||||
|
|
||||||
|
|
||||||
def delete_l2_gw_service(cluster, gateway_id):
|
def delete_l2_gw_service(cluster, gateway_id):
|
||||||
@ -149,7 +149,7 @@ def create_gateway_device(cluster, tenant_id, display_name, neutron_id,
|
|||||||
try:
|
try:
|
||||||
return nsxlib.do_request(
|
return nsxlib.do_request(
|
||||||
HTTP_POST, nsxlib._build_uri_path(TRANSPORTNODE_RESOURCE),
|
HTTP_POST, nsxlib._build_uri_path(TRANSPORTNODE_RESOURCE),
|
||||||
json.dumps(body), cluster=cluster)
|
jsonutils.dumps(body), cluster=cluster)
|
||||||
except api_exc.InvalidSecurityCertificate:
|
except api_exc.InvalidSecurityCertificate:
|
||||||
raise nsx_exc.InvalidSecurityCertificate()
|
raise nsx_exc.InvalidSecurityCertificate()
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ def update_gateway_device(cluster, gateway_id, tenant_id,
|
|||||||
HTTP_PUT,
|
HTTP_PUT,
|
||||||
nsxlib._build_uri_path(TRANSPORTNODE_RESOURCE,
|
nsxlib._build_uri_path(TRANSPORTNODE_RESOURCE,
|
||||||
resource_id=gateway_id),
|
resource_id=gateway_id),
|
||||||
json.dumps(body), cluster=cluster)
|
jsonutils.dumps(body), cluster=cluster)
|
||||||
except api_exc.InvalidSecurityCertificate:
|
except api_exc.InvalidSecurityCertificate:
|
||||||
raise nsx_exc.InvalidSecurityCertificate()
|
raise nsx_exc.InvalidSecurityCertificate()
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from neutron.common import exceptions as exception
|
from neutron.common import exceptions as exception
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log
|
from neutron.openstack.common import log
|
||||||
from neutron.plugins.vmware.api_client import exception as api_exc
|
from neutron.plugins.vmware.api_client import exception as api_exc
|
||||||
from neutron.plugins.vmware.common import exceptions as nsx_exc
|
from neutron.plugins.vmware.common import exceptions as nsx_exc
|
||||||
@ -56,7 +56,7 @@ def lsn_for_network_create(cluster, network_id):
|
|||||||
}
|
}
|
||||||
return nsxlib.do_request(HTTP_POST,
|
return nsxlib.do_request(HTTP_POST,
|
||||||
nsxlib._build_uri_path(LSERVICESNODE_RESOURCE),
|
nsxlib._build_uri_path(LSERVICESNODE_RESOURCE),
|
||||||
json.dumps(lsn_obj),
|
jsonutils.dumps(lsn_obj),
|
||||||
cluster=cluster)["uuid"]
|
cluster=cluster)["uuid"]
|
||||||
|
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ def lsn_port_host_entries_update(
|
|||||||
parent_resource_id=lsn_id,
|
parent_resource_id=lsn_id,
|
||||||
resource_id=lsn_port_id,
|
resource_id=lsn_port_id,
|
||||||
extra_action=conf),
|
extra_action=conf),
|
||||||
json.dumps(hosts_obj),
|
jsonutils.dumps(hosts_obj),
|
||||||
cluster=cluster)
|
cluster=cluster)
|
||||||
|
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ def lsn_port_create(cluster, lsn_id, port_data):
|
|||||||
return nsxlib.do_request(HTTP_POST,
|
return nsxlib.do_request(HTTP_POST,
|
||||||
nsxlib._build_uri_path(LSERVICESNODEPORT_RESOURCE,
|
nsxlib._build_uri_path(LSERVICESNODEPORT_RESOURCE,
|
||||||
parent_resource_id=lsn_id),
|
parent_resource_id=lsn_id),
|
||||||
json.dumps(port_obj),
|
jsonutils.dumps(port_obj),
|
||||||
cluster=cluster)["uuid"]
|
cluster=cluster)["uuid"]
|
||||||
|
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ def lsn_port_plug_network(cluster, lsn_id, lsn_port_id, lswitch_port_id):
|
|||||||
parent_resource_id=lsn_id,
|
parent_resource_id=lsn_id,
|
||||||
resource_id=lsn_port_id,
|
resource_id=lsn_port_id,
|
||||||
is_attachment=True),
|
is_attachment=True),
|
||||||
json.dumps(patch_obj),
|
jsonutils.dumps(patch_obj),
|
||||||
cluster=cluster)
|
cluster=cluster)
|
||||||
except api_exc.Conflict:
|
except api_exc.Conflict:
|
||||||
# This restriction might be lifted at some point
|
# This restriction might be lifted at some point
|
||||||
@ -184,7 +184,7 @@ def _lsn_configure_action(
|
|||||||
nsxlib._build_uri_path(LSERVICESNODE_RESOURCE,
|
nsxlib._build_uri_path(LSERVICESNODE_RESOURCE,
|
||||||
resource_id=lsn_id,
|
resource_id=lsn_id,
|
||||||
extra_action=action),
|
extra_action=action),
|
||||||
json.dumps(lsn_obj),
|
jsonutils.dumps(lsn_obj),
|
||||||
cluster=cluster)
|
cluster=cluster)
|
||||||
|
|
||||||
|
|
||||||
@ -194,14 +194,14 @@ def _lsn_port_configure_action(
|
|||||||
nsxlib._build_uri_path(LSERVICESNODE_RESOURCE,
|
nsxlib._build_uri_path(LSERVICESNODE_RESOURCE,
|
||||||
resource_id=lsn_id,
|
resource_id=lsn_id,
|
||||||
extra_action=action),
|
extra_action=action),
|
||||||
json.dumps({"enabled": is_enabled}),
|
jsonutils.dumps({"enabled": is_enabled}),
|
||||||
cluster=cluster)
|
cluster=cluster)
|
||||||
nsxlib.do_request(HTTP_PUT,
|
nsxlib.do_request(HTTP_PUT,
|
||||||
nsxlib._build_uri_path(LSERVICESNODEPORT_RESOURCE,
|
nsxlib._build_uri_path(LSERVICESNODEPORT_RESOURCE,
|
||||||
parent_resource_id=lsn_id,
|
parent_resource_id=lsn_id,
|
||||||
resource_id=lsn_port_id,
|
resource_id=lsn_port_id,
|
||||||
extra_action=action),
|
extra_action=action),
|
||||||
json.dumps(obj),
|
jsonutils.dumps(obj),
|
||||||
cluster=cluster)
|
cluster=cluster)
|
||||||
|
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ def _lsn_port_host_action(
|
|||||||
resource_id=lsn_port_id,
|
resource_id=lsn_port_id,
|
||||||
extra_action=extra_action,
|
extra_action=extra_action,
|
||||||
filters={"action": action}),
|
filters={"action": action}),
|
||||||
json.dumps(host_obj),
|
jsonutils.dumps(host_obj),
|
||||||
cluster=cluster)
|
cluster=cluster)
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
from neutron.common import constants
|
from neutron.common import constants
|
||||||
from neutron.common import exceptions
|
from neutron.common import exceptions
|
||||||
from neutron.openstack.common import excutils
|
from neutron.openstack.common import excutils
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log
|
from neutron.openstack.common import log
|
||||||
from neutron.plugins.vmware.common import utils
|
from neutron.plugins.vmware.common import utils
|
||||||
from neutron.plugins.vmware import nsxlib
|
from neutron.plugins.vmware import nsxlib
|
||||||
@ -37,7 +37,7 @@ def mk_body(**kwargs):
|
|||||||
:param kwargs: the key/value pirs to be dumped into a json string.
|
:param kwargs: the key/value pirs to be dumped into a json string.
|
||||||
:returns: a json string.
|
:returns: a json string.
|
||||||
"""
|
"""
|
||||||
return json.dumps(kwargs, ensure_ascii=False)
|
return jsonutils.dumps(kwargs, ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
def query_security_profiles(cluster, fields=None, filters=None):
|
def query_security_profiles(cluster, fields=None, filters=None):
|
||||||
@ -125,7 +125,7 @@ def update_security_profile(cluster, spid, name):
|
|||||||
return nsxlib.do_request(
|
return nsxlib.do_request(
|
||||||
HTTP_PUT,
|
HTTP_PUT,
|
||||||
nsxlib._build_uri_path(SECPROF_RESOURCE, resource_id=spid),
|
nsxlib._build_uri_path(SECPROF_RESOURCE, resource_id=spid),
|
||||||
json.dumps({"display_name": utils.check_and_truncate(name)}),
|
jsonutils.dumps({"display_name": utils.check_and_truncate(name)}),
|
||||||
cluster=cluster)
|
cluster=cluster)
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ from oslo.config import cfg
|
|||||||
|
|
||||||
from neutron.common import constants
|
from neutron.common import constants
|
||||||
from neutron.common import exceptions as exception
|
from neutron.common import exceptions as exception
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log
|
from neutron.openstack.common import log
|
||||||
from neutron.plugins.vmware.api_client import exception as api_exc
|
from neutron.plugins.vmware.api_client import exception as api_exc
|
||||||
from neutron.plugins.vmware.common import exceptions as nsx_exc
|
from neutron.plugins.vmware.common import exceptions as nsx_exc
|
||||||
@ -125,7 +125,7 @@ def create_lswitch(cluster, neutron_net_id, tenant_id, display_name,
|
|||||||
if "tags" in kwargs:
|
if "tags" in kwargs:
|
||||||
lswitch_obj["tags"].extend(kwargs["tags"])
|
lswitch_obj["tags"].extend(kwargs["tags"])
|
||||||
uri = nsxlib._build_uri_path(LSWITCH_RESOURCE)
|
uri = nsxlib._build_uri_path(LSWITCH_RESOURCE)
|
||||||
lswitch = nsxlib.do_request(HTTP_POST, uri, json.dumps(lswitch_obj),
|
lswitch = nsxlib.do_request(HTTP_POST, uri, jsonutils.dumps(lswitch_obj),
|
||||||
cluster=cluster)
|
cluster=cluster)
|
||||||
LOG.debug(_("Created logical switch: %s"), lswitch['uuid'])
|
LOG.debug(_("Created logical switch: %s"), lswitch['uuid'])
|
||||||
return lswitch
|
return lswitch
|
||||||
@ -144,7 +144,7 @@ def update_lswitch(cluster, lswitch_id, display_name,
|
|||||||
if tags:
|
if tags:
|
||||||
lswitch_obj['tags'] = tags
|
lswitch_obj['tags'] = tags
|
||||||
try:
|
try:
|
||||||
return nsxlib.do_request(HTTP_PUT, uri, json.dumps(lswitch_obj),
|
return nsxlib.do_request(HTTP_PUT, uri, jsonutils.dumps(lswitch_obj),
|
||||||
cluster=cluster)
|
cluster=cluster)
|
||||||
except exception.NotFound as e:
|
except exception.NotFound as e:
|
||||||
LOG.error(_("Network not found, Error: %s"), str(e))
|
LOG.error(_("Network not found, Error: %s"), str(e))
|
||||||
@ -319,7 +319,7 @@ def update_port(cluster, lswitch_uuid, lport_uuid, neutron_port_id, tenant_id,
|
|||||||
|
|
||||||
path = "/ws.v1/lswitch/" + lswitch_uuid + "/lport/" + lport_uuid
|
path = "/ws.v1/lswitch/" + lswitch_uuid + "/lport/" + lport_uuid
|
||||||
try:
|
try:
|
||||||
result = nsxlib.do_request(HTTP_PUT, path, json.dumps(lport_obj),
|
result = nsxlib.do_request(HTTP_PUT, path, jsonutils.dumps(lport_obj),
|
||||||
cluster=cluster)
|
cluster=cluster)
|
||||||
LOG.debug(_("Updated logical port %(result)s "
|
LOG.debug(_("Updated logical port %(result)s "
|
||||||
"on logical switch %(uuid)s"),
|
"on logical switch %(uuid)s"),
|
||||||
@ -353,7 +353,7 @@ def create_lport(cluster, lswitch_uuid, tenant_id, neutron_port_id,
|
|||||||
|
|
||||||
path = nsxlib._build_uri_path(LSWITCHPORT_RESOURCE,
|
path = nsxlib._build_uri_path(LSWITCHPORT_RESOURCE,
|
||||||
parent_resource_id=lswitch_uuid)
|
parent_resource_id=lswitch_uuid)
|
||||||
result = nsxlib.do_request(HTTP_POST, path, json.dumps(lport_obj),
|
result = nsxlib.do_request(HTTP_POST, path, jsonutils.dumps(lport_obj),
|
||||||
cluster=cluster)
|
cluster=cluster)
|
||||||
|
|
||||||
LOG.debug(_("Created logical port %(result)s on logical switch %(uuid)s"),
|
LOG.debug(_("Created logical port %(result)s on logical switch %(uuid)s"),
|
||||||
@ -382,7 +382,7 @@ def plug_interface(cluster, lswitch_id, lport_id, att_obj):
|
|||||||
nsxlib._build_uri_path(LSWITCHPORT_RESOURCE,
|
nsxlib._build_uri_path(LSWITCHPORT_RESOURCE,
|
||||||
lport_id, lswitch_id,
|
lport_id, lswitch_id,
|
||||||
is_attachment=True),
|
is_attachment=True),
|
||||||
json.dumps(att_obj),
|
jsonutils.dumps(att_obj),
|
||||||
cluster=cluster)
|
cluster=cluster)
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import base64
|
|||||||
import httplib2
|
import httplib2
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
from neutron.services.firewall.agents.varmour import varmour_utils as va_utils
|
from neutron.services.firewall.agents.varmour import varmour_utils as va_utils
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ class vArmourRestAPI(object):
|
|||||||
def rest_api(self, method, url, body=None, headers=None):
|
def rest_api(self, method, url, body=None, headers=None):
|
||||||
url = REST_URL_PREFIX + url
|
url = REST_URL_PREFIX + url
|
||||||
if body:
|
if body:
|
||||||
body_data = json.dumps(body)
|
body_data = jsonutils.dumps(body)
|
||||||
else:
|
else:
|
||||||
body_data = ''
|
body_data = ''
|
||||||
if not headers:
|
if not headers:
|
||||||
@ -118,7 +118,7 @@ class vArmourRestAPI(object):
|
|||||||
if resp.status == 200:
|
if resp.status == 200:
|
||||||
return {'status': resp.status,
|
return {'status': resp.status,
|
||||||
'reason': resp.reason,
|
'reason': resp.reason,
|
||||||
'body': json.loads(resp_str)}
|
'body': jsonutils.loads(resp_str)}
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.error(_('vArmourRestAPI: Could not establish HTTP connection'))
|
LOG.error(_('vArmourRestAPI: Could not establish HTTP connection'))
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ from neutron import context
|
|||||||
from neutron.db.loadbalancer import loadbalancer_db as lb_db
|
from neutron.db.loadbalancer import loadbalancer_db as lb_db
|
||||||
from neutron.extensions import loadbalancer
|
from neutron.extensions import loadbalancer
|
||||||
from neutron.openstack.common import excutils
|
from neutron.openstack.common import excutils
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
from neutron.plugins.common import constants
|
from neutron.plugins.common import constants
|
||||||
from neutron.services.loadbalancer.drivers import abstract_driver
|
from neutron.services.loadbalancer.drivers import abstract_driver
|
||||||
@ -728,7 +728,7 @@ class vDirectRESTClient:
|
|||||||
if binary:
|
if binary:
|
||||||
body = data
|
body = data
|
||||||
else:
|
else:
|
||||||
body = json.dumps(data)
|
body = jsonutils.dumps(data)
|
||||||
|
|
||||||
debug_data = 'binary' if binary else body
|
debug_data = 'binary' if binary else body
|
||||||
debug_data = debug_data if debug_data else 'EMPTY'
|
debug_data = debug_data if debug_data else 'EMPTY'
|
||||||
@ -758,7 +758,7 @@ class vDirectRESTClient:
|
|||||||
respstr = response.read()
|
respstr = response.read()
|
||||||
respdata = respstr
|
respdata = respstr
|
||||||
try:
|
try:
|
||||||
respdata = json.loads(respstr)
|
respdata = jsonutils.loads(respstr)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# response was not JSON, ignore the exception
|
# response was not JSON, ignore the exception
|
||||||
pass
|
pass
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# @author: Kevin Benton, <kevin.benton@bigswitch.com>
|
# @author: Kevin Benton, <kevin.benton@bigswitch.com>
|
||||||
#
|
#
|
||||||
|
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
from neutron.plugins.bigswitch import servermanager
|
from neutron.plugins.bigswitch import servermanager
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ class VerifyMultiTenantFloatingIP(HTTPConnectionMock):
|
|||||||
def request(self, action, uri, body, headers):
|
def request(self, action, uri, body, headers):
|
||||||
# Only handle network update requests
|
# Only handle network update requests
|
||||||
if 'network' in uri and 'tenant' in uri and 'ports' not in uri:
|
if 'network' in uri and 'tenant' in uri and 'ports' not in uri:
|
||||||
req = json.loads(body)
|
req = jsonutils.loads(body)
|
||||||
if 'network' not in req or 'floatingips' not in req['network']:
|
if 'network' not in req or 'floatingips' not in req['network']:
|
||||||
msg = _("No floating IPs in request"
|
msg = _("No floating IPs in request"
|
||||||
"uri=%(uri)s, body=%(body)s") % {'uri': uri,
|
"uri=%(uri)s, body=%(body)s") % {'uri': uri,
|
||||||
|
@ -18,7 +18,7 @@ import mock
|
|||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.plugins.nec.common import config
|
from neutron.plugins.nec.common import config
|
||||||
from neutron.plugins.nec.common import exceptions as nexc
|
from neutron.plugins.nec.common import exceptions as nexc
|
||||||
from neutron.plugins.nec.common import ofc_client
|
from neutron.plugins.nec.common import ofc_client
|
||||||
@ -64,7 +64,7 @@ class OFCClientTest(base.BaseTestCase):
|
|||||||
headers=headers)
|
headers=headers)
|
||||||
|
|
||||||
def test_do_request_200_json_value(self):
|
def test_do_request_200_json_value(self):
|
||||||
self._test_do_request(200, json.dumps([1, 2, 3]), [1, 2, 3])
|
self._test_do_request(200, jsonutils.dumps([1, 2, 3]), [1, 2, 3])
|
||||||
|
|
||||||
def test_do_request_200_string(self):
|
def test_do_request_200_string(self):
|
||||||
self._test_do_request(200, 'abcdef', 'abcdef')
|
self._test_do_request(200, 'abcdef', 'abcdef')
|
||||||
@ -78,7 +78,7 @@ class OFCClientTest(base.BaseTestCase):
|
|||||||
|
|
||||||
def test_do_request_with_path_prefix(self):
|
def test_do_request_with_path_prefix(self):
|
||||||
config.CONF.set_override('path_prefix', '/dummy', group='OFC')
|
config.CONF.set_override('path_prefix', '/dummy', group='OFC')
|
||||||
self._test_do_request(200, json.dumps([1, 2, 3]), [1, 2, 3],
|
self._test_do_request(200, jsonutils.dumps([1, 2, 3]), [1, 2, 3],
|
||||||
path_prefix='/dummy')
|
path_prefix='/dummy')
|
||||||
|
|
||||||
def test_do_request_returns_404(self):
|
def test_do_request_returns_404(self):
|
||||||
@ -100,7 +100,7 @@ class OFCClientTest(base.BaseTestCase):
|
|||||||
exc_checks)
|
exc_checks)
|
||||||
|
|
||||||
def test_do_request_error_json_body(self):
|
def test_do_request_error_json_body(self):
|
||||||
resbody = json.dumps({'err_code': 40022,
|
resbody = jsonutils.dumps({'err_code': 40022,
|
||||||
'err_msg': 'This is an error.'})
|
'err_msg': 'This is an error.'})
|
||||||
errmsg = _("An OFC exception has occurred: Operation on OFC failed")
|
errmsg = _("An OFC exception has occurred: Operation on OFC failed")
|
||||||
exc_checks = {'status': 400, 'err_code': 40022,
|
exc_checks = {'status': 400, 'err_code': 40022,
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.plugins.oneconvergence.lib import nvsdlib
|
from neutron.plugins.oneconvergence.lib import nvsdlib
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
|
|
||||||
@ -65,10 +65,11 @@ class TestNVSDApi(base.BaseTestCase):
|
|||||||
return_value=resp) as send_request:
|
return_value=resp) as send_request:
|
||||||
uri = NETWORKS_URI % TEST_TENANT
|
uri = NETWORKS_URI % TEST_TENANT
|
||||||
net = self.nvsdlib.create_network(network_obj)
|
net = self.nvsdlib.create_network(network_obj)
|
||||||
send_request.assert_called_once_with("POST", uri,
|
send_request.assert_called_once_with(
|
||||||
body=json.dumps(network_obj),
|
"POST", uri,
|
||||||
resource='network',
|
body=jsonutils.dumps(network_obj),
|
||||||
tenant_id=TEST_TENANT)
|
resource='network',
|
||||||
|
tenant_id=TEST_TENANT)
|
||||||
self.assertEqual(net, {'id': 'uuid'})
|
self.assertEqual(net, {'id': 'uuid'})
|
||||||
|
|
||||||
def test_update_network(self):
|
def test_update_network(self):
|
||||||
@ -79,7 +80,7 @@ class TestNVSDApi(base.BaseTestCase):
|
|||||||
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
||||||
self.nvsdlib.update_network(network, update_network)
|
self.nvsdlib.update_network(network, update_network)
|
||||||
send_request.assert_called_once_with(
|
send_request.assert_called_once_with(
|
||||||
"PUT", uri, body=json.dumps(update_network),
|
"PUT", uri, body=jsonutils.dumps(update_network),
|
||||||
resource='network', tenant_id=TEST_TENANT,
|
resource='network', tenant_id=TEST_TENANT,
|
||||||
resource_id=TEST_NET)
|
resource_id=TEST_NET)
|
||||||
|
|
||||||
@ -123,10 +124,11 @@ class TestNVSDApi(base.BaseTestCase):
|
|||||||
"admin_state_up": True,
|
"admin_state_up": True,
|
||||||
"network_id": TEST_NET,
|
"network_id": TEST_NET,
|
||||||
"status": 'ACTIVE'}
|
"status": 'ACTIVE'}
|
||||||
send_request.assert_called_once_with("POST", path,
|
send_request.assert_called_once_with(
|
||||||
body=json.dumps(expected),
|
"POST", path,
|
||||||
resource='port',
|
body=jsonutils.dumps(expected),
|
||||||
tenant_id=TEST_TENANT)
|
resource='port',
|
||||||
|
tenant_id=TEST_TENANT)
|
||||||
|
|
||||||
def test_update_port(self):
|
def test_update_port(self):
|
||||||
port = {'id': TEST_PORT,
|
port = {'id': TEST_PORT,
|
||||||
@ -137,11 +139,12 @@ class TestNVSDApi(base.BaseTestCase):
|
|||||||
|
|
||||||
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
||||||
self.nvsdlib.update_port(TEST_TENANT, port, port_update)
|
self.nvsdlib.update_port(TEST_TENANT, port, port_update)
|
||||||
send_request.assert_called_once_with("PUT", uri,
|
send_request.assert_called_once_with(
|
||||||
body=json.dumps(port_update),
|
"PUT", uri,
|
||||||
resource='port',
|
body=jsonutils.dumps(port_update),
|
||||||
resource_id='test-port',
|
resource='port',
|
||||||
tenant_id=TEST_TENANT)
|
resource_id='test-port',
|
||||||
|
tenant_id=TEST_TENANT)
|
||||||
|
|
||||||
def test_delete_port(self):
|
def test_delete_port(self):
|
||||||
port = {'network_id': TEST_NET,
|
port = {'network_id': TEST_NET,
|
||||||
@ -164,7 +167,7 @@ class TestNVSDApi(base.BaseTestCase):
|
|||||||
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
||||||
self.nvsdlib.create_subnet(subnet)
|
self.nvsdlib.create_subnet(subnet)
|
||||||
send_request.assert_called_once_with("POST", uri,
|
send_request.assert_called_once_with("POST", uri,
|
||||||
body=json.dumps(subnet),
|
body=jsonutils.dumps(subnet),
|
||||||
resource='subnet',
|
resource='subnet',
|
||||||
tenant_id=TEST_TENANT)
|
tenant_id=TEST_TENANT)
|
||||||
|
|
||||||
@ -178,7 +181,8 @@ class TestNVSDApi(base.BaseTestCase):
|
|||||||
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
||||||
self.nvsdlib.update_subnet(subnet, subnet_update)
|
self.nvsdlib.update_subnet(subnet, subnet_update)
|
||||||
send_request.assert_called_once_with(
|
send_request.assert_called_once_with(
|
||||||
"PUT", uri, body=json.dumps(subnet_update), resource='subnet',
|
"PUT", uri,
|
||||||
|
body=jsonutils.dumps(subnet_update), resource='subnet',
|
||||||
tenant_id=TEST_TENANT, resource_id=TEST_SUBNET)
|
tenant_id=TEST_TENANT, resource_id=TEST_SUBNET)
|
||||||
|
|
||||||
def test_delete_subnet(self):
|
def test_delete_subnet(self):
|
||||||
@ -201,10 +205,11 @@ class TestNVSDApi(base.BaseTestCase):
|
|||||||
|
|
||||||
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
||||||
self.nvsdlib.create_floatingip(floatingip)
|
self.nvsdlib.create_floatingip(floatingip)
|
||||||
send_request.assert_called_once_with("POST", uri,
|
send_request.assert_called_once_with(
|
||||||
body=json.dumps(floatingip),
|
"POST", uri,
|
||||||
resource='floating_ip',
|
body=jsonutils.dumps(floatingip),
|
||||||
tenant_id=TEST_TENANT)
|
resource='floating_ip',
|
||||||
|
tenant_id=TEST_TENANT)
|
||||||
|
|
||||||
def test_update_floatingip(self):
|
def test_update_floatingip(self):
|
||||||
floatingip = {'id': TEST_FIP,
|
floatingip = {'id': TEST_FIP,
|
||||||
@ -215,7 +220,8 @@ class TestNVSDApi(base.BaseTestCase):
|
|||||||
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
||||||
self.nvsdlib.update_floatingip(floatingip, floatingip_update)
|
self.nvsdlib.update_floatingip(floatingip, floatingip_update)
|
||||||
send_request.assert_called_once_with(
|
send_request.assert_called_once_with(
|
||||||
"PUT", uri, body=json.dumps(floatingip_update['floatingip']),
|
"PUT", uri,
|
||||||
|
body=jsonutils.dumps(floatingip_update['floatingip']),
|
||||||
resource='floating_ip', tenant_id=TEST_TENANT,
|
resource='floating_ip', tenant_id=TEST_TENANT,
|
||||||
resource_id=TEST_FIP)
|
resource_id=TEST_FIP)
|
||||||
|
|
||||||
@ -237,7 +243,7 @@ class TestNVSDApi(base.BaseTestCase):
|
|||||||
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
||||||
self.nvsdlib.create_router(router)
|
self.nvsdlib.create_router(router)
|
||||||
send_request.assert_called_once_with(
|
send_request.assert_called_once_with(
|
||||||
"POST", uri, body=json.dumps(router), resource='router',
|
"POST", uri, body=jsonutils.dumps(router), resource='router',
|
||||||
tenant_id=TEST_TENANT)
|
tenant_id=TEST_TENANT)
|
||||||
|
|
||||||
def test_update_router(self):
|
def test_update_router(self):
|
||||||
@ -247,7 +253,7 @@ class TestNVSDApi(base.BaseTestCase):
|
|||||||
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
with mock.patch.object(self.nvsdlib, 'send_request') as send_request:
|
||||||
self.nvsdlib.update_router(router)
|
self.nvsdlib.update_router(router)
|
||||||
send_request.assert_called_once_with(
|
send_request.assert_called_once_with(
|
||||||
"PUT", uri, body=json.dumps(router),
|
"PUT", uri, body=jsonutils.dumps(router),
|
||||||
resource='router', tenant_id=TEST_TENANT,
|
resource='router', tenant_id=TEST_TENANT,
|
||||||
resource_id=TEST_ROUTER)
|
resource_id=TEST_ROUTER)
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
import mock
|
import mock
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.plugins.oneconvergence.lib import config # noqa
|
from neutron.plugins.oneconvergence.lib import config # noqa
|
||||||
from neutron.plugins.oneconvergence.lib import plugin_helper as client
|
from neutron.plugins.oneconvergence.lib import plugin_helper as client
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
@ -30,14 +30,14 @@ class TestPluginHelper(base.BaseTestCase):
|
|||||||
def get_response(self, *args, **kwargs):
|
def get_response(self, *args, **kwargs):
|
||||||
response = mock.Mock()
|
response = mock.Mock()
|
||||||
response.status_code = requests.codes.ok
|
response.status_code = requests.codes.ok
|
||||||
response.content = json.dumps({'session_uuid': 'new_auth_token'})
|
response.content = jsonutils.dumps({'session_uuid': 'new_auth_token'})
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def test_login(self):
|
def test_login(self):
|
||||||
login_url = ('http://127.0.0.1:8082/pluginhandler/ocplugin/'
|
login_url = ('http://127.0.0.1:8082/pluginhandler/ocplugin/'
|
||||||
'authmgmt/login')
|
'authmgmt/login')
|
||||||
headers = {'Content-Type': 'application/json'}
|
headers = {'Content-Type': 'application/json'}
|
||||||
data = json.dumps({"user_name": "ocplugin", "passwd": "oc123"})
|
data = jsonutils.dumps({"user_name": "ocplugin", "passwd": "oc123"})
|
||||||
timeout = 30.0
|
timeout = 30.0
|
||||||
|
|
||||||
with mock.patch.object(self.nvsdcontroller, 'do_request',
|
with mock.patch.object(self.nvsdcontroller, 'do_request',
|
||||||
|
@ -24,7 +24,7 @@ from six.moves import queue as Queue
|
|||||||
from neutron import context
|
from neutron import context
|
||||||
from neutron.extensions import loadbalancer
|
from neutron.extensions import loadbalancer
|
||||||
from neutron import manager
|
from neutron import manager
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.plugins.common import constants
|
from neutron.plugins.common import constants
|
||||||
from neutron.services.loadbalancer.drivers.radware import driver
|
from neutron.services.loadbalancer.drivers.radware import driver
|
||||||
from neutron.services.loadbalancer.drivers.radware import exceptions as r_exc
|
from neutron.services.loadbalancer.drivers.radware import exceptions as r_exc
|
||||||
@ -66,9 +66,9 @@ def rest_call_function_mock(action, resource, data, headers, binary=False):
|
|||||||
def _get_handler(resource):
|
def _get_handler(resource):
|
||||||
if resource == GET_200[2]:
|
if resource == GET_200[2]:
|
||||||
if rest_call_function_mock.TEMPLATES_MISSING:
|
if rest_call_function_mock.TEMPLATES_MISSING:
|
||||||
data = json.loads('[]')
|
data = jsonutils.loads('[]')
|
||||||
else:
|
else:
|
||||||
data = json.loads(
|
data = jsonutils.loads(
|
||||||
'[{"name":"openstack_l2_l3"},{"name":"openstack_l4"}]'
|
'[{"name":"openstack_l2_l3"},{"name":"openstack_l4"}]'
|
||||||
)
|
)
|
||||||
return 200, '', '', data
|
return 200, '', '', data
|
||||||
@ -76,7 +76,7 @@ def _get_handler(resource):
|
|||||||
if resource in GET_200:
|
if resource in GET_200:
|
||||||
return 200, '', '', ''
|
return 200, '', '', ''
|
||||||
else:
|
else:
|
||||||
data = json.loads('{"complete":"True", "success": "True"}')
|
data = jsonutils.loads('{"complete":"True", "success": "True"}')
|
||||||
return 202, '', '', data
|
return 202, '', '', data
|
||||||
|
|
||||||
|
|
||||||
@ -86,10 +86,10 @@ def _delete_handler(resource):
|
|||||||
|
|
||||||
def _post_handler(resource, binary):
|
def _post_handler(resource, binary):
|
||||||
if re.search(r'/api/workflow/.+/action/.+', resource):
|
if re.search(r'/api/workflow/.+/action/.+', resource):
|
||||||
data = json.loads('{"uri":"some_uri"}')
|
data = jsonutils.loads('{"uri":"some_uri"}')
|
||||||
return 202, '', '', data
|
return 202, '', '', data
|
||||||
elif re.search(r'/api/service\?name=.+', resource):
|
elif re.search(r'/api/service\?name=.+', resource):
|
||||||
data = json.loads('{"links":{"actions":{"provision":"someuri"}}}')
|
data = jsonutils.loads('{"links":{"actions":{"provision":"someuri"}}}')
|
||||||
return 201, '', '', data
|
return 201, '', '', data
|
||||||
elif binary:
|
elif binary:
|
||||||
return 201, '', '', ''
|
return 201, '', '', ''
|
||||||
|
@ -41,3 +41,29 @@ class HackingTestCase(base.BaseTestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
0, len(list(checks.validate_log_translations(ok,
|
0, len(list(checks.validate_log_translations(ok,
|
||||||
ok, 'f'))))
|
ok, 'f'))))
|
||||||
|
|
||||||
|
def test_use_jsonutils(self):
|
||||||
|
def __get_msg(fun):
|
||||||
|
msg = ("N321: jsonutils.%(fun)s must be used instead of "
|
||||||
|
"json.%(fun)s" % {'fun': fun})
|
||||||
|
return [(0, msg)]
|
||||||
|
|
||||||
|
for method in ('dump', 'dumps', 'load', 'loads'):
|
||||||
|
self.assertEqual(
|
||||||
|
__get_msg(method),
|
||||||
|
list(checks.use_jsonutils("json.%s(" % method,
|
||||||
|
"./neutron/common/rpc.py")))
|
||||||
|
|
||||||
|
self.assertEqual(0,
|
||||||
|
len(list(checks.use_jsonutils("jsonx.%s(" % method,
|
||||||
|
"./neutron/common/rpc.py"))))
|
||||||
|
|
||||||
|
self.assertEqual(0,
|
||||||
|
len(list(checks.use_jsonutils("json.%sx(" % method,
|
||||||
|
"./neutron/common/rpc.py"))))
|
||||||
|
|
||||||
|
self.assertEqual(0,
|
||||||
|
len(list(checks.use_jsonutils(
|
||||||
|
"json.%s" % method,
|
||||||
|
"./neutron/plugins/openvswitch/agent/xenapi/etc/xapi.d/"
|
||||||
|
"plugins/netwrap"))))
|
||||||
|
@ -27,7 +27,7 @@ from neutron.common import exceptions
|
|||||||
from neutron import context
|
from neutron import context
|
||||||
from neutron import manager
|
from neutron import manager
|
||||||
from neutron.openstack.common import importutils
|
from neutron.openstack.common import importutils
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import policy as common_policy
|
from neutron.openstack.common import policy as common_policy
|
||||||
from neutron import policy
|
from neutron import policy
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
@ -524,7 +524,7 @@ class NeutronPolicyTestCase(base.BaseTestCase):
|
|||||||
|
|
||||||
def _test_set_rules_with_deprecated_policy(self, input_rules,
|
def _test_set_rules_with_deprecated_policy(self, input_rules,
|
||||||
expected_rules):
|
expected_rules):
|
||||||
policy._set_rules(json.dumps(input_rules))
|
policy._set_rules(jsonutils.dumps(input_rules))
|
||||||
# verify deprecated policy has been removed
|
# verify deprecated policy has been removed
|
||||||
for pol in input_rules.keys():
|
for pol in input_rules.keys():
|
||||||
self.assertNotIn(pol, common_policy._rules)
|
self.assertNotIn(pol, common_policy._rules)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import six.moves.urllib.parse as urlparse
|
import six.moves.urllib.parse as urlparse
|
||||||
|
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
from neutron.openstack.common import uuidutils
|
from neutron.openstack.common import uuidutils
|
||||||
from neutron.plugins.vmware.api_client import exception as api_exc
|
from neutron.plugins.vmware.api_client import exception as api_exc
|
||||||
@ -153,7 +153,7 @@ class FakeClient:
|
|||||||
return (tag_filter, attr_filter, page_len, page_cursor)
|
return (tag_filter, attr_filter, page_len, page_cursor)
|
||||||
|
|
||||||
def _add_lswitch(self, body):
|
def _add_lswitch(self, body):
|
||||||
fake_lswitch = json.loads(body)
|
fake_lswitch = jsonutils.loads(body)
|
||||||
fake_lswitch['uuid'] = uuidutils.generate_uuid()
|
fake_lswitch['uuid'] = uuidutils.generate_uuid()
|
||||||
self._fake_lswitch_dict[fake_lswitch['uuid']] = fake_lswitch
|
self._fake_lswitch_dict[fake_lswitch['uuid']] = fake_lswitch
|
||||||
# put the tenant_id and the zone_uuid in the main dict
|
# put the tenant_id and the zone_uuid in the main dict
|
||||||
@ -167,7 +167,7 @@ class FakeClient:
|
|||||||
return fake_lswitch
|
return fake_lswitch
|
||||||
|
|
||||||
def _build_lrouter(self, body, uuid=None):
|
def _build_lrouter(self, body, uuid=None):
|
||||||
fake_lrouter = json.loads(body)
|
fake_lrouter = jsonutils.loads(body)
|
||||||
if uuid:
|
if uuid:
|
||||||
fake_lrouter['uuid'] = uuid
|
fake_lrouter['uuid'] = uuid
|
||||||
fake_lrouter['tenant_id'] = self._get_tag(fake_lrouter, 'os_tid')
|
fake_lrouter['tenant_id'] = self._get_tag(fake_lrouter, 'os_tid')
|
||||||
@ -198,13 +198,13 @@ class FakeClient:
|
|||||||
return fake_lrouter
|
return fake_lrouter
|
||||||
|
|
||||||
def _add_lqueue(self, body):
|
def _add_lqueue(self, body):
|
||||||
fake_lqueue = json.loads(body)
|
fake_lqueue = jsonutils.loads(body)
|
||||||
fake_lqueue['uuid'] = uuidutils.generate_uuid()
|
fake_lqueue['uuid'] = uuidutils.generate_uuid()
|
||||||
self._fake_lqueue_dict[fake_lqueue['uuid']] = fake_lqueue
|
self._fake_lqueue_dict[fake_lqueue['uuid']] = fake_lqueue
|
||||||
return fake_lqueue
|
return fake_lqueue
|
||||||
|
|
||||||
def _add_lswitch_lport(self, body, ls_uuid):
|
def _add_lswitch_lport(self, body, ls_uuid):
|
||||||
fake_lport = json.loads(body)
|
fake_lport = jsonutils.loads(body)
|
||||||
new_uuid = uuidutils.generate_uuid()
|
new_uuid = uuidutils.generate_uuid()
|
||||||
fake_lport['uuid'] = new_uuid
|
fake_lport['uuid'] = new_uuid
|
||||||
# put the tenant_id and the ls_uuid in the main dict
|
# put the tenant_id and the ls_uuid in the main dict
|
||||||
@ -231,7 +231,7 @@ class FakeClient:
|
|||||||
return fake_lport
|
return fake_lport
|
||||||
|
|
||||||
def _build_lrouter_lport(self, body, new_uuid=None, lr_uuid=None):
|
def _build_lrouter_lport(self, body, new_uuid=None, lr_uuid=None):
|
||||||
fake_lport = json.loads(body)
|
fake_lport = jsonutils.loads(body)
|
||||||
if new_uuid:
|
if new_uuid:
|
||||||
fake_lport['uuid'] = new_uuid
|
fake_lport['uuid'] = new_uuid
|
||||||
# put the tenant_id and the le_uuid in the main dict
|
# put the tenant_id and the le_uuid in the main dict
|
||||||
@ -243,7 +243,7 @@ class FakeClient:
|
|||||||
'q_port_id')
|
'q_port_id')
|
||||||
# replace ip_address with its json dump
|
# replace ip_address with its json dump
|
||||||
if 'ip_addresses' in fake_lport:
|
if 'ip_addresses' in fake_lport:
|
||||||
ip_addresses_json = json.dumps(fake_lport['ip_addresses'])
|
ip_addresses_json = jsonutils.dumps(fake_lport['ip_addresses'])
|
||||||
fake_lport['ip_addresses_json'] = ip_addresses_json
|
fake_lport['ip_addresses_json'] = ip_addresses_json
|
||||||
return fake_lport
|
return fake_lport
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ class FakeClient:
|
|||||||
return fake_lport
|
return fake_lport
|
||||||
|
|
||||||
def _add_securityprofile(self, body):
|
def _add_securityprofile(self, body):
|
||||||
fake_securityprofile = json.loads(body)
|
fake_securityprofile = jsonutils.loads(body)
|
||||||
fake_securityprofile['uuid'] = uuidutils.generate_uuid()
|
fake_securityprofile['uuid'] = uuidutils.generate_uuid()
|
||||||
fake_securityprofile['tenant_id'] = self._get_tag(
|
fake_securityprofile['tenant_id'] = self._get_tag(
|
||||||
fake_securityprofile, 'os_tid')
|
fake_securityprofile, 'os_tid')
|
||||||
@ -276,18 +276,18 @@ class FakeClient:
|
|||||||
return fake_securityprofile
|
return fake_securityprofile
|
||||||
|
|
||||||
def _add_lrouter_nat(self, body, lr_uuid):
|
def _add_lrouter_nat(self, body, lr_uuid):
|
||||||
fake_nat = json.loads(body)
|
fake_nat = jsonutils.loads(body)
|
||||||
new_uuid = uuidutils.generate_uuid()
|
new_uuid = uuidutils.generate_uuid()
|
||||||
fake_nat['uuid'] = new_uuid
|
fake_nat['uuid'] = new_uuid
|
||||||
fake_nat['lr_uuid'] = lr_uuid
|
fake_nat['lr_uuid'] = lr_uuid
|
||||||
self._fake_lrouter_nat_dict[fake_nat['uuid']] = fake_nat
|
self._fake_lrouter_nat_dict[fake_nat['uuid']] = fake_nat
|
||||||
if 'match' in fake_nat:
|
if 'match' in fake_nat:
|
||||||
match_json = json.dumps(fake_nat['match'])
|
match_json = jsonutils.dumps(fake_nat['match'])
|
||||||
fake_nat['match_json'] = match_json
|
fake_nat['match_json'] = match_json
|
||||||
return fake_nat
|
return fake_nat
|
||||||
|
|
||||||
def _add_gatewayservice(self, body):
|
def _add_gatewayservice(self, body):
|
||||||
fake_gwservice = json.loads(body)
|
fake_gwservice = jsonutils.loads(body)
|
||||||
fake_gwservice['uuid'] = str(uuidutils.generate_uuid())
|
fake_gwservice['uuid'] = str(uuidutils.generate_uuid())
|
||||||
fake_gwservice['tenant_id'] = self._get_tag(
|
fake_gwservice['tenant_id'] = self._get_tag(
|
||||||
fake_gwservice, 'os_tid')
|
fake_gwservice, 'os_tid')
|
||||||
@ -428,7 +428,7 @@ class FakeClient:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def _build_item(resource):
|
def _build_item(resource):
|
||||||
item = json.loads(response_template % resource)
|
item = jsonutils.loads(response_template % resource)
|
||||||
if relations:
|
if relations:
|
||||||
for relation in relations:
|
for relation in relations:
|
||||||
self._build_relation(resource, item,
|
self._build_relation(resource, item,
|
||||||
@ -437,7 +437,7 @@ class FakeClient:
|
|||||||
|
|
||||||
for item in res_dict.itervalues():
|
for item in res_dict.itervalues():
|
||||||
if 'tags' in item:
|
if 'tags' in item:
|
||||||
item['tags_json'] = json.dumps(item['tags'])
|
item['tags_json'] = jsonutils.dumps(item['tags'])
|
||||||
if resource_type in (self.LSWITCH_LPORT_RESOURCE,
|
if resource_type in (self.LSWITCH_LPORT_RESOURCE,
|
||||||
self.LSWITCH_LPORT_ATT,
|
self.LSWITCH_LPORT_ATT,
|
||||||
self.LSWITCH_LPORT_STATUS):
|
self.LSWITCH_LPORT_STATUS):
|
||||||
@ -470,7 +470,7 @@ class FakeClient:
|
|||||||
response_dict['page_cursor'] = next_cursor
|
response_dict['page_cursor'] = next_cursor
|
||||||
if do_result_count:
|
if do_result_count:
|
||||||
response_dict['result_count'] = total_items
|
response_dict['result_count'] = total_items
|
||||||
return json.dumps(response_dict)
|
return jsonutils.dumps(response_dict)
|
||||||
|
|
||||||
def _show(self, resource_type, response_file,
|
def _show(self, resource_type, response_file,
|
||||||
uuid1, uuid2=None, relations=None):
|
uuid1, uuid2=None, relations=None):
|
||||||
@ -482,20 +482,20 @@ class FakeClient:
|
|||||||
res_dict = getattr(self, '_fake_%s_dict' % resource_type)
|
res_dict = getattr(self, '_fake_%s_dict' % resource_type)
|
||||||
for item in res_dict.itervalues():
|
for item in res_dict.itervalues():
|
||||||
if 'tags' in item:
|
if 'tags' in item:
|
||||||
item['tags_json'] = json.dumps(item['tags'])
|
item['tags_json'] = jsonutils.dumps(item['tags'])
|
||||||
|
|
||||||
# replace sec prof rules with their json dump
|
# replace sec prof rules with their json dump
|
||||||
def jsonify_rules(rule_key):
|
def jsonify_rules(rule_key):
|
||||||
if rule_key in item:
|
if rule_key in item:
|
||||||
rules_json = json.dumps(item[rule_key])
|
rules_json = jsonutils.dumps(item[rule_key])
|
||||||
item['%s_json' % rule_key] = rules_json
|
item['%s_json' % rule_key] = rules_json
|
||||||
jsonify_rules('logical_port_egress_rules')
|
jsonify_rules('logical_port_egress_rules')
|
||||||
jsonify_rules('logical_port_ingress_rules')
|
jsonify_rules('logical_port_ingress_rules')
|
||||||
|
|
||||||
items = [json.loads(response_template % res_dict[res_uuid])
|
items = [jsonutils.loads(response_template % res_dict[res_uuid])
|
||||||
for res_uuid in res_dict if res_uuid == target_uuid]
|
for res_uuid in res_dict if res_uuid == target_uuid]
|
||||||
if items:
|
if items:
|
||||||
return json.dumps(items[0])
|
return jsonutils.dumps(items[0])
|
||||||
raise api_exc.ResourceNotFound()
|
raise api_exc.ResourceNotFound()
|
||||||
|
|
||||||
def handle_get(self, url):
|
def handle_get(self, url):
|
||||||
@ -538,7 +538,7 @@ class FakeClient:
|
|||||||
with open("%s/%s" % (self.fake_files_path, response_file)) as f:
|
with open("%s/%s" % (self.fake_files_path, response_file)) as f:
|
||||||
response_template = f.read()
|
response_template = f.read()
|
||||||
add_resource = getattr(self, '_add_%s' % res_type)
|
add_resource = getattr(self, '_add_%s' % res_type)
|
||||||
body_json = json.loads(body)
|
body_json = jsonutils.loads(body)
|
||||||
val_func = self._validators.get(res_type)
|
val_func = self._validators.get(res_type)
|
||||||
if val_func:
|
if val_func:
|
||||||
val_func(body_json)
|
val_func(body_json)
|
||||||
@ -562,7 +562,7 @@ class FakeClient:
|
|||||||
is_attachment = True
|
is_attachment = True
|
||||||
res_type = res_type[:res_type.index('attachment')]
|
res_type = res_type[:res_type.index('attachment')]
|
||||||
res_dict = getattr(self, '_fake_%s_dict' % res_type)
|
res_dict = getattr(self, '_fake_%s_dict' % res_type)
|
||||||
body_json = json.loads(body)
|
body_json = jsonutils.loads(body)
|
||||||
val_func = self._validators.get(res_type)
|
val_func = self._validators.get(res_type)
|
||||||
if val_func:
|
if val_func:
|
||||||
val_func(body_json)
|
val_func(body_json)
|
||||||
@ -577,7 +577,7 @@ class FakeClient:
|
|||||||
resource.update(body_json)
|
resource.update(body_json)
|
||||||
else:
|
else:
|
||||||
relations = resource.get("_relations", {})
|
relations = resource.get("_relations", {})
|
||||||
body_2 = json.loads(body)
|
body_2 = jsonutils.loads(body)
|
||||||
resource['att_type'] = body_2['type']
|
resource['att_type'] = body_2['type']
|
||||||
relations['LogicalPortAttachment'] = body_2
|
relations['LogicalPortAttachment'] = body_2
|
||||||
resource['_relations'] = relations
|
resource['_relations'] = relations
|
||||||
@ -591,7 +591,8 @@ class FakeClient:
|
|||||||
self.LROUTER_RESOURCE)
|
self.LROUTER_RESOURCE)
|
||||||
res_dict_2 = getattr(self, '_fake_%s_dict' % res_type_2)
|
res_dict_2 = getattr(self, '_fake_%s_dict' % res_type_2)
|
||||||
body_2['peer_port_uuid'] = uuids[-1]
|
body_2['peer_port_uuid'] = uuids[-1]
|
||||||
resource_2 = res_dict_2[json.loads(body)['peer_port_uuid']]
|
resource_2 = \
|
||||||
|
res_dict_2[jsonutils.loads(body)['peer_port_uuid']]
|
||||||
relations_2 = resource_2.get("_relations")
|
relations_2 = resource_2.get("_relations")
|
||||||
if not relations_2:
|
if not relations_2:
|
||||||
relations_2 = {}
|
relations_2 = {}
|
||||||
@ -627,7 +628,7 @@ class FakeClient:
|
|||||||
lr_uuid = None
|
lr_uuid = None
|
||||||
lp_uuid = uuids[1]
|
lp_uuid = uuids[1]
|
||||||
response = response_template % self._fill_attachment(
|
response = response_template % self._fill_attachment(
|
||||||
json.loads(body), ls_uuid, lr_uuid, lp_uuid)
|
jsonutils.loads(body), ls_uuid, lr_uuid, lp_uuid)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def handle_delete(self, url):
|
def handle_delete(self, url):
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
import mock
|
import mock
|
||||||
|
|
||||||
from neutron.common import exceptions
|
from neutron.common import exceptions
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.plugins.vmware.api_client import exception as api_exc
|
from neutron.plugins.vmware.api_client import exception as api_exc
|
||||||
from neutron.plugins.vmware.common import exceptions as nsx_exc
|
from neutron.plugins.vmware.common import exceptions as nsx_exc
|
||||||
from neutron.plugins.vmware.common import utils
|
from neutron.plugins.vmware.common import utils
|
||||||
@ -68,7 +68,7 @@ class LSNTestCase(base.BaseTestCase):
|
|||||||
lsnlib.lsn_for_network_create(self.cluster, net_id)
|
lsnlib.lsn_for_network_create(self.cluster, net_id)
|
||||||
self.mock_request.assert_called_once_with(
|
self.mock_request.assert_called_once_with(
|
||||||
"POST", "/ws.v1/lservices-node",
|
"POST", "/ws.v1/lservices-node",
|
||||||
json.dumps(obj), cluster=self.cluster)
|
jsonutils.dumps(obj), cluster=self.cluster)
|
||||||
|
|
||||||
def test_lsn_for_network_get(self):
|
def test_lsn_for_network_get(self):
|
||||||
net_id = "foo_network_id"
|
net_id = "foo_network_id"
|
||||||
@ -120,7 +120,7 @@ class LSNTestCase(base.BaseTestCase):
|
|||||||
'/ws.v1/lservices-node/%s/lport/%s/%s' % (lsn_id,
|
'/ws.v1/lservices-node/%s/lport/%s/%s' % (lsn_id,
|
||||||
lsn_port_id,
|
lsn_port_id,
|
||||||
lsn_type),
|
lsn_type),
|
||||||
json.dumps({'hosts': hosts_data}),
|
jsonutils.dumps({'hosts': hosts_data}),
|
||||||
cluster=self.cluster)
|
cluster=self.cluster)
|
||||||
|
|
||||||
def test_lsn_port_dhcp_entries_update(self):
|
def test_lsn_port_dhcp_entries_update(self):
|
||||||
@ -156,7 +156,7 @@ class LSNTestCase(base.BaseTestCase):
|
|||||||
}
|
}
|
||||||
self.mock_request.assert_called_once_with(
|
self.mock_request.assert_called_once_with(
|
||||||
"POST", "/ws.v1/lservices-node/%s/lport" % lsn_id,
|
"POST", "/ws.v1/lservices-node/%s/lport" % lsn_id,
|
||||||
json.dumps(port_obj), cluster=self.cluster)
|
jsonutils.dumps(port_obj), cluster=self.cluster)
|
||||||
|
|
||||||
def test_lsn_port_delete(self):
|
def test_lsn_port_delete(self):
|
||||||
lsn_id = "foo_lsn_id"
|
lsn_id = "foo_lsn_id"
|
||||||
@ -231,8 +231,8 @@ class LSNTestCase(base.BaseTestCase):
|
|||||||
"PUT",
|
"PUT",
|
||||||
("/ws.v1/lservices-node/%s/lport/%s/"
|
("/ws.v1/lservices-node/%s/lport/%s/"
|
||||||
"attachment") % (lsn_id, lsn_port_id),
|
"attachment") % (lsn_id, lsn_port_id),
|
||||||
json.dumps({"peer_port_uuid": lswitch_port_id,
|
jsonutils.dumps({"peer_port_uuid": lswitch_port_id,
|
||||||
"type": "PatchAttachment"}),
|
"type": "PatchAttachment"}),
|
||||||
cluster=self.cluster)
|
cluster=self.cluster)
|
||||||
|
|
||||||
def test_lsn_port_plug_network_raise_conflict(self):
|
def test_lsn_port_plug_network_raise_conflict(self):
|
||||||
@ -255,12 +255,12 @@ class LSNTestCase(base.BaseTestCase):
|
|||||||
]
|
]
|
||||||
self.mock_request.assert_has_calls([
|
self.mock_request.assert_has_calls([
|
||||||
mock.call("PUT", "/ws.v1/lservices-node/%s/dhcp" % lsn_id,
|
mock.call("PUT", "/ws.v1/lservices-node/%s/dhcp" % lsn_id,
|
||||||
json.dumps({"enabled": is_enabled}),
|
jsonutils.dumps({"enabled": is_enabled}),
|
||||||
cluster=self.cluster),
|
cluster=self.cluster),
|
||||||
mock.call("PUT",
|
mock.call("PUT",
|
||||||
("/ws.v1/lservices-node/%s/"
|
("/ws.v1/lservices-node/%s/"
|
||||||
"lport/%s/dhcp") % (lsn_id, lsn_port_id),
|
"lport/%s/dhcp") % (lsn_id, lsn_port_id),
|
||||||
json.dumps({"options": opt_array}),
|
jsonutils.dumps({"options": opt_array}),
|
||||||
cluster=self.cluster)
|
cluster=self.cluster)
|
||||||
])
|
])
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ class LSNTestCase(base.BaseTestCase):
|
|||||||
self.mock_request.assert_has_calls([
|
self.mock_request.assert_has_calls([
|
||||||
mock.call("PUT",
|
mock.call("PUT",
|
||||||
"/ws.v1/lservices-node/%s/metadata-proxy" % lsn_id,
|
"/ws.v1/lservices-node/%s/metadata-proxy" % lsn_id,
|
||||||
json.dumps(lsn_obj),
|
jsonutils.dumps(lsn_obj),
|
||||||
cluster=self.cluster),
|
cluster=self.cluster),
|
||||||
])
|
])
|
||||||
|
|
||||||
@ -335,7 +335,7 @@ class LSNTestCase(base.BaseTestCase):
|
|||||||
"POST",
|
"POST",
|
||||||
("/ws.v1/lservices-node/%s/lport/"
|
("/ws.v1/lservices-node/%s/lport/"
|
||||||
"%s/%s?action=%s") % (lsn_id, lsn_port_id, extra_action, action),
|
"%s/%s?action=%s") % (lsn_id, lsn_port_id, extra_action, action),
|
||||||
json.dumps(host), cluster=self.cluster)
|
jsonutils.dumps(host), cluster=self.cluster)
|
||||||
|
|
||||||
def test_lsn_port_dhcp_host_add(self):
|
def test_lsn_port_dhcp_host_add(self):
|
||||||
host = {
|
host = {
|
||||||
|
@ -25,7 +25,7 @@ from neutron.common import constants
|
|||||||
from neutron.common import exceptions as n_exc
|
from neutron.common import exceptions as n_exc
|
||||||
from neutron import context
|
from neutron import context
|
||||||
from neutron.extensions import l3
|
from neutron.extensions import l3
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import log
|
from neutron.openstack.common import log
|
||||||
from neutron.plugins.vmware.api_client import client
|
from neutron.plugins.vmware.api_client import client
|
||||||
from neutron.plugins.vmware.api_client import exception as api_exc
|
from neutron.plugins.vmware.api_client import exception as api_exc
|
||||||
@ -61,19 +61,19 @@ class CacheTestCase(base.BaseTestCase):
|
|||||||
self.nsx_cache._lswitches)
|
self.nsx_cache._lswitches)
|
||||||
self.nsx_cache._lswitches[lswitch['uuid']] = (
|
self.nsx_cache._lswitches[lswitch['uuid']] = (
|
||||||
{'data': lswitch,
|
{'data': lswitch,
|
||||||
'hash': hash(json.dumps(lswitch))})
|
'hash': hash(jsonutils.dumps(lswitch))})
|
||||||
for lswitchport in LSWITCHPORTS:
|
for lswitchport in LSWITCHPORTS:
|
||||||
self.nsx_cache._uuid_dict_mappings[lswitchport['uuid']] = (
|
self.nsx_cache._uuid_dict_mappings[lswitchport['uuid']] = (
|
||||||
self.nsx_cache._lswitchports)
|
self.nsx_cache._lswitchports)
|
||||||
self.nsx_cache._lswitchports[lswitchport['uuid']] = (
|
self.nsx_cache._lswitchports[lswitchport['uuid']] = (
|
||||||
{'data': lswitchport,
|
{'data': lswitchport,
|
||||||
'hash': hash(json.dumps(lswitchport))})
|
'hash': hash(jsonutils.dumps(lswitchport))})
|
||||||
for lrouter in LROUTERS:
|
for lrouter in LROUTERS:
|
||||||
self.nsx_cache._uuid_dict_mappings[lrouter['uuid']] = (
|
self.nsx_cache._uuid_dict_mappings[lrouter['uuid']] = (
|
||||||
self.nsx_cache._lrouters)
|
self.nsx_cache._lrouters)
|
||||||
self.nsx_cache._lrouters[lrouter['uuid']] = (
|
self.nsx_cache._lrouters[lrouter['uuid']] = (
|
||||||
{'data': lrouter,
|
{'data': lrouter,
|
||||||
'hash': hash(json.dumps(lrouter))})
|
'hash': hash(jsonutils.dumps(lrouter))})
|
||||||
super(CacheTestCase, self).setUp()
|
super(CacheTestCase, self).setUp()
|
||||||
|
|
||||||
def test_get_lswitches(self):
|
def test_get_lswitches(self):
|
||||||
@ -496,11 +496,11 @@ class SyncTestCase(base.BaseTestCase):
|
|||||||
ctx = context.get_admin_context()
|
ctx = context.get_admin_context()
|
||||||
# Generate 4 networks, 1 port per network, and 4 routers
|
# Generate 4 networks, 1 port per network, and 4 routers
|
||||||
with self._populate_data(ctx, net_size=4, port_size=1, router_size=4):
|
with self._populate_data(ctx, net_size=4, port_size=1, router_size=4):
|
||||||
fake_lswitches = json.loads(
|
fake_lswitches = jsonutils.loads(
|
||||||
self.fc.handle_get('/ws.v1/lswitch'))['results']
|
self.fc.handle_get('/ws.v1/lswitch'))['results']
|
||||||
fake_lrouters = json.loads(
|
fake_lrouters = jsonutils.loads(
|
||||||
self.fc.handle_get('/ws.v1/lrouter'))['results']
|
self.fc.handle_get('/ws.v1/lrouter'))['results']
|
||||||
fake_lswitchports = json.loads(
|
fake_lswitchports = jsonutils.loads(
|
||||||
self.fc.handle_get('/ws.v1/lswitch/*/lport'))['results']
|
self.fc.handle_get('/ws.v1/lswitch/*/lport'))['results']
|
||||||
return_values = [
|
return_values = [
|
||||||
# Chunk 0 - lswitches
|
# Chunk 0 - lswitches
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from neutron.openstack.common import jsonutils as json
|
from neutron.openstack.common import jsonutils
|
||||||
from neutron.openstack.common import uuidutils
|
from neutron.openstack.common import uuidutils
|
||||||
from neutron.plugins.vmware.vshield.common import exceptions
|
from neutron.plugins.vmware.vshield.common import exceptions
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ class FakeVcns(object):
|
|||||||
'moduleName': 'vShield Edge',
|
'moduleName': 'vShield Edge',
|
||||||
'errorData': None
|
'errorData': None
|
||||||
}
|
}
|
||||||
return (header, json.dumps(response))
|
return (header, jsonutils.dumps(response))
|
||||||
|
|
||||||
self._job_idx = self._job_idx + 1
|
self._job_idx = self._job_idx + 1
|
||||||
job_id = "jobdata-%d" % self._job_idx
|
job_id = "jobdata-%d" % self._job_idx
|
||||||
@ -241,7 +241,8 @@ class FakeVcns(object):
|
|||||||
# The lswitch is created via VCNS API so the fake nsx_api will not
|
# The lswitch is created via VCNS API so the fake nsx_api will not
|
||||||
# see it. Added to fake nsx_api here.
|
# see it. Added to fake nsx_api here.
|
||||||
if self._fake_nsx_api:
|
if self._fake_nsx_api:
|
||||||
lswitch = self._fake_nsx_api._add_lswitch(json.dumps(lsconfig))
|
lswitch = \
|
||||||
|
self._fake_nsx_api._add_lswitch(jsonutils.dumps(lsconfig))
|
||||||
else:
|
else:
|
||||||
lswitch = lsconfig
|
lswitch = lsconfig
|
||||||
lswitch['uuid'] = uuidutils.generate_uuid()
|
lswitch['uuid'] = uuidutils.generate_uuid()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user