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