Fix the way how default SG for project if found in SG scenario test

Previously it was just getting list of SGs and assumed that first one in
the list is the "default" one. It's not always true so now there is
helper method which lists of SGs for project and looks for the one with
name "default" as this name is hardcoded in Neutron.

Change-Id: I608677547c9c8ae00af8821622cefa0955d692c6
This commit is contained in:
Slawek Kaplonski 2023-03-02 10:58:04 +01:00
parent 1577dc850a
commit 7b8fa63f41

@ -128,6 +128,13 @@ class BaseNetworkSecGroupTest(base.BaseTempestTestCase):
pkey=self.keypair['private_key']))
return server_ssh_clients, fips, servers
def _get_default_security_group(self):
sgs = self.os_primary.network_client.list_security_groups(
project_id=self.project_id)['security_groups']
for sg in sgs:
if sg['name'] == 'default':
return sg
def _test_ip_prefix(self, rule_list, should_succeed):
# Add specific remote prefix to VMs and check connectivity
ssh_secgrp_name = data_utils.rand_name('ssh_secgrp')
@ -167,8 +174,7 @@ class BaseNetworkSecGroupTest(base.BaseTempestTestCase):
def _test_default_sec_grp_scenarios(self):
# Ensure that SG used in tests is stateful or stateless as required
default_sg_id = self.os_primary.network_client.list_security_groups()[
'security_groups'][0]['id']
default_sg_id = self._get_default_security_group()['id']
self.os_primary.network_client.update_security_group(
default_sg_id, stateful=not self.stateless_sg)
if self.stateless_sg: