Skip to content

Commit

Permalink
Merge pull request #152 from Apcela/rename_getconfig_to_get
Browse files Browse the repository at this point in the history
add 'get' alias for 'getconfig'
  • Loading branch information
tbotnz authored Feb 15, 2021
2 parents 8000c27 + a227992 commit f61c368
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
9 changes: 9 additions & 0 deletions netpalm/routers/getconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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"):
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions tests/integration/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions tests/integration/test_getconfig_cisgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"])


Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit f61c368

Please sign in to comment.