+ """Delete local tarball to prevent disk pollution.
+
+ :param tarball: Path to tarball to upload.
+ :type tarball: str
+ :returns: nothing
+ """
+ call(split('sh -c "rm {0} > /dev/null 2>&1"'.format(tarball)))
+
+
+def delete_openvpp_testing_stuff(node):
+ """Delete openvpp-testing directory and tarball in /tmp/ on given node.
+
+ :param node: Node to delete openvpp-testing stuff on.
+ :type node: dict
+ """
+ logger.console('Deleting openvpp-testing directory and tarball on {0}'
+ .format(node['host']))
+ ssh = SSH()
+ ssh.connect(node)
+ (ret_code, stdout, stderr) = ssh.exec_command(
+ 'cd {0} && sudo rm -rf openvpp-testing*'.format(
+ con.REMOTE_FW_DIR), timeout=100)
+ if ret_code != 0:
+ logger.console('Deleting opvenvpp-testing stuff failed on node {0}: {1}'
+ .format(node, stdout + stderr))
+
+
+def remove_env_directory_at_node(node):
+ """Remove virtualenv directory on given node.
+
+ :param node: Node to remove virtualenv on.
+ :type node: dict
+ """
+ logger.console('Removing virtualenv directory on {0}'.format(node['host']))
+ ssh = SSH()
+ ssh.connect(node)
+ (ret_code, stdout, stderr) = ssh.exec_command(
+ 'cd {0} && sudo rm -rf openvpp-testing*'
+ .format(con.REMOTE_FW_DIR), timeout=100)
+ if ret_code != 0:
+ logger.console('Virtualenv removing failed on node {0}: {1}'.format(
+ node, stdout + stderr))
+
+
+# pylint: disable=broad-except
+def cleanup_node(node):
+ """Run all clean-up methods for a node.
+
+ This method is used as map_async parameter. It receives tuple with all
+ parameters as passed to map_async function.
+
+ :param node: Node to do cleanup on.
+ :type node: dict
+ :returns: True - success, False - error
+ :rtype: bool
+ """
+ try:
+ delete_openvpp_testing_stuff(node)
+ if node['type'] == NodeType.TG:
+ remove_env_directory_at_node(node)
+ except Exception as exc:
+ logger.error("Node {0} cleanup failed, error:'{1}'".format(
+ node['host'], exc.message))
+ return False
+ else:
+ logger.console('Cleanup of node {0} done'.format(node['host']))
+ return True