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

« back to all changes in this revision

Viewing changes to nova/tests/test_powervm.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, James Page
  • Date: 2013-03-20 12:59:22 UTC
  • mfrom: (1.1.69)
  • Revision ID: package-import@ubuntu.com-20130320125922-ohvfav96lemn9wlz
Tags: 1:2013.1~rc1-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/patches/avoid_setuptools_git_dependency.patch: Refreshed.
* debian/control: Clean up dependencies:
  - Dropped python-gflags no longer needed.
  - Dropped python-daemon no longer needed.
  - Dropped python-glance no longer needed.
  - Dropped python-lockfile no longer needed.
  - Dropped python-simplejson no longer needed.
  - Dropped python-tempita no longer needed.
  - Dropped python-xattr no longer needed.
  - Add sqlite3 required for the testsuite.

[ James Page ]
* d/watch: Update uversionmangle to deal with upstream versioning
  changes, remove tarballs.openstack.org. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
2
 
3
 
# Copyright 2012 IBM
 
3
# Copyright 2012 IBM Corp.
4
4
#
5
5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
6
6
#    not use this file except in compliance with the License. You may obtain
18
18
Test suite for PowerVMDriver.
19
19
"""
20
20
 
 
21
import contextlib
 
22
 
21
23
from nova import context
22
24
from nova import db
23
25
from nova import test
24
26
 
 
27
from nova.compute import instance_types
25
28
from nova.compute import power_state
 
29
from nova.compute import task_states
26
30
from nova.network import model as network_model
27
31
from nova.openstack.common import log as logging
28
32
from nova.tests import fake_network_cache_model
 
33
from nova.tests.image import fake
29
34
from nova.virt import images
30
35
from nova.virt.powervm import blockdev as powervm_blockdev
31
36
from nova.virt.powervm import common
58
63
    def start_lpar(self, instance_name):
59
64
        pass
60
65
 
61
 
    def stop_lpar(self, instance_name):
 
66
    def stop_lpar(self, instance_name, time_out=30):
62
67
        pass
63
68
 
64
69
    def remove_lpar(self, instance_name):
96
101
    def get_hostname(self):
97
102
        return 'fake-powervm'
98
103
 
 
104
    def rename_lpar(self, old, new):
 
105
        pass
 
106
 
99
107
 
100
108
class FakeBlockAdapter(powervm_blockdev.PowerVMLocalVolumeAdapter):
101
109
 
102
110
    def __init__(self):
 
111
        self.connection_data = common.Connection(host='fake_compute_1',
 
112
                                                  username='fake_user',
 
113
                                                  password='fake_pass')
103
114
        pass
104
115
 
105
116
    def _create_logical_volume(self, size):
112
123
        pass
113
124
 
114
125
    def _copy_image_file(self, sourcePath, remotePath, decompress=False):
115
 
        finalPath = '/home/images/rhel62.raw.7e358754160433febd6f3318b7c9e335'
 
126
        finalPath = '/tmp/rhel62.raw.7e358754160433febd6f3318b7c9e335'
116
127
        size = 4294967296
117
128
        return finalPath, size
118
129
 
 
130
    def _copy_device_to_file(self, device_name, file_path):
 
131
        pass
 
132
 
 
133
    def _copy_image_file_from_host(self, remote_source_path, local_dest_dir,
 
134
                                   compress=False):
 
135
        snapshot_file = '/tmp/rhel62.raw.7e358754160433febd6f3318b7c9e335'
 
136
        snap_ref = open(snapshot_file, 'w+')
 
137
        snap_ref.close()
 
138
        return snapshot_file
 
139
 
119
140
 
120
141
def fake_get_powervm_operator():
121
142
    return FakeIVMOperator()
134
155
        self.instance = self._create_instance()
135
156
 
136
157
    def _create_instance(self):
137
 
        return db.instance_create(context.get_admin_context(),
138
 
                                  {'user_id': 'fake',
139
 
                                   'project_id': 'fake',
140
 
                                   'instance_type_id': 1,
141
 
                                   'memory_mb': 1024,
142
 
                                   'vcpus': 2})
 
158
        fake.stub_out_image_service(self.stubs)
 
159
        ctxt = context.get_admin_context()
 
160
        instance_type = db.instance_type_get(ctxt, 1)
 
161
        sys_meta = instance_types.save_instance_type_info({}, instance_type)
 
162
        return db.instance_create(ctxt,
 
163
                        {'user_id': 'fake',
 
164
                        'project_id': 'fake',
 
165
                        'instance_type_id': 1,
 
166
                        'memory_mb': 1024,
 
167
                        'vcpus': 2,
 
168
                        'image_ref': '155d900f-4e14-4e4c-a73d-069cbf4541e6',
 
169
                        'system_metadata': sys_meta})
143
170
 
144
171
    def test_list_instances(self):
145
172
        instances = self.powervm_connection.list_instances()
151
178
        self.assertTrue(self.powervm_connection.instance_exists(name))
152
179
 
153
180
    def test_spawn(self):
154
 
        def fake_image_fetch_to_raw(context, image_id, file_path,
 
181
        def fake_image_fetch(context, image_id, file_path,
155
182
                                    user_id, project_id):
156
183
            pass
157
184
        self.flags(powervm_img_local_path='/images/')
158
 
        self.stubs.Set(images, 'fetch_to_raw', fake_image_fetch_to_raw)
 
185
        self.stubs.Set(images, 'fetch', fake_image_fetch)
159
186
        image_meta = {}
160
187
        image_meta['id'] = '666'
161
188
        fake_net_info = network_model.NetworkInfo([
173
200
            raise ex
174
201
 
175
202
        self.flags(powervm_img_local_path='/images/')
176
 
        self.stubs.Set(images, 'fetch_to_raw', lambda *x, **y: None)
 
203
        self.stubs.Set(images, 'fetch', lambda *x, **y: None)
177
204
        self.stubs.Set(
178
205
            self.powervm_connection._powervm._disk_adapter,
179
206
            'create_volume_from_image',
189
216
                          self.instance,
190
217
                          {'id': 'ANY_ID'}, [], 's3cr3t', fake_net_info)
191
218
 
 
219
    def test_snapshot(self):
 
220
 
 
221
        def update_task_state(task_state, expected_state=None):
 
222
            self._loc_task_state = task_state
 
223
            self._loc_expected_task_state = expected_state
 
224
 
 
225
        loc_context = context.get_admin_context()
 
226
        properties = {'instance_id': self.instance['id'],
 
227
                      'user_id': str(loc_context.user_id)}
 
228
        sent_meta = {'name': 'fake_snap', 'is_public': False,
 
229
                     'status': 'creating', 'properties': properties}
 
230
        image_service = fake.FakeImageService()
 
231
        recv_meta = image_service.create(loc_context, sent_meta)
 
232
 
 
233
        self.powervm_connection.snapshot(loc_context,
 
234
                                      self.instance, recv_meta['id'],
 
235
                                      update_task_state)
 
236
 
 
237
        self.assertTrue(self._loc_task_state == task_states.IMAGE_UPLOADING and
 
238
            self._loc_expected_task_state == task_states.IMAGE_PENDING_UPLOAD)
 
239
 
192
240
    def test_destroy(self):
193
241
        self.powervm_connection.destroy(self.instance, None)
194
242
        self.stubs.Set(FakeIVMOperator, 'get_lpar', lambda x, y: None)
230
278
        joined_path = common.aix_path_join(path_one, path_two)
231
279
        expected_path = '/some/file/path/filename'
232
280
        self.assertEqual(joined_path, expected_path)
 
281
 
 
282
    def _test_finish_revert_migration_after_crash(self, backup_made, new_made):
 
283
        inst = {'name': 'foo'}
 
284
 
 
285
        self.mox.StubOutWithMock(self.powervm_connection, 'instance_exists')
 
286
        self.mox.StubOutWithMock(self.powervm_connection._powervm, 'destroy')
 
287
        self.mox.StubOutWithMock(self.powervm_connection._powervm._operator,
 
288
                                 'rename_lpar')
 
289
        self.mox.StubOutWithMock(self.powervm_connection._powervm, 'power_on')
 
290
 
 
291
        self.powervm_connection.instance_exists('rsz_foo').AndReturn(
 
292
            backup_made)
 
293
 
 
294
        if backup_made:
 
295
            self.powervm_connection.instance_exists('foo').AndReturn(new_made)
 
296
            if new_made:
 
297
                self.powervm_connection._powervm.destroy('foo')
 
298
            self.powervm_connection._powervm._operator.rename_lpar('rsz_foo',
 
299
                                                                   'foo')
 
300
        self.powervm_connection._powervm.power_on('foo')
 
301
 
 
302
        self.mox.ReplayAll()
 
303
 
 
304
        self.powervm_connection.finish_revert_migration(inst, [])
 
305
 
 
306
    def test_finish_revert_migration_after_crash(self):
 
307
        self._test_finish_revert_migration_after_crash(True, True)
 
308
 
 
309
    def test_finish_revert_migration_after_crash_before_new(self):
 
310
        self._test_finish_revert_migration_after_crash(True, False)
 
311
 
 
312
    def test_finish_revert_migration_after_crash_before_backup(self):
 
313
        self._test_finish_revert_migration_after_crash(False, False)
 
314
 
 
315
    def test_migrate_volume_use_instance_name(self):
 
316
        inst_name = 'instance-00000000'
 
317
        lv_name = 'logical-vol-name'
 
318
        src_host = 'compute_host_1'
 
319
        dest = 'compute_host_1'
 
320
        image_path = 'some/image/path'
 
321
        fake_noop = lambda *args, **kwargs: None
 
322
 
 
323
        self.stubs.Set(self.powervm_connection._powervm._disk_adapter,
 
324
                       '_copy_device_to_file', fake_noop)
 
325
 
 
326
        self.stubs.Set(self.powervm_connection._powervm._disk_adapter,
 
327
                       'run_vios_command_as_root', fake_noop)
 
328
        blockdev_op = self.powervm_connection._powervm._disk_adapter
 
329
        file_path = blockdev_op.migrate_volume(lv_name, src_host, dest,
 
330
                                               image_path, inst_name)
 
331
        expected_path = 'some/image/path/instance-00000000_rsz.gz'
 
332
        self.assertEqual(file_path, expected_path)
 
333
 
 
334
    def test_migrate_volume_use_lv_name(self):
 
335
        lv_name = 'logical-vol-name'
 
336
        src_host = 'compute_host_1'
 
337
        dest = 'compute_host_1'
 
338
        image_path = 'some/image/path'
 
339
        fake_noop = lambda *args, **kwargs: None
 
340
 
 
341
        self.stubs.Set(self.powervm_connection._powervm._disk_adapter,
 
342
                       '_copy_device_to_file', fake_noop)
 
343
 
 
344
        self.stubs.Set(self.powervm_connection._powervm._disk_adapter,
 
345
                       'run_vios_command_as_root', fake_noop)
 
346
        blockdev_op = self.powervm_connection._powervm._disk_adapter
 
347
        file_path = blockdev_op.migrate_volume(lv_name, src_host, dest,
 
348
                                               image_path)
 
349
        expected_path = 'some/image/path/logical-vol-name_rsz.gz'
 
350
        self.assertEqual(file_path, expected_path)
 
351
 
 
352
    def test_migrate_build_scp_command(self):
 
353
        lv_name = 'logical-vol-name'
 
354
        src_host = 'compute_host_1'
 
355
        dest = 'compute_host_2'
 
356
        image_path = 'some/image/path'
 
357
        fake_noop = lambda *args, **kwargs: None
 
358
 
 
359
        @contextlib.contextmanager
 
360
        def fake_vios_to_vios_auth(*args, **kwargs):
 
361
            key_name = 'some_key'
 
362
            yield key_name
 
363
        self.stubs.Set(common, 'vios_to_vios_auth',
 
364
                       fake_vios_to_vios_auth)
 
365
 
 
366
        self.stubs.Set(self.powervm_connection._powervm._disk_adapter,
 
367
                       'run_vios_command_as_root', fake_noop)
 
368
 
 
369
        def fake_run_vios_command(*args, **kwargs):
 
370
            cmd = args[0]
 
371
            exp_cmd = ' '.join(['scp -o "StrictHostKeyChecking no" -i',
 
372
                                'some_key',
 
373
                                'some/image/path/logical-vol-name_rsz.gz',
 
374
                                'fake_user@compute_host_2:some/image/path'])
 
375
            self.assertEqual(exp_cmd, cmd)
 
376
 
 
377
        self.stubs.Set(self.powervm_connection._powervm._disk_adapter,
 
378
                       'run_vios_command',
 
379
                       fake_run_vios_command)
 
380
 
 
381
        blockdev_op = self.powervm_connection._powervm._disk_adapter
 
382
        file_path = blockdev_op.migrate_volume(lv_name, src_host, dest,
 
383
                                               image_path)
 
384
 
 
385
    def test_get_resize_name(self):
 
386
        inst_name = 'instance-00000001'
 
387
        expected_name = 'rsz_instance-00000001'
 
388
        result = self.powervm_connection._get_resize_name(inst_name)
 
389
        self.assertEqual(expected_name, result)
 
390
 
 
391
    def test_get_long_resize_name(self):
 
392
        inst_name = 'some_really_long_instance_name_00000001'
 
393
        expected_name = 'rsz__really_long_instance_name_00000001'
 
394
        result = self.powervm_connection._get_resize_name(inst_name)
 
395
        self.assertEqual(expected_name, result)
 
396
 
 
397
    def test_get_host_stats(self):
 
398
        host_stats = self.powervm_connection.get_host_stats(True)
 
399
        self.assertIsNotNone(host_stats)
 
400
        self.assertEquals(host_stats['vcpus'], 8.0)
 
401
        self.assertEquals(round(host_stats['vcpus_used'], 1), 1.7)
 
402
        self.assertEquals(host_stats['host_memory_total'], 65536)
 
403
        self.assertEquals(host_stats['host_memory_free'], 46336)
 
404
        self.assertEquals(host_stats['disk_total'], 10168)
 
405
        self.assertEquals(host_stats['disk_used'], 0)
 
406
        self.assertEquals(host_stats['disk_available'], 10168)
 
407
        self.assertEquals(host_stats['disk_total'],
 
408
                          host_stats['disk_used'] +
 
409
                          host_stats['disk_available'])
 
410
 
 
411
        self.assertEquals(host_stats['cpu_info'], ('ppc64', 'powervm', '3940'))
 
412
        self.assertEquals(host_stats['hypervisor_type'], 'powervm')
 
413
        self.assertEquals(host_stats['hypervisor_version'], '7.1')
 
414
 
 
415
        self.assertEquals(host_stats['hypervisor_hostname'], "fake-powervm")
 
416
        self.assertEquals(host_stats['supported_instances'][0][0], "ppc64")
 
417
        self.assertEquals(host_stats['supported_instances'][0][1], "powervm")
 
418
        self.assertEquals(host_stats['supported_instances'][0][2], "hvm")