Skip to content

Commit

Permalink
Fix Py3 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceaulinic committed Aug 8, 2017
1 parent f862c50 commit e368e3a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions napalm_logs/listener/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def start(self):
while self.__up:
try:
msg, addr = self.skt.recvfrom(BUFFER_SIZE)
msg.decode('utf-8')
except socket.error as error:
if self.__up is False:
return
Expand Down
10 changes: 7 additions & 3 deletions napalm_logs/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import zmq

# Import napalm-logs pkgs
import napalm_logs.ext.six as six
from napalm_logs.config import LST_IPC_URL
from napalm_logs.config import DEV_IPC_URL_TPL
from napalm_logs.config import UNKNOWN_DEVICE_NAME
Expand Down Expand Up @@ -152,8 +153,8 @@ def _identify_os(self, msg):

# The pri has to be an int as it is retrived using regex '\<(\d+)\>'
if 'pri' in ret:
ret['facility'] = int(ret['pri']) / 8
ret['severity'] = int(ret['pri']) - (ret['facility'] * 8)
ret['facility'] = int(int(ret['pri']) / 8)
ret['severity'] = int(int(ret['pri']) - (ret['facility'] * 8))
# TODO Should we stop searching and just return, or should we return all matches OS?
return dev_os, ret
log.debug('No prefix matched under %s', dev_os)
Expand Down Expand Up @@ -204,7 +205,10 @@ def start(self):
msg = 'Received IOError from server pipe: {}'.format(error)
log.error(msg, exc_info=True)
raise NapalmLogsExit(msg)
msg = msg.encode('utf8')
if six.PY3:
msg = str(msg, 'utf-8')
else:
msg = msg.encode('utf-8')
log.debug('[%s] Dequeued message from %s: %s', address, msg, time.time())
dev_os, msg_dict = self._identify_os(msg)
log.debug('Identified OS: %s', dev_os)
Expand Down
2 changes: 1 addition & 1 deletion napalm_logs/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def extract(rgx, msg, mapping, time_format=None):
else:
group_index = 0
for group_value in matched.groups():
group_name = mapping.keys()[group_index]
group_name = list(mapping.keys())[group_index]
ret[group_name] = group_value
group_index += 1
log.debug('Regex matched')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_config(os_name, error_name, test_case):
log.debug('Struct YANG message:')
log.debug(struct_yang_message)
log.debug('Sending the raw message to the napalm-logs daemon')
TEST_SKT.sendto(raw_message.strip(), (NAPALM_LOGS_TEST_ADDR, NAPALM_LOGS_TEST_PORT))
TEST_SKT.sendto(raw_message.strip().encode('utf-8'), (NAPALM_LOGS_TEST_ADDR, NAPALM_LOGS_TEST_PORT))
zmq_msg = TEST_CLIENT.recv()
deserialised_zmq_msg = napalm_logs.utils.unserialize(zmq_msg)
log.debug('Received from the napalm-logs daemon:')
Expand Down

0 comments on commit e368e3a

Please sign in to comment.