aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--resources/libraries/bash/entry/per_patch_perf.sh4
-rw-r--r--resources/libraries/bash/function/common.sh13
-rwxr-xr-xresources/tools/scripts/topo_cleanup.py137
3 files changed, 2 insertions, 152 deletions
diff --git a/resources/libraries/bash/entry/per_patch_perf.sh b/resources/libraries/bash/entry/per_patch_perf.sh
index 8c9d7d2ca3..95b067bbd3 100644
--- a/resources/libraries/bash/entry/per_patch_perf.sh
+++ b/resources/libraries/bash/entry/per_patch_perf.sh
@@ -68,7 +68,7 @@ for ((iter=0; iter<iterations; iter++)); do
if ((iter)); then
# Function reserve_and_cleanup_testbed has already cleaned it once,
# but we need to clean it explicitly on subsequent iterations.
- cleanup_topo
+ ansible_hosts "cleanup" || die
fi
# Testing current first. Good for early failures or for API changes.
select_build "build_current" || die
@@ -78,7 +78,7 @@ for ((iter=0; iter<iterations; iter++)); do
archive_parse_test_results "csit_current/${iter}" || die
die_on_pybot_error || die
# TODO: Use less heavy way to avoid apt remove failures.
- cleanup_topo
+ ansible_hosts "cleanup" || die
select_build "build_parent" || die
check_download_dir || die
run_pybot || die
diff --git a/resources/libraries/bash/function/common.sh b/resources/libraries/bash/function/common.sh
index 93adda7e0c..491b47fb48 100644
--- a/resources/libraries/bash/function/common.sh
+++ b/resources/libraries/bash/function/common.sh
@@ -182,19 +182,6 @@ function check_prerequisites () {
fi
}
-function cleanup_topo () {
-
- # Variables read:
- # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
- # - PYTHON_SCRIPTS_DIR - Path to directory holding the reservation script.
-
- set -exuo pipefail
-
- python "${PYTHON_SCRIPTS_DIR}/topo_cleanup.py" -t "${WORKING_TOPOLOGY}"
- # Not using "|| die" as some callers might want to ignore errors,
- # e.g. in teardowns, such as unreserve.
-}
-
function common_dirs () {
diff --git a/resources/tools/scripts/topo_cleanup.py b/resources/tools/scripts/topo_cleanup.py
deleted file mode 100755
index 89055944c5..0000000000
--- a/resources/tools/scripts/topo_cleanup.py
+++ /dev/null
@@ -1,137 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright (c) 2019 Cisco and/or its affiliates.
-# 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.
-
-"""This script provides cleanup routines on all DUTs."""
-
-import argparse
-import sys
-from platform import dist
-from yaml import load
-
-from resources.libraries.python.ssh import SSH
-
-
-def execute_command_ssh(ssh, cmd, sudo=False):
- """Execute a command over ssh channel, and print outputs.
-
- :param ssh: SSH() object connected to a node.
- :param cmd: Command line to execute on remote node.
- :param sudo: Run command with sudo privilege level..
- :type ssh: SSH() object
- :type cmd: str
- :type sudo: bool
- :returns return_code, stdout, stderr
- :rtype: tuple(int, str, str)
- """
- if sudo:
- ret, stdout, stderr = ssh.exec_command_sudo(cmd, timeout=60)
- else:
- ret, stdout, stderr = ssh.exec_command(cmd, timeout=60)
-
- print 'Executing: {cmd}'.format(cmd=cmd)
- print '({ret}) {stdout} {stderr}'.format(ret=ret, stdout=stdout,
- stderr=stderr)
-
- return ret, stdout, stdout
-
-
-def uninstall_package(ssh, package):
- """If there are packages installed, clean them up.
-
- :param ssh: SSH() object connected to a node.
- :param package: Package name.
- :type ssh: SSH() object
- :type package: str
- """
- if dist()[0] == 'Ubuntu':
- ret, _, _ = ssh.exec_command("dpkg -l | grep {package}".format(
- package=package))
- if ret == 0:
- # Try to fix interrupted installations first.
- execute_command_ssh(ssh, 'dpkg --configure -a', sudo=True)
- # Try to remove installed packages
- execute_command_ssh(ssh, 'apt-get purge -y "*{package}*"'.format(
- package=package), sudo=True)
-
-
-def kill_process(ssh, process):
- """If there are running processes, kill them.
-
- :param ssh: SSH() object connected to a node.
- :param process: Process name.
- :type ssh: SSH() object
- :type process: str
- """
- execute_command_ssh(ssh, 'killall -v -s 9 {process}'.format(
- process=process), sudo=True)
-
-
-def main():
- """Testbed cleanup."""
-
- parser = argparse.ArgumentParser()
- parser.add_argument("-t", "--topo", required=True, help="Topology file")
-
- args = parser.parse_args()
- topology_file = args.topo
-
- topology = load(open(topology_file).read())['nodes']
-
- ssh = SSH()
- for node in topology:
- if topology[node]['type'] == "DUT":
- print "###TI host: {}".format(topology[node]['host'])
- ssh.connect(topology[node])
-
- # Kill processes.
- kill_process(ssh, 'qemu')
- kill_process(ssh, 'l3fwd')
- kill_process(ssh, 'testpmd')
-
- # Uninstall packages
- uninstall_package(ssh, 'vpp')
- uninstall_package(ssh, 'honeycomb')
-
- # Remove HC logs.
- execute_command_ssh(
- ssh, 'rm -rf /var/log/honeycomb', sudo=True)
-
- # Kill all containers.
- execute_command_ssh(
- ssh, 'docker rm --force $(sudo docker ps -q)', sudo=True)
-
- # Destroy kubernetes.
- execute_command_ssh(
- ssh, 'kubeadm reset --force', sudo=True)
-
- # Remove corefiles leftovers.
- execute_command_ssh(
- ssh, 'rm -f /tmp/*tar.lzo.lrz.xz*', sudo=True)
-
- # Remove corefiles leftovers.
- execute_command_ssh(
- ssh, 'rm -f /tmp/*core*', sudo=True)
-
- # Set interfaces in topology down.
- for interface in topology[node]['interfaces']:
- pci = topology[node]['interfaces'][interface]['pci_address']
- execute_command_ssh(
- ssh, "[[ -d {path}/{pci}/net ]] && "
- "sudo ip link set $(basename {path}/{pci}/net/*) down".
- format(pci=pci, path='/sys/bus/pci/devices'))
-
-
-if __name__ == "__main__":
- sys.exit(main())