Ben Kwa | c0ce545 | 2017-07-12 12:12:46 +0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 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 | |
| 6 | import os |
| 7 | |
| 8 | import common |
| 9 | from autotest_lib.client.bin import utils |
| 10 | from autotest_lib.client.common_lib import error |
| 11 | from autotest_lib.site_utils import lxc |
| 12 | from autotest_lib.site_utils.lxc import utils as lxc_utils |
| 13 | |
| 14 | |
| 15 | TEST_CONTAINER_PATH = os.path.join(lxc.DEFAULT_CONTAINER_PATH, 'test') |
| 16 | TEST_HOST_PATH = os.path.join(TEST_CONTAINER_PATH, 'host') |
| 17 | |
| 18 | def 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 | |
| 35 | if __name__ == '__main__': |
| 36 | main() |