From a227992324b25972e5f634bebae65833973f69e9 Mon Sep 17 00:00:00 2001 From: Will George Date: Wed, 3 Feb 2021 11:23:12 -0500 Subject: [PATCH] Add '/get' as alias for all '/getconfig' endpoints --- netpalm/routers/getconfig.py | 9 +++++++++ tests/integration/helper.py | 1 + tests/integration/test_getconfig_cisgo.py | 23 +++++++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/netpalm/routers/getconfig.py b/netpalm/routers/getconfig.py index 9ca5c91..2316613 100644 --- a/netpalm/routers/getconfig.py +++ b/netpalm/routers/getconfig.py @@ -30,6 +30,7 @@ def _get_config(getcfg: GetConfig, library: str = None): # read config @router.post("/getconfig", response_model=Response, status_code=201) +@router.post("/get", response_model=Response, status_code=201) @error_handle_w_cache @whitelist def get_config(getcfg: GetConfig): @@ -38,6 +39,7 @@ def get_config(getcfg: GetConfig): # read config @router.post("/getconfig/netmiko", response_model=Response, status_code=201) +@router.post("/get/netmiko", response_model=Response, status_code=201) @error_handle_w_cache @whitelist def get_config_netmiko(getcfg: NetmikoGetConfig): @@ -46,6 +48,7 @@ def get_config_netmiko(getcfg: NetmikoGetConfig): # read config @router.post("/getconfig/napalm", response_model=Response, status_code=201) +@router.post("/get/napalm", response_model=Response, status_code=201) @error_handle_w_cache @whitelist def get_config_napalm(getcfg: NapalmGetConfig): @@ -54,6 +57,7 @@ def get_config_napalm(getcfg: NapalmGetConfig): # read config @router.post("/getconfig/puresnmp", response_model=Response, status_code=201) +@router.post("/get/puresnmp", response_model=Response, status_code=201) @error_handle_w_cache @whitelist def get_config_puresnmp(getcfg: PureSNMPGetConfig): @@ -62,6 +66,7 @@ def get_config_puresnmp(getcfg: PureSNMPGetConfig): # read config @router.post("/getconfig/ncclient", response_model=Response, status_code=201) +@router.post("/get/ncclient", response_model=Response, status_code=201) @error_handle_w_cache @whitelist def get_config_ncclient(getcfg: NcclientGetConfig): @@ -74,6 +79,9 @@ def get_config_ncclient(getcfg: NcclientGetConfig): @router.post("/getconfig/ncclient/get", response_model=Response, status_code=201) +@router.post("/get/ncclient/get", + response_model=Response, + status_code=201) @error_handle_w_cache @whitelist def ncclient_get(getcfg: NcclientGet, library: str = "ncclient"): @@ -87,6 +95,7 @@ def ncclient_get(getcfg: NcclientGet, library: str = "ncclient"): # read config @router.post("/getconfig/restconf", response_model=Response, status_code=201) +@router.post("/get/restconf", response_model=Response, status_code=201) @error_handle_w_cache @whitelist def get_config_restconf(getcfg: Restconf): diff --git a/tests/integration/helper.py b/tests/integration/helper.py index 411e9b0..4c0d6a4 100644 --- a/tests/integration/helper.py +++ b/tests/integration/helper.py @@ -91,6 +91,7 @@ def poll_task_errors(self, taskid, timeout=None) -> List: def post_and_check(self, endpoint, payload) -> Dict: url = f"{self.base_url}{endpoint}" r = requests.post(url, json=payload, headers=self.headers, timeout=self.http_timeout) + r.raise_for_status() task_id = r.json()["data"]["task_id"] result, errors = self.poll_task(task_id) return result diff --git a/tests/integration/test_getconfig_cisgo.py b/tests/integration/test_getconfig_cisgo.py index d61bec1..d398e8b 100644 --- a/tests/integration/test_getconfig_cisgo.py +++ b/tests/integration/test_getconfig_cisgo.py @@ -93,6 +93,8 @@ def test_getconfig_netmiko(cisgo_helper: CisgoHelper): } res = helper.post_and_check('/getconfig', pl) assert hostname_from_config(res["show running-config"]) == CISGO_DEFAULT_HOSTNAME + res = helper.post_and_check('/get', pl) + assert hostname_from_config(res["show running-config"]) == CISGO_DEFAULT_HOSTNAME @pytest.mark.getconfig @@ -108,6 +110,8 @@ def test_getconfig_netmiko_with_textfsm(cisgo_helper: CisgoHelper): } res = helper.post_and_check('/getconfig', pl) assert res["show ip interface brief"][0]["status"] == "up" + res = helper.post_and_check('/get', pl) + assert res["show ip interface brief"][0]["status"] == "up" @pytest.mark.getconfig @@ -121,6 +125,9 @@ def test_getconfig_netmiko_multiple(cisgo_helper: CisgoHelper): res = helper.post_and_check('/getconfig', pl) assert len(res["show ip interface brief"]) > 1 assert hostname_from_config(res["show running-config"]) == CISGO_DEFAULT_HOSTNAME + res = helper.post_and_check('/get', pl) + assert len(res["show ip interface brief"]) > 1 + assert hostname_from_config(res["show running-config"]) == CISGO_DEFAULT_HOSTNAME @pytest.mark.getconfig @@ -135,6 +142,10 @@ def test_getconfig_napalm_multiple(cisgo_helper: CisgoHelper): log.error(res) assert len(res["show ip interface brief"]) > 1 assert hostname_from_config(res["show running-config"]) + res = helper.post_and_check('/get', pl) + log.error(res) + assert len(res["show ip interface brief"]) > 1 + assert hostname_from_config(res["show running-config"]) @pytest.mark.getconfig @@ -148,6 +159,9 @@ def test_getconfig_napalm_getter(cisgo_helper: CisgoHelper): res = helper.post_and_check('/getconfig', pl) log.error(res["get_facts"]) assert res["get_facts"]["hostname"] == CISGO_DEFAULT_HOSTNAME + res = helper.post_and_check('/get', pl) + log.error(res["get_facts"]) + assert res["get_facts"]["hostname"] == CISGO_DEFAULT_HOSTNAME @pytest.mark.getconfig @@ -159,7 +173,8 @@ def test_getconfig_napalm(cisgo_helper: CisgoHelper): "command": "show running-config" } res = helper.post_and_check('/getconfig', pl) - + assert hostname_from_config(res["show running-config"]) + res = helper.post_and_check('/get', pl) assert hostname_from_config(res["show running-config"]) @@ -183,7 +198,7 @@ def test_getconfig_netmiko_post_check(cisgo_helper: CisgoHelper): } ] } - errors = helper.post_and_check_errors('/getconfig', pl) + errors = helper.post_and_check_errors('/get', pl) assert len(errors) == 0 pl["post_checks"][0]["match_str"][0] += "asdf" errors = helper.post_and_check_errors('/getconfig', pl) @@ -212,6 +227,8 @@ def test_getconfig_netmiko_post_check_fails(cisgo_helper: CisgoHelper): } errors = helper.post_and_check_errors('/getconfig', pl) assert len(errors) > 0 + errors = helper.post_and_check_errors('/get', pl) + assert len(errors) > 0 @pytest.mark.getconfig @@ -236,3 +253,5 @@ def test_getconfig_napalm_post_check(cisgo_helper: CisgoHelper): } errors = helper.post_and_check_errors('/getconfig', pl) assert len(errors) == 0 + errors = helper.post_and_check_errors('/get', pl) + assert len(errors) == 0