Skip to content

Commit

Permalink
Remove usages of py23_compat
Browse files Browse the repository at this point in the history
Signed-off-by: tang hao <thddaniel92@gmail.com>
  • Loading branch information
thddaniel committed Feb 14, 2021
1 parent 1a9e409 commit f451371
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
31 changes: 15 additions & 16 deletions napalm_ce/ce.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
# import NAPALM Base
import napalm.base.helpers
from napalm.base.base import NetworkDriver
from napalm.base.utils import py23_compat
import napalm.base.constants as c
from napalm.base.exceptions import (
ConnectionException,
Expand Down Expand Up @@ -206,10 +205,10 @@ def get_facts(self):
return {
'uptime': int(uptime),
'vendor': vendor,
'os_version': py23_compat.text_type(os_version),
'serial_number': py23_compat.text_type(serial_number),
'model': py23_compat.text_type(model),
'hostname': py23_compat.text_type(hostname),
'os_version': str(os_version),
'serial_number': str(serial_number),
'model': str(model),
'hostname': str(hostname),
'fqdn': fqdn, # ? fqdn(fully qualified domain name)
'interface_list': interface_list
}
Expand All @@ -222,7 +221,7 @@ def cli(self, commands):

for command in commands:
output = self.device.send_command(command)
cli_output[py23_compat.text_type(command)] = output
cli_output[str(command)] = output
return cli_output

def commit_config(self):
Expand Down Expand Up @@ -684,10 +683,10 @@ def get_config(self, retrieve='all'):

if retrieve.lower() in ('running', 'all'):
command = 'display current-configuration'
config['running'] = py23_compat.text_type(self.device.send_command(command))
config['running'] = str(self.device.send_command(command))
if retrieve.lower() in ('startup', 'all'):
# command = 'display saved-configuration last'
# config['startup'] = py23_compat.text_type(self.device.send_command(command))
# config['startup'] = str(self.device.send_command(command))
pass
return config

Expand Down Expand Up @@ -720,8 +719,8 @@ def get_lldp_neighbors(self):
results[local_iface] = []

neighbor_dict = dict()
neighbor_dict['port'] = py23_compat.text_type(neighbor[1])
neighbor_dict['hostname'] = py23_compat.text_type(neighbor[2])
neighbor_dict['port'] = str(neighbor[1])
neighbor_dict['hostname'] = str(neighbor[2])
results[local_iface].append(neighbor_dict)
return results

Expand Down Expand Up @@ -760,7 +759,7 @@ def get_mac_address_table(self):
for mac_info in match:
mac_dict = {
'mac': napalm.base.helpers.mac(mac_info[0]),
'interface': py23_compat.text_type(mac_info[2]),
'interface': str(mac_info[2]),
'vlan': int(mac_info[1]),
'static': True if mac_info[3] == "static" else False,
'active': True if mac_info[3] == "dynamic" else False,
Expand Down Expand Up @@ -863,7 +862,7 @@ def ping(self, destination, source=c.PING_SOURCE, ttl=c.PING_TTL, timeout=c.PING
results_array = []
match = re.findall(r"Reply from.+time=(\d+)", output, re.M)
for i in match:
results_array.append({'ip_address': py23_compat.text_type(destination),
results_array.append({'ip_address': str(destination),
'rtt': float(i)})
ping_dict['success'].update({'results': results_array})
return ping_dict
Expand All @@ -874,10 +873,10 @@ def __get_snmp_information(self):
# output = self.device.send_command(command)

snmp_information = {
'contact': py23_compat.text_type(''),
'location': py23_compat.text_type(''),
'contact': str(''),
'location': str(''),
'community': {},
'chassis_id': py23_compat.text_type('')
'chassis_id': str('')
}
return snmp_information

Expand Down Expand Up @@ -1175,7 +1174,7 @@ def _parse_uptime(uptime_str):
@staticmethod
def _create_tmp_file(config):
tmp_dir = tempfile.gettempdir()
rand_fname = py23_compat.text_type(uuid.uuid4())
rand_fname = str(uuid.uuid4())
filename = os.path.join(tmp_dir, rand_fname)
with open(filename, 'wt') as fobj:
fobj.write(config)
Expand Down
3 changes: 1 addition & 2 deletions test/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pytest
from napalm.base.test import conftest as parent_conftest
from napalm.base.test.double import BaseTestDouble
from napalm.base.utils import py23_compat
from napalm_ce import ce


Expand Down Expand Up @@ -59,7 +58,7 @@ def send_command(self, command, **kwargs):
filename = '{}.txt'.format(self.sanitize_text(command))
full_path = self.find_file(filename)
result = self.read_txt_file(full_path)
return py23_compat.text_type(result)
return str(result)

def disconnect(self):
"""Disconnect from the device."""
Expand Down

0 comments on commit f451371

Please sign in to comment.