• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python2
2# Copyright 2017 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import os
7
8import common
9from autotest_lib.client.bin import utils
10from autotest_lib.client.common_lib import error
11from autotest_lib.site_utils import lxc
12from autotest_lib.site_utils.lxc import utils as lxc_utils
13
14
15TEST_CONTAINER_PATH = os.path.join(lxc.DEFAULT_CONTAINER_PATH, 'test')
16TEST_HOST_PATH = os.path.join(TEST_CONTAINER_PATH, 'host')
17
18def main():
19    """Clean up the remnants from any old aborted unit tests."""
20    # Manually clean out the host dir.
21    if lxc_utils.path_exists(TEST_HOST_PATH):
22        for host_dir in os.listdir(TEST_HOST_PATH):
23            host_dir = os.path.realpath(os.path.join(TEST_HOST_PATH, host_dir))
24            try:
25                utils.run('sudo umount %s' % host_dir)
26            except error.CmdError:
27                pass
28            utils.run('sudo rm -r %s' % host_dir)
29
30    # Utilize the container_bucket to clear out old test containers.
31    bucket = lxc.ContainerBucket(TEST_CONTAINER_PATH, TEST_HOST_PATH)
32    bucket.destroy_all()
33
34
35if __name__ == '__main__':
36    main()
37