Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP | Consolidating fabric operations related methods #56

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 16 additions & 18 deletions common/neutron/lbaas/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from common.neutron.base import BaseNeutronTest
from tcutils.commands import ssh, execute_cmd, execute_cmd_out
from fabric.context_managers import settings, hide
from tcutils.util import run_cmd_through_node, retry
from tcutils.util import run_cmd, retry
from fabric.exceptions import CommandTimeout
import re
from time import sleep
Expand Down Expand Up @@ -102,21 +101,20 @@ def start_simpleHTTPserver(self, servers):
for server in servers:
cmd1 = 'hostname > index.html'
cmd2 = 'python -m SimpleHTTPServer 80 &> /tmp/http.log'
run_cmd_through_node(host_string='%s@%s'%(server.vm_username,
server.local_ip),
password=server.vm_password, cmd=cmd1,
gateway='@'.join([self.inputs.username,
server.vm_node_ip]),
gateway_password=self.inputs.password,
cd='/tmp')
run_cmd(host_string='%s@%s'%(server.vm_username,
server.local_ip),
password=server.vm_password, cmd=cmd1,
gateway='@'.join([self.inputs.username,
server.vm_node_ip]),
gateway_password=self.inputs.password, cwd='/tmp')
try:
run_cmd_through_node(host_string = '%s@%s'%(server.vm_username,
server.local_ip),
password=server.vm_password, cmd=cmd2,
gateway='@'.join([self.inputs.username,
server.vm_node_ip]),
gateway_password=self.inputs.password,
with_sudo=True, timeout=1, cd='/tmp')
run_cmd(host_string = '%s@%s'%(server.vm_username,
server.local_ip),
password=server.vm_password, cmd=cmd2,
gateway='@'.join([self.inputs.username,
server.vm_node_ip]),
gateway_password=self.inputs.password,
with_sudo=True, timeout=1, cwd='/tmp')
except CommandTimeout:
pass
return
Expand All @@ -127,7 +125,7 @@ def run_wget(self, vm, vip):
result = False
cmd1 = 'wget http://%s' % vip
cmd2 = 'cat index.html'
result = run_cmd_through_node(
result = run_cmd(
host_string='%s@%s'%(vm.vm_username, vm.local_ip),
password=vm.vm_password, cmd=cmd1,
gateway='@'.join([self.inputs.username, vm.vm_node_ip]),
Expand All @@ -137,7 +135,7 @@ def run_wget(self, vm, vip):
if result.count('200 OK'):
result = True
self.logger.info("connections to vip %s successful" % (vip))
response = run_cmd_through_node(
response = run_cmd(
host_string='%s@%s'%(vm.vm_username, vm.local_ip),
password=vm.vm_password, cmd=cmd2,
gateway='@'.join([self.inputs.username, vm.vm_node_ip]),
Expand Down
29 changes: 11 additions & 18 deletions fixtures/vm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ def ping_to_ip(self, ip, return_output=False, other_opt='', size='56', count='5'
vm_host_string = '%s@%s' % (self.vm_username, self.local_ip)
if af is None:
cmd = """python -c 'import socket;socket.getaddrinfo("%s", None, socket.AF_INET6)'""" % ip
output = run_cmd_through_node(
output = run_cmd(
vm_host_string, cmd, gateway_password=host['password'],
gateway='%s@%s' % (host['username'], self.vm_node_ip),
with_sudo=True
Expand All @@ -1039,7 +1039,7 @@ def ping_to_ip(self, ip, return_output=False, other_opt='', size='56', count='5'
util, str(size), str(count), other_opt, ip
)

output = run_cmd_through_node(
output = run_cmd(
vm_host_string, cmd, gateway_password=host['password'],
gateway='%s@%s' % (host['username'], self.vm_node_ip),
with_sudo=True
Expand Down Expand Up @@ -1714,21 +1714,14 @@ def scp_file_to_vm(self, file, vm_ip, dest_vm_username='ubuntu'):
timeout = math.floor(40 * float(delay_factor))

try:
self.orch.put_key_file_to_host(self.vm_node_ip)
with hide('everything'):
with settings(host_string='%s@%s' % (
host['username'], self.vm_node_ip),
password=host['password'],
warn_only=True, abort_on_prompts=False):
self.get_rsa_to_vm()
i = 'timeout %d scp -o StrictHostKeyChecking=no -i id_rsa %s %s@[%s]:' % (
timeout, file, dest_vm_username, vm_ip)
cmd_outputs = self.run_cmd_on_vm(
cmds=[i], timeout=timeout + 10)
self.logger.debug(cmd_outputs)
i = 'timeout %d scp -o StrictHostKeyChecking=no %s %s@[%s]:' % (
timeout, file, dest_vm_username, vm_ip)
cmd_outputs = self.run_cmd_on_vm(
cmds=[i], timeout=timeout + 10)
self.logger.debug(cmd_outputs)
except Exception, e:
self.logger.exception(
'Exception occured while trying to scp the file ')
'Exception occured while trying to scp the file\n%s' % e)
# end scp_file_to_vm

def put_pub_key_to_vm(self):
Expand Down Expand Up @@ -1887,7 +1880,7 @@ def run_cmd_on_vm(self, cmds=[], as_sudo=False, timeout=30,
for cmd in cmdList:
self.logger.debug('Running Cmd on %s: %s' % (
self.vm_node_ip, cmd))
output = run_cmd_through_node(
output = run_cmd(
vm_host_string, cmd, gateway_password=host['password'],
gateway='%s@%s' % (host['username'], self.vm_node_ip),
with_sudo=as_sudo, timeout=timeout, as_daemon=as_daemon,
Expand Down Expand Up @@ -2196,13 +2189,13 @@ def start_webserver(self, listen_port=8000, content=None):
try:
vm_host_string = '%s@%s'%(self.vm_username, self.local_ip)
cmd = 'echo %s >& index.html'%(content or self.vm_name)
output = run_cmd_through_node(
output = run_cmd(
vm_host_string, cmd, gateway_password=host['password'],
gateway='%s@%s' % (host['username'], self.vm_node_ip),
with_sudo=True
)
cmd = 'python -m SimpleHTTPServer %d &> /dev/null' % listen_port
output = run_cmd_through_node(
output = run_cmd(
vm_host_string, cmd, gateway_password=host['password'],
gateway='%s@%s' % (host['username'], self.vm_node_ip),
with_sudo=True, as_daemon=True
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ linecache2
eventlet
nose
tabulate
fabric
netaddr
16 changes: 6 additions & 10 deletions run_ci.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash

source tools/common.sh

function die
{
Expand All @@ -13,13 +14,15 @@ function usage {
echo "Usage: $0 [OPTION]..."
echo "Run Contrail test suite"
echo ""
echo " -p, --prepare Run only preparation steps"
echo " -t, --parallel Run testr in parallel"
echo " -h, --help Print this usage message"
echo " -m, --send-mail Send the report at the end"
echo " -c, --concurrency Number of threads to be spawned"
echo " --contrail-fab-path Contrail fab path, default to /opt/contrail/utils"
echo " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr "
}

testrargs=""
debug=0
force=0
Expand All @@ -34,7 +37,7 @@ contrail_fab_path='/opt/contrail/utils'
test_tag='suite1'
export SCRIPT_TS=${SCRIPT_TS:-$(date +"%Y_%m_%d_%H_%M_%S")}

if ! options=$(getopt -o UthdC:lLmc: -l upload,parallel,help,debug,config:,logging,logging-config,send-mail,concurrency:,contrail-fab-path: -- "$@")
if ! options=$(getopt -o pUthdC:lLmc: -l prepare,upload,parallel,help,debug,config:,logging,logging-config,send-mail,concurrency:,contrail-fab-path: -- "$@")
then
# parse error
usage
Expand All @@ -45,6 +48,7 @@ eval set -- $options
first_uu=yes
while [ $# -gt 0 ]; do
case "$1" in
-p|--prepare) prepare; exit;;
-h|--help) usage; exit;;
-U|--upload) upload=1;;
-d|--debug) debug=1;;
Expand All @@ -64,15 +68,7 @@ done
testrargs+=" $test_tag"
export TAGS="$test_tag"

if [ -n "$config_file" ]; then
config_file=`readlink -f "$config_file"`
export TEST_CONFIG_DIR=`dirname "$config_file"`
export TEST_CONFIG_FILE=`basename "$config_file"`
fi

if [ ! -f "$config_file" ]; then
python tools/configure.py $(readlink -f .) -p $contrail_fab_path
fi
prepare

if [ $logging -eq 1 ]; then
if [ ! -f "$logging_config" ]; then
Expand Down