Add ssh_client option to Octavia validators module
So far Octavia validators module didn't allow sending requests from given ssh clients (it used only the client_stack's ssh). This patch adds the option of providing an ssh_client parameter to the validators' request function. Change-Id: I24c259b569b3b0df09c319d2d1288de97d1ec5b3
This commit is contained in:
@@ -17,10 +17,9 @@ from __future__ import absolute_import
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
import netaddr
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
from tobiko.openstack import octavia
|
|
||||||
from tobiko.shell import ssh
|
|
||||||
from tobiko.shell import sh
|
from tobiko.shell import sh
|
||||||
|
|
||||||
|
|
||||||
@@ -28,34 +27,21 @@ LOG = log.getLogger(__name__)
|
|||||||
CURL_OPTIONS = "-f --connect-timeout 2 -g"
|
CURL_OPTIONS = "-f --connect-timeout 2 -g"
|
||||||
|
|
||||||
|
|
||||||
def request(client_stack, server_ip_address, protocol, server_port):
|
def request(client_stack, ip_address, protocol, port, ssh_client=None):
|
||||||
"""Perform a request on a server.
|
ssh_client = ssh_client or client_stack.ssh_client
|
||||||
|
|
||||||
Returns the response in case of success, throws an RequestException
|
if netaddr.IPAddress(ip_address) == 6:
|
||||||
otherwise.
|
ip_address = f"[{ip_address}]"
|
||||||
"""
|
|
||||||
if ':' in server_ip_address:
|
|
||||||
# Add square brackets around IPv6 address to please curl
|
|
||||||
server_ip_address = "[{}]".format(server_ip_address)
|
|
||||||
cmd = "curl {} {}://{}:{}/id".format(
|
|
||||||
CURL_OPTIONS, protocol.lower(), server_ip_address, server_port)
|
|
||||||
|
|
||||||
ssh_client = ssh.ssh_client(
|
cmd = f"curl {CURL_OPTIONS} {protocol.lower()}://{ip_address}:{port}/id"
|
||||||
client_stack.floating_ip_address,
|
|
||||||
username=client_stack.image_fixture.username)
|
|
||||||
|
|
||||||
ret = sh.ssh_execute(ssh_client, cmd)
|
return sh.ssh_execute(ssh_client, cmd).stdout
|
||||||
if ret.exit_status != 0:
|
|
||||||
raise octavia.RequestException(command=cmd,
|
|
||||||
error=ret.stderr)
|
|
||||||
|
|
||||||
return ret.stdout
|
|
||||||
|
|
||||||
|
|
||||||
def check_members_balanced(pool_stack, client_stack,
|
def check_members_balanced(pool_stack, client_stack,
|
||||||
members_count,
|
members_count,
|
||||||
loadbalancer_vip, loadbalancer_protocol,
|
loadbalancer_vip, loadbalancer_protocol,
|
||||||
loadbalancer_port):
|
loadbalancer_port, ssh_client=None):
|
||||||
|
|
||||||
"""Check if traffic is properly balanced between members."""
|
"""Check if traffic is properly balanced between members."""
|
||||||
|
|
||||||
@@ -66,7 +52,7 @@ def check_members_balanced(pool_stack, client_stack,
|
|||||||
for _ in range(members_count * 10):
|
for _ in range(members_count * 10):
|
||||||
content = request(
|
content = request(
|
||||||
client_stack, loadbalancer_vip,
|
client_stack, loadbalancer_vip,
|
||||||
loadbalancer_protocol, loadbalancer_port)
|
loadbalancer_protocol, loadbalancer_port, ssh_client)
|
||||||
|
|
||||||
if content not in replies:
|
if content not in replies:
|
||||||
replies[content] = 0
|
replies[content] = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user