2
2
# This tool keeps a local copy of the maas images used by vmtests.
3
3
# It keeps only the latest copy of the available images.
7
9
# Fix path so we can import ImageStore class.
8
10
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
10
12
from tests.vmtests import (
11
ImageStore, IMAGE_DIR, IMAGE_SRC_URL, DEFAULT_FILTERS)
13
IMAGE_DIR, IMAGE_SRC_URL, sync_images)
14
from tests.vmtests.image_sync import ITEM_NAME_FILTERS
12
15
from tests.vmtests.helpers import find_releases
16
DEFAULT_ARCH = "amd64"
15
19
if __name__ == '__main__':
16
# Instantiate the ImageStore object.
17
store = ImageStore(IMAGE_SRC_URL, IMAGE_DIR)
18
release_filter = 'release~{}'.format('|'.join(find_releases()))
19
DEFAULT_FILTERS.append(release_filter)
20
if len(sys.argv) > 1 and sys.argv[1] == "--clean":
21
print("cleaning image dir %s" % IMAGE_DIR)
22
for subd in (".vmtest-data", "streams"):
23
fp = os.path.join(IMAGE_DIR, subd)
24
if os.path.exists(fp):
25
print(" removing %s" % subd)
27
if os.path.exists(IMAGE_DIR):
28
for dirpath, dirnames, filenames in os.walk(IMAGE_DIR):
30
if f.startswith("vmtest"):
31
fpath = os.path.join(dirpath, f)
32
print(" removing vmtest file %s" % fpath)
35
releases = find_releases()
36
release_filter = 'release~{}'.format('|'.join(releases))
37
my_filters = ['arch=' + DEFAULT_ARCH, release_filter] + ITEM_NAME_FILTERS
21
store.sync_images(filters=DEFAULT_FILTERS)
39
sync_images(IMAGE_SRC_URL, IMAGE_DIR, filters=my_filters, verbosity=1)