nat: Add CTRL command test case for the new control commands

This commit is contained in:
Holger Hans Peter Freyther 2014-03-04 15:38:00 +01:00
parent 472f3bd198
commit 4ecc6877a2
3 changed files with 50 additions and 3 deletions

View File

@ -62,6 +62,7 @@ nat
timeout ping 20
timeout pong 5
ip-dscp 0
access-list bla imsi-allow ^11$
bsc 0
token bla

View File

@ -132,8 +132,12 @@ class TestCtrlBase(unittest.TestCase):
if mtype == "ERROR":
rsp['error'] = msg
else:
[rsp['var'], rsp['value']] = msg.split(None, 1)
split = msg.split(None, 1)
rsp['var'] = split[0]
if len(split) > 1:
rsp['value'] = split[1]
else:
rsp['value'] = None
responses[id] = rsp
if verbose:
@ -282,6 +286,40 @@ class TestCtrlBSC(TestCtrlBase):
self.assertEquals(r['var'], 'mcc')
self.assertEquals(r['value'], '201')
class TestCtrlNAT(TestCtrlBase):
def ctrl_command(self):
return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-c",
"doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
def ctrl_app(self):
return (4250, "./src/osmo-bsc_nat/osmo-bsc_nat", "OsmoNAT", "nat")
def testAccessList(self):
r = self.do_get('net.0.bsc_cfg.0.access-list-name')
self.assertEquals(r['mtype'], 'GET_REPLY')
self.assertEquals(r['var'], 'net')
self.assertEquals(r['value'], None)
r = self.do_set('net.0.bsc_cfg.0.access-list-name', 'bla')
self.assertEquals(r['mtype'], 'SET_REPLY')
self.assertEquals(r['var'], 'net')
self.assertEquals(r['value'], 'bla')
r = self.do_get('net.0.bsc_cfg.0.access-list-name')
self.assertEquals(r['mtype'], 'GET_REPLY')
self.assertEquals(r['var'], 'net')
self.assertEquals(r['value'], 'bla')
r = self.do_set('net.0.bsc_cfg.0.no-access-list-name', '1')
self.assertEquals(r['mtype'], 'SET_REPLY')
self.assertEquals(r['var'], 'net')
self.assertEquals(r['value'], None)
r = self.do_set('net.0.bsc_cfg.0.no-access-list-name', '1')
self.assertEquals(r['mtype'], 'SET_REPLY')
self.assertEquals(r['var'], 'net')
self.assertEquals(r['value'], None)
def add_bsc_test(suite, workdir):
if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
@ -290,6 +328,13 @@ def add_bsc_test(suite, workdir):
test = unittest.TestLoader().loadTestsFromTestCase(TestCtrlBSC)
suite.addTest(test)
def add_nat_test(suite, workdir):
if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
print("Skipping the NAT test")
return
test = unittest.TestLoader().loadTestsFromTestCase(TestCtrlNAT)
suite.addTest(test)
if __name__ == '__main__':
import argparse
import sys
@ -321,5 +366,6 @@ if __name__ == '__main__':
print "Running tests for specific control commands"
suite = unittest.TestSuite()
add_bsc_test(suite, workdir)
add_nat_test(suite, workdir)
res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
sys.exit(len(res.errors) + len(res.failures))

View File

@ -525,7 +525,7 @@ class TestVTYNAT(TestVTYGenericBSC):
res = self.vty.command("show running-config").split("\r\n")
asserted = False
for line in res:
if line.startswith(" access-list"):
if line.startswith(" access-list test-default"):
self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
asserted = True
self.assert_(asserted)