~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/tests/xenapi/stubs.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-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:
15
15
 
16
16
"""Stubouts, mocks and fixtures for the test suite"""
17
17
 
18
 
import contextlib
19
18
import pickle
20
19
import random
21
 
import sys
22
20
 
23
21
from nova.openstack.common import jsonutils
24
22
from nova import test
34
32
    def fake_none(self, *args):
35
33
        return
36
34
 
37
 
    vmops = conn._vmops
38
 
    stubs.Set(vmops.firewall_driver, 'prepare_instance_filter', fake_none)
39
 
    stubs.Set(vmops.firewall_driver, 'instance_filter_exists', fake_none)
 
35
    _vmops = conn._vmops
 
36
    stubs.Set(_vmops.firewall_driver, 'prepare_instance_filter', fake_none)
 
37
    stubs.Set(_vmops.firewall_driver, 'instance_filter_exists', fake_none)
40
38
 
41
39
 
42
40
def stubout_instance_snapshot(stubs):
140
138
    """Simulates a failure in create_vm."""
141
139
 
142
140
    def f(*args):
143
 
        raise fake.Failure("Test Exception raised by " +
144
 
                           "fake create_vm")
 
141
        raise fake.Failure("Test Exception raised by fake create_vm")
145
142
    stubs.Set(vm_utils, 'create_vm', f)
146
143
 
147
144
 
 
145
def stubout_attach_disks(stubs):
 
146
    """Simulates a failure in _attach_disks."""
 
147
 
 
148
    def f(*args):
 
149
        raise fake.Failure("Test Exception raised by fake _attach_disks")
 
150
    stubs.Set(vmops.VMOps, '_attach_disks', f)
 
151
 
 
152
 
148
153
def _make_fake_vdi():
149
154
    sr_ref = fake.get_all('SR')[0]
150
155
    vdi_ref = fake.create_vdi('', sr_ref)
164
169
                                  "COMMIT\n"
165
170
                                  "# Completed on Sun Nov  6 22:49:02 2011\n")
166
171
 
167
 
    def __init__(self, uri):
168
 
        super(FakeSessionForVMTests, self).__init__(uri)
169
 
 
170
172
    def host_call_plugin(self, _1, _2, plugin, method, _5):
171
173
        if (plugin, method) == ('glance', 'download_vhd'):
172
174
            root_uuid = _make_fake_vdi()
178
180
            return (super(FakeSessionForVMTests, self).
179
181
                    host_call_plugin(_1, _2, plugin, method, _5))
180
182
 
181
 
    def host_call_plugin_swap(self, _1, _2, plugin, method, _5):
182
 
        if (plugin, method) == ('glance', 'download_vhd'):
183
 
            root_uuid = _make_fake_vdi()
184
 
            swap_uuid = _make_fake_vdi()
185
 
            return pickle.dumps(dict(root=dict(uuid=root_uuid),
186
 
                                     swap=dict(uuid=swap_uuid)))
187
 
        else:
188
 
            return (super(FakeSessionForVMTests, self).
189
 
                    host_call_plugin(_1, _2, plugin, method, _5))
190
 
 
191
183
    def VM_start(self, _1, ref, _2, _3):
192
184
        vm = fake.get_record('VM', ref)
193
185
        if vm['power_state'] != 'Halted':
203
195
        vm_rec = self.VM_start(_1, vm_ref, _2, _3)
204
196
        vm_rec['resident_on'] = host_ref
205
197
 
206
 
    def VM_snapshot(self, session_ref, vm_ref, label):
207
 
        status = "Running"
208
 
        template_vm_ref = fake.create_vm(label, status, is_a_template=True,
209
 
            is_control_domain=False)
210
 
 
 
198
    def VDI_snapshot(self, session_ref, vm_ref, _1):
211
199
        sr_ref = "fakesr"
212
 
        template_vdi_ref = fake.create_vdi(label, sr_ref, read_only=True)
213
 
 
214
 
        template_vbd_ref = fake.create_vbd(template_vm_ref, template_vdi_ref)
215
 
        return template_vm_ref
 
200
        return fake.create_vdi('fakelabel', sr_ref, read_only=True)
216
201
 
217
202
    def SR_scan(self, session_ref, sr_ref):
218
203
        pass
286
271
 
287
272
class FakeSessionForVolumeTests(fake.SessionBase):
288
273
    """ Stubs out a XenAPISession for Volume tests """
289
 
    def __init__(self, uri):
