From 60ccca94417429b372d973c6943770fd2bcf6bb3 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Tue, 3 Jan 2017 21:17:44 -0800 Subject: [PATCH 1/9] Removing coveralls duplication --- requirements-dev.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 28df03e..e2b6fc0 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,5 +5,4 @@ pytest-json pytest-pythonpath pylama flake8-import-order -coveralls -r requirements.txt From 8a1779b10a0aa0c06d9d36f61a1cc1d817101107 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Wed, 11 Jan 2017 17:57:24 -0800 Subject: [PATCH 2/9] Python3 unicode fixes --- napalm_fortios/fortios.py | 41 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/napalm_fortios/fortios.py b/napalm_fortios/fortios.py index a9cddcc..968278d 100644 --- a/napalm_fortios/fortios.py +++ b/napalm_fortios/fortios.py @@ -11,6 +11,8 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. +from __future__ import unicode_literals + import re from pyFG.fortios import FortiOS, FortiConfig, logger from pyFG.exceptions import FailedCommit, CommandExecutionException @@ -18,6 +20,7 @@ from napalm_base.exceptions import ReplaceConfigException, MergeConfigException from napalm_base.utils.string_parsers import colon_separated_string_to_dict,\ convert_uptime_string_seconds +from napalm_base.utils import py23_compat class FortiOSDriver(NetworkDriver): @@ -164,7 +167,7 @@ def get_config(self, retrieve="all"): return { 'startup': u"", - 'running': unicode(text_result), + 'running': py23_compat.text_type(text_result), 'candidate': u"", } @@ -188,12 +191,12 @@ def get_facts(self): vdom='global')['domain'] return { - 'vendor': unicode('Fortigate'), - 'os_version': unicode(system_status['Version'].split(',')[0].split()[1]), + 'vendor': py23_compat.text_type('Fortigate'), + 'os_version': py23_compat.text_type(system_status['Version'].split(',')[0].split()[1]), 'uptime': convert_uptime_string_seconds(performance_status['Uptime']), - 'serial_number': unicode(system_status['Serial-Number']), - 'model': unicode(system_status['Version'].split(',')[0].split()[0]), - 'hostname': unicode(system_status['Hostname']), + 'serial_number': py23_compat.text_type(system_status['Serial-Number']), + 'model': py23_compat.text_type(system_status['Version'].split(',')[0].split()[0]), + 'hostname': py23_compat.text_type(system_status['Hostname']), 'fqdn': u'{}.{}'.format(system_status['Hostname'], domain), 'interface_list': interface_list } @@ -239,7 +242,7 @@ def get_interfaces(self): elif line.startswith('Link'): parsed_data['is_up'] = line.split('\t')[-1] is 'up' elif line.startswith('Current_HWaddr'): - parsed_data['mac_address'] = unicode(line.split('\t')[-1]) + parsed_data['mac_address'] = py23_compat.text_type(line.split('\t')[-1]) parsed_data['is_enabled'] = True parsed_data['description'] = u'' parsed_data['last_flapped'] = -1.0 @@ -252,7 +255,7 @@ def get_interfaces(self): elif line.startswith('PHY Speed'): parsed_data['speed'] = int(line.split(':')[-1]) elif line.startswith('Current_HWaddr'): - parsed_data['mac_address'] = unicode(line.split(' ')[-1]) + parsed_data['mac_address'] = py23_compat.text_type(line.split(' ')[-1]) parsed_data['description'] = u'' parsed_data['last_flapped'] = -1.0 interface_statistics[interface] = parsed_data @@ -294,16 +297,16 @@ def get_firewall_policies(self): policy_item['position'] = position policy_item['packet_hits'] = -1 policy_item['byte_hits'] = -1 - policy_item['id'] = unicode(key) + policy_item['id'] = py23_compat.text_type(key) policy_item['enabled'] = enabled - policy_item['schedule'] = unicode(policy[key]['schedule']) - policy_item['log'] = unicode(logtraffic) - policy_item['l3_src'] = unicode(policy[key]['srcaddr']) - policy_item['l3_dst'] = unicode(policy[key]['dstaddr']) - policy_item['service'] = unicode(policy[key]['service']) - policy_item['src_zone'] = unicode(policy[key]['srcintf']) - policy_item['dst_zone'] = unicode(policy[key]['dstintf']) - policy_item['action'] = unicode(action) + policy_item['schedule'] = py23_compat.text_type(policy[key]['schedule']) + policy_item['log'] = py23_compat.text_type(logtraffic) + policy_item['l3_src'] = py23_compat.text_type(policy[key]['srcaddr']) + policy_item['l3_dst'] = py23_compat.text_type(policy[key]['dstaddr']) + policy_item['service'] = py23_compat.text_type(policy[key]['service']) + policy_item['src_zone'] = py23_compat.text_type(policy[key]['srcintf']) + policy_item['dst_zone'] = py23_compat.text_type(policy[key]['dstintf']) + policy_item['action'] = py23_compat.text_type(action) default_policy[key].append(policy_item) position = position + 1 @@ -346,7 +349,7 @@ def get_bgp_neighbors(self): self._execute_command_with_vdom(command_detail.format(neighbor))] m = re.search('remote router id (.+?)\n', '\n'.join(detail_output)) if m: - neighbor_dict['remote_id'] = unicode(m.group(1)) + neighbor_dict['remote_id'] = py23_compat.text_type(m.group(1)) else: raise Exception('cannot find remote router id for %s' % neighbor) @@ -371,7 +374,7 @@ def get_bgp_neighbors(self): return { 'global': { - 'router_id': unicode(bgp_sum[0].split()[3]), + 'router_id': py23_compat.text_type(bgp_sum[0].split()[3]), 'peers': peers } } From f9d7bd0aa961f45983c497f8d706edf308950eab Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Wed, 11 Jan 2017 17:59:39 -0800 Subject: [PATCH 3/9] Fix iteritems for py3 --- napalm_fortios/fortios.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/napalm_fortios/fortios.py b/napalm_fortios/fortios.py index 968278d..9787095 100644 --- a/napalm_fortios/fortios.py +++ b/napalm_fortios/fortios.py @@ -328,7 +328,7 @@ def get_bgp_neighbors(self): self.device.load_config('router bgp') - for neighbor, parameters in neighbors.iteritems(): + for neighbor, parameters in neighbors.items(): logger.debug('NEW PEER') neigh_conf = self.device.running_config['router bgp']['neighbor']['{}'.format(neighbor)] @@ -358,7 +358,7 @@ def get_bgp_neighbors(self): x = detail_output.index(' for address family: {} unicast'.format(family)) block = detail_output[x:] - for term, fortiname in terms.iteritems(): + for term, fortiname in terms.items(): text = self._search_line_in_lines('%s prefixes' % fortiname, block) t = [int(s) for s in text.split() if s.isdigit()][0] neighbor_dict['address_family'][family][term] = t From 62299ccf28707c042dd404b3dda301b002b446ca Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Wed, 11 Jan 2017 20:35:43 -0800 Subject: [PATCH 4/9] Fixing bug with is_critical --- napalm_fortios/fortios.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/napalm_fortios/fortios.py b/napalm_fortios/fortios.py index 9787095..c7fc01b 100644 --- a/napalm_fortios/fortios.py +++ b/napalm_fortios/fortios.py @@ -468,9 +468,10 @@ def get_temperature(temperature_lines, detail_block): v = int(self._search_line_in_lines('upper_non_recoverable', sensor_block).split('=')[1]) + temp_value = int(temp_value) output[sensor_name] = dict(temperature=float(temp_value), is_alert=is_alert, - is_critical=True if v > temp_value else False) + is_critical=True if temp_value > v else False) return output From 13a82b7e81b1caec644da1f7a60dff16c99454be Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Wed, 11 Jan 2017 20:41:52 -0800 Subject: [PATCH 5/9] Enabling PY3 tests --- .travis.yml | 2 ++ tox.ini | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f96538c..d465b6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: python python: - 2.7 + - 3.4 + - 3.5 install: - pip install tox-travis - pip install coveralls diff --git a/tox.ini b/tox.ini index 910c4f4..5ae5d81 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27 +envlist = py27,py34,py35 [testenv] deps = From b0308075f4031fe3555c4c287b51761ef821f107 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Thu, 9 Feb 2017 10:25:50 -0800 Subject: [PATCH 6/9] Use pyfg that supports PY3 --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0554366..9dc20cd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -napalm-base>=0.18.0 -pyFG +napalm-base>=0.23.0 +pyFG>=0.48 future From 2ccad9982f244330c25f5b8076817fa3193dd3b4 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Thu, 9 Feb 2017 12:17:49 -0800 Subject: [PATCH 7/9] Fix testing issue show firewall policy, dictionary order issue --- .../normal/expected_result.json | 2 +- .../normal/show_firewall_policy.txt | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/test/unit/mocked_data/test_get_firewall_policies/normal/expected_result.json b/test/unit/mocked_data/test_get_firewall_policies/normal/expected_result.json index 89f9399..31d459e 100644 --- a/test/unit/mocked_data/test_get_firewall_policies/normal/expected_result.json +++ b/test/unit/mocked_data/test_get_firewall_policies/normal/expected_result.json @@ -1 +1 @@ -{"1": [{"src_zone": "any", "log": "False", "service": "ALL", "schedule": "always", "l3_src": "all", "enabled": false, "packet_hits": -1, "l3_dst": "all", "dst_zone": "any", "action": "permit", "position": 1, "byte_hits": -1, "id": "1"}], "2": [{"src_zone": "port3", "log": "all", "service": "ALL", "schedule": "always", "l3_src": "all", "enabled": false, "packet_hits": -1, "l3_dst": "all", "dst_zone": "port2", "action": "reject", "position": 2, "byte_hits": -1, "id": "2"}]} +{"1": [{"src_zone": "any", "log": "False", "service": "ALL", "schedule": "always", "l3_src": "all", "enabled": false, "packet_hits": -1, "l3_dst": "all", "dst_zone": "any", "action": "permit", "position": 1, "byte_hits": -1, "id": "1"}] } diff --git a/test/unit/mocked_data/test_get_firewall_policies/normal/show_firewall_policy.txt b/test/unit/mocked_data/test_get_firewall_policies/normal/show_firewall_policy.txt index 996a5d7..299d7c0 100644 --- a/test/unit/mocked_data/test_get_firewall_policies/normal/show_firewall_policy.txt +++ b/test/unit/mocked_data/test_get_firewall_policies/normal/show_firewall_policy.txt @@ -9,15 +9,4 @@ config firewall policy set schedule "always" set service "ALL" next - edit 2 - set name "bla" - set uuid de597b64-aca8-51e6-5d00-b7874e6b72b8 - set srcintf "port3" - set dstintf "port2" - set srcaddr "all" - set dstaddr "all" - set schedule "always" - set service "ALL" - set logtraffic all - next end From fbe3c04cbb01f84d65fe40a77d1d8e4010dd61dd Mon Sep 17 00:00:00 2001 From: Eric Beahan Date: Sat, 1 Apr 2017 16:38:26 -0500 Subject: [PATCH 8/9] bumping pyFG version for python3 support --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9dc20cd..6ec64b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ napalm-base>=0.23.0 -pyFG>=0.48 +pyFG>=0.49_1 future From 4b78a4d7314a644559b3dc3f7c954bd69e0f9391 Mon Sep 17 00:00:00 2001 From: Eric Beahan Date: Sat, 1 Apr 2017 17:00:57 -0500 Subject: [PATCH 9/9] version bump to 0.4.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 934edc1..4e73667 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="napalm-fortios", - version="0.3.1", + version="0.4.0", packages=find_packages(), author="David Barroso", author_email="dbarrosop@dravetech.com",