Merge "Make dynamic routing tests use clients as others"
diff --git a/neutron_tempest_plugin/api/test_qos_negative.py b/neutron_tempest_plugin/api/test_qos_negative.py
index c069360..8432c6a 100644
--- a/neutron_tempest_plugin/api/test_qos_negative.py
+++ b/neutron_tempest_plugin/api/test_qos_negative.py
@@ -12,6 +12,7 @@
 
 from neutron_lib.api.definitions import qos as qos_apidef
 from neutron_lib.db import constants as db_const
+from tempest.lib.common.utils import data_utils
 from tempest.lib import decorators
 from tempest.lib import exceptions as lib_exc
 
@@ -65,3 +66,35 @@
         self.assertRaises(lib_exc.BadRequest,
                           self.client.update_qos_policy, policy['id'],
                           description=LONG_DESCRIPTION_NG)
+
+
+class QosBandwidthLimitRuleNegativeTestJSON(base.BaseAdminNetworkTest):
+
+    required_extensions = [qos_apidef.ALIAS]
+
+    @decorators.attr(type='negative')
+    @decorators.idempotent_id('e9ce8042-c828-4cb9-b1f1-85bd35e6553a')
+    def test_rule_update_rule_nonexistent_policy(self):
+        non_exist_id = data_utils.rand_name('qos_policy')
+        policy = self.create_qos_policy(name='test-policy',
+                                        description='test policy',
+                                        shared=False)
+        rule = self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
+                                                    max_kbps=1,
+                                                    max_burst_kbps=1)
+        self.assertRaises(
+            lib_exc.NotFound,
+            self.admin_client.update_bandwidth_limit_rule,
+            non_exist_id, rule['id'], max_kbps=200, max_burst_kbps=1337)
+
+    @decorators.attr(type='negative')
+    @decorators.idempotent_id('a2c72066-0c32-4f28-be7f-78fa721588b6')
+    def test_rule_update_rule_nonexistent_rule(self):
+        non_exist_id = data_utils.rand_name('qos_rule')
+        policy = self.create_qos_policy(name='test-policy',
+                                        description='test policy',
+                                        shared=False)
+        self.assertRaises(
+            lib_exc.NotFound,
+            self.admin_client.update_bandwidth_limit_rule,
+            policy['id'], non_exist_id, max_kbps=200, max_burst_kbps=1337)
diff --git a/neutron_tempest_plugin/neutron_dynamic_routing/api/test_bgp_speaker_extensions.py b/neutron_tempest_plugin/neutron_dynamic_routing/api/test_bgp_speaker_extensions.py
index 3467e35..5cdd524 100644
--- a/neutron_tempest_plugin/neutron_dynamic_routing/api/test_bgp_speaker_extensions.py
+++ b/neutron_tempest_plugin/neutron_dynamic_routing/api/test_bgp_speaker_extensions.py
@@ -128,6 +128,19 @@
     def delete_address_scope(self, id):
         return self.admin_client.delete_address_scope(id)
 
+    def create_router(self, ext_gw_info):
+        try:
+            router = self.admin_client.create_router(
+                                            'my-router',
+                                            external_gateway_info=ext_gw_info,
+                                            distributed=False)
+        # Retry if not running with DVR enabled
+        except lib_exc.BadRequest:
+            router = self.admin_client.create_router(
+                                            'my-router',
+                                            external_gateway_info=ext_gw_info)
+        return router['router']
+
 
 class BgpSpeakerTestJSON(BgpSpeakerTestJSONBase):
 
@@ -232,16 +245,12 @@
         tenant_net = self.create_network()
         tenant_subnet = self.create_subnet(tenant_net)
         ext_gw_info = {'network_id': self.ext_net_id}
-        router = self.admin_client.create_router(
-                                            'my-router',
-                                            external_gateway_info=ext_gw_info,
-                                            admin_state_up=True,
-                                            distributed=False)
-        self.admin_routers.append(router['router'])
+        router = self.create_router(ext_gw_info)
+        self.admin_routers.append(router)
         self.admin_client.add_router_interface_with_subnet_id(
-                                                       router['router']['id'],
+                                                       router['id'],
                                                        tenant_subnet['id'])
