Skip to content

Commit

Permalink
v1.0.6 (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisero authored Apr 1, 2021
1 parent a6030ad commit d42a5cf
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.0.6 [2020-04-01]

## Fixed

* Bulk create/update failed due to bulk param not being set automatically for some resources
* RateLimiter error was not handled correctly leading to retry operations not being tried

# 1.0.5 [2020-03-19]

## Fixed
Expand Down Expand Up @@ -186,4 +193,4 @@ replaced by `FMC` that provides a hierarchical access to all resources on FMC.

* Getbyid operations fails due to incorrect limit param
* Api calls for ftd ipv4/ipv6 static routing fails due to incorrect URLs
* Update ftd sub interface fails due to missing param
* Update ftd sub interface fails due to missing param
7 changes: 7 additions & 0 deletions fireREST/fmc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,15 @@ def _request(self, method: str, url: str, params=None, auth=None, data=None):
:return: api response
:rtype: requests.Response
"""

params = utils.fix_params(params)

# if payload is of type list the bulk param should be set automatically
if isinstance(data, list):
params['bulk'] = True

response = None

# dry_run only affects PUT, POST and DELETE operations
# dry_run is not applicable for authentication related operations (login/refresh)
if self.dry_run and method.lower() != 'get' and '/v1/auth/' not in url:
Expand Down
10 changes: 3 additions & 7 deletions fireREST/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,17 @@ def wrapper(*args, **kwargs):
def support_params(f):
"""Apply `Resource` specific params to api operation
decorator that adds support for specified filter or params options. If a list is passed
in PUT or POST operations the `bulk` param is automatically set. Available filters and params
decorator that adds support for specified filter or params options. Available filters and params
are checked against `Resource.SUPPORTED_FILTERS` and `Resource.SUPPORTED_PARAMS`. If a match is found
params are set accordingly and passed to the operations implementation
"""

@wraps(f)
def wrapper(*args, **kwargs):
resource = args[0]
data = kwargs.get('data', None)
filters = []
params = {}

# if payload is of type list the bulk param should be set automatically
if isinstance(data, list):
params['bulk'] = True

# search through function kwargs to locate filter and param arguments
for k, v in kwargs.items():
if v:
Expand Down Expand Up @@ -245,6 +239,8 @@ def raise_for_status(response):
raise exceptions.get(status_code, exc.GenericApiError)(
msg=response.json()['error']['messages'][0]['description']
)
except KeyError:
raise exceptions.get(status_code, exc.GenericApiError)(msg=response.text)
except ValueError:
raise exceptions.get(status_code, HTTPError)()

Expand Down
2 changes: 1 addition & 1 deletion fireREST/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.5'
__version__ = '1.0.6'
23 changes: 23 additions & 0 deletions test/fmc/object/network/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ def test_create_network_object(fmc):
assert expected_result == actual_result


def test_create_network_object_bulk(fmc):
expected_result = 201
data = [
{'name': 'FireREST-NetworkObjBulk1', 'value': '198.18.1.0/24'},
{'name': 'FireREST-NetworkObjBulk2', 'value': '198.18.2.0/24'}
]

actual_result = fmc.object.network.create(data)
STATE['object']['network']['bulk'] = actual_result.json()
actual_result = actual_result.status_code

assert expected_result == actual_result


def test_get_network_objects(fmc):
expected_result = 'FireREST-NetworkObj'
actual_result = None
Expand Down Expand Up @@ -60,3 +74,12 @@ def test_delete_network_object(fmc):
actual_result = fmc.object.network.delete(uuid=obj_id).status_code

assert expected_result == actual_result


def test_delete_network_object_bulk(fmc):
expected_result = 200
actual_result_first = fmc.object.network.delete(name='FireREST-NetworkObjBulk1').status_code
actual_result_second = fmc.object.network.delete(name='FireREST-NetworkObjBulk2').status_code

assert expected_result == actual_result_first
assert expected_result == actual_result_second
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[testenv]
[testenv:test]
description = execute pytest suite
deps =
pytest
Expand Down

0 comments on commit d42a5cf

Please sign in to comment.