/usr/lib/python3/dist-packages/provisioningserver/import_images/testing/factory.py is in python3-maas-provisioningserver 2.0.0~beta3+bzr4941-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | # Copyright 2014-2015 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Factory helpers for the `import_images` package."""
__all__ = [
'make_boot_resource',
'make_image_spec',
'make_maas_meta',
'make_maas_meta_without_os',
'set_resource',
]
from textwrap import dedent
from maastesting.factory import factory
from provisioningserver.import_images.boot_image_mapping import (
BootImageMapping,
)
from provisioningserver.import_images.helpers import ImageSpec
def make_maas_meta():
"""Return fake maas.meta data."""
return dedent("""\
{"ubuntu": {"amd64": {"generic": {"precise": {"release": {"content_id": "com.ubuntu.maas:v2:download", "path": "precise/amd64/20140410/raring/generic/boot-kernel", "product_name": "com.ubuntu.maas:v2:boot:12.04:amd64:hwe-r", "subarches": "generic,hwe-p,hwe-q,hwe-r", "version_name": "20140410"}}, "trusty": {"release": {"content_id": "com.ubuntu.maas:v2:download", "path": "trusty/amd64/20140416.1/root-image.gz", "product_name": "com.ubuntu.maas:v2:boot:14.04:amd64:hwe-t", "subarches": "generic,hwe-p,hwe-q,hwe-r,hwe-s,hwe-t", "version_name": "20140416.1"}}}, "hwe-s": {"precise": {"release": {"content_id": "com.ubuntu.maas:v2:download", "path": "precise/amd64/20140410/saucy/generic/boot-kernel", "product_name": "com.ubuntu.maas:v2:boot:12.04:amd64:hwe-s", "subarches": "generic,hwe-p,hwe-q,hwe-r,hwe-s", "version_name": "20140410"}}}}}}""") # NOQA
def make_maas_meta_without_os():
"""Return fake maas.meta data, without the os field."""
return dedent("""\
{"amd64": {"generic": {"precise": {"release": {"content_id": "com.ubuntu.maas:v2:download", "path": "precise/amd64/20140410/raring/generic/boot-kernel", "product_name": "com.ubuntu.maas:v2:boot:12.04:amd64:hwe-r", "subarches": "generic,hwe-p,hwe-q,hwe-r", "version_name": "20140410"}}, "trusty": {"release": {"content_id": "com.ubuntu.maas:v2:download", "path": "trusty/amd64/20140416.1/root-image.gz", "product_name": "com.ubuntu.maas:v2:boot:14.04:amd64:hwe-t", "subarches": "generic,hwe-p,hwe-q,hwe-r,hwe-s,hwe-t", "version_name": "20140416.1"}}}, "hwe-s": {"precise": {"release": {"content_id": "com.ubuntu.maas:v2:download", "path": "precise/amd64/20140410/saucy/generic/boot-kernel", "product_name": "com.ubuntu.maas:v2:boot:12.04:amd64:hwe-s", "subarches": "generic,hwe-p,hwe-q,hwe-r,hwe-s", "version_name": "20140410"}}}}}""") # NOQA
def make_boot_resource():
"""Create a fake resource dict."""
return {
'content_id': factory.make_name('content_id'),
'product_name': factory.make_name('product_name'),
'version_name': factory.make_name('version_name'),
}
def make_image_spec(os=None, arch=None, subarch=None, release=None,
label=None):
"""Return an `ImageSpec` with random values."""
if os is None:
os = factory.make_name('os')
if arch is None:
arch = factory.make_name('arch')
if subarch is None:
subarch = factory.make_name('subarch')
if release is None:
release = factory.make_name('release')
if label is None:
label = factory.make_name('label')
return ImageSpec(os, arch, subarch, release, label)
def set_resource(boot_dict=None, image_spec=None, resource=None):
"""Add boot resource to a `BootImageMapping`, creating it if necessary."""
if boot_dict is None:
boot_dict = BootImageMapping()
if image_spec is None:
image_spec = make_image_spec()
if resource is None:
resource = factory.make_name('boot-resource')
boot_dict.mapping[image_spec] = resource
return boot_dict
|