Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added config reset test fixture (empty for Demo) #35

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/client_server_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ def mk_gnmi_if_path(path_str, if_state_str="", if_id=None):
path_str = path_str.format(if_state_str, if_id)
return make_gnmi_path(path_str)

def _do_reset_cfg(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why underscore, as it is not private for the class? It is overridden in derived classes.

raise NotImplementedError

@pytest.fixture
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it, do we need extra fixture? I know it is slightly different, but for now adding _do_reset_cfg into
existing fixture def fix_method(self, request): would do.

def reset_cfg(self):
self._do_reset_cfg()


class AdapterTests(GrpcBase):
def test_capabilities(self, request):
Expand Down Expand Up @@ -561,6 +568,7 @@ def test_subscribe_stream_sample(self, request, data_type):
datatype=datatype_str_to_int(data_type),
sample_interval=1000, read_count=2)

@pytest.mark.usefixtures("reset_cfg")
def test_set(self, request):
log.info("testing set")
if_id = 8
Expand Down Expand Up @@ -590,6 +598,7 @@ def test_set(self, request):
AdapterTests.assert_set_response(response.response[0],
(paths[0], gnmi_pb2.UpdateResult.UPDATE))

@pytest.mark.usefixtures("reset_cfg")
def test_set_encoding(self, request):
log.info("testing set_encoding")
if_id = 8
Expand Down
34 changes: 23 additions & 11 deletions tests/test_client_server_confd.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@

_confd_DEBUG = 1


def reset_confd_config():
with maapi.single_read_trans('admin', 'system') as trans:
with socket.socket() as sock:
sid = trans.save_config(_confd.maapi.CONFIG_J, '')
_confd.stream_connect(sock, sid, 0, '127.0.0.1', _confd.PORT)
data = b''.join(iter(lambda: sock.recv(1024), b''))
yield
with maapi.single_write_trans('admin', 'system') as trans:
with socket.socket() as sock:
sid = trans.load_config_stream(_confd.maapi.CONFIG_J)
_confd.stream_connect(sock, sid, 0, '127.0.0.1', _confd.PORT)
sock.send(data)
assert trans.maapi.load_config_stream_result(sid) == _confd.OK
trans.apply()


@pytest.mark.grpc
@pytest.mark.confd
@pytest.mark.usefixtures("fix_method")
Expand Down Expand Up @@ -235,22 +252,14 @@ def test_set_trans_order(self, request):
val=gnmi_pb2.TypedValue(json_ietf_val=b'true'))
self.client.set_request(None, update=[update])

def _do_reset_cfg(self):
reset_confd_config()


class TestGrpcConfDSet(GrpcBase):
def set_adapter_type(self):
self.adapter_type = AdapterType.API

@pytest.fixture
def reset_cfg(self, request):
yield
with maapi.single_write_trans('admin', 'system') as trans:
gt = maagic.get_node(trans, '/gnmi-tools')
for lst in (gt.top_list, gt.double_key_list):
for inst in lst:
if inst.name.startswith('test-'):
trans.delete(inst._path)
trans.apply()

def assert_instance(self, lst='top-list', list_ix=1, leaf='down/str-leaf', value='abcd'):
key = f'{{test-{list_ix} test}}' if lst == 'double-key-list' \
else f'{{test-{list_ix}}}'
Expand Down Expand Up @@ -310,3 +319,6 @@ def test_set_list_two_instances(self, request):
self.client_set('/gnmi-tools:gnmi-tools', obj)
self.assert_instance(value='efgh')
self.assert_instance(list_ix=2, value='efgh')

def _do_reset_cfg(self):
reset_confd_config()
3 changes: 3 additions & 0 deletions tests/test_client_server_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ class TestGrpcDemo(AdapterTests):

def set_adapter_type(self):
self.adapter_type = AdapterType.DEMO

def _do_reset_cfg(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disadvantage of making new class. just for Set. Perhaps there can be common (abstract) ConfDTests class, so _do_reset_cfg is implemented only once. And functionality could be implemented in this function (no need for reset_confd_config()).

pass
Loading