From 4ecc6877a2a2fd3244979ec4a8d13a2862f5e6a4 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 4 Mar 2014 15:38:00 +0100 Subject: nat: Add CTRL command test case for the new control commands --- openbsc/doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg | 1 + openbsc/tests/ctrl_test_runner.py | 50 +++++++++++++++++++++- openbsc/tests/vty_test_runner.py | 2 +- 3 files changed, 50 insertions(+), 3 deletions(-) (limited to 'openbsc') diff --git a/openbsc/doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg b/openbsc/doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg index 78eb4ba10..737d10474 100644 --- a/openbsc/doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg +++ b/openbsc/doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg @@ -62,6 +62,7 @@ nat timeout ping 20 timeout pong 5 ip-dscp 0 + access-list bla imsi-allow ^11$ bsc 0 token bla diff --git a/openbsc/tests/ctrl_test_runner.py b/openbsc/tests/ctrl_test_runner.py index 5691d76aa..22f378dd5 100644 --- a/openbsc/tests/ctrl_test_runner.py +++ b/openbsc/tests/ctrl_test_runner.py @@ -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)) diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py index 092f5ae6f..7c8fe8c30 100644 --- a/openbsc/tests/vty_test_runner.py +++ b/openbsc/tests/vty_test_runner.py @@ -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) -- cgit v1.2.3