Support connectivity check without FIPs

This commit is contained in:
Frode Nordahl
2022-04-12 17:43:13 +02:00
parent ad16b5a7fc
commit ba0dc0232d
2 changed files with 46 additions and 19 deletions

View File

@@ -28,6 +28,7 @@ from neutronclient.common import exceptions as neutronexceptions
import yaml
import zaza
import zaza.openstack.charm_tests.neutron.setup as neutron_setup
import zaza.openstack.charm_tests.nova.utils as nova_utils
import zaza.openstack.charm_tests.test_utils as test_utils
import zaza.openstack.configure.guest as guest
@@ -805,6 +806,11 @@ class NeutronOvsVsctlTest(NeutronPluginApiSharedTests):
self.assertEqual(actual_external_id, expected_external_id)
def router_address_from_subnet(subnet):
"""Retrieve router address from subnet."""
return subnet['gateway_ip']
class NeutronNetworkingBase(test_utils.OpenStackBaseTest):
"""Base for checking openstack instances have valid networking."""
@@ -818,6 +824,17 @@ class NeutronNetworkingBase(test_utils.OpenStackBaseTest):
cls.neutron_client = (
openstack_utils.get_neutron_session_client(cls.keystone_session))
cls.project_subnet = cls.neutron_client.find_resource(
'subnet',
neutron_setup.OVERCLOUD_NETWORK_CONFIG['project_subnet_name'])
cls.external_subnet = cls.neutron_client.find_resource(
'subnet',
neutron_setup.OVERCLOUD_NETWORK_CONFIG['external_subnet_name'])
# Override this if you want your test to attach instances directly to
# the external provider network
cls.attach_to_external_network = False
@tenacity.retry(wait=tenacity.wait_exponential(multiplier=1, max=60),
reraise=True, stop=tenacity.stop_after_attempt(8))
def validate_instance_can_reach_other(self,
@@ -840,8 +857,10 @@ class NeutronNetworkingBase(test_utils.OpenStackBaseTest):
:param mtu: Check that we can send non-fragmented packets of given size
:type mtu: Optional[int]
"""
floating_1 = floating_ips_from_instance(instance_1)[0]
floating_2 = floating_ips_from_instance(instance_2)[0]
if not self.attach_to_external_network:
floating_1 = floating_ips_from_instance(instance_1)[0]
floating_2 = floating_ips_from_instance(instance_2)[0]
address_1 = fixed_ips_from_instance(instance_1)[0]
address_2 = fixed_ips_from_instance(instance_2)[0]
username = guest.boot_tests['bionic']['username']
@@ -859,15 +878,21 @@ class NeutronNetworkingBase(test_utils.OpenStackBaseTest):
'ping -M do -s {} -c 1'.format(packetsize))
for cmd in cmds:
openstack_utils.ssh_command(
username, floating_1, 'instance-1',
'{} {}'.format(cmd, address_2),
password=password, privkey=privkey, verify=verify)
if self.attach_to_external_network:
openstack_utils.ssh_command(
username, address_1, 'instance-1',
'{} {}'.format(cmd, address_2),
password=password, privkey=privkey, verify=verify)
else:
openstack_utils.ssh_command(
username, floating_1, 'instance-1',
'{} {}'.format(cmd, address_2),
password=password, privkey=privkey, verify=verify)
openstack_utils.ssh_command(
username, floating_1, 'instance-1',
'{} {}'.format(cmd, floating_2),
password=password, privkey=privkey, verify=verify)
openstack_utils.ssh_command(
username, floating_1, 'instance-1',
'{} {}'.format(cmd, floating_2),
password=password, privkey=privkey, verify=verify)
@tenacity.retry(wait=tenacity.wait_exponential(multiplier=1, max=60),
reraise=True, stop=tenacity.stop_after_attempt(8))
@@ -875,11 +900,6 @@ class NeutronNetworkingBase(test_utils.OpenStackBaseTest):
"""
Validate that an instance can reach it's primary gateway.
We make the assumption that the router's IP is 192.168.0.1
as that's the network that is setup in
neutron.setup.basic_overcloud_network which is used in all
Zaza Neutron validations.
:param instance: The instance to check networking from
:type instance: nova_client.Server
@@ -889,7 +909,12 @@ class NeutronNetworkingBase(test_utils.OpenStackBaseTest):
:param mtu: Check that we can send non-fragmented packets of given size
:type mtu: Optional[int]
"""
address = floating_ips_from_instance(instance)[0]
if self.attach_to_external_network:
router = router_address_from_subnet(self.external_subnet)
address = fixed_ips_from_instance(instance)[0]
else:
router = router_address_from_subnet(self.project_subnet)
address = floating_ips_from_instance(instance)[0]
username = guest.boot_tests['bionic']['username']
password = guest.boot_tests['bionic'].get('password')
@@ -907,7 +932,7 @@ class NeutronNetworkingBase(test_utils.OpenStackBaseTest):
for cmd in cmds:
openstack_utils.ssh_command(
username, address, 'instance', '{} 192.168.0.1'.format(cmd),
username, address, 'instance', '{} {}'.format(cmd, router),
password=password, privkey=privkey, verify=verify)
@tenacity.retry(wait=tenacity.wait_exponential(min=5, max=60),
@@ -1086,7 +1111,8 @@ class NeutronNetworkingTest(NeutronNetworkingBase):
"""
instance_1, instance_2 = self.retrieve_guests()
if not all([instance_1, instance_2]):
self.launch_guests()
self.launch_guests(
attach_to_external_network=self.attach_to_external_network)
instance_1, instance_2 = self.retrieve_guests()
self.check_connectivity(instance_1, instance_2)
self.run_resource_cleanup = self.get_my_tests_options(

View File

@@ -139,7 +139,8 @@ def setup_sdn(network_config, keystone_session=None):
network_config["default_gateway"],
network_config["external_net_cidr"],
network_config["start_floating_ip"],
network_config["end_floating_ip"])
network_config["end_floating_ip"],
dhcp=True)
provider_router = (
openstack_utils.create_provider_router(neutron_client, project_id))
openstack_utils.plug_extnet_into_router(