simplify ssh code

We create a new fuction in dynamic utils for ssh functionality
which other files can use.

Logging router and network which we use in every 5th iteration
for the resources will help for debugging.

Change-Id: Iddc4a1a410670b902f0bc1154a1d28a58b00dcda
This commit is contained in:
venkata anil 2021-09-29 16:40:17 +05:30
parent 73380ad35d
commit 57baa24e73
3 changed files with 19 additions and 25 deletions

View File

@ -45,6 +45,15 @@ class NovaUtils(vm_utils.VMScenario):
log_msg = " DYNAMIC_WORKLOADS ITER: {} {} ".format(self.context["iteration"], msg)
LOG.error(log_msg)
def get_ssh(self, user, ip, password=None, timeout=300, interval=5):
if password:
ssh = sshutils.SSH(user, ip, password=password)
else:
ssh = sshutils.SSH(user, ip, pkey=self.context["user"]["keypair"]["private"])
self._wait_for_ssh(ssh, timeout=timeout, interval=interval)
return ssh
def _run_command_with_attempts(self, ssh_connection, cmd, max_attempts=120, timeout=2):
"""Run command over ssh connection with multiple attempts
:param ssh_connection: ssh connection to run command
@ -93,7 +102,6 @@ class NovaUtils(vm_utils.VMScenario):
:param port_id: id of port to ping from jumphost
:param success_on_ping_failure: bool, flag to ping till failure/success
"""
keypair = self.context["user"]["keypair"]
if not(success_on_ping_failure):
fip_update_dict = {"port_id": port_id}
self.clients("neutron").update_floatingip(
@ -101,8 +109,7 @@ class NovaUtils(vm_utils.VMScenario):
)
address = fip["floating_ip_address"]
jumphost_ssh = sshutils.SSH(jumphost_user, jumphost_fip, pkey=keypair["private"])
self._wait_for_ssh(jumphost_ssh)
jumphost_ssh = self.get_ssh(jumphost_user, jumphost_fip)
cmd = f"ping -c1 -w1 {address}"
if success_on_ping_failure:
self._run_command_until_failure(jumphost_ssh, cmd)

View File

@ -12,8 +12,6 @@
import random
from rally.common import sshutils
import dynamic_utils
# This test simulates trunk subports using vlan interfaces inside the VM.
@ -53,10 +51,7 @@ class TrunkDynamicScenario(
:param gateway: network gateway
"""
script = f"sudo ip r a {dest_vm} via {gateway} dev eth0.{subport_number}"
source_ssh = sshutils.SSH(
local_vm_user, local_vm, pkey=self.keypair["private"]
)
self._wait_for_ssh(source_ssh)
source_ssh = self.get_ssh(local_vm_user, local_vm)
self._run_command_with_attempts(source_ssh, script)
def delete_route_from_vm_to_jumphost(self, local_vm, dest_vm, local_vm_user,
@ -69,10 +64,7 @@ class TrunkDynamicScenario(
:param gateway: network gateway
"""
script = f"sudo ip r d {dest_vm} via {gateway} dev eth0.{subport_number}"
source_ssh = sshutils.SSH(
local_vm_user, local_vm, pkey=self.keypair["private"]
)
self._wait_for_ssh(source_ssh)
source_ssh = self.get_ssh(local_vm_user, local_vm)
self._run_command_with_attempts(source_ssh, script)
def simulate_subport_connection(self, trunk_id, vm_fip, jump_fip):
@ -236,11 +228,7 @@ class TrunkDynamicScenario(
"created".format(vm, trunk["trunk"], parent["port"],
subports, jump_host)
self.log_info(msg)
vm_ssh = sshutils.SSH(self.trunk_vm_user,
vm_fip, pkey=self.keypair["private"])
# centos7 image is taking 2 minutes for cloud-init and 4 minutes
# for the ssh availability
self._wait_for_ssh(vm_ssh, timeout=240, interval=5)
vm_ssh = self.get_ssh(self.trunk_vm_user, vm_fip)
self.add_subports_to_trunk_and_vm(subports, trunk["trunk"]["id"], vm_ssh, 1)
@ -279,10 +267,7 @@ class TrunkDynamicScenario(
trunk_server_fip = self.get_server_by_trunk(trunk)
jump_fip = self.get_jumphost_by_trunk(trunk)
vm_ssh = sshutils.SSH(
self.trunk_vm_user, trunk_server_fip, pkey=self.keypair["private"]
)
self._wait_for_ssh(vm_ssh)
vm_ssh = self.get_ssh(self.trunk_vm_user, trunk_server_fip)
self.add_subports_to_trunk_and_vm(subports, trunk["id"],
vm_ssh, len(trunk["sub_ports"])+1)
@ -331,9 +316,7 @@ class TrunkDynamicScenario(
trunk_server_fip = self.get_server_by_trunk(trunk)
jump_fip = self.get_jumphost_by_trunk(trunk)
vm_ssh = sshutils.SSH(self.trunk_vm_user,
trunk_server_fip, pkey=self.keypair["private"])
self._wait_for_ssh(vm_ssh)
vm_ssh = self.get_ssh(self.trunk_vm_user, trunk_server_fip)
trunk_subports = trunk['sub_ports']
num_trunk_subports = len(trunk_subports)

View File

@ -92,6 +92,10 @@ class VMDynamicScenario(dynamic_utils.NovaUtils,
router = self.get_router_from_context()
network = self.get_network_from_context()
subnet = self.get_subnet_from_context()
self.log_info("Re-use iteration: {} tenant: {} network: {} router: {}".format(
self.context["iteration"], self.context["tenant"]["id"],
self.context["tenant"]["networks"][0]["id"],
self.context["tenant"]["networks"][0]["router_id"]))
else:
router = self.router
network = self._create_network(network_create_args or {})