Fix remote connectivity checks
Given that _check_remote_connectivity just returns True/False, callers should check the result. Also, simplify some callers. Closes-Bug: #1659454 Change-Id: I982c803bf036721814c09982e52d77527e9421af
This commit is contained in:
parent
efdb3f67d1
commit
4c3ebb07c4
|
@ -926,14 +926,15 @@ class NetworkScenarioTest(ScenarioTest):
|
|||
|
||||
def _check_remote_connectivity(self, source, dest, should_succeed=True,
|
||||
nic=None):
|
||||
"""check ping server via source ssh connection
|
||||
"""assert ping server via source ssh connection
|
||||
|
||||
Note: This is an internal method. Use check_remote_connectivity
|
||||
instead.
|
||||
|
||||
:param source: RemoteClient: an ssh connection from which to ping
|
||||
:param dest: and IP to ping against
|
||||
:param should_succeed: boolean should ping succeed or not
|
||||
:param nic: specific network interface to ping from
|
||||
:returns: boolean -- should_succeed == ping
|
||||
:returns: ping is false if ping failed
|
||||
"""
|
||||
def ping_remote():
|
||||
try:
|
||||
|
@ -948,6 +949,25 @@ class NetworkScenarioTest(ScenarioTest):
|
|||
CONF.validation.ping_timeout,
|
||||
1)
|
||||
|
||||
def check_remote_connectivity(self, source, dest, should_succeed=True,
|
||||
nic=None):
|
||||
"""assert ping server via source ssh connection
|
||||
|
||||
:param source: RemoteClient: an ssh connection from which to ping
|
||||
:param dest: and IP to ping against
|
||||
:param should_succeed: boolean should ping succeed or not
|
||||
:param nic: specific network interface to ping from
|
||||
"""
|
||||
result = self._check_remote_connectivity(source, dest, should_succeed,
|
||||
nic)
|
||||
source_host = source.ssh_client.host
|
||||
if should_succeed:
|
||||
msg = "Timed out waiting for %s to become reachable from %s" \
|
||||
% (dest, source_host)
|
||||
else:
|
||||
msg = "%s is reachable from %s" % (dest, source_host)
|
||||
self.assertTrue(result, msg)
|
||||
|
||||
def _create_security_group(self, security_group_rules_client=None,
|
||||
tenant_id=None,
|
||||
namestart='secgroup-smoke',
|
||||
|
|
|
@ -347,20 +347,8 @@ class TestNetworkBasicOps(manager.NetworkScenarioTest):
|
|||
ip_address, private_key=private_key)
|
||||
|
||||
for remote_ip in address_list:
|
||||
if should_connect:
|
||||
msg = ("Timed out waiting for %s to become "
|
||||
"reachable") % remote_ip
|
||||
else:
|
||||
msg = "ip address %s is reachable" % remote_ip
|
||||
try:
|
||||
self.assertTrue(self._check_remote_connectivity
|
||||
(ssh_source, remote_ip, should_connect),
|
||||
msg)
|
||||
except Exception:
|
||||
LOG.exception("Unable to access {dest} via ssh to "
|
||||
"floating-ip {src}".format(dest=remote_ip,
|
||||
src=floating_ip))
|
||||
raise
|
||||
self.check_remote_connectivity(ssh_source, remote_ip,
|
||||
should_connect)
|
||||
|
||||
@test.attr(type='smoke')
|
||||
@decorators.idempotent_id('f323b3ba-82f8-4db7-8ea6-6a895869ec49')
|
||||
|
@ -648,21 +636,21 @@ class TestNetworkBasicOps(manager.NetworkScenarioTest):
|
|||
self.check_public_network_connectivity(
|
||||
should_connect=True, msg="before updating "
|
||||
"admin_state_up of instance port to False")
|
||||
self._check_remote_connectivity(ssh_client, dest=server_pip,
|
||||
should_succeed=True)
|
||||
self.check_remote_connectivity(ssh_client, dest=server_pip,
|
||||
should_succeed=True)
|
||||
self.ports_client.update_port(port_id, admin_state_up=False)
|
||||
self.check_public_network_connectivity(
|
||||
should_connect=False, msg="after updating "
|
||||
"admin_state_up of instance port to False",
|
||||
should_check_floating_ip_status=False)
|
||||
self._check_remote_connectivity(ssh_client, dest=server_pip,
|
||||
should_succeed=False)
|
||||
self.check_remote_connectivity(ssh_client, dest=server_pip,
|
||||
should_succeed=False)
|
||||
self.ports_client.update_port(port_id, admin_state_up=True)
|
||||
self.check_public_network_connectivity(
|
||||
should_connect=True, msg="after updating "
|
||||
"admin_state_up of instance port to True")
|
||||
self._check_remote_connectivity(ssh_client, dest=server_pip,
|
||||
should_succeed=True)
|
||||
self.check_remote_connectivity(ssh_client, dest=server_pip,
|
||||
should_succeed=True)
|
||||
|
||||
@decorators.idempotent_id('759462e1-8535-46b0-ab3a-33aa45c55aaa')
|
||||
@test.services('compute', 'network')
|
||||
|
@ -833,15 +821,15 @@ class TestNetworkBasicOps(manager.NetworkScenarioTest):
|
|||
spoof_nic = ssh_client.get_nic_name_by_mac(spoof_port["mac_address"])
|
||||
peer = self._create_server(self.new_net)
|
||||
peer_address = peer['addresses'][self.new_net['name']][0]['addr']
|
||||
self._check_remote_connectivity(ssh_client, dest=peer_address,
|
||||
nic=spoof_nic, should_succeed=True)
|
||||
self.check_remote_connectivity(ssh_client, dest=peer_address,
|
||||
nic=spoof_nic, should_succeed=True)
|
||||
ssh_client.set_mac_address(spoof_nic, spoof_mac)
|
||||
new_mac = ssh_client.get_mac_address(nic=spoof_nic)
|
||||
self.assertEqual(spoof_mac, new_mac)
|
||||
self._check_remote_connectivity(ssh_client, dest=peer_address,
|
||||
nic=spoof_nic, should_succeed=False)
|
||||
self.check_remote_connectivity(ssh_client, dest=peer_address,
|
||||
nic=spoof_nic, should_succeed=False)
|
||||
self.ports_client.update_port(spoof_port["id"],
|
||||
port_security_enabled=False,
|
||||
security_groups=[])
|
||||
self._check_remote_connectivity(ssh_client, dest=peer_address,
|
||||
nic=spoof_nic, should_succeed=True)
|
||||
self.check_remote_connectivity(ssh_client, dest=peer_address,
|
||||
nic=spoof_nic, should_succeed=True)
|
||||
|
|
|
@ -191,25 +191,18 @@ class TestGettingAddress(manager.NetworkScenarioTest):
|
|||
self.assertTrue(test_utils.call_until_true(srv2_v6_addr_assigned,
|
||||
CONF.validation.ping_timeout, 1))
|
||||
|
||||
self._check_connectivity(sshv4_1, ips_from_api_2['4'])
|
||||
self._check_connectivity(sshv4_2, ips_from_api_1['4'])
|
||||
self.check_remote_connectivity(sshv4_1, ips_from_api_2['4'])
|
||||
self.check_remote_connectivity(sshv4_2, ips_from_api_1['4'])
|
||||
|
||||
for i in range(n_subnets6):
|
||||
self._check_connectivity(sshv4_1,
|
||||
ips_from_api_2['6'][i])
|
||||
self._check_connectivity(sshv4_1,
|
||||
self.subnets_v6[i]['gateway_ip'])
|
||||
self._check_connectivity(sshv4_2,
|
||||
ips_from_api_1['6'][i])
|
||||
self._check_connectivity(sshv4_2,
|
||||
self.subnets_v6[i]['gateway_ip'])
|
||||
|
||||
def _check_connectivity(self, source, dest):
|
||||
self.assertTrue(
|
||||
self._check_remote_connectivity(source, dest),
|
||||
"Timed out waiting for %s to become reachable from %s" %
|
||||
(dest, source.ssh_client.host)
|
||||
)
|
||||
self.check_remote_connectivity(sshv4_1,
|
||||
ips_from_api_2['6'][i])
|
||||
self.check_remote_connectivity(sshv4_1,
|
||||
self.subnets_v6[i]['gateway_ip'])
|
||||
self.check_remote_connectivity(sshv4_2,
|
||||
ips_from_api_1['6'][i])
|
||||
self.check_remote_connectivity(sshv4_2,
|
||||
self.subnets_v6[i]['gateway_ip'])
|
||||
|
||||
@test.attr(type='slow')
|
||||
@decorators.idempotent_id('2c92df61-29f0-4eaa-bee3-7c65bef62a43')
|
||||
|
|
|
@ -368,20 +368,12 @@ class TestSecurityGroupsBasicOps(manager.NetworkScenarioTest):
|
|||
access_point_ssh, private_key=private_key)
|
||||
return access_point_ssh
|
||||
|
||||
def _check_connectivity(self, access_point, ip, should_succeed=True):
|
||||
if should_succeed:
|
||||
msg = "Timed out waiting for %s to become reachable" % ip
|
||||
else:
|
||||
msg = "%s is reachable" % ip
|
||||
self.assertTrue(self._check_remote_connectivity(access_point, ip,
|
||||
should_succeed), msg)
|
||||
|
||||
def _test_in_tenant_block(self, tenant):
|
||||
access_point_ssh = self._connect_to_access_point(tenant)
|
||||
for server in tenant.servers:
|
||||
self._check_connectivity(access_point=access_point_ssh,
|
||||
ip=self._get_server_ip(server),
|
||||
should_succeed=False)
|
||||
self.check_remote_connectivity(source=access_point_ssh,
|
||||
dest=self._get_server_ip(server),
|
||||
should_succeed=False)
|
||||
|
||||
def _test_in_tenant_allow(self, tenant):
|
||||
ruleset = dict(
|
||||
|
@ -396,8 +388,8 @@ class TestSecurityGroupsBasicOps(manager.NetworkScenarioTest):
|
|||
)
|
||||
access_point_ssh = self._connect_to_access_point(tenant)
|
||||
for server in tenant.servers:
|
||||
self._check_connectivity(access_point=access_point_ssh,
|
||||
ip=self._get_server_ip(server))
|
||||
self.check_remote_connectivity(source=access_point_ssh,
|
||||
dest=self._get_server_ip(server))
|
||||
|
||||
def _test_cross_tenant_block(self, source_tenant, dest_tenant):
|
||||
# if public router isn't defined, then dest_tenant access is via
|
||||
|
@ -405,8 +397,8 @@ class TestSecurityGroupsBasicOps(manager.NetworkScenarioTest):
|
|||
access_point_ssh = self._connect_to_access_point(source_tenant)
|
||||
ip = self._get_server_ip(dest_tenant.access_point,
|
||||
floating=self.floating_ip_access)
|
||||
self._check_connectivity(access_point=access_point_ssh, ip=ip,
|
||||
should_succeed=False)
|
||||
self.check_remote_connectivity(source=access_point_ssh, dest=ip,
|
||||
should_succeed=False)
|
||||
|
||||
def _test_cross_tenant_allow(self, source_tenant, dest_tenant):
|
||||
"""check for each direction:
|
||||
|
@ -427,7 +419,7 @@ class TestSecurityGroupsBasicOps(manager.NetworkScenarioTest):
|
|||
access_point_ssh = self._connect_to_access_point(source_tenant)
|
||||
ip = self._get_server_ip(dest_tenant.access_point,
|
||||
floating=self.floating_ip_access)
|
||||
self._check_connectivity(access_point_ssh, ip)
|
||||
self.check_remote_connectivity(access_point_ssh, ip)
|
||||
|
||||
# test that reverse traffic is still blocked
|
||||
self._test_cross_tenant_block(dest_tenant, source_tenant)
|
||||
|
@ -444,7 +436,7 @@ class TestSecurityGroupsBasicOps(manager.NetworkScenarioTest):
|
|||
access_point_ssh_2 = self._connect_to_access_point(dest_tenant)
|
||||
ip = self._get_server_ip(source_tenant.access_point,
|
||||
floating=self.floating_ip_access)
|
||||
self._check_connectivity(access_point_ssh_2, ip)
|
||||
self.check_remote_connectivity(access_point_ssh_2, ip)
|
||||
|
||||
def _verify_mac_addr(self, tenant):
|
||||
"""Verify that VM has the same ip, mac as listed in port"""
|
||||
|
@ -537,9 +529,9 @@ class TestSecurityGroupsBasicOps(manager.NetworkScenarioTest):
|
|||
# Check connectivity failure with default security group
|
||||
try:
|
||||
access_point_ssh = self._connect_to_access_point(new_tenant)
|
||||
self._check_connectivity(access_point=access_point_ssh,
|
||||
ip=self._get_server_ip(server),
|
||||
should_succeed=False)
|
||||
self.check_remote_connectivity(source=access_point_ssh,
|
||||
dest=self._get_server_ip(server),
|
||||
should_succeed=False)
|
||||
server_id = server['id']
|
||||
port_id = self.admin_manager.ports_client.list_ports(
|
||||
device_id=server_id)['ports'][0]['id']
|
||||
|
@ -547,9 +539,9 @@ class TestSecurityGroupsBasicOps(manager.NetworkScenarioTest):
|
|||
# update port with new security group and check connectivity
|
||||
self.ports_client.update_port(port_id, security_groups=[
|
||||
new_tenant.security_groups['new_sg']['id']])
|
||||
self._check_connectivity(
|
||||
access_point=access_point_ssh,
|
||||
ip=self._get_server_ip(server))
|
||||
self.check_remote_connectivity(
|
||||
source=access_point_ssh,
|
||||
dest=self._get_server_ip(server))
|
||||
except Exception:
|
||||
for tenant in self.tenants.values():
|
||||
self._log_console_output(servers=tenant.servers)
|
||||
|
@ -612,16 +604,16 @@ class TestSecurityGroupsBasicOps(manager.NetworkScenarioTest):
|
|||
self.ports_client.update_port(port_id,
|
||||
port_security_enabled=True,
|
||||
security_groups=[])
|
||||
self._check_connectivity(access_point=access_point_ssh,
|
||||
ip=self._get_server_ip(server),
|
||||
should_succeed=False)
|
||||
self.check_remote_connectivity(source=access_point_ssh,
|
||||
dest=self._get_server_ip(server),
|
||||
should_succeed=False)
|
||||
|
||||
self.ports_client.update_port(port_id,
|
||||
port_security_enabled=False,
|
||||
security_groups=[])
|
||||
self._check_connectivity(
|
||||
access_point=access_point_ssh,
|
||||
ip=self._get_server_ip(server))
|
||||
self.check_remote_connectivity(
|
||||
source=access_point_ssh,
|
||||
dest=self._get_server_ip(server))
|
||||
except Exception:
|
||||
for tenant in self.tenants.values():
|
||||
self._log_console_output(servers=tenant.servers)
|
||||
|
|
Loading…
Reference in New Issue