summaryrefslogtreecommitdiff
path: root/smoketest/scripts/cli/test_nat66.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-03-17 19:12:04 +0100
committerChristian Poessinger <christian@poessinger.com>2021-03-17 19:18:17 +0100
commit0f3def974fbaa4a26e6ad590ee37dd965bc2358f (patch)
tree36cc09af1fefbc3f6a4f6ad7b946d00baaecb703 /smoketest/scripts/cli/test_nat66.py
parent42d3cfbd3ee893ec567582a04467a899191f44fd (diff)
downloadvyos-1x-0f3def974fbaa4a26e6ad590ee37dd965bc2358f.tar.gz
vyos-1x-0f3def974fbaa4a26e6ad590ee37dd965bc2358f.zip
smoketest: add shim for every test to re-use common tasts
Currently every smoketest does the setup and destruction of the configsession on its own durin setUp(). This creates a lot of overhead and one configsession should be re-used during execution of every smoketest script. In addiion a test that failed will leaf the system in an unconsistent state. For this reason before the test is executed we will save the running config to /tmp and the will re-load the config after the test has passed, always ensuring a clean environment for the next test.
Diffstat (limited to 'smoketest/scripts/cli/test_nat66.py')
-rwxr-xr-xsmoketest/scripts/cli/test_nat66.py67
1 files changed, 34 insertions, 33 deletions
diff --git a/smoketest/scripts/cli/test_nat66.py b/smoketest/scripts/cli/test_nat66.py
index 4838fb8d8..dca92c97d 100755
--- a/smoketest/scripts/cli/test_nat66.py
+++ b/smoketest/scripts/cli/test_nat66.py
@@ -19,6 +19,8 @@ import jmespath
import json
import unittest
+from base_vyostest_shim import VyOSUnitTestSHIM
+
from vyos.configsession import ConfigSession
from vyos.configsession import ConfigSessionError
from vyos.util import cmd
@@ -28,26 +30,25 @@ base_path = ['nat66']
src_path = base_path + ['source']
dst_path = base_path + ['destination']
-class TestNAT66(unittest.TestCase):
+class TestNAT66(VyOSUnitTestSHIM.TestCase):
def setUp(self):
# ensure we can also run this test on a live system - so lets clean
# out the current configuration :)
- self.session = ConfigSession(os.getpid())
- self.session.delete(base_path)
+ self.cli_delete(base_path)
def tearDown(self):
- self.session.delete(base_path)
- self.session.commit()
+ self.cli_delete(base_path)
+ self.cli_commit()
def test_source_nat66(self):
source_prefix = 'fc00::/64'
translation_prefix = 'fc01::/64'
- self.session.set(src_path + ['rule', '1', 'outbound-interface', 'eth1'])
- self.session.set(src_path + ['rule', '1', 'source', 'prefix', source_prefix])
- self.session.set(src_path + ['rule', '1', 'translation', 'address', translation_prefix])
+ self.cli_set(src_path + ['rule', '1', 'outbound-interface', 'eth1'])
+ self.cli_set(src_path + ['rule', '1', 'source', 'prefix', source_prefix])
+ self.cli_set(src_path + ['rule', '1', 'translation', 'address', translation_prefix])
# check validate() - outbound-interface must be defined
- self.session.commit()
+ self.cli_commit()
tmp = cmd('sudo nft -j list table ip6 nat')
data_json = jmespath.search('nftables[?rule].rule[?chain]', json.loads(tmp))
@@ -69,16 +70,16 @@ class TestNAT66(unittest.TestCase):
# check for translation address
self.assertEqual(f'{translation_address}/{translation_mask}', translation_prefix)
self.assertEqual(f'{address}/{mask}', source_prefix)
-
+
def test_source_nat66_address(self):
source_prefix = 'fc00::/64'
translation_address = 'fc00::1'
- self.session.set(src_path + ['rule', '1', 'outbound-interface', 'eth1'])
- self.session.set(src_path + ['rule', '1', 'source', 'prefix', source_prefix])
- self.session.set(src_path + ['rule', '1', 'translation', 'address', translation_address])
+ self.cli_set(src_path + ['rule', '1', 'outbound-interface', 'eth1'])
+ self.cli_set(src_path + ['rule', '1', 'source', 'prefix', source_prefix])
+ self.cli_set(src_path + ['rule', '1', 'translation', 'address', translation_address])
# check validate() - outbound-interface must be defined
- self.session.commit()
+ self.cli_commit()
tmp = cmd('sudo nft -j list table ip6 nat')
data_json = jmespath.search('nftables[?rule].rule[?chain]', json.loads(tmp))
@@ -99,16 +100,16 @@ class TestNAT66(unittest.TestCase):
# check for translation address
self.assertEqual(snat_address, translation_address)
self.assertEqual(f'{address}/{mask}', source_prefix)
-
+
def test_destination_nat66(self):
destination_address = 'fc00::1'
translation_address = 'fc01::1'
- self.session.set(dst_path + ['rule', '1', 'inbound-interface', 'eth1'])
- self.session.set(dst_path + ['rule', '1', 'destination', 'address', destination_address])
- self.session.set(dst_path + ['rule', '1', 'translation', 'address', translation_address])
+ self.cli_set(dst_path + ['rule', '1', 'inbound-interface', 'eth1'])
+ self.cli_set(dst_path + ['rule', '1', 'destination', 'address', destination_address])
+ self.cli_set(dst_path + ['rule', '1', 'translation', 'address', translation_address])
# check validate() - outbound-interface must be defined
- self.session.commit()
+ self.cli_commit()
tmp = cmd('sudo nft -j list table ip6 nat')
data_json = jmespath.search('nftables[?rule].rule[?chain]', json.loads(tmp))
@@ -125,16 +126,16 @@ class TestNAT66(unittest.TestCase):
self.assertEqual(dnat_addr, translation_address)
self.assertEqual(iface, 'eth1')
-
+
def test_destination_nat66_prefix(self):
destination_prefix = 'fc00::/64'
translation_prefix = 'fc01::/64'
- self.session.set(dst_path + ['rule', '1', 'inbound-interface', 'eth1'])
- self.session.set(dst_path + ['rule', '1', 'destination', 'address', destination_prefix])
- self.session.set(dst_path + ['rule', '1', 'translation', 'address', translation_prefix])
+ self.cli_set(dst_path + ['rule', '1', 'inbound-interface', 'eth1'])
+ self.cli_set(dst_path + ['rule', '1', 'destination', 'address', destination_prefix])
+ self.cli_set(dst_path + ['rule', '1', 'translation', 'address', translation_prefix])
# check validate() - outbound-interface must be defined
- self.session.commit()
+ self.cli_commit()
tmp = cmd('sudo nft -j list table ip6 nat')
data_json = jmespath.search('nftables[?rule].rule[?chain]', json.loads(tmp))
@@ -157,19 +158,19 @@ class TestNAT66(unittest.TestCase):
# T2813: Ensure translation address is specified
rule = '5'
source_prefix = 'fc00::/64'
- self.session.set(src_path + ['rule', rule, 'source', 'prefix', source_prefix])
+ self.cli_set(src_path + ['rule', rule, 'source', 'prefix', source_prefix])
# check validate() - outbound-interface must be defined
with self.assertRaises(ConfigSessionError):
- self.session.commit()
- self.session.set(src_path + ['rule', rule, 'outbound-interface', 'eth0'])
+ self.cli_commit()
+ self.cli_set(src_path + ['rule', rule, 'outbound-interface', 'eth0'])
# check validate() - translation address not specified
with self.assertRaises(ConfigSessionError):
- self.session.commit()
+ self.cli_commit()
- self.session.set(src_path + ['rule', rule, 'translation', 'address', 'masquerade'])
- self.session.commit()
+ self.cli_set(src_path + ['rule', rule, 'translation', 'address', 'masquerade'])
+ self.cli_commit()
def test_nat66_no_rules(self):
# T3206: deleting all rules but keep the direction 'destination' or
@@ -177,9 +178,9 @@ class TestNAT66(unittest.TestCase):
#
# Test that both 'nat destination' and 'nat source' nodes can exist
# without any rule
- self.session.set(src_path)
- self.session.set(dst_path)
- self.session.commit()
+ self.cli_set(src_path)
+ self.cli_set(dst_path)
+ self.cli_commit()
if __name__ == '__main__':
unittest.main(verbosity=2)