diff --git a/mistral_tempest_tests/services/base.py b/mistral_tempest_tests/services/base.py index 50030f2..1e3f02e 100644 --- a/mistral_tempest_tests/services/base.py +++ b/mistral_tempest_tests/services/base.py @@ -13,11 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -import json import os import time - +from oslo_serialization import jsonutils from tempest import config from tempest.lib import auth from tempest.lib.common import rest_client @@ -77,7 +76,7 @@ class MistralClientBase(rest_client.RestClient): def get_list_obj(self, url_path): resp, body = self.get(url_path) - return resp, json.loads(body) + return resp, jsonutils.loads(body) def delete_obj(self, obj, name, force=None): if force: @@ -97,7 +96,7 @@ class MistralClientBase(rest_client.RestClient): def get_object(self, obj, id): resp, body = self.get('{obj}/{id}'.format(obj=obj, id=id)) - return resp, json.loads(body) + return resp, jsonutils.loads(body) def wait_execution_success(self, ex_body, timeout=180, url='executions'): return self.wait_execution(ex_body, timeout=timeout, url=url) diff --git a/mistral_tempest_tests/services/v2/mistral_client.py b/mistral_tempest_tests/services/v2/mistral_client.py index d0d3585..c9f3b37 100644 --- a/mistral_tempest_tests/services/v2/mistral_client.py +++ b/mistral_tempest_tests/services/v2/mistral_client.py @@ -12,8 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -import json - +from oslo_serialization import jsonutils from oslo_utils import uuidutils from tempest import config @@ -41,7 +40,9 @@ class MistralClientV2(base.MistralClientBase): def post_json(self, url_path, obj, extra_headers={}): headers = {"Content-Type": "application/json"} headers = dict(headers, **extra_headers) - return self.post(url_path, json.dumps(obj), headers=headers) + return self.post(url_path, + jsonutils.dump_as_bytes(obj), + headers=headers) def update_request(self, url_path, file_name): headers = {"headers": "Content-Type:text/plain"} @@ -52,17 +53,17 @@ class MistralClientV2(base.MistralClientBase): headers=headers ) - return resp, json.loads(body) + return resp, jsonutils.loads(body) def get_definition(self, item, name): resp, body = self.get("%s/%s" % (item, name)) - return resp, json.loads(body)['definition'] + return resp, jsonutils.loads(body)['definition'] def create_workbook(self, yaml_file): resp, body = self.post_request('workbooks', yaml_file) - wb_name = json.loads(body)['name'] + wb_name = jsonutils.loads(body)['name'] self.workbooks.append(wb_name) _, wfs = self.get_list_obj('workflows') @@ -71,7 +72,7 @@ class MistralClientV2(base.MistralClientBase): if wf['name'].startswith(wb_name): self.workflows.append(wf['id']) - return resp, json.loads(body) + return resp, jsonutils.loads(body) def create_workflow(self, yaml_file, scope=None, namespace=None): url_path = 'workflows?' @@ -84,10 +85,10 @@ class MistralClientV2(base.MistralClientBase): resp, body = self.post_request(url_path, yaml_file) - for wf in json.loads(body)['workflows']: + for wf in jsonutils.loads(body)['workflows']: self.workflows.append(wf['id']) - return resp, json.loads(body) + return resp, jsonutils.loads(body) def get_workflow(self, wf_identifier, namespace=None): @@ -97,7 +98,7 @@ class MistralClientV2(base.MistralClientBase): resp, body = self.get_request(url_path) - return resp, json.loads(body) + return resp, jsonutils.loads(body) def update_workflow(self, file_name, namespace=None): url_path = "workflows?" @@ -128,20 +129,20 @@ class MistralClientV2(base.MistralClientBase): body.update({'workflow_namespace': wf_namespace}) if wf_input: - body.update({'input': json.dumps(wf_input)}) + body.update({'input': jsonutils.dump_as_bytes(wf_input)}) if params: - body.update({'params': json.dumps(params)}) + body.update({'params': jsonutils.dump_as_bytes(params)}) - resp, body = self.post('executions', json.dumps(body)) + resp, body = self.post('executions', jsonutils.dump_as_bytes(body)) - self.executions.append(json.loads(body)['id']) + self.executions.append(jsonutils.loads(body)['id']) - return resp, json.loads(body) + return resp, jsonutils.loads(body) def update_execution(self, execution_id, put_body): resp, body = self.put('executions/%s' % execution_id, put_body) - return resp, json.loads(body) + return resp, jsonutils.loads(body) def get_execution(self, execution_id): return self.get('executions/%s' % execution_id) @@ -171,21 +172,23 @@ class MistralClientV2(base.MistralClientBase): } if wf_input: - post_body.update({'workflow_input': json.dumps(wf_input)}) + post_body.update({ + 'workflow_input': jsonutils.dump_as_bytes(wf_input)}) - rest, body = self.post('cron_triggers', json.dumps(post_body)) + rest, body = self.post('cron_triggers', + jsonutils.dump_as_bytes(post_body)) self.triggers.append(name) - return rest, json.loads(body) + return rest, jsonutils.loads(body) def create_action(self, yaml_file): resp, body = self.post_request('actions', yaml_file) self.actions.extend( - [action['name'] for action in json.loads(body)['actions']]) + [action['name'] for action in jsonutils.loads(body)['actions']]) - return resp, json.loads(body) + return resp, jsonutils.loads(body) def get_wf_tasks(self, wf_name): all_tasks = self.get_list_obj('tasks')[1]['tasks'] @@ -196,11 +199,11 @@ class MistralClientV2(base.MistralClientBase): resp, body = self.post_json('action_executions', request_body, extra_headers) - params = json.loads(request_body.get('params', '{}')) + params = jsonutils.loads(request_body.get('params', '{}')) if params.get('save_result', False): - self.action_executions.append(json.loads(body)['id']) + self.action_executions.append(jsonutils.loads(body)['id']) - return resp, json.loads(body) + return resp, jsonutils.loads(body) def create_event_trigger(self, wf_id, exchange, topic, event, name='', wf_input=None, wf_params=None): @@ -213,14 +216,17 @@ class MistralClientV2(base.MistralClientBase): } if wf_input: - post_body.update({'workflow_input': json.dumps(wf_input)}) + post_body.update({ + 'workflow_input': jsonutils.dump_as_bytes(wf_input)}) if wf_params: - post_body.update({'workflow_params': json.dumps(wf_params)}) + post_body.update({ + 'workflow_params': jsonutils.dump_as_bytes(wf_params)}) - rest, body = self.post('event_triggers', json.dumps(post_body)) + rest, body = self.post('event_triggers', + jsonutils.dump_as_bytes(post_body)) - event_trigger = json.loads(body) + event_trigger = jsonutils.loads(body) self.event_triggers.append(event_trigger['id']) return rest, event_trigger diff --git a/mistral_tempest_tests/tests/api/v2/test_action_executions.py b/mistral_tempest_tests/tests/api/v2/test_action_executions.py index 99b8f06..4d47230 100644 --- a/mistral_tempest_tests/tests/api/v2/test_action_executions.py +++ b/mistral_tempest_tests/tests/api/v2/test_action_executions.py @@ -12,10 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. -import json import six from oslo_log import log as logging +from oslo_serialization import jsonutils from tempest.lib import decorators from tempest.lib import exceptions @@ -64,7 +64,7 @@ class ActionExecutionTestsV2(base.TestCase): ) self.assertEqual(201, resp.status) - output = json.loads(body['output']) + output = jsonutils.loads(body['output']) self.assertDictEqual( {'result': 'Hello, Mistral!'}, output @@ -137,7 +137,7 @@ class ActionExecutionTestsV2(base.TestCase): ) self.assertEqual(201, resp.status) - output = json.loads(body['output']) + output = jsonutils.loads(body['output']) self.assertTrue(output['result']['status'] in range(200, 307)) @decorators.attr(type='sanity') @@ -151,7 +151,7 @@ class ActionExecutionTestsV2(base.TestCase): ) self.assertEqual(201, resp.status) - output = json.loads(body['output']) + output = jsonutils.loads(body['output']) self.assertEqual(404, output['result']['status']) @decorators.attr(type='sanity') @@ -167,7 +167,7 @@ class ActionExecutionTestsV2(base.TestCase): ) self.assertEqual(201, resp.status) - output = json.loads(body['output']) + output = jsonutils.loads(body['output']) self.assertEqual(200, output['result']['status']) @decorators.attr(type='sanity') @@ -190,7 +190,7 @@ class ActionExecutionTestsV2(base.TestCase): body, url='action_executions' ) - output = json.loads(body['output']) + output = jsonutils.loads(body['output']) self.assertEqual('SUCCESS', body['state']) self.assertDictEqual( @@ -219,7 +219,7 @@ class ActionExecutionTestsV2(base.TestCase): ) self.assertEqual(201, resp.status) - output = json.loads(body['output']) + output = jsonutils.loads(body['output']) self.assertEqual("Hello Tempest", output['result']) @decorators.idempotent_id('9438e195-031c-4502-b216-6d72941ec281') diff --git a/mistral_tempest_tests/tests/api/v2/test_executions.py b/mistral_tempest_tests/tests/api/v2/test_executions.py index df50d7b..a4aa232 100644 --- a/mistral_tempest_tests/tests/api/v2/test_executions.py +++ b/mistral_tempest_tests/tests/api/v2/test_executions.py @@ -13,14 +13,13 @@ # under the License. from oslo_concurrency.fixture import lockutils +from oslo_serialization import jsonutils from tempest.lib import decorators from tempest.lib import exceptions from mistral_tempest_tests.tests import base from mistral_tempest_tests.tests import utils -import json - class ExecutionTestsV2(base.TestCase): @@ -370,7 +369,7 @@ class ExecutionTestsV2(base.TestCase): self.assertEqual( namespace, - json.loads(top_execution['params'])['namespace'] + jsonutils.loads(top_execution['params'])['namespace'] ) resp, tasks = self.client.get_tasks(top_execution['id']) @@ -387,7 +386,7 @@ class ExecutionTestsV2(base.TestCase): self.assertEqual( namespace, - json.loads(middle_execution['params'])['namespace'] + jsonutils.loads(middle_execution['params'])['namespace'] ) resp, tasks = self.client.get_tasks(middle_execution['id']) @@ -404,7 +403,7 @@ class ExecutionTestsV2(base.TestCase): self.assertEqual( namespace, - json.loads(lowest_execution['params'])['namespace'] + jsonutils.loads(lowest_execution['params'])['namespace'] ) resp, tasks = self.client.get_tasks(lowest_execution['id']) diff --git a/mistral_tempest_tests/tests/api/v2/test_workflows.py b/mistral_tempest_tests/tests/api/v2/test_workflows.py index ff10241..9eebb4b 100644 --- a/mistral_tempest_tests/tests/api/v2/test_workflows.py +++ b/mistral_tempest_tests/tests/api/v2/test_workflows.py @@ -11,9 +11,9 @@ # 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 json from oslo_concurrency.fixture import lockutils +from oslo_serialization import jsonutils from tempest.lib import decorators from tempest.lib import exceptions @@ -57,7 +57,7 @@ class WorkflowTestsV2(base.TestCase): name = body['workflows'][0]['name'] resp, raw_body = self.admin_client.get('workflows?all_projects=true') - body = json.loads(raw_body) + body = jsonutils.loads(raw_body) self.assertEqual(200, resp.status) @@ -78,7 +78,7 @@ class WorkflowTestsV2(base.TestCase): 'workflows?project_id=%s' % self.client.auth_provider.credentials.tenant_id ) - body = json.loads(raw_body) + body = jsonutils.loads(raw_body) self.assertEqual(200, resp.status) @@ -99,7 +99,7 @@ class WorkflowTestsV2(base.TestCase): 'workflows?project_id=%s' % self.client.auth_provider.credentials.tenant_id ) - body = json.loads(raw_body) + body = jsonutils.loads(raw_body) self.assertEqual(200, resp.status) diff --git a/mistral_tempest_tests/tests/scenario/engine/actions/v2/test_ssh_actions.py b/mistral_tempest_tests/tests/scenario/engine/actions/v2/test_ssh_actions.py index a4c038e..5ef9390 100644 --- a/mistral_tempest_tests/tests/scenario/engine/actions/v2/test_ssh_actions.py +++ b/mistral_tempest_tests/tests/scenario/engine/actions/v2/test_ssh_actions.py @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json import os from os import path import time from oslo_log import log as logging +from oslo_serialization import jsonutils from paramiko import ssh_exception from tempest import config from tempest.lib import decorators @@ -243,13 +243,13 @@ class SSHActionsTestsV2(base.TestCaseAdvanced): resp, body = self.client.create_action_execution( { 'name': 'std.ssh', - 'input': json.dumps(input_data) + 'input': jsonutils.dump_as_bytes(input_data) } ) self.assertEqual(201, resp.status) - output = json.loads(body['output']) + output = jsonutils.loads(body['output']) self.assertIn(self.public_vm['name'], output['result']) @@ -271,12 +271,12 @@ class SSHActionsTestsV2(base.TestCaseAdvanced): resp, body = self.client.create_action_execution( { 'name': 'std.ssh_proxied', - 'input': json.dumps(input_data) + 'input': jsonutils.dump_as_bytes(input_data) } ) self.assertEqual(201, resp.status) - output = json.loads(body['output']) + output = jsonutils.loads(body['output']) self.assertIn(self.guest_vm['name'], output['result']) diff --git a/mistral_tempest_tests/tests/utils.py b/mistral_tempest_tests/tests/utils.py index 05487b7..1955db9 100755 --- a/mistral_tempest_tests/tests/utils.py +++ b/mistral_tempest_tests/tests/utils.py @@ -15,12 +15,12 @@ # limitations under the License. import contextlib -import json import os import shutil import tempfile from oslo_concurrency import processutils +from oslo_serialization import jsonutils class NotDefined(object): @@ -47,7 +47,7 @@ def get_dict_from_string(string, delimiter=','): if len(kv_list) > 1: try: - value = json.loads(kv_list[1]) + value = jsonutils.loads(kv_list[1]) except ValueError: value = kv_list[1]