Merge "Refactor test_floating_ip using the new required_fixture_setup function"

This commit is contained in:
Zuul 2019-04-17 16:30:02 +00:00 committed by Gerrit Code Review
commit 176b15bb7d
2 changed files with 66 additions and 58 deletions

View File

@ -53,7 +53,6 @@ class HeatStackFixture(tobiko.SharedFixture):
template_fixture = None template_fixture = None
parameters = None parameters = None
stack = None stack = None
outputs = None
def __init__(self, stack_name=None, template=None, parameters=None, def __init__(self, stack_name=None, template=None, parameters=None,
wait_interval=None, client=None): wait_interval=None, client=None):
@ -165,7 +164,7 @@ class HeatStackFixture(tobiko.SharedFixture):
stack = self.wait_for_stack_status( stack = self.wait_for_stack_status(
expected_status={DELETE_COMPLETE}) expected_status={DELETE_COMPLETE})
self.stack = self.outputs = None self.stack = self._outputs = None
try: try:
LOG.debug('Creating stack %r (re-tries left %d)...', LOG.debug('Creating stack %r (re-tries left %d)...',
self.stack_name, retry) self.stack_name, retry)
@ -191,7 +190,7 @@ class HeatStackFixture(tobiko.SharedFixture):
"""Deletes stack.""" """Deletes stack."""
if not stack_id: if not stack_id:
stack_id = self.stack_id stack_id = self.stack_id
self.stack = self.outputs = None self.stack = self._outputs = None
try: try:
self.client.stacks.delete(stack_id) self.client.stacks.delete(stack_id)
except exc.NotFound: except exc.NotFound:
@ -217,7 +216,7 @@ class HeatStackFixture(tobiko.SharedFixture):
except exc.HTTPNotFound: except exc.HTTPNotFound:
self.stack = stack = None self.stack = stack = None
finally: finally:
self.outputs = None self._outputs = None
return stack return stack
def wait_for_create_complete(self, check=True): def wait_for_create_complete(self, check=True):
@ -247,18 +246,27 @@ class HeatStackFixture(tobiko.SharedFixture):
check_stack_status(stack, expected_status) check_stack_status(stack, expected_status)
return stack return stack
_outputs = None
@property
def outputs(self):
return self.wait_for_outputs()
def get_outputs(self): def get_outputs(self):
stack = self.stack stack = self.stack
if not hasattr(stack, 'outputs'): if not hasattr(stack, 'outputs'):
stack = self.get_stack(resolve_outputs=True) stack = self.get_stack(resolve_outputs=True)
check_stack_status(stack, {CREATE_COMPLETE}) check_stack_status(stack, {CREATE_COMPLETE})
self.outputs = outputs = HeatStackOutputs( self._outputs = outputs = HeatStackOutputs(
stack_name=self.stack_name, stack_name=self.stack_name,
outputs={output['output_key']: output['output_value'] outputs={output['output_key']: output['output_value']
for output in stack.outputs}) for output in stack.outputs})
return outputs return outputs
def wait_for_outputs(self): def wait_for_outputs(self):
if self._outputs:
return self._outputs
else:
self.wait_for_create_complete() self.wait_for_create_complete()
return self.get_outputs() return self.get_outputs()

View File

