diff --git a/tests/client_server_test_base.py b/tests/client_server_test_base.py index 3a60c25..917984b 100644 --- a/tests/client_server_test_base.py +++ b/tests/client_server_test_base.py @@ -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): + raise NotImplementedError + + @pytest.fixture + def reset_cfg(self): + self._do_reset_cfg() + class AdapterTests(GrpcBase): def test_capabilities(self, request): @@ -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 @@ -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 diff --git a/tests/test_client_server_confd.py b/tests/test_client_server_confd.py index ba6f52c..5aa0686 100644 --- a/tests/test_client_server_confd.py +++ b/tests/test_client_server_confd.py @@ -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") @@ -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}}}' @@ -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() diff --git a/tests/test_client_server_demo.py b/tests/test_client_server_demo.py index 0c263f1..f9831c5 100644 --- a/tests/test_client_server_demo.py +++ b/tests/test_client_server_demo.py @@ -13,3 +13,6 @@ class TestGrpcDemo(AdapterTests): def set_adapter_type(self): self.adapter_type = AdapterType.DEMO + + def _do_reset_cfg(self): + pass