Skip to content

Commit

Permalink
[ignore] Added value error for the invalid op value
Browse files Browse the repository at this point in the history
  • Loading branch information
sajagana committed Nov 28, 2024
1 parent f7dcddb commit bb18a64
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions plugins/module_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def generate_api_endpoint(path, **kwargs):
return path if not kwargs else "{0}?{1}".format(path, "&".join(["{0}={1}".format(key, value) for key, value in kwargs.items()]))


def append_update_ops_data(ops, existing_data, update_path, changes=dict(), op="replace"):
def append_update_ops_data(ops, existing_data, update_path, changes=None, op="replace"):
"""
Append Update ops payload data.
:param ops: Variable which contains the PATCH replace actions for the update operation -> List
:param existing_data: Variable which contains the existing data -> Dict
:param update_path: The object path is used to update an existing object -> Str
:param changes: Input dictionary which contains the attribute to be updated and its new value -> Dict
:param changes: Defaults to None when not specified, expected a dictionary object. Which contains the attribute to be updated and its new value -> Dict
:param op: Defaults to "replace" when not specified, value "remove" is used clear the existing configuration -> Str
:return: None
If attributes is not empty then the ops and existing_data are updated with the input value.
Expand Down Expand Up @@ -164,10 +164,7 @@ def append_update_ops_data(ops, existing_data, update_path, changes=dict(), op="
"""

def recursive_update(data, path, keys, new_value):
if len(keys) == 0:
return
key = keys[0]

Check warning on line 167 in plugins/module_utils/utils.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/utils.py#L166-L167

Added lines #L166 - L167 were not covered by tests

if len(keys) == 1:
# Update the existing configuration
if new_value is not None and data.get(key) != new_value and op == "replace":
Expand All @@ -192,6 +189,10 @@ def recursive_update(data, path, keys, new_value):
elif key in data:
recursive_update(data[key], "{}/{}".format(path, key), keys[1:], new_value)

Check warning on line 190 in plugins/module_utils/utils.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/utils.py#L190

Added line #L190 was not covered by tests

valid_ops = ["replace", "remove"]

Check warning on line 192 in plugins/module_utils/utils.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/utils.py#L192

Added line #L192 was not covered by tests
if op not in valid_ops:
raise ValueError("Invalid op value. Expected one of: {0}. Got: {1}".format(valid_ops, op))

Check warning on line 194 in plugins/module_utils/utils.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/utils.py#L194

Added line #L194 was not covered by tests

if changes:
for key, value in changes.items():
if isinstance(key, tuple):
Expand Down

0 comments on commit bb18a64

Please sign in to comment.