/
vmimage.rst
117 lines (89 loc) · 3.53 KB
/
vmimage.rst
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
avocado.utils.vmimage
=====================
This utility provides a API to download/cache VM images (QCOW) from the
official distributions repositories.
Basic Usage
-----------
Import ``vmimage`` module::
>>> from avocado.utils import vmimage
Get an image, which consists in an object with the path of the downloaded/cached
base image and the path of the external snapshot created out of that base
image::
>>> image = vmimage.get()
>>> image
<Image name=Fedora version=26 arch=x86_64>
>>> image.name
'Fedora'
>>> image.path
'/tmp/Fedora-Cloud-Base-26-1.5.x86_64-d369c285.qcow2'
>>> image.get()
'/tmp/Fedora-Cloud-Base-26-1.5.x86_64-e887c743.qcow2'
>>> image.path
'/tmp/Fedora-Cloud-Base-26-1.5.x86_64-e887c743.qcow2'
>>> image.version
26
>>> image.base_image
'/tmp/Fedora-Cloud-Base-26-1.5.x86_64.qcow2'
If you provide more details about the image, the object is expected to
reflect those details::
>>> image = vmimage.get(arch='aarch64')
>>> image
<Image name=FedoraSecondary version=26 arch=aarch64>
>>> image.name
'FedoraSecondary'
>>> image.path
'/tmp/Fedora-Cloud-Base-26-1.5.aarch64-07b8fbda.qcow2'
>>> image = vmimage.get(version=7)
>>> image
<Image name=CentOS version=7 arch=x86_64>
>>> image.path
'/tmp/CentOS-7-x86_64-GenericCloud-1708-dd8139c5.qcow2'
Notice that, unlike the ``base_image`` attribute, the ``path`` attribute
will be always different in each instance, as it actually points to an
external snapshot created out of the base image::
>>> i1 = vmimage.get()
>>> i2 = vmimage.get()
>>> i1.path == i2.path
False
Custom Image Provider
---------------------
If you need your own Image Provider, you can extend the
``vmimage.IMAGE_PROVIDERS`` list, including your provider class. For instance,
using the ``vmimage`` utility in an Avocado test, we could add our own provider
with::
from avocado import Test
from avocado.utils import vmimage
class MyProvider(vmimage.ImageProviderBase):
name = 'MyDistro'
def __init__(self, version='[0-9]+', build='[0-9]+.[0-9]+',
arch=os.uname()[4]):
"""
:params version: The regular expression that represents
your distro version numbering.
:params build: The regular expression that represents
your build version numbering.
:params arch: The default architecture to look images for.
"""
super(MyProvider, self).__init__(version, build, arch)
# The URL which contains a list of the distro versions
self.url_versions = 'https://dl.fedoraproject.org/pub/fedora/linux/releases/'
# The URL which contains a list of distro images
self.url_images = self.url_versions + '{version}/CloudImages/{arch}/images/'
# The images naming pattern
self.image_pattern = 'Fedora-Cloud-Base-{version}-{build}.{arch}.qcow2$'
class MyTest(Test):
def setUp(self):
vmimage.IMAGE_PROVIDERS.add(MyProvider)
image = vmimage.get('MyDistro')
...
def test(self):
...
.. _avocado.utils.vmimage.supported_images:
Supported images
----------------
The vmimage library has no hardcoded limitations of versions or architectures
that can be supported. You can use it as you wish. This is the list of images
that we tested and they work with vmimage:
.. csv-table::
:file: ./data/vmimage/supported_images.csv
:header-rows: 1