mirror of
https://github.com/ansible-collections/community.routeros.git
synced 2025-07-31 00:05:11 +02:00
Allow to differ on API paths based on RouterOS version (1/2) (#209)
* Allow to provide definition for path based on API version.
* The paths added in 343c4883c0
are RouterOS 7+.
This commit is contained in:
parent
1ed4690240
commit
4b0995135c
7 changed files with 3158 additions and 2710 deletions
|
@ -10,7 +10,7 @@ __metaclass__ = type
|
|||
import pytest
|
||||
|
||||
from ansible_collections.community.routeros.plugins.module_utils._api_data import (
|
||||
APIData,
|
||||
VersionedAPIData,
|
||||
KeyInfo,
|
||||
split_path,
|
||||
join_path,
|
||||
|
@ -19,7 +19,7 @@ from ansible_collections.community.routeros.plugins.module_utils._api_data impor
|
|||
|
||||
def test_api_data_errors():
|
||||
with pytest.raises(ValueError) as exc:
|
||||
APIData()
|
||||
VersionedAPIData()
|
||||
assert exc.value.args[0] == 'fields must be provided'
|
||||
|
||||
values = [
|
||||
|
@ -33,39 +33,39 @@ def test_api_data_errors():
|
|||
for index, (param, param_value) in enumerate(values):
|
||||
for param2, param2_value in values[index + 1:]:
|
||||
with pytest.raises(ValueError) as exc:
|
||||
APIData(**{param: param_value, param2: param2_value})
|
||||
VersionedAPIData(**{param: param_value, param2: param2_value})
|
||||
assert exc.value.args[0] == 'primary_keys, stratify_keys, has_identifier, single_value, and unknown_mechanism are mutually exclusive'
|
||||
|
||||
with pytest.raises(ValueError) as exc:
|
||||
APIData(unknown_mechanism=True, fully_understood=True)
|
||||
VersionedAPIData(unknown_mechanism=True, fully_understood=True)
|
||||
assert exc.value.args[0] == 'unknown_mechanism and fully_understood cannot be combined'
|
||||
|
||||
with pytest.raises(ValueError) as exc:
|
||||
APIData(unknown_mechanism=True, fixed_entries=True)
|
||||
VersionedAPIData(unknown_mechanism=True, fixed_entries=True)
|
||||
assert exc.value.args[0] == 'fixed_entries can only be used with primary_keys'
|
||||
|
||||
with pytest.raises(ValueError) as exc:
|
||||
APIData(primary_keys=['foo'], fields={})
|
||||
VersionedAPIData(primary_keys=['foo'], fields={})
|
||||
assert exc.value.args[0] == 'Primary key foo must be in fields!'
|
||||
|
||||
with pytest.raises(ValueError) as exc:
|
||||
APIData(stratify_keys=['foo'], fields={})
|
||||
VersionedAPIData(stratify_keys=['foo'], fields={})
|
||||
assert exc.value.args[0] == 'Stratify key foo must be in fields!'
|
||||
|
||||
with pytest.raises(ValueError) as exc:
|
||||
APIData(required_one_of=['foo'], fields={})
|
||||
VersionedAPIData(required_one_of=['foo'], fields={})
|
||||
assert exc.value.args[0] == 'Require one of element at index #1 must be a list!'
|
||||
|
||||
with pytest.raises(ValueError) as exc:
|
||||
APIData(required_one_of=[['foo']], fields={})
|
||||
VersionedAPIData(required_one_of=[['foo']], fields={})
|
||||
assert exc.value.args[0] == 'Require one of key foo must be in fields!'
|
||||
|
||||
with pytest.raises(ValueError) as exc:
|
||||
APIData(mutually_exclusive=['foo'], fields={})
|
||||
VersionedAPIData(mutually_exclusive=['foo'], fields={})
|
||||
assert exc.value.args[0] == 'Mutually exclusive element at index #1 must be a list!'
|
||||
|
||||
with pytest.raises(ValueError) as exc:
|
||||
APIData(mutually_exclusive=[['foo']], fields={})
|
||||
VersionedAPIData(mutually_exclusive=[['foo']], fields={})
|
||||
assert exc.value.args[0] == 'Mutually exclusive key foo must be in fields!'
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,9 @@ __metaclass__ = type
|
|||
from ansible_collections.community.routeros.plugins.module_utils._api_data import PATHS
|
||||
|
||||
|
||||
FAKE_ROS_VERSION = '7.0.0'
|
||||
|
||||
|
||||
class FakeLibRouterosError(Exception):
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
@ -16,7 +19,7 @@ class FakeLibRouterosError(Exception):
|
|||
|
||||
|
||||
class TrapError(FakeLibRouterosError):
|
||||
def __init__(self, message="failure: already have interface with such name"):
|
||||
def __init__(self, message='failure: already have interface with such name'):
|
||||
super(TrapError, self).__init__(message)
|
||||
|
||||
|
||||
|
@ -133,7 +136,9 @@ def _normalize_entry(entry, path_info, on_create=False):
|
|||
|
||||
|
||||
def massage_expected_result_data(values, path, keep_all=False, remove_dynamic=False, remove_builtin=False):
|
||||
path_info = PATHS[path]
|
||||
versioned_path_info = PATHS[path]
|
||||
versioned_path_info.provide_version(FAKE_ROS_VERSION)
|
||||
path_info = versioned_path_info.get_data()
|
||||
if remove_dynamic:
|
||||
values = [entry for entry in values if not entry.get('dynamic', False)]
|
||||
if remove_builtin:
|
||||
|
@ -155,7 +160,9 @@ def massage_expected_result_data(values, path, keep_all=False, remove_dynamic=Fa
|
|||
class Path(object):
|
||||
def __init__(self, path, initial_values, read_only=False):
|
||||
self._path = path
|
||||
self._path_info = PATHS[path]
|
||||
versioned_path_info = PATHS[path]
|
||||
versioned_path_info.provide_version(FAKE_ROS_VERSION)
|
||||
self._path_info = versioned_path_info.get_data()
|
||||
self._values = [entry.copy() for entry in initial_values]
|
||||
for entry in self._values:
|
||||
_normalize_entry(entry, self._path_info)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue