~james-page/ubuntu/raring/nova/myfixes

« back to all changes in this revision

Viewing changes to nova/tests/test_image_utils.py

  • Committer: James Page
  • Author(s): Adam Gandelman, Adam Gandelman, Chuck Short
  • Date: 2012-10-31 13:49:10 UTC
  • mfrom: (1.1.66)
  • Revision ID: james.page@canonical.com-20121031134910-ifumii7temgy4vmd
Tags: 2013.1~g1~20121120.17206-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
#    Copyright (C) 2012 Yahoo! Inc. All Rights Reserved.
 
4
#
 
5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
6
#    not use this file except in compliance with the License. You may obtain
 
7
#    a copy of the License at
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
11
#    Unless required by applicable law or agreed to in writing, software
 
12
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
13
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
14
#    License for the specific language governing permissions and limitations
 
15
#    under the License.
 
16
 
 
17
from nova import test
 
18
from nova import utils
 
19
 
 
20
from nova.virt import images
 
21
from nova.virt.libvirt import utils as libvirt_utils
 
22
 
 
23
 
 
24
class ImageUtilsTestCase(test.TestCase):
 
25
    def test_disk_type(self):
 
26
        # Seems like lvm detection
 
27
        # if its in /dev ??
 
28
        for p in ['/dev/b', '/dev/blah/blah']:
 
29
            d_type = libvirt_utils.get_disk_type(p)
 
30
            self.assertEquals('lvm', d_type)
 
31
        # Try the other types
 
32
        template_output = """image: %(path)s
 
33
file format: %(format)s
 
34
virtual size: 64M (67108864 bytes)
 
35
cluster_size: 65536
 
36
disk size: 96K
 
37
"""
 
38
        path = '/myhome/disk.config'
 
39
        for f in ['raw', 'qcow2']:
 
40
            output = template_output % ({
 
41
                'format': f,
 
42
                'path': path,
 
43
            })
 
44
            self.mox.StubOutWithMock(utils, 'execute')
 
45
            utils.execute('env', 'LC_ALL=C', 'LANG=C',
 
46
                          'qemu-img', 'info', path).AndReturn((output, ''))
 
47
            self.mox.ReplayAll()
 
48
            d_type = libvirt_utils.get_disk_type(path)
 
49
            self.assertEquals(f, d_type)
 
50
            self.mox.UnsetStubs()
 
51
 
 
52
    def test_disk_backing(self):
 
53
        path = '/myhome/disk.config'
 
54
        template_output = """image: %(path)s
 
55
file format: raw
 
56
virtual size: 2K (2048 bytes)
 
57
cluster_size: 65536
 
58
disk size: 96K
 
59
"""
 
60
        output = template_output % ({
 
61
            'path': path,
 
62
        })
 
63
        self.mox.StubOutWithMock(utils, 'execute')
 
64
        utils.execute('env', 'LC_ALL=C', 'LANG=C',
 
65
                      'qemu-img', 'info', path).AndReturn((output, ''))
 
66
        self.mox.ReplayAll()
 
67
        d_backing = libvirt_utils.get_disk_backing_file(path)
 
68
        self.assertEquals(None, d_backing)
 
69
 
 
70
    def test_disk_size(self):
 
71
        path = '/myhome/disk.config'
 
72
        template_output = """image: %(path)s
 
73
file format: raw
 
74
virtual size: %(v_size)s (%(vsize_b)s bytes)
 
75
cluster_size: 65536
 
76
disk size: 96K
 
77
"""
 
78
        for i in range(0, 128):
 
79
            bytes = i * 65336
 
80
            kbytes = bytes / 1024
 
81
            mbytes = kbytes / 1024
 
82
            output = template_output % ({
 
83
                'v_size': "%sM" % (mbytes),
 
84
                'vsize_b': i,
 
85
                'path': path,
 
86
            })
 
87
            self.mox.StubOutWithMock(utils, 'execute')
 
88
            utils.execute('env', 'LC_ALL=C', 'LANG=C',
 
89
                          'qemu-img', 'info', path).AndReturn((output, ''))
 
90
            self.mox.ReplayAll()
 
91
            d_size = libvirt_utils.get_disk_size(path)
 
92
            self.assertEquals(i, d_size)
 
93
            self.mox.UnsetStubs()
 
94
            output = template_output % ({
 
95
                'v_size': "%sK" % (kbytes),
 
96
                'vsize_b': i,
 
97
                'path': path,
 
98
            })
 
99
            self.mox.StubOutWithMock(utils, 'execute')
 
100
            utils.execute('env', 'LC_ALL=C', 'LANG=C',
 
101
                          'qemu-img', 'info', path).AndReturn((output, ''))
 
102
            self.mox.ReplayAll()
 
103
            d_size = libvirt_utils.get_disk_size(path)
 
104
            self.assertEquals(i, d_size)
 
105
            self.mox.UnsetStubs()
 
106
 
 
107
    def test_qemu_info_canon(self):
 
108
        path = "disk.config"
 
109
        example_output = """image: disk.config
 
110
file format: raw
 
111
virtual size: 64M (67108864 bytes)
 
112
cluster_size: 65536
 
113
disk size: 96K
 
114
blah BLAH: bb
 
115
"""
 
116
        self.mox.StubOutWithMock(utils, 'execute')
 
117
        utils.execute('env', 'LC_ALL=C', 'LANG=C',
 
118
                      'qemu-img', 'info', path).AndReturn((example_output, ''))
 
119
        self.mox.ReplayAll()
 
120
        image_info = images.qemu_img_info(path)
 
121
        self.assertEquals('disk.config', image_info.image)
 
122
        self.assertEquals('raw', image_info.file_format)
 
123
        self.assertEquals(67108864, image_info.virtual_size)
 
124
        self.assertEquals(98304, image_info.disk_size)
 
125
        self.assertEquals(65536, image_info.cluster_size)
 
126
 
 
127
    def test_qemu_info_canon2(self):
 
128
        path = "disk.config"
 
129
        example_output = """image: disk.config
 
130
file format: QCOW2
 
131
virtual size: 67108844
 
132
cluster_size: 65536
 
133
disk size: 963434
 
134
backing file: /var/lib/nova/a328c7998805951a_2
 
135
"""
 
136
        self.mox.StubOutWithMock(utils, 'execute')
 
137
        utils.execute('env', 'LC_ALL=C', 'LANG=C',
 
138
                      'qemu-img', 'info', path).AndReturn((example_output, ''))
 
139
        self.mox.ReplayAll()
 
140
        image_info = images.qemu_img_info(path)
 
141
        self.assertEquals('disk.config', image_info.image)
 
142
        self.assertEquals('qcow2', image_info.file_format)
 
143
        self.assertEquals(67108844, image_info.virtual_size)
 
144
        self.assertEquals(963434, image_info.disk_size)
 
145
        self.assertEquals(65536, image_info.cluster_size)
 
146
        self.assertEquals('/var/lib/nova/a328c7998805951a_2',
 
147
                          image_info.backing_file)
 
148
 
 
149
    def test_qemu_backing_file_actual(self):
 
150
        path = "disk.config"
 
151
        example_output = """image: disk.config
 
152
file format: raw
 
153
virtual size: 64M (67108864 bytes)
 
154
cluster_size: 65536
 
155
disk size: 96K
 
156
Snapshot list:
 
157
ID        TAG                 VM SIZE                DATE       VM CLOCK
 
158
1     d9a9784a500742a7bb95627bb3aace38      0 2012-08-20 10:52:46 00:00:00.000
 
159
backing file: /var/lib/nova/a328c7998805951a_2 (actual path: /b/3a988059e51a_2)
 
160
"""
 
161
        self.mox.StubOutWithMock(utils, 'execute')
 
162
        utils.execute('env', 'LC_ALL=C', 'LANG=C',
 
163
                      'qemu-img', 'info', path).AndReturn((example_output, ''))
 
164
        self.mox.ReplayAll()
 
165
        image_info = images.qemu_img_info(path)
 
166
        self.assertEquals('disk.config', image_info.image)
 
167
        self.assertEquals('raw', image_info.file_format)
 
168
        self.assertEquals(67108864, image_info.virtual_size)
 
169
        self.assertEquals(98304, image_info.disk_size)
 
170
        self.assertEquals(1, len(image_info.snapshots))
 
171
        self.assertEquals('/b/3a988059e51a_2',
 
172
                          image_info.backing_file)
 
173
 
 
174
    def test_qemu_info_convert(self):
 
175
        path = "disk.config"
 
176
        example_output = """image: disk.config
 
177
file format: raw
 
178
virtual size: 64M
 
179
disk size: 96K
 
180
Snapshot list:
 
181
ID        TAG                 VM SIZE                DATE       VM CLOCK
 
182
1        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
 
183
3        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
 
184
4        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
 
185
junk stuff: bbb
 
186
"""
 
187
        self.mox.StubOutWithMock(utils, 'execute')
 
188
        utils.execute('env', 'LC_ALL=C', 'LANG=C',
 
189
                      'qemu-img', 'info', path).AndReturn((example_output, ''))
 
190
        self.mox.ReplayAll()
 
191
        image_info = images.qemu_img_info(path)
 
192
        self.assertEquals('disk.config', image_info.image)
 
193
        self.assertEquals('raw', image_info.file_format)
 
194
        self.assertEquals(67108864, image_info.virtual_size)
 
195
        self.assertEquals(98304, image_info.disk_size)
 
196
 
 
197
    def test_qemu_info_snaps(self):
 
198
        path = "disk.config"
 
199
        example_output = """image: disk.config
 
200
file format: raw
 
201
virtual size: 64M (67108864 bytes)
 
202
disk size: 96K
 
203
Snapshot list:
 
204
ID        TAG                 VM SIZE                DATE       VM CLOCK
 
205
1        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
 
206
3        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
 
207
4        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
 
208
"""
 
209
        self.mox.StubOutWithMock(utils, 'execute')
 
210
        utils.execute('env', 'LC_ALL=C', 'LANG=C',
 
211
                      'qemu-img', 'info', path).AndReturn((example_output, ''))
 
212
        self.mox.ReplayAll()
 
213
        image_info = images.qemu_img_info(path)
 
214
        self.assertEquals('disk.config', image_info.image)
 
215
        self.assertEquals('raw', image_info.file_format)
 
216
        self.assertEquals(67108864, image_info.virtual_size)
 
217
        self.assertEquals(98304, image_info.disk_size)
 
218
        self.assertEquals(3, len(image_info.snapshots))