290
 
        super(FakeSessionForVolumeTests, self).__init__(uri)
291
 
 
292
274
    def VDI_introduce(self, _1, uuid, _2, _3, _4, _5,
293
275
                      _6, _7, _8, _9, _10, _11):
294
276
        valid_vdi = False
303
285
 
304
286
class FakeSessionForVolumeFailedTests(FakeSessionForVolumeTests):
305
287
    """ Stubs out a XenAPISession for Volume tests: it injects failures """
306
 
    def __init__(self, uri):
307
 
        super(FakeSessionForVolumeFailedTests, self).__init__(uri)
308
 
 
309
288
    def VDI_introduce(self, _1, uuid, _2, _3, _4, _5,
310
289
                      _6, _7, _8, _9, _10, _11):
311
290
        # This is for testing failure
320
299
 
321
300
 
322
301
def stub_out_migration_methods(stubs):
323
 
    @contextlib.contextmanager
324
 
    def fake_snapshot_attached_here(session, instance, vm_ref, label):
325
 
        yield ['bar', 'foo']
 
302
    fakesr = fake.create_sr()
326
303
 
327
304
    def fake_move_disks(self, instance, disk_info):
328
 
        vdi_ref = fake.create_vdi(instance['name'], 'fake')
 
305
        vdi_ref = fake.create_vdi(instance['name'], fakesr)
329
306
        vdi_rec = fake.get_record('VDI', vdi_ref)
330
307
        vdi_rec['other_config']['nova_disk_type'] = 'root'
331
308
        return {'uuid': vdi_rec['uuid'], 'ref': vdi_ref}
332
309
 
333
310
    def fake_get_vdi(session, vm_ref):
334
 
        vdi_ref = fake.create_vdi('derp', 'herp')
 
311
        vdi_ref_parent = fake.create_vdi('derp-parent', fakesr)
 
312
        vdi_rec_parent = fake.get_record('VDI', vdi_ref_parent)
 
313
        vdi_ref = fake.create_vdi('derp', fakesr,
 
314
                sm_config={'vhd-parent': vdi_rec_parent['uuid']})
335
315
        vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref)
336
 
        return vdi_ref, {'uuid': vdi_rec['uuid'], }
 
316
        return vdi_ref, vdi_rec
337
317
 
338
318
    def fake_sr(session, *args):
339
 
        pass
 
319
        return fakesr
340
320
 
341
321
    def fake_get_sr_path(*args):
342
322
        return "fake"
350
330
    stubs.Set(vmops.VMOps, '_destroy', fake_destroy)
351
331
    stubs.Set(vm_utils, 'move_disks', fake_move_disks)
352
332
    stubs.Set(vm_utils, 'scan_default_sr', fake_sr)
353
 
    stubs.Set(vm_utils, '_scan_sr', fake_sr)
354
 
    stubs.Set(vm_utils, 'snapshot_attached_here', fake_snapshot_attached_here)
355
333
    stubs.Set(vm_utils, 'get_vdi_for_vm_safely', fake_get_vdi)
356
334
    stubs.Set(vm_utils, 'get_sr_path', fake_get_sr_path)
357
335
    stubs.Set(vm_utils, 'generate_ephemeral', fake_generate_ephemeral)
358
336
 
359
337
 
360
338
class FakeSessionForFailedMigrateTests(FakeSessionForVMTests):
361
 
    def __init__(self, uri):
362
 
        super(FakeSessionForFailedMigrateTests, self).__init__(uri)
363
 
 
364
339
    def VM_assert_can_migrate(self, session, vmref, migrate_data,
365
340
                              live, vdi_map, vif_map, options):
366
341
        raise fake.Failure("XenAPI VM.assert_can_migrate failed")
377
352
    def setUp(self):
378
353
        super(XenAPITestBase, self).setUp()
379
354
 
380
 
        self.orig_XenAPI = sys.modules.get('XenAPI')
381
 
        sys.modules['XenAPI'] = fake
 
355
        self.stub_module('XenAPI', fake)
382
356
 
383
357
        fake.reset()
384
 
 
385
 
    def tearDown(self):
386
 
        if self.orig_XenAPI is not None:
387
 
            sys.modules['XenAPI'] = self.orig_XenAPI
388
 
            self.orig_XenAPI = None
389
 
        else:
390
 
            sys.modules.pop('XenAPI')
391
 
 
392
 
        super(XenAPITestBase, self).tearDown()