aboutsummaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
authorPeter Mikus <pmikus@cisco.com>2018-07-30 17:28:16 +0000
committerJan Gelety <jgelety@cisco.com>2018-08-10 09:16:13 +0000
commit325bf96ce5fc13780fab0731855a2e2092208a2b (patch)
tree16c8c679c890dc7e0f18ec63a7a3f6c39cbec4cd /resources
parent8f5f344d59674ea4c158e8ff1528716276f5b071 (diff)
CSIT-1193 De-duplicate bootstrap scripts into one
- DPDK and VPP bootstrap merged into one (ligato will follow). - Added more error detections - Added topo-cleanup.py to cleanup TB before and after test. - Remove installation of VPP Change-Id: I7a86117eb03cbe4ee8fde47baeed58bc86c0dfb2 Signed-off-by: Peter Mikus <pmikus@cisco.com>
Diffstat (limited to 'resources')
-rw-r--r--resources/libraries/python/ContainerUtils.py9
-rw-r--r--resources/libraries/python/SetupFramework.py2
-rwxr-xr-xresources/tools/scripts/topo_cleanup.py118
3 files changed, 125 insertions, 4 deletions
diff --git a/resources/libraries/python/ContainerUtils.py b/resources/libraries/python/ContainerUtils.py
index 9a141767b9..eadc0a8a5a 100644
--- a/resources/libraries/python/ContainerUtils.py
+++ b/resources/libraries/python/ContainerUtils.py
@@ -329,12 +329,15 @@ class ContainerEngine(object):
if self.container.install_dkms:
self.execute(
'apt-get install -y dkms && '
- 'dpkg -i --force-all {guest_dir}/install_dir/*.deb'.
+ 'dpkg -i --force-all '
+ '{guest_dir}/openvpp-testing/download_dir/*.deb'.
format(guest_dir=self.container.mnt[0].split(':')[1]))
else:
self.execute(
- 'for i in $(ls -I \"*dkms*\" {guest_dir}/install_dir/); do '
- 'dpkg -i --force-all {guest_dir}/install_dir/$i; done'.
+ 'for i in $(ls -I \"*dkms*\" '
+ '{guest_dir}/openvpp-testing/download_dir/); do '
+ 'dpkg -i --force-all '
+ '{guest_dir}/openvpp-testing/download_dir/$i; done'.
format(guest_dir=self.container.mnt[0].split(':')[1]))
self.execute('apt-get -f install -y')
self.execute('apt-get install -y ca-certificates')
diff --git a/resources/libraries/python/SetupFramework.py b/resources/libraries/python/SetupFramework.py
index 558d5d4097..46b8597e87 100644
--- a/resources/libraries/python/SetupFramework.py
+++ b/resources/libraries/python/SetupFramework.py
@@ -56,7 +56,7 @@ def pack_framework_dir():
proc = Popen(
split("tar --sparse --exclude-vcs --exclude=output*.xml "
- "--exclude=./tmp --exclude=*.deb --exclude=*.rpm -zcf {0} ."
+ "--exclude=./tmp -zcf {0} ."
.format(file_name)), stdout=PIPE, stderr=PIPE)
(stdout, stderr) = proc.communicate()
diff --git a/resources/tools/scripts/topo_cleanup.py b/resources/tools/scripts/topo_cleanup.py
new file mode 100755
index 0000000000..c708a5d4b6
--- /dev/null
+++ b/resources/tools/scripts/topo_cleanup.py
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2018 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 $(sudo docker ps -a -q)',
+ sudo=True)
+
+ # Destroy kubernetes.
+ execute_command_ssh(ssh, 'kubeadm reset --force',
+ sudo=True)
+
+if __name__ == "__main__":
+ sys.exit(main())