Use instance variables for subnet tests

Commit 78a832441af3928994446d2afab07f0abb0dd26a let to random
failures of test_create_with_tags. This addresses that issue.

Change-Id: I470da7a1863a8c22257b1c27bc6d2b1c45c9cca3
This commit is contained in:
Gary Kotton 2017-07-26 23:52:04 -07:00
parent 86bda36963
commit 1134249a5e

View File

@ -38,23 +38,25 @@ class TestSubnet(network_fakes.TestNetworkV2):
class TestCreateSubnet(TestSubnet): class TestCreateSubnet(TestSubnet):
project = identity_fakes_v3.FakeProject.create_one_project() def _init_subnet_variables(self):
domain = identity_fakes_v3.FakeDomain.create_one_domain() self.project = identity_fakes_v3.FakeProject.create_one_project()
self.domain = identity_fakes_v3.FakeDomain.create_one_domain()
# An IPv4 subnet to be created with mostly default values # An IPv4 subnet to be created with mostly default values
_subnet = network_fakes.FakeSubnet.create_one_subnet( self._subnet = network_fakes.FakeSubnet.create_one_subnet(
attrs={ attrs={
'tenant_id': project.id, 'tenant_id': self.project.id,
} }
) )
# Subnet pool to be used to create a subnet from a pool # Subnet pool to be used to create a subnet from a pool
_subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool() self._subnet_pool = \
network_fakes.FakeSubnetPool.create_one_subnet_pool()
# An IPv4 subnet to be created using a specific subnet pool # An IPv4 subnet to be created using a specific subnet pool
_subnet_from_pool = network_fakes.FakeSubnet.create_one_subnet( self._subnet_from_pool = network_fakes.FakeSubnet.create_one_subnet(
attrs={ attrs={
'tenant_id': project.id, 'tenant_id': self.project.id,
'subnetpool_id': _subnet_pool.id, 'subnetpool_id': self._subnet_pool.id,
'dns_nameservers': ['8.8.8.8', 'dns_nameservers': ['8.8.8.8',
'8.8.4.4'], '8.8.4.4'],
'host_routes': [{'destination': '10.20.20.0/24', 'host_routes': [{'destination': '10.20.20.0/24',
@ -67,9 +69,9 @@ class TestCreateSubnet(TestSubnet):
) )
# An IPv6 subnet to be created with most options specified # An IPv6 subnet to be created with most options specified
_subnet_ipv6 = network_fakes.FakeSubnet.create_one_subnet( self._subnet_ipv6 = network_fakes.FakeSubnet.create_one_subnet(
attrs={ attrs={
'tenant_id': project.id, 'tenant_id': self.project.id,
'cidr': 'fe80:0:0:a00a::/64', 'cidr': 'fe80:0:0:a00a::/64',
'enable_dhcp': True, 'enable_dhcp': True,
'dns_nameservers': ['fe80:27ff:a00a:f00f::ffff', 'dns_nameservers': ['fe80:27ff:a00a:f00f::ffff',
@ -93,21 +95,21 @@ class TestCreateSubnet(TestSubnet):
) )
# The network to be returned from find_network # The network to be returned from find_network
_network = network_fakes.FakeNetwork.create_one_network( self._network = network_fakes.FakeNetwork.create_one_network(
attrs={ attrs={
'id': _subnet.network_id, 'id': self._subnet.network_id,
} }
) )
# The network segment to be returned from find_segment # The network segment to be returned from find_segment
_network_segment = \ self._network_segment = \
network_fakes.FakeNetworkSegment.create_one_network_segment( network_fakes.FakeNetworkSegment.create_one_network_segment(
attrs={ attrs={
'network_id': _subnet.network_id, 'network_id': self._subnet.network_id,
} }
) )
columns = ( self.columns = (
'allocation_pools', 'allocation_pools',
'cidr', 'cidr',
'description', 'description',
@ -128,70 +130,73 @@ class TestCreateSubnet(TestSubnet):
'tags', 'tags',
) )
data = ( self.data = (
subnet_v2._format_allocation_pools(_subnet.allocation_pools), subnet_v2._format_allocation_pools(self._subnet.allocation_pools),
_subnet.cidr, self._subnet.cidr,
_subnet.description, self._subnet.description,
utils.format_list(_subnet.dns_nameservers), utils.format_list(self._subnet.dns_nameservers),
_subnet.enable_dhcp, self._subnet.enable_dhcp,
_subnet.gateway_ip, self._subnet.gateway_ip,
subnet_v2._format_host_routes(_subnet.host_routes), subnet_v2._format_host_routes(self._subnet.host_routes),
_subnet.id, self._subnet.id,
_subnet.ip_version, self._subnet.ip_version,
_subnet.ipv6_address_mode, self._subnet.ipv6_address_mode,
_subnet.ipv6_ra_mode, self._subnet.ipv6_ra_mode,
_subnet.name, self._subnet.name,
_subnet.network_id, self._subnet.network_id,
_subnet.project_id, self._subnet.project_id,
_subnet.segment_id, self._subnet.segment_id,
utils.format_list(_subnet.service_types), utils.format_list(self._subnet.service_types),
_subnet.subnetpool_id, self._subnet.subnetpool_id,
utils.format_list(_subnet.tags), utils.format_list(self._subnet.tags),
) )
data_subnet_pool = ( self.data_subnet_pool = (
subnet_v2._format_allocation_pools(_subnet_from_pool.allocation_pools), subnet_v2._format_allocation_pools(
_subnet_from_pool.cidr, self._subnet_from_pool.allocation_pools),
_subnet_from_pool.description, self._subnet_from_pool.cidr,
utils.format_list(_subnet_from_pool.dns_nameservers), self._subnet_from_pool.description,
_subnet_from_pool.enable_dhcp, utils.format_list(self._subnet_from_pool.dns_nameservers),
_subnet_from_pool.gateway_ip, self._subnet_from_pool.enable_dhcp,
subnet_v2._format_host_routes(_subnet_from_pool.host_routes), self._subnet_from_pool.gateway_ip,
_subnet_from_pool.id, subnet_v2._format_host_routes(self._subnet_from_pool.host_routes),
_subnet_from_pool.ip_version, self._subnet_from_pool.id,
_subnet_from_pool.ipv6_address_mode, self._subnet_from_pool.ip_version,
_subnet_from_pool.ipv6_ra_mode, self._subnet_from_pool.ipv6_address_mode,
_subnet_from_pool.name, self._subnet_from_pool.ipv6_ra_mode,
_subnet_from_pool.network_id, self._subnet_from_pool.name,
_subnet_from_pool.project_id, self._subnet_from_pool.network_id,
_subnet_from_pool.segment_id, self._subnet_from_pool.project_id,
utils.format_list(_subnet_from_pool.service_types), self._subnet_from_pool.segment_id,
_subnet_from_pool.subnetpool_id, utils.format_list(self._subnet_from_pool.service_types),
utils.format_list(_subnet.tags), self._subnet_from_pool.subnetpool_id,
utils.format_list(self._subnet.tags),
) )
data_ipv6 = ( self.data_ipv6 = (
subnet_v2._format_allocation_pools(_subnet_ipv6.allocation_pools), subnet_v2._format_allocation_pools(
_subnet_ipv6.cidr, self._subnet_ipv6.allocation_pools),
_subnet_ipv6.description, self._subnet_ipv6.cidr,
utils.format_list(_subnet_ipv6.dns_nameservers), self._subnet_ipv6.description,
_subnet_ipv6.enable_dhcp, utils.format_list(self._subnet_ipv6.dns_nameservers),
_subnet_ipv6.gateway_ip, self._subnet_ipv6.enable_dhcp,
subnet_v2._format_host_routes(_subnet_ipv6.host_routes), self._subnet_ipv6.gateway_ip,
_subnet_ipv6.id, subnet_v2._format_host_routes(self._subnet_ipv6.host_routes),
_subnet_ipv6.ip_version, self._subnet_ipv6.id,
_subnet_ipv6.ipv6_address_mode, self._subnet_ipv6.ip_version,
_subnet_ipv6.ipv6_ra_mode, self._subnet_ipv6.ipv6_address_mode,
_subnet_ipv6.name, self._subnet_ipv6.ipv6_ra_mode,
_subnet_ipv6.network_id, self._subnet_ipv6.name,
_subnet_ipv6.project_id, self._subnet_ipv6.network_id,
_subnet_ipv6.segment_id, self._subnet_ipv6.project_id,
utils.format_list(_subnet_ipv6.service_types), self._subnet_ipv6.segment_id,
_subnet_ipv6.subnetpool_id, utils.format_list(self._subnet_ipv6.service_types),
utils.format_list(_subnet.tags), self._subnet_ipv6.subnetpool_id,
utils.format_list(self._subnet.tags),
) )
def setUp(self): def setUp(self):
self._init_subnet_variables()
super(TestCreateSubnet, self).setUp() super(TestCreateSubnet, self).setUp()
# Get the command object to test # Get the command object to test