Skip to content

Fix BGP4 on no bgp #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2018
Merged
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: 3 additions & 1 deletion src/sonic_ax_impl/lib/vtysh_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def vtysh_run(command):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))

cmd = b"zebra\r\n" + command.encode() + b"\r\nexit\r\n"
cmd = b"zebra\n" + command.encode() + b"\nexit\n"
s.send(cmd)

acc = b""
Expand Down Expand Up @@ -59,6 +59,8 @@ def parse_bgp_summary(summ):
if l.startswith('Neighbor '): break
if l.startswith('No IPv'): # eg. No IPv6 neighbor is configured
return bgpinfo
if l.endswith('> exit'): # last command in the lines
return bgpinfo
li += 1

## Read and store the table header
Expand Down
3 changes: 2 additions & 1 deletion src/sonic_ax_impl/mibs/vendor/cisco/bgp4.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
class BgpSessionUpdater(MIBUpdater):
def __init__(self):
super().__init__()
self.update_data()
self.session_status_map = {}
self.session_status_list = []

def update_data(self):
self.session_status_map = {}
Expand Down
4 changes: 4 additions & 0 deletions tests/mock_tables/bgpsummary_ipv6_nobgp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Hello, this is Quagga (version 0.99.24.1). Copyright 1996-2005 Kunihiro Ishiguro, et al. User Access Verification
"Password:
str-msn2700-03> show ipv6 bgp summary
str-msn2700-03> exit
18 changes: 8 additions & 10 deletions tests/mock_tables/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,28 @@

# Monkey patch
class MockSocket(_socket_class):
_instance_count = 0

def __init__(self, *args, **kwargs):
super(MockSocket, self).__init__(*args, **kwargs)
MockSocket._instance_count %= 2
MockSocket._instance_count += 1
self.first = True
self._string_sent = b''

def connect(self, *args, **kwargs):
pass

def send(self, *args, **kwargs):
string = args[0]
self._string_sent = string
pass

def recv(self, *args, **kwargs):
if not self.first:
return None
self.first = False

if MockSocket._instance_count == 1:
if b'show ip bgp summary' in self._string_sent:
filename = INPUT_DIR + '/bgpsummary_ipv4.txt'
elif MockSocket._instance_count == 2:
elif b'show ipv6 bgp summary' in self._string_sent:
filename = INPUT_DIR + '/bgpsummary_ipv6.txt'
else:
return None

self._string_sent = b''
ret = namedtuple('ret', ['returncode', 'stdout'])
ret.returncode = 0
with open(filename, 'rb') as f:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_vtysh.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
from ax_interface.constants import PduTypes
from sonic_ax_impl.mibs.ietf import rfc4363
from sonic_ax_impl.main import SonicMIB
from sonic_ax_impl.lib.vtysh_helper import parse_bgp_summary

class TestSonicMIB(TestCase):
@classmethod
def setUpClass(cls):
cls.lut = MIBTable(SonicMIB)
for updater in cls.lut.updater_instances:
updater.update_data()

def test_getpdu_established(self):
oid = ObjectIdentifier(20, 0, 0, 0, (1, 3, 6, 1, 4, 1, 9, 9, 187, 1, 2, 5, 1, 3, 1, 4, 10, 0, 0, 61))
Expand Down Expand Up @@ -98,3 +101,10 @@ def test_getpdu_ipv4_overwite_ipv6(self):
self.assertEqual(value0.type_, ValueType.INTEGER)
self.assertEqual(str(value0.name), str(oid))
self.assertEqual(value0.data, 6)

def parse_no_bgp():
filename = 'bgpsummary_ipv6_nobgp.txt'
with open(filename, 'rb') as f:
bgpsu = f.read()
bgpsumm_ipv6 = parse_bgp_summary(bgpsu)
self.assertEqual(bgpsumm_ipv6, [])