Fix race condition in test_security_groups

Listing security groups and taking the first one to change
rules doesn't give any warranty listed security group is
exactly the one used to create servers ports.

This avoids this problem by creating a security group and
passing it to server instead of having to search for it
after the server has been created.

Despite a test cases require a general refactory this should
at least fix the CI job intermittent failures related to
this test.

Partial-Bug: #1801306
Change-Id: I5ecb3c8711e7455e7f1588943a2ffd08ce154578
This commit is contained in:
Federico Ressi 2018-10-23 17:35:47 +02:00
parent 254815c308
commit 6f9bb77d98
1 changed files with 7 additions and 5 deletions

View File

@ -137,16 +137,18 @@ class NetworkSecGroupTest(base.BaseTempestTestCase):
@decorators.idempotent_id('3d73ec1a-2ec6-45a9-b0f8-04a283d9d864')
def test_protocol_number_rule(self):
# protocol number is added instead of str in security rule creation
server_ssh_clients, fips, _ = self.create_vm_testing_sec_grp(
num_servers=1)
name = data_utils.rand_name("test_protocol_number_rule")
security_group = self.create_security_group(name=name)
port = self.create_port(network=self.network, name=name,
security_groups=[security_group['id']])
_, fips, _ = self.create_vm_testing_sec_grp(num_servers=1,
ports=[port])
self.ping_ip_address(fips[0]['floating_ip_address'],
should_succeed=False)
rule_list = [{'protocol': constants.PROTO_NUM_ICMP,
'direction': constants.INGRESS_DIRECTION,
'remote_ip_prefix': '0.0.0.0/0'}]
secgroup_id = self.os_primary.network_client.list_security_groups()[
'security_groups'][0]['id']
self.create_secgroup_rules(rule_list, secgroup_id=secgroup_id)
self.create_secgroup_rules(rule_list, secgroup_id=security_group['id'])
self.ping_ip_address(fips[0]['floating_ip_address'])
@decorators.idempotent_id('3d73ec1a-2ec6-45a9-b0f8-04a283d9d964')