Update json module to jsonutils

json is deprecated, should use oslo_serialization.jsonutils
instead.

Change-Id: I1392004e32cc835e803c9a953b4581c75049b950
This commit is contained in:
zhulingjie 2019-02-20 00:38:21 +08:00 committed by Michael Johnson
parent 9ce614ad84
commit 2a057474a8
4 changed files with 112 additions and 105 deletions

View File

@ -15,10 +15,10 @@
import binascii
import hashlib
import hmac
import json
import zlib
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import secretutils
from octavia.common import exceptions
@ -35,14 +35,14 @@ def to_hex(byte_array):
def encode_obj(obj):
json_bytes = json.dumps(obj).encode('utf-8')
json_bytes = jsonutils.dumps(obj).encode('utf-8')
binary_array = zlib.compress(json_bytes, 9)
return binary_array
def decode_obj(binary_array):
json_str = zlib.decompress(binary_array).decode('utf-8')
obj = json.loads(json_str)
obj = jsonutils.loads(json_str)
return obj

View File

@ -11,8 +11,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import hashlib
import json
import os
import random
import socket
@ -23,6 +23,7 @@ import fixtures
import mock
import netifaces
from oslo_config import fixture as oslo_fixture
from oslo_serialization import jsonutils
from oslo_utils import uuidutils
import six
@ -228,7 +229,7 @@ class TestServerTestCase(base.TestCase):
self.assertEqual(400, rv.status_code)
self.assertEqual(
{'message': 'Invalid request', u'details': u'random error'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mode = stat.S_IRUSR | stat.S_IWUSR
mock_open.assert_called_with(file_name, flags, mode)
mock_fdopen.assert_called_with(123, 'w')
@ -284,7 +285,7 @@ class TestServerTestCase(base.TestCase):
self.assertEqual(
{'message': 'Invalid Request',
'details': 'Unknown action: error', },
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mock_exists.return_value = False
if distro == consts.UBUNTU:
@ -297,7 +298,7 @@ class TestServerTestCase(base.TestCase):
self.assertEqual(
{'message': 'Listener Not Found',
'details': 'No listener with UUID: 123'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mock_exists.assert_called_with('/var/lib/octavia/123/haproxy.cfg')
mock_exists.return_value = True
@ -312,7 +313,7 @@ class TestServerTestCase(base.TestCase):
{'message': 'OK',
'details': 'Configuration file is valid\nhaproxy daemon for'
' 123 started'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mock_subprocess.assert_called_with(
['/usr/sbin/service', 'haproxy-123', 'start'], stderr=-2)
@ -330,7 +331,7 @@ class TestServerTestCase(base.TestCase):
{
'message': 'Error starting haproxy',
'details': RANDOM_ERROR,
}, json.loads(rv.data.decode('utf-8')))
}, jsonutils.loads(rv.data.decode('utf-8')))
mock_subprocess.assert_called_with(
['/usr/sbin/service', 'haproxy-123', 'start'], stderr=-2)
@ -364,7 +365,7 @@ class TestServerTestCase(base.TestCase):
self.assertEqual(
{'message': 'OK',
'details': 'Listener 123 reloaded'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mock_subprocess.assert_called_with(
['/usr/sbin/service', 'haproxy-123', 'reload'], stderr=-2)
@ -382,7 +383,7 @@ class TestServerTestCase(base.TestCase):
{'message': 'OK',
'details': 'Configuration file is valid\nhaproxy daemon for'
' 123 started'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mock_subprocess.assert_called_with(
['/usr/sbin/service', 'haproxy-123', 'start'], stderr=-2)
@ -413,7 +414,7 @@ class TestServerTestCase(base.TestCase):
api_version='0.5',
haproxy_version='9.9.99-9',
hostname='test-host'),
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
@mock.patch('octavia.amphorae.backends.agent.api_server.util.'
'get_listener_protocol', return_value='TCP')
@ -472,7 +473,7 @@ class TestServerTestCase(base.TestCase):
rv = self.centos_app.delete('/' + api_server.VERSION +
'/listeners/123')
self.assertEqual(200, rv.status_code)
self.assertEqual(OK, json.loads(rv.data.decode('utf-8')))
self.assertEqual(OK, jsonutils.loads(rv.data.decode('utf-8')))
mock_exists.assert_called_with('/var/lib/octavia/123/haproxy.cfg')
# service is stopped + no upstart script + no vrrp
@ -485,7 +486,7 @@ class TestServerTestCase(base.TestCase):
'/listeners/123')
self.assertEqual(200, rv.status_code)
self.assertEqual({u'message': u'OK'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mock_rmtree.assert_called_with('/var/lib/octavia/123')
if init_system == consts.INIT_SYSTEMD:
@ -512,7 +513,7 @@ class TestServerTestCase(base.TestCase):
'/listeners/123')
self.assertEqual(200, rv.status_code)
self.assertEqual({u'message': u'OK'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mock_rmtree.assert_called_with('/var/lib/octavia/123')
if init_system == consts.INIT_SYSTEMD:
@ -539,7 +540,7 @@ class TestServerTestCase(base.TestCase):
'/listeners/123')
self.assertEqual(200, rv.status_code)
self.assertEqual({u'message': u'OK'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
if init_system == consts.INIT_SYSTEMD:
mock_remove.assert_called_with(consts.SYSTEMD_DIR +
@ -563,7 +564,7 @@ class TestServerTestCase(base.TestCase):
'/listeners/123')
self.assertEqual(200, rv.status_code)
self.assertEqual({u'message': u'OK'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
if init_system == consts.INIT_SYSTEMD:
mock_remove.assert_called_with(consts.SYSTEMD_DIR +
@ -588,7 +589,7 @@ class TestServerTestCase(base.TestCase):
'/listeners/123')
self.assertEqual(200, rv.status_code)
self.assertEqual({u'message': u'OK'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mock_pid.assert_called_once_with('123')
mock_check_output.assert_any_call(
['/usr/sbin/service', 'haproxy-123', 'stop'], stderr=-2)
@ -618,7 +619,7 @@ class TestServerTestCase(base.TestCase):
'/listeners/123')
self.assertEqual(200, rv.status_code)
self.assertEqual({u'message': u'OK'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mock_pid.assert_called_with('123')
mock_check_output.assert_any_call(
['/usr/sbin/service', 'haproxy-123', 'stop'], stderr=-2)
@ -650,7 +651,7 @@ class TestServerTestCase(base.TestCase):
self.assertEqual(500, rv.status_code)
self.assertEqual(
{'details': 'random error', 'message': 'Error stopping haproxy'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
# that's the last call before exception
mock_exists.assert_called_with('/proc/456')
@ -715,7 +716,7 @@ class TestServerTestCase(base.TestCase):
rv = self.centos_app.get('/' + api_server.VERSION + '/listeners')
self.assertEqual(200, rv.status_code)
self.assertFalse(json.loads(rv.data.decode('utf-8')))
self.assertFalse(jsonutils.loads(rv.data.decode('utf-8')))
# one listener ACTIVE
mock_listener.side_effect = [['123']]
@ -729,7 +730,7 @@ class TestServerTestCase(base.TestCase):
self.assertEqual(200, rv.status_code)
self.assertEqual(
[{'status': consts.ACTIVE, 'type': 'test', 'uuid': '123'}],
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
# two listener one ACTIVE, one ERROR
mock_listener.side_effect = [['123', '456']]
@ -744,7 +745,7 @@ class TestServerTestCase(base.TestCase):
self.assertEqual(
[{'status': consts.ACTIVE, 'type': 'test', 'uuid': '123'},
{'status': consts.ERROR, 'type': '', 'uuid': '456'}],
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
def test_ubuntu_get_listener(self):
self._test_get_listener(consts.UBUNTU)
@ -775,7 +776,7 @@ class TestServerTestCase(base.TestCase):
self.assertEqual(
{'message': 'Listener Not Found',
'details': 'No listener with UUID: 123'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
# Listener not ACTIVE
mock_parse.side_effect = [dict(mode='test')]
@ -791,7 +792,7 @@ class TestServerTestCase(base.TestCase):
self.assertEqual(dict(
status=consts.ERROR,
type='',
uuid='123'), json.loads(rv.data.decode('utf-8')))
uuid='123'), jsonutils.loads(rv.data.decode('utf-8')))
# Listener ACTIVE
mock_parse.side_effect = [dict(mode='test', stats_socket='blah')]
@ -823,7 +824,7 @@ class TestServerTestCase(base.TestCase):
members=[
{u'id-34833': u'DOWN'},
{u'id-34836': u'DOWN'}])]),
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
def test_ubuntu_delete_cert(self):
self._test_delete_cert(consts.UBUNTU)
@ -843,7 +844,7 @@ class TestServerTestCase(base.TestCase):
rv = self.centos_app.delete('/' + api_server.VERSION +
'/listeners/123/certificates/test.pem')
self.assertEqual(200, rv.status_code)
self.assertEqual(OK, json.loads(rv.data.decode('utf-8')))
self.assertEqual(OK, jsonutils.loads(rv.data.decode('utf-8')))
mock_exists.assert_called_once_with(
'/var/lib/octavia/certs/123/test.pem')
@ -865,7 +866,7 @@ class TestServerTestCase(base.TestCase):
rv = self.centos_app.delete('/' + api_server.VERSION +
'/listeners/123/certificates/test.pem')
self.assertEqual(200, rv.status_code)
self.assertEqual(OK, json.loads(rv.data.decode('utf-8')))
self.assertEqual(OK, jsonutils.loads(rv.data.decode('utf-8')))
mock_remove.assert_called_once_with(
'/var/lib/octavia/certs/123/test.pem')
@ -893,7 +894,7 @@ class TestServerTestCase(base.TestCase):
self.assertEqual(dict(
details='No certificate with filename: test.pem',
message='Certificate Not Found'),
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mock_exists.assert_called_with('/var/lib/octavia/certs/123/test.pem')
# wrong file name
@ -925,7 +926,7 @@ class TestServerTestCase(base.TestCase):
'/listeners/123/certificates/test.pem')
self.assertEqual(200, rv.status_code)
self.assertEqual(dict(md5sum=hashlib.md5(six.b(CONTENT)).hexdigest()),
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
def test_ubuntu_upload_certificate_md5(self):
self._test_upload_certificate_md5(consts.UBUNTU)
@ -969,7 +970,7 @@ class TestServerTestCase(base.TestCase):
'/listeners/123/certificates/'
'test.pem', data='TestTest')
self.assertEqual(200, rv.status_code)
self.assertEqual(OK, json.loads(rv.data.decode('utf-8')))
self.assertEqual(OK, jsonutils.loads(rv.data.decode('utf-8')))
handle = m()
handle.write.assert_called_once_with(six.b('TestTest'))
@ -986,7 +987,7 @@ class TestServerTestCase(base.TestCase):
'/listeners/123/certificates/'
'test.pem', data='TestTest')
self.assertEqual(200, rv.status_code)
self.assertEqual(OK, json.loads(rv.data.decode('utf-8')))
self.assertEqual(OK, jsonutils.loads(rv.data.decode('utf-8')))
handle = m()
handle.write.assert_called_once_with(six.b('TestTest'))
mock_makedir.assert_called_once_with('/var/lib/octavia/certs/123')
@ -1009,7 +1010,7 @@ class TestServerTestCase(base.TestCase):
rv = self.centos_app.put('/' + api_server.VERSION +
'/certificate', data='TestTest')
self.assertEqual(202, rv.status_code)
self.assertEqual(OK, json.loads(rv.data.decode('utf-8')))
self.assertEqual(OK, jsonutils.loads(rv.data.decode('utf-8')))
handle = m()
handle.write.assert_any_call(six.b('TestT'))
handle.write.assert_any_call(six.b('est'))
@ -1055,15 +1056,15 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
self.assertEqual(409, rv.status_code)
self.assertEqual(dict(message="Interface already exists"),
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mock_int_exists.return_value = False
# No interface at all
@ -1077,18 +1078,18 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
mock_open.assert_called_with(file_name, os.O_WRONLY)
mock_fdopen.assert_called_with(123, 'w')
m().write.assert_called_once_with('1')
self.assertEqual(404, rv.status_code)
self.assertEqual(dict(details="No suitable network interface found"),
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
# No interface down
m().reset_mock()
@ -1101,18 +1102,18 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
mock_open.assert_called_with(file_name, os.O_WRONLY)
mock_fdopen.assert_called_with(123, 'w')
m().write.assert_called_once_with('1')
self.assertEqual(404, rv.status_code)
self.assertEqual(dict(details="No suitable network interface found"),
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mock_ifaddress.assert_called_once_with('blah')
# One Interface down, Happy Path
@ -1146,12 +1147,12 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
self.assertEqual(202, rv.status_code)
mock_open.assert_any_call(file_name, flags, mode)
@ -1217,12 +1218,12 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
self.assertEqual(202, rv.status_code)
mock_open.assert_any_call(file_name, flags, mode)
@ -1295,12 +1296,12 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
self.assertEqual(202, rv.status_code)
mock_open.assert_any_call(file_name, flags, mode)
@ -1357,12 +1358,12 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
self.assertEqual(400, rv.status_code)
# same as above but ifup fails
@ -1381,17 +1382,17 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
self.assertEqual(500, rv.status_code)
self.assertEqual(
{'details': RANDOM_ERROR,
'message': 'Error plugging network'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
# Bad port_info tests
port_info = 'Bad data'
@ -1399,12 +1400,12 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
self.assertEqual(400, rv.status_code)
port_info = {'fixed_ips': [{'ip_address': '10.0.0.5',
@ -1413,12 +1414,12 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
self.assertEqual(400, rv.status_code)
def test_ubuntu_plug_network_host_routes(self):
@ -1480,12 +1481,12 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/network",
content_type='application/json',
data=json.dumps(port_info))
data=jsonutils.dumps(port_info))
self.assertEqual(202, rv.status_code)
mock_open.assert_any_call(file_name, flags, mode)
@ -1584,12 +1585,12 @@ class TestServerTestCase(base.TestCase):
if distro == consts.UBUNTU:
rv = self.ubuntu_app.post('/' + api_server.VERSION +
'/plug/vip/error',
data=json.dumps(subnet_info),
data=jsonutils.dumps(subnet_info),
content_type='application/json')
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
'/plug/vip/error',
data=json.dumps(subnet_info),
data=jsonutils.dumps(subnet_info),
content_type='application/json')
self.assertEqual(400, rv.status_code)
@ -1609,15 +1610,15 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/vip/203.0.113.2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/vip/203.0.113.2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
self.assertEqual(409, rv.status_code)
self.assertEqual(dict(message="Interface already exists"),
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
mock_int_exists.return_value = False
# No interface at all
@ -1632,18 +1633,18 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/vip/203.0.113.2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/vip/203.0.113.2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
mock_open.assert_called_with(file_name, os.O_WRONLY)
mock_fdopen.assert_called_with(123, 'w')
m().write.assert_called_once_with('1')
self.assertEqual(404, rv.status_code)
self.assertEqual(dict(details="No suitable network interface found"),
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
# Two interfaces down
m().reset_mock()
@ -1657,18 +1658,18 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/vip/203.0.113.2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/vip/203.0.113.2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
mock_open.assert_called_with(file_name, os.O_WRONLY)
mock_fdopen.assert_called_with(123, 'w')
m().write.assert_called_once_with('1')
self.assertEqual(404, rv.status_code)
self.assertEqual(dict(details="No suitable network interface found"),
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
# Happy Path IPv4, with VRRP_IP and host route
full_subnet_info = {
@ -1714,12 +1715,14 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/vip/203.0.113.2",
content_type='application/json',
data=json.dumps(full_subnet_info))
data=jsonutils.dumps(
full_subnet_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/vip/203.0.113.2",
content_type='application/json',
data=json.dumps(full_subnet_info))
data=jsonutils.dumps(
full_subnet_info))
self.assertEqual(202, rv.status_code)
mock_open.assert_any_call(file_name, flags, mode)
mock_fdopen.assert_any_call(123, 'w')
@ -1846,12 +1849,12 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/vip/203.0.113.2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/vip/203.0.113.2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
self.assertEqual(202, rv.status_code)
mock_open.assert_any_call(file_name, flags, mode)
mock_fdopen.assert_any_call(123, 'w')
@ -1918,17 +1921,17 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/vip/203.0.113.2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/vip/203.0.113.2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
self.assertEqual(500, rv.status_code)
self.assertEqual(
{'details': RANDOM_ERROR,
'message': 'Error plugging VIP'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
def test_ubuntu_plug_VIP6(self):
self._test_plug_vip6(consts.UBUNTU)
@ -1967,12 +1970,14 @@ class TestServerTestCase(base.TestCase):
if distro == consts.UBUNTU:
rv = self.ubuntu_app.post('/' + api_server.VERSION +
'/plug/vip/error',
data=json.dumps(subnet_info),
data=jsonutils.dumps(
subnet_info),
content_type='application/json')
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
'/plug/vip/error',
data=json.dumps(subnet_info),
data=jsonutils.dumps(
subnet_info),
content_type='application/json')
self.assertEqual(400, rv.status_code)
@ -1980,12 +1985,12 @@ class TestServerTestCase(base.TestCase):
if distro == consts.UBUNTU:
rv = self.ubuntu_app.post('/' + api_server.VERSION +
'/plug/vip/error',
data=json.dumps(subnet_info),
data=jsonutils.dumps(subnet_info),
content_type='application/json')
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
'/plug/vip/error',
data=json.dumps(subnet_info),
data=jsonutils.dumps(subnet_info),
content_type='application/json')
self.assertEqual(400, rv.status_code)
@ -2000,18 +2005,18 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/vip/2001:db8::2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/vip/2001:db8::2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
mock_open.assert_called_with(file_name, os.O_WRONLY)
mock_fdopen.assert_called_with(123, 'w')
m().write.assert_called_once_with('1')
self.assertEqual(404, rv.status_code)
self.assertEqual(dict(details="No suitable network interface found"),
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
# Two interfaces down
m().reset_mock()
@ -2024,18 +2029,18 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/vip/2001:db8::2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/vip/2001:db8::2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
mock_open.assert_called_with(file_name, os.O_WRONLY)
mock_fdopen.assert_called_with(123, 'w')
m().write.assert_called_once_with('1')
self.assertEqual(404, rv.status_code)
self.assertEqual(dict(details="No suitable network interface found"),
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
# Happy Path IPv6, with VRRP_IP and host route
full_subnet_info = {
@ -2076,12 +2081,14 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/vip/2001:db8::2",
content_type='application/json',
data=json.dumps(full_subnet_info))
data=jsonutils.dumps(
full_subnet_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/vip/2001:db8::2",
content_type='application/json',
data=json.dumps(full_subnet_info))
data=jsonutils.dumps(
full_subnet_info))
self.assertEqual(202, rv.status_code)
mock_open.assert_any_call(file_name, flags, mode)
mock_fdopen.assert_any_call(123, 'w')
@ -2208,12 +2215,12 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/vip/2001:db8::2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/vip/2001:db8::2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
self.assertEqual(202, rv.status_code)
mock_open.assert_any_call(file_name, flags, mode)
mock_fdopen.assert_any_call(123, 'w')
@ -2293,17 +2300,17 @@ class TestServerTestCase(base.TestCase):
rv = self.ubuntu_app.post('/' + api_server.VERSION +
"/plug/vip/2001:db8::2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
elif distro == consts.CENTOS:
rv = self.centos_app.post('/' + api_server.VERSION +
"/plug/vip/2001:db8::2",
content_type='application/json',
data=json.dumps(subnet_info))
data=jsonutils.dumps(subnet_info))
self.assertEqual(500, rv.status_code)
self.assertEqual(
{'details': RANDOM_ERROR,
'message': 'Error plugging VIP'},
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
def test_ubuntu_get_interface(self):
self._test_get_interface(consts.UBUNTU)
@ -2329,12 +2336,12 @@ class TestServerTestCase(base.TestCase):
if distro == consts.UBUNTU:
rv = self.ubuntu_app.get('/' + api_server.VERSION +
'/interface/203.0.113.2',
data=json.dumps(interface_res),
data=jsonutils.dumps(interface_res),
content_type='application/json')
elif distro == consts.CENTOS:
rv = self.centos_app.get('/' + api_server.VERSION +
'/interface/203.0.113.2',
data=json.dumps(interface_res),
data=jsonutils.dumps(interface_res),
content_type='application/json')
self.assertEqual(200, rv.status_code)
@ -2348,12 +2355,12 @@ class TestServerTestCase(base.TestCase):
if distro == consts.UBUNTU:
rv = self.ubuntu_app.get('/' + api_server.VERSION +
'/interface/::1',
data=json.dumps(interface_res),
data=jsonutils.dumps(interface_res),
content_type='application/json')
elif distro == consts.CENTOS:
rv = self.centos_app.get('/' + api_server.VERSION +
'/interface/::1',
data=json.dumps(interface_res),
data=jsonutils.dumps(interface_res),
content_type='application/json')
self.assertEqual(200, rv.status_code)
@ -2361,12 +2368,12 @@ class TestServerTestCase(base.TestCase):
if distro == consts.UBUNTU:
rv = self.ubuntu_app.get('/' + api_server.VERSION +
'/interface/10.0.0.1',
data=json.dumps(interface_res),
data=jsonutils.dumps(interface_res),
content_type='application/json')
elif distro == consts.CENTOS:
rv = self.centos_app.get('/' + api_server.VERSION +
'/interface/10.0.0.1',
data=json.dumps(interface_res),
data=jsonutils.dumps(interface_res),
content_type='application/json')
self.assertEqual(404, rv.status_code)
@ -2374,12 +2381,12 @@ class TestServerTestCase(base.TestCase):
if distro == consts.UBUNTU:
rv = self.ubuntu_app.get('/' + api_server.VERSION +
'/interface/00:00:00:00:00:00',
data=json.dumps(interface_res),
data=jsonutils.dumps(interface_res),
content_type='application/json')
elif distro == consts.CENTOS:
rv = self.centos_app.get('/' + api_server.VERSION +
'/interface/00:00:00:00:00:00',
data=json.dumps(interface_res),
data=jsonutils.dumps(interface_res),
content_type='application/json')
self.assertEqual(400, rv.status_code)
@ -2656,7 +2663,7 @@ class TestServerTestCase(base.TestCase):
self.assertEqual(200, rv.status_code)
self.assertEqual(expected_dict,
json.loads(rv.data.decode('utf-8')))
jsonutils.loads(rv.data.decode('utf-8')))
def test_ubuntu_upload_config(self):
self._test_upload_config(consts.UBUNTU)
@ -2677,7 +2684,7 @@ class TestServerTestCase(base.TestCase):
rv = self.centos_app.put('/' + api_server.VERSION +
'/config', data='TestTest')
self.assertEqual(202, rv.status_code)
self.assertEqual(OK, json.loads(rv.data.decode('utf-8')))
self.assertEqual(OK, jsonutils.loads(rv.data.decode('utf-8')))
handle = m()
handle.write.assert_any_call(six.b('TestT'))
handle.write.assert_any_call(six.b('est'))

View File

@ -25,6 +25,7 @@ oslo.messaging>=5.29.0 # Apache-2.0
oslo.middleware>=3.31.0 # Apache-2.0
oslo.policy>=1.30.0 # Apache-2.0
oslo.reports>=1.18.0 # Apache-2.0
oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
oslo.upgradecheck>=0.1.0 # Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0
pyasn1!=0.2.3,>=0.1.8 # BSD

View File

@ -8,7 +8,6 @@ flake8-import-order==0.12 # LGPLv3
mock>=2.0.0 # BSD
python-subunit>=1.0.0 # Apache-2.0/BSD
oslotest>=3.2.0 # Apache-2.0
oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
pylint==1.9.2 # GPLv2
testrepository>=0.0.18 # Apache-2.0/BSD
testtools>=2.2.0 # MIT