Add workaround for issue with deletion of TF security-group

In case of TungstenFabric we can encounter a issue when security
group is still referred to virtual-machine-interface and TF need
some time to sync changes after deletion of VM.

Related-PROD: PRODX-4003
Change-Id: Iab1b9bfdbe8413c73bdf47ca20859132e55a3a10
diff --git a/tempest/lib/common/dynamic_creds.py b/tempest/lib/common/dynamic_creds.py
index f27e926..2cb0669 100644
--- a/tempest/lib/common/dynamic_creds.py
+++ b/tempest/lib/common/dynamic_creds.py
@@ -13,6 +13,7 @@
 #    under the License.
 
 import ipaddress
+import time
 
 import netaddr
 from oslo_log import log as logging
@@ -402,11 +403,20 @@
                                                     name="default")
         secgroups_to_delete = resp_body['security_groups']
         for secgroup in secgroups_to_delete:
-            try:
-                nsg_client.delete_security_group(secgroup['id'])
-            except lib_exc.NotFound:
-                LOG.warning('Security group %s, id %s not found for clean-up',
-                            secgroup['name'], secgroup['id'])
+            # Workaround for PRODX-4003
+            for i in range(5):
+                try:
+                    nsg_client.delete_security_group(secgroup['id'])
+                    break
+                except lib_exc.NotFound:
+                    LOG.warning('Security group %s, id %s not found for '
+                                'clean-up', secgroup['name'], secgroup['id'])
+                    break
+                except lib_exc.Conflict:
+                    LOG.warning('Conflict with state of security group %s, '
+                                'id %s.', secgroup['name'], secgroup['id'])
+                    time.sleep(1)
+                    continue
 
     def _clear_isolated_net_resources(self):
         client = self.routers_admin_client