Fix VlanServerStackFixture.list_vlan_fixed_ips when has any IPs

It allows Ubuntu server to work without VLAN when not trunk is available

Change-Id: If0ac6aa7482ab83ef69d5849bb6efb96c518a077
This commit is contained in:
Federico Ressi 2021-09-24 10:24:52 +02:00
parent 8213faaa0b
commit 04b7a66e52
3 changed files with 34 additions and 35 deletions

View File

@ -218,7 +218,9 @@ class ServerStackFixture(heat.HeatStackFixture, abc.ABC):
def fixed_ipv6(self):
return self.find_fixed_ip(ip_version=6)
has_vlan = False
@property
def has_vlan(self) -> bool:
return False
#: Schedule on different host that this Nova server instance ID
different_host = None

View File

@ -41,10 +41,11 @@ class VlanProxyServerStackFixture(_cirros.CirrosServerStackFixture):
network_stack = tobiko.required_fixture(VlanNetworkStackFixture)
@neutron.skip_if_missing_networking_extensions('trunk')
class VlanServerStackFixture(_nova.ServerStackFixture, abc.ABC):
has_vlan = True
@property
def has_vlan(self) -> bool:
return neutron.has_networking_extensions('trunk')
#: stack with the newtwork where the trunk support is attached
vlan_network_stack = tobiko.required_fixture(VlanNetworkStackFixture)
@ -77,11 +78,12 @@ class VlanServerStackFixture(_nova.ServerStackFixture, abc.ABC):
def list_vlan_fixed_ips(self,
ip_version: int = None) \
-> tobiko.Selection[netaddr.IPAddress]:
fixed_ips: tobiko.Selection[netaddr.IPAddress] = tobiko.Selection(
netaddr.IPAddress(fixed_ip['ip_address'])
for fixed_ip in self.vlan_fixed_ips)
if ip_version is not None:
fixed_ips = fixed_ips.with_attributes(version=ip_version)
fixed_ips = tobiko.Selection[netaddr.IPAddress]()
if self.vlan_fixed_ips:
fixed_ips.extend(netaddr.IPAddress(fixed_ip['ip_address'])
for fixed_ip in self.vlan_fixed_ips)
if ip_version is not None and fixed_ips:
fixed_ips = fixed_ips.with_attributes(version=ip_version)
return fixed_ips
@property
@ -91,18 +93,25 @@ class VlanServerStackFixture(_nova.ServerStackFixture, abc.ABC):
def assert_vlan_is_reachable(self,
ip_version: int = None):
fixed_ips = self.list_vlan_fixed_ips(ip_version=ip_version)
ping.assert_reachable_hosts(fixed_ips,
ssh_client=self.vlan_ssh_proxy_client)
if fixed_ips:
ping.assert_reachable_hosts(
fixed_ips, ssh_client=self.vlan_ssh_proxy_client)
else:
tobiko.fail(f'Server {self.stack_name} has any IP on VLAN port')
def assert_vlan_is_unreachable(self,
ip_version: int = None):
fixed_ips = self.list_vlan_fixed_ips(ip_version=ip_version)
ping.assert_unreachable_hosts(fixed_ips,
ssh_client=self.vlan_ssh_proxy_client)
if fixed_ips:
ping.assert_unreachable_hosts(
fixed_ips, ssh_client=self.vlan_ssh_proxy_client)
else:
tobiko.fail(f'Server {self.stack_name} has any IP on VLAN port')
@property
def neutron_required_quota_set(self) -> typing.Dict[str, int]:
requirements = super().neutron_required_quota_set
requirements['port'] += 1
requirements['trunk'] += 1
if self.has_vlan:
requirements['trunk'] += 1
requirements['port'] += 1
return requirements

View File

@ -20,6 +20,7 @@ import testtools
import tobiko
from tobiko import config
from tobiko.openstack import neutron
from tobiko.openstack import stacks
@ -31,29 +32,16 @@ class RebootTrunkServerStackFixture(stacks.UbuntuServerStackFixture):
pass
class TrunkTest(testtools.TestCase):
@neutron.skip_if_missing_networking_extensions('trunk')
class RebootTrunkTest(testtools.TestCase):
"""Tests trunk functionality"""
stack = tobiko.required_fixture(RebootTrunkServerStackFixture)
vlan_proxy_stack = tobiko.required_fixture(
stacks.VlanProxyServerStackFixture)
@property
def vlan_proxy_ssh_client(self):
return self.vlan_proxy_stack.ssh_client
def test_activate_server(self):
self.stack.ensure_server_status('ACTIVE')
self.stack.assert_is_reachable()
self.stack.assert_vlan_is_reachable(ip_version=4)
def test_shutoff_server(self):
self.stack.ensure_server_status('SHUTOFF')
self.stack.assert_is_unreachable()
self.stack.assert_vlan_is_unreachable(ip_version=4)
@pytest.mark.ovn_migration
def test_shutoff_then_activate_server(self):
self.test_shutoff_server()
self.test_activate_server()
def test_reboot(self):
self.stack.ensure_server_status('SHUTOFF')
self.stack.assert_vlan_is_unreachable()
self.stack.ensure_server_status('ACTIVE')
self.stack.assert_vlan_is_reachable()