Remove oslo.serialization dependency
Use pure json instead of jsonutils. Borrow encode function from oslo.serialization to be used in the utils module. Change-Id: Ied9a2259a4329a86b4f0853bd1fb187563c0a036
This commit is contained in:
parent
09ea41c83d
commit
64ffd2ee80
@ -13,6 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
|
||||
@ -20,7 +21,6 @@ from ironic_lib import mdns
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import excutils
|
||||
import requests
|
||||
import stevedore
|
||||
@ -290,10 +290,10 @@ def collect_extra_hardware(data, failures):
|
||||
return
|
||||
|
||||
try:
|
||||
data['data'] = jsonutils.loads(out)
|
||||
except ValueError as exc:
|
||||
data['data'] = json.loads(out)
|
||||
except json.decoder.JSONDecodeError as ex:
|
||||
msg = 'JSON returned from hardware-detect cannot be decoded: %s'
|
||||
failures.add(msg, exc)
|
||||
failures.add(msg, ex)
|
||||
|
||||
|
||||
def collect_pci_devices_info(data, failures):
|
||||
|
@ -12,9 +12,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_serialization import jsonutils
|
||||
import requests
|
||||
import tenacity
|
||||
|
||||
@ -103,7 +104,7 @@ class APIClient(object):
|
||||
|
||||
try:
|
||||
response = self._request('GET', '/')
|
||||
data = jsonutils.loads(response.content)
|
||||
data = json.loads(response.content)
|
||||
version = data['default_version']['version'].split('.')
|
||||
self._ironic_api_version = (int(version[0]), int(version[1]))
|
||||
return self._ironic_api_version
|
||||
@ -127,8 +128,8 @@ class APIClient(object):
|
||||
if not isinstance(body, dict):
|
||||
# Old ironic format
|
||||
try:
|
||||
body = jsonutils.loads(body)
|
||||
except ValueError:
|
||||
body = json.loads(body)
|
||||
except json.decoder.JSONDecodeError:
|
||||
body = {}
|
||||
|
||||
text = (body.get('faultstring')
|
||||
@ -253,8 +254,8 @@ class APIClient(object):
|
||||
return False
|
||||
|
||||
try:
|
||||
content = jsonutils.loads(response.content)
|
||||
except Exception as e:
|
||||
content = json.loads(response.content)
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
LOG.warning('Error decoding response: %s', e)
|
||||
return False
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
import socket
|
||||
import time
|
||||
from unittest import mock
|
||||
@ -19,7 +20,6 @@ from unittest import mock
|
||||
from ironic_lib import exception as lib_exc
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import jsonutils
|
||||
import pkg_resources
|
||||
from stevedore import extension
|
||||
|
||||
@ -192,8 +192,8 @@ class TestBaseAgent(ironic_agent_base.IronicAgentTest):
|
||||
# object.
|
||||
a_encoded = self.encoder.encode(a)
|
||||
b_encoded = self.encoder.encode(b)
|
||||
self.assertEqual(jsonutils.loads(a_encoded),
|
||||
jsonutils.loads(b_encoded))
|
||||
self.assertEqual(json.loads(a_encoded),
|
||||
json.loads(b_encoded))
|
||||
|
||||
def test_get_status(self):
|
||||
started_at = time.time()
|
||||
|
@ -16,7 +16,6 @@ import json
|
||||
from unittest import mock
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import jsonutils
|
||||
import requests
|
||||
|
||||
from ironic_python_agent import errors
|
||||
@ -149,7 +148,7 @@ class TestBaseIronicPythonAgent(base.IronicAgentTest):
|
||||
expected_data = {
|
||||
'callback_url': 'http://192.0.2.1:9999',
|
||||
'agent_version': version.__version__}
|
||||
self.assertEqual(jsonutils.dumps(expected_data), data)
|
||||
self.assertEqual(json.dumps(expected_data), data)
|
||||
|
||||
def test_successful_heartbeat_ip6(self):
|
||||
response = FakeResponse(status_code=202)
|
||||
@ -172,7 +171,7 @@ class TestBaseIronicPythonAgent(base.IronicAgentTest):
|
||||
expected_data = {
|
||||
'callback_url': 'http://[fc00:1111::4]:9999',
|
||||
'agent_version': version.__version__}
|
||||
self.assertEqual(jsonutils.dumps(expected_data), data)
|
||||
self.assertEqual(json.dumps(expected_data), data)
|
||||
|
||||
def test_successful_heartbeat_with_token(self):
|
||||
response = FakeResponse(status_code=202)
|
||||
@ -197,7 +196,7 @@ class TestBaseIronicPythonAgent(base.IronicAgentTest):
|
||||
'callback_url': 'http://192.0.2.1:9999',
|
||||
'agent_token': 'magical',
|
||||
'agent_version': version.__version__}
|
||||
self.assertEqual(jsonutils.dumps(expected_data), data)
|
||||
self.assertEqual(json.dumps(expected_data), data)
|
||||
|
||||
def test_heartbeat_agent_version_unsupported(self):
|
||||
response = FakeResponse(status_code=202)
|
||||
@ -218,7 +217,7 @@ class TestBaseIronicPythonAgent(base.IronicAgentTest):
|
||||
self.assertEqual(API_URL + heartbeat_path, request_args[1])
|
||||
expected_data = {
|
||||
'callback_url': 'http://[fc00:1111::4]:9999'}
|
||||
self.assertEqual(jsonutils.dumps(expected_data), data)
|
||||
self.assertEqual(json.dumps(expected_data), data)
|
||||
|
||||
def test_successful_heartbeat_with_verify_ca(self):
|
||||
response = FakeResponse(status_code=202)
|
||||
@ -246,7 +245,7 @@ class TestBaseIronicPythonAgent(base.IronicAgentTest):
|
||||
'agent_token': 'magical',
|
||||
'agent_version': version.__version__,
|
||||
'agent_verify_ca': 'I am a cert'}
|
||||
self.assertEqual(jsonutils.dumps(expected_data), data)
|
||||
self.assertEqual(json.dumps(expected_data), data)
|
||||
headers = self.api_client.session.request.call_args[1]['headers']
|
||||
self.assertEqual(
|
||||
'%d.%d' % ironic_api_client.AGENT_VERIFY_CA_IRONIC_VERSION,
|
||||
|
@ -13,6 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import base64
|
||||
import errno
|
||||
import glob
|
||||
import io
|
||||
@ -25,7 +26,6 @@ from unittest import mock
|
||||
|
||||
from ironic_lib import utils as ironic_utils
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_serialization import base64
|
||||
import requests
|
||||
import testtools
|
||||
|
||||
@ -320,7 +320,7 @@ class TestUtils(ironic_agent_base.IronicAgentTest):
|
||||
data = utils.gzip_and_b64encode(io_dict=io_dict)
|
||||
self.assertIsInstance(data, str)
|
||||
|
||||
res = io.BytesIO(base64.decode_as_bytes(data))
|
||||
res = io.BytesIO(base64.b64decode(data))
|
||||
with tarfile.open(fileobj=res) as tar:
|
||||
members = [(m.name, m.size) for m in tar]
|
||||
self.assertEqual([('fake-name', len(contents))], members)
|
||||
|
@ -12,12 +12,14 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import base64
|
||||
from collections import abc
|
||||
import contextlib
|
||||
import copy
|
||||
import errno
|
||||
import glob
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
@ -30,8 +32,6 @@ from ironic_lib import utils as ironic_utils
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import base64
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import units
|
||||
import requests
|
||||
import tenacity
|
||||
@ -502,6 +502,13 @@ def get_journalctl_output(lines=None, units=None):
|
||||
return get_command_output(cmd)
|
||||
|
||||
|
||||
def _encode_as_text(s):
|
||||
if isinstance(s, str):
|
||||
s = s.encode('utf-8')
|
||||
s = base64.b64encode(s)
|
||||
return s.decode('ascii')
|
||||
|
||||
|
||||
def gzip_and_b64encode(io_dict=None, file_list=None):
|
||||
"""Gzip and base64 encode files and BytesIO buffers.
|
||||
|
||||
@ -527,7 +534,8 @@ def gzip_and_b64encode(io_dict=None, file_list=None):
|
||||
tar.add(f)
|
||||
|
||||
fp.seek(0)
|
||||
return base64.encode_as_text(fp.getvalue())
|
||||
|
||||
return _encode_as_text(fp.getvalue())
|
||||
|
||||
|
||||
def collect_system_logs(journald_max_lines=None):
|
||||
@ -643,8 +651,8 @@ def parse_capabilities(root):
|
||||
capabilities = root.get('capabilities', {})
|
||||
if isinstance(capabilities, str):
|
||||
try:
|
||||
capabilities = jsonutils.loads(capabilities)
|
||||
except (ValueError, TypeError):
|
||||
capabilities = json.loads(capabilities)
|
||||
except json.decoder.JSONDecodeError:
|
||||
capabilities = _parse_capabilities_str(capabilities)
|
||||
|
||||
if not isinstance(capabilities, dict):
|
||||
|
@ -8,7 +8,6 @@ netifaces>=0.10.4 # MIT
|
||||
oslo.config>=5.2.0 # Apache-2.0
|
||||
oslo.concurrency>=3.26.0 # Apache-2.0
|
||||
oslo.log>=4.6.1 # Apache-2.0
|
||||
oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
|
||||
oslo.service!=1.28.1,>=1.24.0 # Apache-2.0
|
||||
oslo.utils>=3.34.0 # Apache-2.0
|
||||
Pint>=0.5 # BSD
|
||||
|
Loading…
Reference in New Issue
Block a user