Skip to content
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/testrun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# - run: docker-compose -f docker-compose.ci.yml build cisgo redis # don't cache this

- run: docker pull python:3.8-slim
- run: docker pull apcela/cisshgo:v0.1.0
- run: docker pull apcela/cisshgo:v0.1.1
- run: docker pull redis:6.0.7-alpine

- uses: satackey/[email protected]
Expand Down Expand Up @@ -48,4 +48,4 @@ jobs:
# SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
# uses: abinoda/slack-action@master
# with:
# args: '{\"channel\":\"CUCQA382D\",\"blocks\": [ { \"type\": \"section\", \"text\": { \"type\": \"mrkdwn\", \"text\": \"Hey! ${{ github.actor }} just pushed to ${{ github.base_ref }} @ ${{ github.repositoryUrl }}. The Job status is ${{ job.status }}, the step outcome is ${{ steps.test.outcome }}, and the step conclusion is ${{ steps.test.conclusion }}!\" } } ]}'
# args: '{\"channel\":\"CUCQA382D\",\"blocks\": [ { \"type\": \"section\", \"text\": { \"type\": \"mrkdwn\", \"text\": \"Hey! ${{ github.actor }} just pushed to ${{ github.base_ref }} @ ${{ github.repositoryUrl }}. The Job status is ${{ job.status }}, the step outcome is ${{ steps.test.outcome }}, and the step conclusion is ${{ steps.test.conclusion }}!\" } } ]}'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
venv
backend/plugins/extensibles/ntc-templates/
backend/plugins/extensibles/ntc-templates
vagrant/*.log
vagrant/roles
vagrant/.vagrant
92 changes: 41 additions & 51 deletions tests/integration/test_getconfig_cisgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def clean(self):
pl = {
"library": "netmiko",
"connection_args": self.netmiko_connection_args,
"command": "reset state"
"command": "reset state",
}
result = helper.post_and_check('/getconfig', pl)
result = helper.post_and_check("/getconfig", pl)

@property
def netmiko_connection_args(self):
Expand All @@ -55,7 +55,7 @@ def napalm_connection_args(self):
"port": self.port_number,
"fast_cli": True,
# "default_enter": "\r\n"
}
},
}


Expand All @@ -73,7 +73,9 @@ def hostname_from_config(config_lines: Union[List[str], str]) -> str:
continue
command, *args = line.split()
if command == "hostname":
hostname = ' '.join(args) # this will false-match if there's weird whitespace in hostname like \t, etc
hostname = " ".join(
args
) # this will false-match if there's weird whitespace in hostname like \t, etc
break

else:
Expand All @@ -91,9 +93,9 @@ def test_getconfig_netmiko_fifo(cisgo_helper: CisgoHelper):
"command": "show running-config",
# "cache": {"enabled": False}
}
res = helper.post_and_check('/getconfig', pl)
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)
res = helper.post_and_check("/get", pl)
assert hostname_from_config(res["show running-config"]) == CISGO_DEFAULT_HOSTNAME


Expand All @@ -107,9 +109,9 @@ def test_getconfig_netmiko_pinned(cisgo_helper: CisgoHelper):
"queue_strategy": "pinned",
# "cache": {"enabled": False}
}
res = helper.post_and_check('/getconfig', pl)
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)
res = helper.post_and_check("/get", pl)
assert hostname_from_config(res["show running-config"]) == CISGO_DEFAULT_HOSTNAME


Expand All @@ -120,13 +122,11 @@ def test_getconfig_netmiko_with_textfsm(cisgo_helper: CisgoHelper):
"library": "netmiko",
"connection_args": cisgo_helper.netmiko_connection_args,
"command": "show ip interface brief",
"args": {
"use_textfsm": True
}
"args": {"use_textfsm": True},
}
res = helper.post_and_check('/getconfig', pl)
res = helper.post_and_check("/getconfig", pl)
assert res["show ip interface brief"][0]["status"] == "up"
res = helper.post_and_check('/get', pl)
res = helper.post_and_check("/get", pl)
assert res["show ip interface brief"][0]["status"] == "up"


Expand All @@ -136,12 +136,12 @@ def test_getconfig_netmiko_multiple(cisgo_helper: CisgoHelper):
pl = {
"library": "netmiko",
"connection_args": cisgo_helper.netmiko_connection_args,
"command": ["show running-config", "show ip interface brief"]
"command": ["show running-config", "show ip interface brief"],
}
res = helper.post_and_check('/getconfig', pl)
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)
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

Expand All @@ -152,13 +152,13 @@ def test_getconfig_napalm_multiple(cisgo_helper: CisgoHelper):
pl = {
"connection_args": cisgo_helper.napalm_connection_args,
"library": "napalm",
"command": ["show running-config", "show ip interface brief"]
"command": ["show running-config", "show ip interface brief"],
}
res = helper.post_and_check('/getconfig', pl)
res = helper.post_and_check("/getconfig", pl)
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)
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"])
Expand All @@ -170,12 +170,12 @@ def test_getconfig_napalm_getter(cisgo_helper: CisgoHelper):
pl = {
"library": "napalm",
"connection_args": cisgo_helper.napalm_connection_args,
"command": "get_facts"
"command": "get_facts",
}
res = helper.post_and_check('/getconfig', pl)
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)
res = helper.post_and_check("/get", pl)
log.error(res["get_facts"])
assert res["get_facts"]["hostname"] == CISGO_DEFAULT_HOSTNAME

Expand All @@ -186,11 +186,11 @@ def test_getconfig_napalm(cisgo_helper: CisgoHelper):
pl = {
"library": "napalm",
"connection_args": cisgo_helper.napalm_connection_args,
"command": "show running-config"
"command": "show running-config",
}
res = helper.post_and_check('/getconfig', pl)
res = helper.post_and_check("/getconfig", pl)
assert hostname_from_config(res["show running-config"])
res = helper.post_and_check('/get', pl)
res = helper.post_and_check("/get", pl)
assert hostname_from_config(res["show running-config"])


Expand All @@ -205,19 +205,15 @@ def test_getconfig_netmiko_post_check(cisgo_helper: CisgoHelper):
"post_checks": [
{
"match_type": "include",
"get_config_args": {
"command": "show running-config"
},
"match_str": [
"hostname " + CISGO_DEFAULT_HOSTNAME
]
"get_config_args": {"command": "show running-config"},
"match_str": ["hostname " + CISGO_DEFAULT_HOSTNAME],
}
]
],
}
errors = helper.post_and_check_errors('/get', 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)
errors = helper.post_and_check_errors("/getconfig", pl)
assert len(errors) > 0


Expand All @@ -232,18 +228,16 @@ def test_getconfig_netmiko_post_check_fails(cisgo_helper: CisgoHelper):
"post_checks": [
{
"match_type": "include",
"get_config_args": {
"command": "show running-config"
},
"get_config_args": {"command": "show running-config"},
"match_str": [
"hostname " + CISGO_DEFAULT_HOSTNAME + "DEFINITELY WRONG"
]
],
}
]
],
}
errors = helper.post_and_check_errors('/getconfig', pl)
errors = helper.post_and_check_errors("/getconfig", pl)
assert len(errors) > 0
errors = helper.post_and_check_errors('/get', pl)
errors = helper.post_and_check_errors("/get", pl)
assert len(errors) > 0


Expand All @@ -253,21 +247,17 @@ def test_getconfig_napalm_post_check(cisgo_helper: CisgoHelper):
pl = {
"library": "napalm",
"connection_args": cisgo_helper.napalm_connection_args,
"command": "show run | i hostname",
"command": "show running-config",
"queue_strategy": "pinned",
"post_checks": [
{
"match_type": "include",
"get_config_args": {
"command": "show running-config"
},
"match_str": [
"hostname " + CISGO_DEFAULT_HOSTNAME
]
"get_config_args": {"command": "show running-config"},
"match_str": ["hostname " + CISGO_DEFAULT_HOSTNAME],
}
]
],
}
errors = helper.post_and_check_errors('/getconfig', pl)
errors = helper.post_and_check_errors("/getconfig", pl)
assert len(errors) == 0
errors = helper.post_and_check_errors('/get', pl)
errors = helper.post_and_check_errors("/get", pl)
assert len(errors) == 0
9 changes: 9 additions & 0 deletions vagrant/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.network "forwarded_port", guest: 9000, host: 9000, host_ip: "127.0.0.1"
config.vm.provision "ansible_local" do |ansible|
ansible.galaxy_role_file = "requirements.yml"
ansible.playbook = "setup.yml"
end
end

3 changes: 3 additions & 0 deletions vagrant/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- src: geerlingguy.docker
- src: geerlingguy.pip
32 changes: 32 additions & 0 deletions vagrant/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- hosts: all
vars:
pip_install_packages:
- name: docker
ansible_python_interpreter: /usr/bin/python3
docker_install_compose_plugin: true
docker_compose_package: docker-compose-plugin
docker_compose_package_state: present
roles:
- geerlingguy.pip
- geerlingguy.docker
become: true
tasks:
- name: add vagrant user to docker group
user:
name: vagrant
groups: docker
append: yes
- name: Clone netpalm into /opt/netpalm
git:
repo: "https://github.com/tbotnz/netpalm.git"
dest: /opt/netpalm/
force: true
- name: Build netpalm - [ This may take a while ] !
ansible.builtin.shell:
cmd: docker compose build
chdir: /opt/netpalm
- name: Run netpalm
ansible.builtin.shell:
cmd: docker compose up -d
chdir: /opt/netpalm