-        self.admin_routerports.append({'router_id': router['router']['id'],
+        self.admin_routerports.append({'router_id': router['id'],
                                        'subnet_id': tenant_subnet['id']})
         tenant_port = self.create_port(tenant_net)
         floatingip = self.create_floatingip(self.ext_net_id)
@@ -281,10 +290,7 @@
                                        ip_version=4,
                                        subnetpool_id=tenant_subnetpool['id'])
         ext_gw_info = {'network_id': ext_net['id']}
-        router = self.admin_client.create_router(
-                                            'my-router',
-                                            external_gateway_info=ext_gw_info,
-                                            distributed=False)['router']
+        router = self.create_router(ext_gw_info)
         self.admin_routers.append(router)
         self.admin_client.add_router_interface_with_subnet_id(
                                                        router['id'],
diff --git a/neutron_tempest_plugin/neutron_dynamic_routing/api/test_bgp_speaker_extensions_negative.py b/neutron_tempest_plugin/neutron_dynamic_routing/api/test_bgp_speaker_extensions_negative.py
index 78569ea..fea7a46 100644
--- a/neutron_tempest_plugin/neutron_dynamic_routing/api/test_bgp_speaker_extensions_negative.py
+++ b/neutron_tempest_plugin/neutron_dynamic_routing/api/test_bgp_speaker_extensions_negative.py
@@ -98,10 +98,7 @@
                                        ip_version=4,
                                        subnetpool_id=tenant_subnetpool2['id'])
         ext_gw_info = {'network_id': ext_net['id']}
-        router = self.admin_client.create_router(
-                                  'my-router',
-                                  distributed=False,
-                                  external_gateway_info=ext_gw_info)['router']
+        router = self.create_router(ext_gw_info)
         self.admin_routers.append(router)
         self.admin_client.add_router_interface_with_subnet_id(
                                                        router['id'],
diff --git a/neutron_tempest_plugin/scenario/base.py b/neutron_tempest_plugin/scenario/base.py
index 9223893..78b766b 100644
--- a/neutron_tempest_plugin/scenario/base.py
+++ b/neutron_tempest_plugin/scenario/base.py
@@ -302,7 +302,8 @@
     def _check_remote_connectivity(self, source, dest, count,
                                    should_succeed=True,
                                    nic=None, mtu=None, fragmentation=True,
-                                   timeout=None, pattern=None):
+                                   timeout=None, pattern=None,
+                                   forbid_packet_loss=False):
         """check ping server via source ssh connection
 
         :param source: RemoteClient: an ssh connection from which to ping
@@ -314,6 +315,7 @@
         :param fragmentation: Flag for packet fragmentation
         :param timeout: Timeout for all ping packet(s) to succeed
         :param pattern: hex digits included in ICMP messages
+        :param forbid_packet_loss: forbid or allow some lost packets
         :returns: boolean -- should_succeed == ping
         :returns: ping is false if ping failed
         """
@@ -352,6 +354,10 @@
                 return not should_succeed
             LOG.debug('ping result: %s', result)
 
+            if forbid_packet_loss and ' 0% packet loss' not in result:
+                LOG.debug('Packet loss detected')
+                return not should_succeed
+
             if validators.validate_ip_address(dest) is None:
                 # Assert that the return traffic was from the correct
                 # source address.
@@ -366,12 +372,13 @@
                                   nic=None, mtu=None, fragmentation=True,
                                   servers=None, timeout=None,
                                   ping_count=CONF.validation.ping_count,
-                                  pattern=None):
+                                  pattern=None, forbid_packet_loss=False):
         try:
             self.assertTrue(self._check_remote_connectivity(
                 source, dest, ping_count, should_succeed, nic, mtu,
                 fragmentation,
-                timeout=timeout, pattern=pattern))
+                timeout=timeout, pattern=pattern,
+                forbid_packet_loss=forbid_packet_loss))
         except lib_exc.SSHTimeout as ssh_e:
             LOG.debug(ssh_e)
             self._log_console_output(servers)
diff --git a/neutron_tempest_plugin/scenario/test_dns_integration.py b/neutron_tempest_plugin/scenario/test_dns_integration.py
index 533f043..e5995c0 100644
--- a/neutron_tempest_plugin/scenario/test_dns_integration.py
+++ b/neutron_tempest_plugin/scenario/test_dns_integration.py
@@ -158,6 +158,15 @@
         self.client.delete_port(port['id'])
         self._verify_dns_records(addr, name, found=False)
 
+    @decorators.idempotent_id('d44cd5b8-ac67-4965-96ff-cb77ab6aea8b')
+    def test_fip_admin_delete(self):
+        name = data_utils.rand_name('fip-test')
+        fip = self._create_floatingip_with_dns(name)
+        addr = fip['floating_ip_address']
+        self._verify_dns_records(addr, name)
+        self.delete_floatingip(fip, client=self.admin_client)
+        self._verify_dns_records(addr, name, found=False)
+
 
 class DNSIntegrationExtraTests(BaseDNSIntegrationTests):