Exemple #1
0
 def test_delete_router_nat_rules_by_match_on_source_ip(self):
     lrouter = self._prepare_nat_rules_for_delete_tests()
     rules = routerlib.query_nat_rules(self.fake_cluster, lrouter['uuid'])
     self.assertEqual(len(rules), 3)
     routerlib.delete_nat_rules_by_match(
         self.fake_cluster, lrouter['uuid'], 'SourceNatRule', 1, 1,
         source_ip_addresses='192.168.0.2/32')
     rules = routerlib.query_nat_rules(self.fake_cluster, lrouter['uuid'])
     self.assertEqual(len(rules), 2)
Exemple #2
0
 def test_delete_router_nat_rules_by_match_on_destination_ip(self):
     lrouter = self._prepare_nat_rules_for_delete_tests()
     rules = routerlib.query_nat_rules(self.fake_cluster, lrouter['uuid'])
     self.assertEqual(len(rules), 3)
     routerlib.delete_nat_rules_by_match(
         self.fake_cluster, lrouter['uuid'], 'DestinationNatRule', 1, 1,
         destination_ip_addresses='10.0.0.3')
     rules = routerlib.query_nat_rules(self.fake_cluster, lrouter['uuid'])
     self.assertEqual(len(rules), 2)
Exemple #3
0
 def test_delete_router_nat_rules_by_match_no_match_expected(self):
     lrouter = self._prepare_nat_rules_for_delete_tests()
     rules = routerlib.query_nat_rules(self.fake_cluster, lrouter['uuid'])
     self.assertEqual(len(rules), 3)
     routerlib.delete_nat_rules_by_match(
         self.fake_cluster, lrouter['uuid'], 'SomeWeirdType', 0)
     rules = routerlib.query_nat_rules(self.fake_cluster, lrouter['uuid'])
     self.assertEqual(len(rules), 3)
     routerlib.delete_nat_rules_by_match(
         self.fake_cluster, lrouter['uuid'], 'DestinationNatRule', 0,
         destination_ip_addresses='99.99.99.99')
     rules = routerlib.query_nat_rules(self.fake_cluster, lrouter['uuid'])
     self.assertEqual(len(rules), 3)
Exemple #4
0
 def test_delete_nat_rules_by_match_len_mismatch_does_not_raise(self):
     lrouter = self._prepare_nat_rules_for_delete_tests()
     rules = routerlib.query_nat_rules(self.fake_cluster, lrouter['uuid'])
     self.assertEqual(len(rules), 3)
     deleted_rules = routerlib.delete_nat_rules_by_match(
         self.fake_cluster, lrouter['uuid'],
         'DestinationNatRule',
         max_num_expected=1, min_num_expected=1,
         raise_on_len_mismatch=False,
         destination_ip_addresses='99.99.99.99')
     self.assertEqual(0, deleted_rules)
     # add an extra rule to emulate a duplicate one
     with mock.patch.object(self.fake_cluster.api_client,
                            'get_version',
                            new=lambda: ver_module.Version('2.0')):
         routerlib.create_lrouter_snat_rule(
             self.fake_cluster, lrouter['uuid'],
             '10.0.0.2', '10.0.0.2', order=220,
             match_criteria={'source_ip_addresses': '192.168.0.0/24'})
     deleted_rules_2 = routerlib.delete_nat_rules_by_match(
         self.fake_cluster, lrouter['uuid'], 'SourceNatRule',
         min_num_expected=1, max_num_expected=1,
         raise_on_len_mismatch=False,
         source_ip_addresses='192.168.0.0/24')
     self.assertEqual(2, deleted_rules_2)
Exemple #5
0
 def test_delete_router_nat_rules_by_match_no_match_raises(self):
     lrouter = self._prepare_nat_rules_for_delete_tests()
     rules = routerlib.query_nat_rules(self.fake_cluster, lrouter['uuid'])
     self.assertEqual(len(rules), 3)
     self.assertRaises(
         nsx_exc.NatRuleMismatch,
         routerlib.delete_nat_rules_by_match,
         self.fake_cluster, lrouter['uuid'],
         'SomeWeirdType', 1, 1)
Exemple #6
0
 def _test_create_router_dnat_rule(self, version, dest_port=None):
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(),
                                        'pippo',
                                        'fake-lrouter',
                                        '10.0.0.1')
     with mock.patch.object(self.fake_cluster.api_client,
                            'get_version',
                            return_value=ver_module.Version(version)):
         routerlib.create_lrouter_dnat_rule(
             self.fake_cluster, lrouter['uuid'], '192.168.0.2', order=200,
             dest_port=dest_port,
             match_criteria={'destination_ip_addresses': '10.0.0.3'})
         rules = routerlib.query_nat_rules(
             self.fake_cluster, lrouter['uuid'])
         self.assertEqual(len(rules), 1)
Exemple #7
0
 def _test_create_router_snat_rule(self, version):
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(),
                                        'pippo',
                                        'fake-lrouter',
                                        '10.0.0.1')
     with mock.patch.object(self.fake_cluster.api_client,
                            'get_version',
                            new=lambda: ver_module.Version(version)):
         routerlib.create_lrouter_snat_rule(
             self.fake_cluster, lrouter['uuid'],
             '10.0.0.2', '10.0.0.2', order=200,
             match_criteria={'source_ip_addresses': '192.168.0.24'})
         rules = routerlib.query_nat_rules(
             self.fake_cluster, lrouter['uuid'])
         self.assertEqual(len(rules), 1)
Exemple #8
0
 def _test_create_router_nosnat_rule(self, version, expected=1):
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        uuidutils.generate_uuid(),
                                        'pippo',
                                        'fake-lrouter',
                                        '10.0.0.1')
     with mock.patch.object(self.fake_cluster.api_client,
                            'get_version',
                            new=lambda: ver_module.Version(version)):
         routerlib.create_lrouter_nosnat_rule(
             self.fake_cluster, lrouter['uuid'],
             order=100,
             match_criteria={'destination_ip_addresses': '192.168.0.0/24'})
         rules = routerlib.query_nat_rules(
             self.fake_cluster, lrouter['uuid'])
         # NoSNAT rules do not exist in V2
         self.assertEqual(len(rules), expected)