@ -29,65 +29,70 @@ CONF = config.CONF
class FloatingIPFixture(heat.HeatStackFixture): class FloatingIPFixture(heat.HeatStackFixture):
template = stacks.heat_template_file('floating_ip.yaml') template = stacks.heat_template_file('floating_ip.yaml')
# template parameters # --- template parameters ---
floating_network = CONF.tobiko.neutron.floating_network floating_network = CONF.tobiko.neutron.floating_network
image = CONF.tobiko.nova.image image = CONF.tobiko.nova.image
flavor = CONF.tobiko.nova.flavor flavor = CONF.tobiko.nova.flavor
internal_network_fixture = stacks.InternalNetworkFixture @property
def internal_network(self):
return self.internal_network_stack.outputs.network_id
# --- required fixtures ---
internal_network_stack = tobiko.required_setup_fixture(
stacks.InternalNetworkFixture)
# --- class parameters ---
# derived attributes
internal_network = None
port_security_enabled = False port_security_enabled = False
security_groups = None security_groups = None
def setup_parameters(self): def setup_parameters(self):
super(FloatingIPFixture, self).setup_parameters() super(FloatingIPFixture, self).setup_parameters()
self.setup_internal_network()
if self.port_security_enabled: if self.port_security_enabled:
self.setup_port_security() self.setup_port_security()
def setup_internal_network(self):
self.internal_network = tobiko.setup_fixture(
self.internal_network_fixture).wait_for_outputs()
self.parameters['internal_network'] = self.internal_network.network_id
@neutron.skip_if_missing_networking_extensions('port-security') @neutron.skip_if_missing_networking_extensions('port-security')
def setup_port_security(self): def setup_port_security(self):
self.parameters.update( self.parameters.update(
port_security_enabled=self.port_security_enabled, port_security_enabled=self.port_security_enabled,
security_groups=self.security_groups or []) security_groups=self.security_groups or [])
# --- outputs ---
@property
def floating_ip_address(self):
return self.outputs.floating_ip_address
@property
def internal_network_mtu(self):
return self.internal_network_stack.outputs.mtu
class FloatingIPTest(base.TobikoTest): class FloatingIPTest(base.TobikoTest):
"""Tests server connectivity""" """Tests server connectivity"""
floating_ip_fixture = FloatingIPFixture floating_ip_stack = tobiko.required_setup_fixture(FloatingIPFixture)
@classmethod def setUp(self):
def setUpClass(cls): super(FloatingIPTest, self).setUp()
super(FloatingIPTest, cls).setUpClass() stack = self.floating_ip_stack
stack = tobiko.setup_fixture(cls.floating_ip_fixture) self.floating_ip_address = stack.floating_ip_address
outputs = stack.wait_for_outputs() self.internal_network_mtu = stack.internal_network_mtu
cls.floating_ip_address = outputs.floating_ip_address
cls.mtu = stack.internal_network.mtu
def test_ping(self): def test_ping(self):
ping.ping_until_received(self.floating_ip_address).assert_replied() ping.ping_until_received(self.floating_ip_address).assert_replied()
@neutron.skip_if_missing_networking_extensions('net-mtu') @neutron.skip_if_missing_networking_extensions('net-mtu')
def test_ping_with_mtu_packet(self): def test_ping_with_mtu(self):
ping.ping_until_received(self.floating_ip_address, ping.ping_until_received(self.floating_ip_address,
packet_size=self.mtu, packet_size=self.internal_network_mtu,
fragmentation=False).assert_replied() fragmentation=False).assert_replied()
@neutron.skip_if_missing_networking_extensions('net-mtu')
def test_ping_with_oversized_packet(self):
# Wait for VM to get ready
ping.ping_until_received(self.floating_ip_address)
# Send 5 over-sized packets # Send 5 over-sized packets
ping.ping(self.floating_ip_address, packet_size=self.mtu + 1, ping.ping(self.floating_ip_address,
packet_size=self.internal_network_mtu + 1,
fragmentation=False, count=5, fragmentation=False, count=5,
check=False).assert_not_replied() check=False).assert_not_replied()
@ -98,22 +103,20 @@ class FloatingIPWithPortSecurityFixture(FloatingIPFixture):
class FloatingIPWithPortSecurityTest(base.TobikoTest): class FloatingIPWithPortSecurityTest(base.TobikoTest):
floating_ip_fixture = FloatingIPFixture floating_ip_stack = tobiko.required_setup_fixture(FloatingIPFixture)
floating_ip_with_securtity_fixture = FloatingIPWithPortSecurityFixture floating_ip_with_securtity_stack = tobiko.required_setup_fixture(
FloatingIPWithPortSecurityFixture)
@classmethod def setUp(self):
def setUpClass(cls): super(FloatingIPWithPortSecurityTest, self).setUp()
super(FloatingIPWithPortSecurityTest, cls).setUpClass()
# Setup VM with port security # Setup VM with port security
stack = tobiko.setup_fixture(cls.floating_ip_with_securtity_fixture) self.floating_ip_address_with_security = (
outputs = stack.wait_for_outputs() self.floating_ip_with_securtity_stack.outputs.floating_ip_address)
cls.floating_ip_address_with_security = outputs.floating_ip_address
# Setup VM without port security # Setup VM without port security
stack = tobiko.setup_fixture(cls.floating_ip_fixture) self.floating_ip_address = (
outputs = stack.wait_for_outputs() self.floating_ip_stack.outputs.floating_ip_address)
cls.floating_ip_address = outputs.floating_ip_address
def test_ping(self): def test_ping(self):
ping.ping_until_received(self.floating_ip_address).assert_replied() ping.ping_until_received(self.floating_ip_address).assert_replied()
@ -122,27 +125,24 @@ class FloatingIPWithPortSecurityTest(base.TobikoTest):
class FloatingIPWithSecurityGroupFixture(FloatingIPWithPortSecurityFixture): class FloatingIPWithSecurityGroupFixture(FloatingIPWithPortSecurityFixture):
security_groups_fixture = stacks.SecurityGroupsFixture security_groups_stack = tobiko.required_setup_fixture(
security_groups = None stacks.SecurityGroupsFixture)
def setup_parameters(self): @property
super(FloatingIPWithSecurityGroupFixture, self).setup_parameters() def security_groups(self):
self.setup_security_groups() return [self.security_groups_stack.outputs.icmp_security_group_id]
self.parameters['security_groups'] = [
self.security_groups.icmp_security_group_id]
def setup_security_groups(self):
self.security_groups = tobiko.setup_fixture(
self.security_groups_fixture).wait_for_outputs()
class FloatingIPWithSecurityGroupTest(FloatingIPTest): class FloatingIPWithSecurityGroupTest(FloatingIPTest):
floating_ip_fixture = FloatingIPWithSecurityGroupFixture floating_ip_stack = tobiko.required_setup_fixture(
FloatingIPWithSecurityGroupFixture)
class FloatingIPWithNetMtuWritableFixture(FloatingIPFixture): class FloatingIPWithNetMtuWritableFixture(FloatingIPFixture):
internal_network_fixture = stacks.InternalNetworkWithNetMtuWritableFixture internal_network_stack = tobiko.required_setup_fixture(
stacks.InternalNetworkWithNetMtuWritableFixture)
class FlatingIpWithMtuWritableTest(FloatingIPTest): class FlatingIpWithMtuWritableTest(FloatingIPTest):
floating_ip_fixture = FloatingIPWithNetMtuWritableFixture floating_ip_stack = tobiko.required_setup_fixture(
FloatingIPWithNetMtuWritableFixture)