Skip to content

Commit

Permalink
OPENSTACK-2894: use utf-8 code for bigip configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
zhang-shengping committed Oct 9, 2023
1 parent b4660d1 commit 3959cc9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 8 additions & 3 deletions f5/bigip/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"orderreddict external dependency installed.")
raise exc(message)
import copy
import json
import keyword
import re
import time
Expand Down Expand Up @@ -404,7 +405,8 @@ def _modify(self, **patch):
# Handles ConnectionAborted errors
for i in range(0, 30):
try:
response = session.patch(patch_uri, json=patch, **requests_params)
response = session.patch(
patch_uri, data=patch, **requests_params)
break
except ConnectionError as ex:
if 'Connection aborted' in str(ex) and i < 29:
Expand Down Expand Up @@ -451,6 +453,7 @@ def _prepare_request_json(self, kwargs):
kwargs.pop('check')
od.update(kwargs)
return od
kwargs = json.dumps(kwargs, ensure_ascii=False).encode('utf-8')
return kwargs

def _iter_list_for_dicts(self, check_list):
Expand Down Expand Up @@ -588,7 +591,8 @@ def _update(self, **kwargs):
# @see https://github.com/requests/requests/issues/2364
for i in range(0, 30):
try:
response = session.put(update_uri, json=data_dict, **requests_params)
response = session.put(
update_uri, data=data_dict, **requests_params)
self._meta_data = temp_meta
self._local_update(response.json())
break
Expand Down Expand Up @@ -993,7 +997,8 @@ def _create(self, **kwargs):
# Handles ConnectionAborted errors
for i in range(0, 30):
try:
response = session.post(_create_uri, json=kwargs, **requests_params)
response = session.post(
_create_uri, data=kwargs, **requests_params)
break
except ConnectionError as ex:
if 'Connection aborted' in str(ex) and i < 29:
Expand Down
12 changes: 6 additions & 6 deletions f5/bigip/test/unit/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,23 +272,23 @@ def test_reduce_boolean_removes_enabled(self, fake_vs):
fake_vs.create(partition="Common", name="test_create", enabled=False)
session = fake_vs._meta_data['bigip']._meta_data['icr_session']
pos, kwargs = session.post.call_args
assert kwargs['json']['disabled'] is True
assert 'enabled' not in kwargs['json']
assert '"disabled": true' in kwargs
assert 'enabled' not in kwargs

def test_reduce_boolean_removes_disabled(self, fake_vs):
fake_vs.create(partition='Common', name='test_create',
disabled=False)
session = fake_vs._meta_data['bigip']._meta_data['icr_session']
pos, kwargs = session.post.call_args
assert kwargs['json']['enabled'] is True
assert 'disabled' not in kwargs['json']
assert '"enabled": true' in kwargs
assert 'disabled' not in kwargs

def test_reduce_boolean_removes_nothing(self, fake_vs):
fake_vs.create(partition='Common', name='test_create', enabled=True)
session = fake_vs._meta_data['bigip']._meta_data['icr_session']
pos, kwargs = session.post.call_args
assert kwargs['json']['enabled'] is True
assert 'disabled' not in kwargs['json']
assert '"enabled": true' in kwargs
assert 'disabled' not in kwargs

def test_reduce_boolean_same_value(self, fake_vs):
with pytest.raises(ExclusiveAttributesPresent) as ex:
Expand Down

0 comments on commit 3959cc9

Please sign in to comment.