Test VM to VM connectivity
Change-Id: I83e6584cccaa3701f137d9574944350af8a5952a
This commit is contained in:
parent
cd00feb2bc
commit
6369dd113d
|
@ -24,4 +24,6 @@ nova_client = _client.nova_client
|
|||
NovaClientFixture = _client.NovaClientFixture
|
||||
find_hypervisor = _client.find_hypervisor
|
||||
|
||||
get_server = _client.get_server
|
||||
|
||||
skip_if_missing_hypervisors = _hypervisor.skip_if_missing_hypervisors
|
||||
|
|
|
@ -74,3 +74,7 @@ def find_hypervisor(client=None, unique=False, **params):
|
|||
return hypervisors.unique
|
||||
else:
|
||||
return hypervisors.first
|
||||
|
||||
|
||||
def get_server(server=None, client=None):
|
||||
return nova_client(client).servers.get(server)
|
||||
|
|
|
@ -23,6 +23,10 @@ from tobiko.openstack.stacks import _ubuntu
|
|||
CirrosFlavorStackFixture = _cirros.CirrosFlavorStackFixture
|
||||
CirrosImageFixture = _cirros.CirrosImageFixture
|
||||
CirrosServerStackFixture = _cirros.CirrosServerStackFixture
|
||||
CirrosPeerServerStackFixture = _cirros.CirrosPeerServerStackFixture
|
||||
CirrosDifferentHostServerStackFixture = (
|
||||
_cirros.CirrosDifferentHostServerStackFixture)
|
||||
CirrosSameHostServerStackFixture = _cirros.CirrosSameHostServerStackFixture
|
||||
|
||||
NetworkStackFixture = _neutron.NetworkStackFixture
|
||||
NetworkWithNetMtuWriteStackFixture = (
|
||||
|
|
|
@ -47,3 +47,19 @@ class CirrosServerStackFixture(_nova.ServerStackFixture):
|
|||
|
||||
#: Glance image used to create a Nova server instance
|
||||
flavor_stack = tobiko.required_setup_fixture(CirrosFlavorStackFixture)
|
||||
|
||||
|
||||
class CirrosPeerServerStackFixture(CirrosServerStackFixture,
|
||||
_nova.PeerServerStackFixture):
|
||||
#: Peer server used to reach this one
|
||||
peer_stack = tobiko.required_setup_fixture(CirrosServerStackFixture)
|
||||
|
||||
|
||||
class CirrosSameHostServerStackFixture(
|
||||
CirrosPeerServerStackFixture, _nova.SameHostServerStackFixture):
|
||||
pass
|
||||
|
||||
|
||||
class CirrosDifferentHostServerStackFixture(
|
||||
CirrosPeerServerStackFixture, _nova.DifferentHostServerStackFixture):
|
||||
pass
|
||||
|
|
|
@ -23,6 +23,7 @@ import tobiko
|
|||
from tobiko import config
|
||||
from tobiko.openstack import heat
|
||||
from tobiko.openstack import neutron
|
||||
from tobiko.openstack import nova
|
||||
from tobiko.openstack.stacks import _hot
|
||||
from tobiko.openstack.stacks import _neutron
|
||||
from tobiko.shell import ssh
|
||||
|
@ -134,20 +135,83 @@ class ServerStackFixture(heat.HeatStackFixture):
|
|||
|
||||
@property
|
||||
def has_floating_ip(self):
|
||||
"""Whenever to allocate floating IP for the server"""
|
||||
return bool(self.floating_network)
|
||||
|
||||
@property
|
||||
def ssh_client(self):
|
||||
client = ssh.ssh_client(host=self.floating_ip_address,
|
||||
username=self.username,
|
||||
password=self.password)
|
||||
return client
|
||||
return ssh.ssh_client(host=self.ip_address,
|
||||
username=self.username,
|
||||
password=self.password)
|
||||
|
||||
@property
|
||||
def ssh_command(self):
|
||||
return ssh.ssh_command(host=self.floating_ip_address,
|
||||
return ssh.ssh_command(host=self.ip_address,
|
||||
username=self.username)
|
||||
|
||||
@property
|
||||
def ip_address(self):
|
||||
if self.has_floating_ip:
|
||||
return self.floating_ip_address
|
||||
else:
|
||||
return self.outputs.fixed_ips[0]['ip_address']
|
||||
|
||||
#: Schedule on different host that this Nova server instance ID
|
||||
different_host = None
|
||||
|
||||
#: Schedule on same host as this Nova server instance ID
|
||||
same_host = None
|
||||
|
||||
@property
|
||||
def scheduler_hints(self):
|
||||
scheduler_hints = {}
|
||||
if self.different_host:
|
||||
scheduler_hints.update(different_host=self.different_host)
|
||||
if self.same_host:
|
||||
scheduler_hints.update(same_host=self.same_host)
|
||||
return scheduler_hints
|
||||
|
||||
@property
|
||||
def server_details(self):
|
||||
return nova.get_server(self.server_id)
|
||||
|
||||
|
||||
class PeerServerStackFixture(ServerStackFixture):
|
||||
"""Server witch networking access requires passing by a peer Nova server
|
||||
"""
|
||||
|
||||
has_floating_ip = False
|
||||
|
||||
#: Peer server used to reach this one
|
||||
peer_stack = None
|
||||
|
||||
@property
|
||||
def ssh_client(self):
|
||||
return ssh.ssh_client(host=self.ip_address,
|
||||
username=self.username,
|
||||
password=self.password,
|
||||
proxy_jump=self.peer_stack.ssh_client)
|
||||
|
||||
@property
|
||||
def ssh_command(self):
|
||||
return ssh.ssh_command(host=self.ip_address,
|
||||
username=self.username,
|
||||
proxy_command=self.peer_stack.ssh_command)
|
||||
|
||||
|
||||
class DifferentHostServerStackFixture(PeerServerStackFixture):
|
||||
|
||||
@property
|
||||
def different_host(self):
|
||||
return [self.peer_stack.server_id]
|
||||
|
||||
|
||||
class SameHostServerStackFixture(PeerServerStackFixture):
|
||||
|
||||
@property
|
||||
def same_host(self):
|
||||
return [self.peer_stack.server_id]
|
||||
|
||||
|
||||
def as_str(text):
|
||||
if isinstance(text, six.string_types):
|
||||
|
|
|
@ -53,6 +53,10 @@ parameters:
|
|||
constraints:
|
||||
- custom_constraint: neutron.network
|
||||
|
||||
scheduler_hints:
|
||||
type: json
|
||||
description: Hints to create server
|
||||
|
||||
|
||||
conditions:
|
||||
|
||||
|
@ -86,6 +90,7 @@ resources:
|
|||
flavor: {get_param: flavor}
|
||||
networks:
|
||||
- port: {get_resource: port}
|
||||
scheduler_hints: {get_param: scheduler_hints}
|
||||
|
||||
floating_ip:
|
||||
type: OS::Neutron::FloatingIP
|
||||
|
@ -115,3 +120,6 @@ outputs:
|
|||
|
||||
server_name:
|
||||
value: {get_attr: [server, name]}
|
||||
|
||||
server_id:
|
||||
value: {get_resource: server}
|
||||
|
|
|
@ -261,14 +261,17 @@ class SSHClientManager(object):
|
|||
# Put a placeholder client to avoid infinite recursive lookup
|
||||
self.clients[host_key] = None
|
||||
proxy_client = self.get_proxy_client(host=host,
|
||||
proxy_jump=proxy_jump,
|
||||
config_files=config_files)
|
||||
self.clients[host_key] = client = SSHClientFixture(
|
||||
host=host, hostname=hostname, port=port, username=username,
|
||||
proxy_client=proxy_client, **connect_parameters)
|
||||
return client
|
||||
|
||||
def get_proxy_client(self, host=None, host_config=None,
|
||||
def get_proxy_client(self, host=None, proxy_jump=None, host_config=None,
|
||||
config_files=None):
|
||||
if isinstance(proxy_jump, SSHClientFixture):
|
||||
return proxy_jump
|
||||
host_config = host_config or _config.ssh_host_config(
|
||||
host=host, config_files=config_files)
|
||||
proxy_host = host_config.proxy_jump
|
||||
|
|
|
@ -14,19 +14,20 @@
|
|||
# under the License.
|
||||
from __future__ import absolute_import
|
||||
|
||||
import testtools
|
||||
|
||||
import tobiko
|
||||
from tobiko import config
|
||||
from tobiko.shell import ping
|
||||
from tobiko.shell import sh
|
||||
from tobiko.openstack import neutron
|
||||
from tobiko.openstack import stacks
|
||||
from tobiko.tests import base
|
||||
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
class FloatingIPTest(base.TobikoTest):
|
||||
class FloatingIPTest(testtools.TestCase):
|
||||
"""Tests connectivity via floating IPs"""
|
||||
|
||||
#: Resources stack with floating IP and Nova server
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
# Copyright (c) 2019 Red Hat
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from __future__ import absolute_import
|
||||
|
||||
|
||||
import testtools
|
||||
|
||||
import tobiko
|
||||
from tobiko.openstack import stacks
|
||||
from tobiko.shell import sh
|
||||
|
||||
|
||||
class NetworkTest(testtools.TestCase):
|
||||
|
||||
#: Resources stack with Nova server to send messages to
|
||||
stack = tobiko.required_setup_fixture(stacks.CirrosPeerServerStackFixture)
|
||||
|
||||
def test_ssh(self):
|
||||
"""Test SSH connectivity to floating IP address"""
|
||||
result = sh.execute("hostname",
|
||||
ssh_client=self.stack.ssh_client)
|
||||
hostname = result.stdout.rstrip()
|
||||
self.assertEqual(self.stack.server_name.lower(), hostname)
|
||||
|
||||
|
||||
# --- Same compute host VM to VM scenario -------------------------------------
|
||||
|
||||
|
||||
class SameHostNetworkTest(NetworkTest):
|
||||
|
||||
#: Resources stack with Nova server to send messages to
|
||||
stack = tobiko.required_setup_fixture(
|
||||
stacks.CirrosSameHostServerStackFixture)
|
||||
|
||||
def test_same_host(self):
|
||||
sender = self.stack.peer_stack.server_details
|
||||
receiver = self.stack.server_details
|
||||
self.assertEqual({'same_host': [sender.id]},
|
||||
self.stack.scheduler_hints)
|
||||
self.assertEqual(getattr(sender, 'OS-EXT-SRV-ATTR:host'),
|
||||
getattr(receiver, 'OS-EXT-SRV-ATTR:host'))
|
||||
|
||||
|
||||
# --- Different compute host VM to VM scenario --------------------------------
|
||||
|
||||
|
||||
class DifferentHostNetworkTest(NetworkTest):
|
||||
|
||||
#: Resources stack with Nova server to send messages to
|
||||
stack = tobiko.required_setup_fixture(
|
||||
stacks.CirrosDifferentHostServerStackFixture)
|
||||
|
||||
def test_different_host(self):
|
||||
sender = self.stack.peer_stack.server_details
|
||||
receiver = self.stack.server_details
|
||||
self.assertEqual({'different_host': [sender.id]},
|
||||
self.stack.scheduler_hints)
|
||||
self.assertNotEqual(getattr(sender, 'OS-EXT-SRV-ATTR:host'),
|
||||
getattr(receiver, 'OS-EXT-SRV-ATTR:host'))
|
Loading…
Reference in New Issue