From 6f9bb77d9872a1cac4e1815ce13d97b8a143b3a8 Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Tue, 23 Oct 2018 17:35:47 +0200 Subject: [PATCH] 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 --- .../scenario/test_security_groups.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/neutron_tempest_plugin/scenario/test_security_groups.py b/neutron_tempest_plugin/scenario/test_security_groups.py index ebdcf93a..7b43a7ec 100644 --- a/neutron_tempest_plugin/scenario/test_security_groups.py +++ b/neutron_tempest_plugin/scenario/test_security_groups.py @@ -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')