Skip to content

Commit

Permalink
added tests for double list get and subscribe (currently only version…
Browse files Browse the repository at this point in the history
… with aggregation), minor logging and test param update, update for confd path creation

Signed-off-by: Michal Novak <[email protected]>
  • Loading branch information
micnovak committed Sep 21, 2023
1 parent f7ea2b1 commit fd942dd
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 18 deletions.
20 changes: 20 additions & 0 deletions gnmi-tools.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,25 @@
<int-leaf>23</int-leaf>
</down>
</top-list>
<double-list>
<name>n1</name>
<type>t1</type>
<admin-state>In-Service</admin-state>
</double-list>
<double-list>
<name>1010/0/AD-2-RX</name>
<type>opticalTransport</type>
<admin-state>In-Service</admin-state>
</double-list>
<double-list>
<name>1010/0/[AD 4-11]-1-RX</name>
<type>opticalTransport</type>
<admin-state>In-Service</admin-state>
</double-list>
<double-list>
<name>ab[cd</name>
<type>opticalTransport</type>
<admin-state>In-Service</admin-state>
</double-list>
</gnmi-tools>
</config>
7 changes: 7 additions & 0 deletions gnmi-tools.yang
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ module gnmi-tools {
leaf name {type string;}
uses combo;
}

list double-list {
key "name type";
leaf name {type string;}
leaf type {type string;}
leaf admin-state {type string;}
}
}

}
1 change: 1 addition & 0 deletions src/confd_gnmi_api_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ def make_updates_with_maagic(self, tr, path_str):
def get_updates(self, trans, path_str, confd_path, save_flags, allow_aggregation=False):
log.debug("==> path_str=%s", path_str)
tagpath = '/' + '/'.join(tag for tag, _ in parse_instance_path(path_str))
log.debug("tagpath=%s", tagpath)
if tagpath != '/':
csnode = _tm.cs_node_cd(None, tagpath)
else:
Expand Down
16 changes: 11 additions & 5 deletions src/confd_gnmi_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def parse_instance_path(xpath_string) -> Iterable[Tuple[str, List[Tuple[str, str
yield mdict['tag'], keys


# Crate gNMI Path object from string representation of path
# Create gNMI Path object from string representation of path
# see: https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-specification.md#222-paths
# TODO tests
def make_gnmi_path(xpath_string: str, origin: str = None, target: str = None) -> gnmi_pb2.Path:
Expand Down Expand Up @@ -157,10 +157,16 @@ def make_path(gnmi_path):
path = ""
for e in gnmi_path.elem:
path += "/" + e.name
for k, v in e.key.items():
val = v if not quote_val else "\"{}\"".format(v)
path += "[{}={}]".format(k, val) if xpath else "{{{}}}".format(
val)
len_items = len(e.key.items())
if len_items:
if not xpath: path += '{'
for index, (k, v) in enumerate(e.key.items()):
val = v if not quote_val else "\"{}\"".format(v)
path += "[{}={}]".format(k, val) if xpath else "{}".format(
val)
if not xpath and index < len_items - 1: path += " "
if not xpath: path += '}'

if path == "":
path = "/"
return path
Expand Down
22 changes: 17 additions & 5 deletions tests/client_server_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ def _setup(self):
("/top-pres/empty-leaf", [None]),
("/top-pres/down/str-leaf", "test4"),
("/top-pres/down/int-leaf", 10),
("/top-pres/pres", {})
("/top-pres/pres", {}),
("/double-list[type=t1][name=n1]/admin-state", "In-Service"),
("/double-list[name=1010/0/AD-2-RX]/admin-state", "In-Service",
{"check_path": False}),
("/double-list[name=1010/0/AD-2-RX][type=opticalTransport]/admin-state", "In-Service"),
("/double-list[name=\"1010/0/[AD 4-11]-1-RX\"][type=opticalTransport]/admin-state", "In-Service"),
("/double-list[name=\"ab[cd\"][type=opticalTransport]/admin-state", "In-Service")
]

@staticmethod
Expand Down Expand Up @@ -84,7 +90,13 @@ def capability_supported(cap):

@staticmethod
def assert_update(update, path_val):
assert (update.path == path_val[0])
check_path = True
#do we have options attribute?
if len(path_val) >= 3:
if "check_path" in path_val[2]:
check_path = path_val[2]["check_path"]
if check_path:
assert (update.path == path_val[0])
json_value = json.loads(update.val.json_ietf_val)
assert json_value == path_val[1]

Expand Down Expand Up @@ -352,15 +364,15 @@ def test_it(encoding):
self._test_get_subscribe(datatype=datatype_str_to_int(data_type),
encoding=encoding)

@pytest.mark.parametrize("allow_aggregation", [True, False])
@pytest.mark.parametrize("allow_aggregation", [True, False], ids=["aggr", "no-aggr"])
@pytest.mark.parametrize("data_type", ["CONFIG", "STATE"])
def test_subscribe_once(self, request, data_type, allow_aggregation):
log.info("testing subscribe_once")
self._test_get_subscribe(is_subscribe=True,
datatype=datatype_str_to_int(data_type),
allow_aggregation=allow_aggregation)

@pytest.mark.parametrize("allow_aggregation", [True, False])
@pytest.mark.parametrize("allow_aggregation", [True, False], ids=["aggr", "no-aggr"])
@pytest.mark.parametrize("data_type", ["CONFIG", "STATE"])
def test_subscribe_once_encoding(self, request, data_type, allow_aggregation):
log.info("testing subscribe_once_encoding")
Expand All @@ -373,7 +385,7 @@ def test_it(encoding):
allow_aggregation=allow_aggregation)

@pytest.mark.long
@pytest.mark.parametrize("allow_aggregation", [True, False])
@pytest.mark.parametrize("allow_aggregation", [True, False], ids=["aggr", "no-aggr"])
@pytest.mark.parametrize("data_type", ["CONFIG", "STATE"])
@pytest.mark.parametrize("poll_args",
[(0.2, 2), (0.5, 2), (1, 2), (0.2, 10)])
Expand Down
25 changes: 17 additions & 8 deletions tests/test_client_server_confd.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def _test_gnmi_tools_get_subscribe_gnmi_tools(self, is_subscribe=False,
kwargs = {"assert_fun": GrpcBase.assert_updates}
kwargs["prefix"] = make_gnmi_path("/gnmi-tools:gnmi-tools")

leaf_paths_val = [
(GrpcBase.mk_gnmi_if_path(p[0]), p[1]) if len(p) == 2 else (
GrpcBase.mk_gnmi_if_path(p[0]), p[1], p[2]) for p in
self.gnmi_tools_leaf_paths_str_val]

if is_subscribe:
verify_response_updates = self.verify_sub_sub_response_updates
kwargs["subscription_mode"] = subscription_mode
Expand All @@ -82,12 +87,13 @@ def _test_gnmi_tools_get_subscribe_gnmi_tools(self, is_subscribe=False,
kwargs["read_count"] = read_count
kwargs["sample_interval"] = sample_interval
kwargs["allow_aggregation"] = allow_aggregation
# TODO temporarily disabled subscription tests for double lists
if not allow_aggregation:
leaf_paths_val = [ p for p in leaf_paths_val if not "double-list" in p[0].elem[0].name]
else:
verify_response_updates = self.verify_get_response_updates
kwargs["datatype"] = datatype

leaf_paths_val = [(GrpcBase.mk_gnmi_if_path(p[0]), p[1]) for p in self.gnmi_tools_leaf_paths_str_val]

kwargs["encoding"] = encoding
kwargs["paths"] = [ p[0] for p in leaf_paths_val]
kwargs["path_value"] = [p for p in leaf_paths_val]
Expand All @@ -99,27 +105,30 @@ def test_gnmi_tools_get(self, request):
self._test_gnmi_tools_get_subscribe_gnmi_tools()

@pytest.mark.confd
def test_gnmi_tools_subscribe_once(self, request):
@pytest.mark.parametrize("allow_aggregation", [True, False], ids=["aggr", "no-aggr"])
def test_gnmi_tools_subscribe_once(self, request, allow_aggregation):
log.info("testing subscribe_once")
self._test_gnmi_tools_get_subscribe_gnmi_tools(is_subscribe=True, allow_aggregation=False)
self._test_gnmi_tools_get_subscribe_gnmi_tools(is_subscribe=True, allow_aggregation=allow_aggregation)

@pytest.mark.long
@pytest.mark.confd
@pytest.mark.parametrize("allow_aggregation", [True, False], ids=["aggr", "no-aggr"])
@pytest.mark.parametrize("poll_args", [(0.2, 2), (0.5, 2), (1, 2)])
def test_gnmi_tools_subscribe_poll(self, request, poll_args):
def test_gnmi_tools_subscribe_poll(self, request, poll_args, allow_aggregation):
log.info("testing subscribe_poll")
self._test_gnmi_tools_get_subscribe_gnmi_tools(is_subscribe=True,
subscription_mode=gnmi_pb2.SubscriptionList.POLL,
poll_interval=poll_args[0],
poll_count=poll_args[1],
allow_aggregation=False)
allow_aggregation=allow_aggregation)

@pytest.mark.confd
def test_gnmi_tools_subscribe_stream_sample(self, request):
@pytest.mark.parametrize("allow_aggregation", [True, False], ids=["aggr", "no-aggr"])
def test_gnmi_tools_subscribe_stream_sample(self, request, allow_aggregation):
log.info("testing subscribe_stream_sample")
self._test_gnmi_tools_get_subscribe_gnmi_tools(is_subscribe=True,
subscription_mode=gnmi_pb2.SubscriptionList.STREAM,
sample_interval=1000, read_count=2, allow_aggregation=False)
sample_interval=1000, read_count=2, allow_aggregation=allow_aggregation)

@pytest.mark.long
@pytest.mark.confd
Expand Down

0 comments on commit fd942dd

Please sign in to comment.