From 224944dac73fd9efd6de1ac2cbe6428249205927 Mon Sep 17 00:00:00 2001 From: Elisa Jasinska Date: Mon, 19 Sep 2016 00:06:41 +0200 Subject: [PATCH 1/5] adding coveralls --- .travis.yml | 13 ++++++++----- README.md | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index f14df8b..ae7eb95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ python: install: - pip install -r requirements.txt - pip install . +- pip install coveralls deploy: provider: pypi user: dbarroso @@ -14,9 +15,11 @@ deploy: branch: master script: - cd test/unit -- nosetests -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_bgp_neighbors -- nosetests -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_environment -- nosetests -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_facts -- nosetests -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_interfaces -- nosetests -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_interfaces_counters +- nosetests --with-coverage --cover-package napalm_fortios -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_bgp_neighbors +- nosetests --with-coverage --cover-package napalm_fortios -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_environment +- nosetests --with-coverage --cover-package napalm_fortios -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_facts +- nosetests --with-coverage --cover-package napalm_fortios -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_interfaces +- nosetests --with-coverage --cover-package napalm_fortios -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_interfaces_counters - cd ../.. +- coverage combine test/unit/.coverage +after_success: coveralls diff --git a/README.md b/README.md index bde95cf..9ac8884 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ [![PyPI](https://img.shields.io/pypi/v/napalm-fortios.svg)](https://pypi.python.org/pypi/napalm-fortios) [![PyPI](https://img.shields.io/pypi/dm/napalm-fortios.svg)](https://pypi.python.org/pypi/napalm-fortios) [![Build Status](https://travis-ci.org/napalm-automation/napalm-fortios.svg?branch=master)](https://travis-ci.org/napalm-automation/napalm-fortios) +[![Coverage Status](https://coveralls.io/repos/github/napalm-automation/napalm-fortios/badge.svg?branch=master)](https://coveralls.io/github/napalm-automation/napalm-fortios) + # napalm-fortios From 341e0342c6797a4d8c798dc24e9b5e816ff5dc6e Mon Sep 17 00:00:00 2001 From: Eric Beahan Date: Sun, 18 Sep 2016 14:30:45 -0500 Subject: [PATCH 2/5] Added get_config method --- .travis.yml | 1 + napalm_fortios/fortios.py | 23 ++ test/unit/fortios/mock_data/show.txt | 402 +++++++++++++++++++++++++++ 3 files changed, 426 insertions(+) create mode 100644 test/unit/fortios/mock_data/show.txt diff --git a/.travis.yml b/.travis.yml index ae7eb95..06cedb1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ script: - nosetests --with-coverage --cover-package napalm_fortios -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_facts - nosetests --with-coverage --cover-package napalm_fortios -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_interfaces - nosetests --with-coverage --cover-package napalm_fortios -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_interfaces_counters +- nosetests --with-coverage --cover-package napalm_fortios -v TestFortiOSDriver:TestGetterFortiOSDriver.test_get_config - cd ../.. - coverage combine test/unit/.coverage after_success: coveralls diff --git a/napalm_fortios/fortios.py b/napalm_fortios/fortios.py index cf47e63..3a5c919 100644 --- a/napalm_fortios/fortios.py +++ b/napalm_fortios/fortios.py @@ -138,6 +138,29 @@ class FortiOSDriver(NetworkDriver): self.device.candidate_config['vpn certificate local']['Fortinet_SSLProxy'].del_param('certificate') self.device.commit() + def get_config(self, retrieve="all"): + """get_config implementation for FortiOS.""" + get_startup = retrieve == "all" or retrieve == "startup" + get_running = retrieve == "all" or retrieve == "running" + get_candidate = retrieve == "all" or retrieve == "candidate" + + if retrieve == "all" or get_running: + result = self.execute_command_with_vdom('show') + text_result = '\n'.join(result) + + return { + 'startup': "", + 'running': text_result, + 'candidate': "", + } + + elif get_startup or get_candidate: + return { + 'startup': "", + 'running': "", + 'candidate': "", + } + def get_facts(self): system_status = self.get_command_with_vdom('get system status', vdom='global') performance_status = self.get_command_with_vdom('get system performance status', vdom='global') diff --git a/test/unit/fortios/mock_data/show.txt b/test/unit/fortios/mock_data/show.txt new file mode 100644 index 0000000..9102184 --- /dev/null +++ b/test/unit/fortios/mock_data/show.txt @@ -0,0 +1,402 @@ +#config-version=FWF60D-5.00-FW-build271-140124:opmode=1:vdom=0:user=admin +#conf_file_ver=9284291339995375843 +#buildno=0271 +#global_vdom=1 +config system global + set admintimeout 15 + set fgd-alert-subscription advisory latest-threat + set gui-certificates enable + set gui-dynamic-routing enable + set gui-ipv6 enable + set gui-local-in-policy enable + set gui-nat46-64 enable + set gui-policy-based-ipsec enable + set hostname "FORTINET" + set service-expire-notification disable + set timezone 08 +end +config system accprofile + edit "prof_admin" + set admingrp read-write + set authgrp read-write + set endpoint-control-grp read-write + set fwgrp read-write + set loggrp read-write + set mntgrp read-write + set netgrp read-write + set routegrp read-write + set sysgrp read-write + set updategrp read-write + set utmgrp read-write + set vpngrp read-write + set wanoptgrp read-write + set wifi read-write + next +end +config system interface + edit "dmz" + set vdom "root" + set ip 10.10.10.1 255.255.255.0 + set allowaccess ping https fgfm capwap + set type physical + set snmp-index 5 + next + edit "wan1" + set vdom "root" + set mode dhcp + set allowaccess ping https ssh snmp + set type physical + set snmp-index 3 + config ipv6 + set ip6-allowaccess ping https ssh + end + set defaultgw enable + next + edit "wan2" + set vdom "root" + set ip 192.168.101.99 255.255.255.0 + set allowaccess ping fgfm auto-ipsec + set type physical + set snmp-index 4 + next + edit "modem" + set vdom "root" + set mode pppoe + set type physical + set snmp-index 6 + set defaultgw enable + next + edit "ssl.root" + set vdom "root" + set type tunnel + set alias "sslvpn tunnel interface" + set snmp-index 7 + next + edit "mesh.root" + set vdom "root" + set type vap-switch + set snmp-index 9 + next + edit "internal" + set vdom "root" + set ip 10.10.90.1 255.255.255.0 + set allowaccess ping https ssh snmp http fgfm capwap + set status down + set type physical + set snmp-index 2 + next + edit "wifi" + set vdom "root" + set ip 10.10.80.1 255.255.255.0 + set allowaccess ping https ssh fgfm + set status down + set type vap-switch + set snmp-index 1 + next +end +config system admin + edit "admin" + set accprofile "super_admin" + set vdom "root" + config dashboard-tabs + edit 1 + set name "Status" + next + edit 2 + set columns 1 + set name "Top Sources" + next + edit 3 + set columns 1 + set name "Top Destinations" + next + edit 4 + set columns 1 + set name "Top Applications" + next + end + config dashboard + edit 1 + set tab-id 1 + set column 1 + next + edit 2 + set widget-type licinfo + set tab-id 1 + set column 1 + next + edit 3 + set widget-type jsconsole + set tab-id 1 + set column 1 + next + edit 4 + set widget-type sysres + set tab-id 1 + set column 2 + next + edit 5 + set widget-type gui-features + set tab-id 1 + set column 2 + next + edit 6 + set widget-type alert + set tab-id 1 + set column 2 + set top-n 10 + next + edit 21 + set widget-type sessions + set tab-id 2 + set column 1 + set top-n 25 + set sort-by msg-counts + next + edit 31 + set widget-type sessions + set tab-id 3 + set column 1 + set top-n 25 + set sort-by msg-counts + set report-by destination + next + edit 41 + set widget-type sessions + set tab-id 4 + set column 1 + set top-n 25 + set sort-by msg-counts + set report-by application + next + end + config login-time + edit "admin" + set last-login 2014-03-05 20:18:42 + next + end + set password ENC AK1mbPadQmYqP8Q4f7ClXXWGrgEMVWbGGwf6IgRwHQduoc= + next +end +config system ha + set override disable +end +config system storage + edit "FLASH1" + set media-type "scsi" + set partition "4E6CD8C90723C14B" + next +end +config system replacemsg-image + edit "logo_fnet" + set image-base64 '' + set image-type gif + next + edit "logo_fguard_wf" + set image-base64 '' + set image-type gif + next + edit "logo_fw_auth" + set image-base64 '' + set image-type png + next + edit "logo_v2_fnet" + set image-base64 '' + set image-type png + next + edit "logo_v2_fguard_wf" + set image-base64 '' + set image-type png + next +end +config system snmp sysinfo + set status enable +end +config vpn certificate ca +end +config vpn certificate local +end +config wanopt storage + edit "FLASH1" + set size 4563 + next +end +config system session-sync +end +config ips global + set default-app-cat-mask 18446744073474670591 +end +config ips dbinfo + set version 1 +end +config gui console + unset preferences +end +config system auto-install + set auto-install-config enable + set auto-install-image enable +end +config system console + set output standard +end +config system ntp + set ntpsync enable + set syncinterval 60 +end +config system settings + set sip-tcp-port 5060 + set sip-udp-port 5060 +end +config firewall service group + edit "Email Access" + set member "DNS" "IMAP" "IMAPS" "POP3" "POP3S" "SMTP" "SMTPS" + next + edit "Web Access" + set member "DNS" "HTTP" "HTTPS" + next + edit "Windows AD" + set member "DCE-RPC" "DNS" "KERBEROS" "LDAP" "LDAP_UDP" "SAMBA" "SMB" + next + edit "Exchange Server" + set member "DCE-RPC" "DNS" "HTTPS" + next +end +config webfilter ftgd-local-cat + edit "custom1" + set id 140 + next + edit "custom2" + set id 141 + next +end +config user fortitoken + edit "FTKMOB4302463E0E" + set license "FTMTRIAL00138836" + next + edit "FTKMOB433B7004CF" + set license "FTMTRIAL00138836" + next +end +config user local + edit "guest" + set type password + set passwd ENC SWv0LitZXJWqXLGveoEXgcboipAFM2wg7Np0oxyQpRubIce9royFr2/bxJ2nzvoPR0CN3p1/2+VWuPJlLTDGuYX0ojfBAbWkgLXI2AxwB3jpUp7PMWMyyfn4aT2Y35HnSP5mP87q2d1lMYJkBttbceEmZsDgkmeRyLPDNdtSCFvZ7pKm0gNDILk7sLPyJT7k5ZXxtw== + next +end +config user group + edit "FSSO_Guest_Users" + set group-type fsso-service + next + edit "Guest-group" + set member "guest" + next +end +config spamfilter profile + edit "default" + set comment "malware and phishing URL filtering" + next +end +config wanopt settings + set host-id "default-id" +end +config wanopt profile + edit "default" + set comments "default WANopt profile" + next +end +config web-proxy global + set proxy-fqdn "default.fqdn" +end +config firewall schedule recurring + edit "always" + set day sunday monday tuesday wednesday thursday friday saturday + next +end +config firewall profile-protocol-options + edit "default" + set comment "all default services" + config http + set ports 80 + set options clientcomfort no-content-summary + unset post-lang + end + config ftp + set ports 21 + set options clientcomfort no-content-summary splice + end + config imap + set ports 143 + set options fragmail no-content-summary + end + config mapi + set ports 135 + set options fragmail no-content-summary + end + config pop3 + set ports 110 + set options fragmail no-content-summary + end + config smtp + set ports 25 + set options fragmail no-content-summary splice + end + config nntp + set ports 119 + set options no-content-summary splice + end + config im + unset options + end + config dns + set ports 53 + end + next +end +config firewall deep-inspection-options + edit "default" + set comment "all default services" + config https + set ports 443 + end + config ftps + set ports 990 + end + config imaps + set ports 993 + end + config pop3s + set ports 995 + end + config smtps + set ports 465 + end + next +end +config firewall identity-based-route +end +config firewall policy + edit 5 + set srcintf "internal" + set dstintf "wifi" + set srcaddr "all" + set dstaddr "all" + set action accept + set schedule "always" + set service "ALL" + next +end +config wireless-controller wtp + edit "FWF60D-WIFI0" + next +end +config log disk setting + set status enable + set storage "FLASH1" +end +config log eventfilter + set user disable + set wan-opt disable +end +config log setting + set gui-location disk +end \ No newline at end of file From 225b3256fc462adc7b9e9c0d8e36f8ce05f84568 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Fri, 14 Oct 2016 12:53:03 -0700 Subject: [PATCH 3/5] Pin napalm-base Eliminate pylama.ini; replace with setup.cfg Add requirements-dev.txt Implement __version__ solution --- napalm_fortios/__init__.py | 13 ++++++++++++- pylama.ini | 6 ------ requirements-dev.txt | 7 +++++++ requirements.txt | 2 +- setup.cfg | 6 ++++++ 5 files changed, 26 insertions(+), 8 deletions(-) delete mode 100644 pylama.ini create mode 100644 requirements-dev.txt create mode 100644 setup.cfg diff --git a/napalm_fortios/__init__.py b/napalm_fortios/__init__.py index a95ba2b..277200a 100644 --- a/napalm_fortios/__init__.py +++ b/napalm_fortios/__init__.py @@ -13,4 +13,15 @@ # the License. """napalm_fortios package.""" -from fortios import FortiOSDriver +# Import stdlib +import pkg_resources + +# Import local modules +from napalm_fortios.fortios import FortiOSDriver + +try: + __version__ = pkg_resources.get_distribution('napalm-fortios').version +except pkg_resources.DistributionNotFound: + __version__ = "Not installed" + +__all__ = ('FortiOSDriver',) diff --git a/pylama.ini b/pylama.ini deleted file mode 100644 index 3146a20..0000000 --- a/pylama.ini +++ /dev/null @@ -1,6 +0,0 @@ -[pylama] -linters = mccabe,pep257,pep8,pyflakes -ignore = D203, - -[pylama:pep8] -max_line_length = 120 diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..491f338 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,7 @@ +pytest +pytest-cov +pytest-json +pytest-pythonpath +pylama +flake8-import-order +-r requirements.txt diff --git a/requirements.txt b/requirements.txt index 3b4589b..dc815fb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -napalm_base +napalm-base==0.17.0 pyFG diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..ffae4a5 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,6 @@ +[pylama] +linters = mccabe,pep8,pyflakes +ignore = D203,C901 + +[pylama:pep8] +max_line_length = 100 From 3cab0dd9c46fa143f35003c9acc422032cd2f9b2 Mon Sep 17 00:00:00 2001 From: Eric Beahan Date: Tue, 18 Oct 2016 21:06:14 -0500 Subject: [PATCH 4/5] Adding ISSUE_TEMPLATE, PULL_REQUEST_TEMPLATE, and CONTRIBUTING files (#17) Thanks @ebeahan --- .github/ISSUE_TEMPLATE | 32 ++++++++++++++++++++++++++++++++ .github/PULL_REQUEST_TEMPLATE | 1 + CONTRIBUTING | 1 + 3 files changed, 34 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE create mode 100644 .github/PULL_REQUEST_TEMPLATE create mode 100644 CONTRIBUTING diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE new file mode 100644 index 0000000..032fc9b --- /dev/null +++ b/.github/ISSUE_TEMPLATE @@ -0,0 +1,32 @@ +###Description of Issue/Question + + +### Did you follow the steps from https://github.com/napalm-automation/napalm#faq +- [ ] Yes +- [ ] No + + +### Setup + +### napalm-fortios version +(Paste verbatim output from `pip freeze | grep napalm-fortios` between quotes below) + +``` + +``` + +### FortiOS version +(Paste verbatim output from `get sys status` between quotes below) + +``` + +``` + +### Steps to Reproduce the Issue + +### Error Traceback +(Paste the complete traceback of the exception between quotes below) + +``` + +``` diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE new file mode 100644 index 0000000..8767eea --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE @@ -0,0 +1 @@ + diff --git a/CONTRIBUTING b/CONTRIBUTING new file mode 100644 index 0000000..6ccfd34 --- /dev/null +++ b/CONTRIBUTING @@ -0,0 +1 @@ +Please, read http://napalm.readthedocs.io/en/latest/contributing/index.html From 2000a9388d2017476c9e89caef6a4508c7bda351 Mon Sep 17 00:00:00 2001 From: David Barroso Date: Mon, 24 Oct 2016 15:56:51 +0200 Subject: [PATCH 5/5] bump version 0.2.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 99be57b..9075c14 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ reqs = [str(ir.req) for ir in install_reqs] setup( name="napalm-fortios", - version="0.1.1", + version="0.2.0", packages=find_packages(), author="David Barroso", author_email="dbarrosop@dravetech.com",