~smoser/ubuntu/zesty/curtin/pkg

« back to all changes in this revision

Viewing changes to tools/vmtest-sync-images

  • Committer: Scott Moser
  • Date: 2016-02-12 22:07:36 UTC
  • mfrom: (1.1.33)
  • Revision ID: smoser@ubuntu.com-20160212220736-9xdkp6t1t8501fh0
Tags: 0.1.0~bzr351-0ubuntu1
releasing package curtin version 0.1.0~bzr351-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python3
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.
 
4
import errno
4
5
import os
 
6
import shutil
5
7
import sys
6
8
 
7
9
# Fix path so we can import ImageStore class.
8
10
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
9
11
 
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"
13
17
 
14
18
 
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)
 
26
                shutil.rmtree(fp)
 
27
        if os.path.exists(IMAGE_DIR):
 
28
            for dirpath, dirnames, filenames in os.walk(IMAGE_DIR):
 
29
                for f in filenames:
 
30
                    if f.startswith("vmtest"):
 
31
                        fpath = os.path.join(dirpath, f)
 
32
                        print(" removing vmtest file %s" % fpath)
 
33
                        os.unlink(fpath)
 
34
 
 
35
    releases = find_releases()
 
36
    release_filter = 'release~{}'.format('|'.join(releases))
 
37
    my_filters = ['arch=' + DEFAULT_ARCH, release_filter] + ITEM_NAME_FILTERS
20
38
    # Sync images.
21
 
    store.sync_images(filters=DEFAULT_FILTERS)
 
39
    sync_images(IMAGE_SRC_URL, IMAGE_DIR, filters=my_filters, verbosity=1)