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

« back to all changes in this revision

Viewing changes to nova/tests/test_vmwareapi.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2013-08-09 10:12:27 UTC
  • mfrom: (1.1.74)
  • Revision ID: package-import@ubuntu.com-20130809101227-4n60fzcgra8dzk3d
Tags: 1:2013.1.3-0ubuntu1
* Resynchronize with stable/grizzly (89c7ee4) (LP: #1210447):
  - [8e6edd2] Bump stable/grizzly next version to 2013.1.3
  - [61fc529] attach quantum security group to an existing vm failed
    LP: 1189059
  - [60774bd] nova-compute fails to start if quantum is down LP: 1186357
  - [8e6d4b6] asymmetric routes in nova network with external gateway and
    routing_source_ip LP: 1182143
  - [8849413] Failed VM's not set to error state on exception LP: 1182056
  - [ef10eee] Double healing of info_cache with cells LP: 1180304
  - [7422d83] Can't log into  VM after powervm is resized LP: 1169848
  - [49ab0e8] stack trace when instance_actions extension can not find
    instance in GET LP: 1182867
  - [e71247c] nova service-list returns illegal result with non db service
    heartbeat LP: 1168861
  - [3f60606] Volume IO usage gets reset to 0 after a reboot / crash
    LP: 1169097
  - [19c443b] unused method  list_interfaces in vmware driver can be removed
    LP: 1187251
  - [a8dab9f] No cleanup done when file transfer fails with powervm driver
    LP: 1173017
  - [fc98015] nova consoleauth depends on Conductor Service LP: 1186123
  - [1066418] VMware drivers are no longer passing quantum port-id to
    vCenter LP: 1183452
  - [b92075c] nova net-list fails on empty list with Quantum backend
    LP: 1189976
  - [3ba31f2] Create VM with no networks with Quantum Gives SecurityGroups
    Exception LP: 1191044
  - [89150b2] Periodic ValueErrors when using qpid LP: 1185465
  - [0e0d615] Libvirt pre-Grizzly instances cannot be block migrated
    LP: 1185588
  - [27960ef] ZMQ ipc socket file is created using un-sanitized network
    input LP: 1122763
  - [265b868] cannot block migrate old style instances libvirt complains
    LP: 1175286
  - [008a68a] code logical error exists in vmwareapi vif.py  LP: 1177635
  - [378c045] Instance IP addresses are re-used even when previous instance
    could not be powered off LP: 1180178
  - [48ddffe] Reboot of compute node breaks VMs with volumes LP: 1188326
  - [f427f01] Missing dashes from console-log LP: 1194032
  - [78ebf1a] network-create returns an internal error when network
    conflicts LP: 1158075
  - [767c850] Instance nics are reorder after reboot LP: 1187092
  - [0b45996] instance directory naming update to use uuid  LP: 1186944
  - [06cfad5] Disassociate failed dhcp fixed ip in deallocate_for_instance()
    method LP: 1180766
  - [cbcdfc5] Allow confirm_resize action on an instance in 'deleting'
    status LP: 1189391
  - [2563c44] aggregate_get_by_host returns aggregates from other hosts
    LP: 1201277
  - [109f3a9] nova libvirt driver requires iscsi initiator name regardless
    of using it in volume drivers LP: 1007084
  - [7f1c336] Host is always set to None in get_instance_nw_info(...)
    LP: 1194178
  - [1cf30a3] nova boot with colume should fail if the volume is already
    attached to another instance LP: 1166770
  - [9cb9361] Aggregate metadata filtering by key returns unrelated metadata
    LP: 1201283
  - [a61872b] Need clean up  ftp transfer faiure  in powervm driver
    LP: 1188884
  - [91bcd15] Race can cause soft deleted instance to be erased by mistake
    LP: 1186243
  - [c57fded] Nova fails to create a security group rule if ::0/0 is used as
    cidr LP: 1199943
  - [c698dd3] VMwareESXDriver and VMwareVCDriver report incorrect stat
    LP: 1180779
  - [e572faf] novnc fails when amqp_rpc_single_reply_queue=True LP: 1193031
  - [34ddd27] eventlet.monkey_patch() for spice and vnc proxy
  - [864837f] hypervisor_hostname not updated on evacuate LP: 1198284
  - [756a772] libvirt migrate/resize on shared storage can cause data loss
    LP: 1177247
  - [889b215] nova live-migration of volume-backed VM fails because of image
    is None LP: 1199811
  - [60712a4] VNC console does not work with VCDriver LP: 1178369
  - [e0aa0f5] metadata service throws error 500 when compute_driver is not
    set LP: 1184641
  - [340d337] Instance IP addresses are re-used even when previous instance
    could not be powered off LP: 1180178
  - [8247dc8] Resource limit circumvention in Nova private flavors
    (CVE-2013-2256) LP: 1194093
  - [bd7e467] Denial of Service in Nova network source security groups
    (CVE-2013-4185) LP: 1184041
  - [c3fddb7] Resize a VM when a volume is attached fails LP: 1190364
  - [01edbaa] Hyper-V versions before 2012 are not properly recognized
    LP: 1203059
  - [b18818a] driver libvirt doesn't honor vif quota LP: 1185030
  - [798984d] config drive not visible to windows LP: 1155842
  - [d18ceb1] nova live-migration failed due to exception.MigrationError
    LP: 1171526
  - [1934dbc] vmware Hyper for nova vnc console url parameters error
    LP: 1172177
  - [89c7ee4] [OSSA 2013-023] Potential unsafe XML usage (CVE-2013-4179,
    CVE-2013-4202) LP: 1190229
* debian/rules: Clean new setuptools-git cruft.
* debian/control: Update Vcs fields.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""
20
20
Test suite for VMwareAPI.
21
21
"""
 
22
import urllib2
 
23
 
 
24
import mox
22
25
 
23
26
from nova.compute import power_state
24
27
from nova.compute import task_states
33
36
from nova.tests.vmwareapi import stubs
34
37
from nova.virt.vmwareapi import driver
35
38
from nova.virt.vmwareapi import fake as vmwareapi_fake
 
39
from nova.virt.vmwareapi import vm_util
 
40
from nova.virt.vmwareapi import volume_util
 
41
 
 
42
 
 
43
class fake_vm_ref(object):
 
44
    def __init__(self):
 
45
        self.value = 4
 
46
        self._type = 'VirtualMachine'
 
47
 
 
48
 
 
49
class fake_http_resp(object):
 
50
    def __init__(self):
 
51
        self.code = 200
 
52
 
 
53
    def read(self):
 
54
        return "console log"
36
55
 
37
56
 
38
57
class VMwareAPIVMTestCase(test.TestCase):
52
71
        vmwareapi_fake.reset()
53
72
        db_fakes.stub_out_db_instance_api(self.stubs)
54
73
        stubs.set_stubs(self.stubs)
55
 
        self.conn = driver.VMwareESXDriver(None, False)
 
74
        self.conn = driver.VMwareVCDriver(None, False)
56
75
        # NOTE(vish): none of the network plugging code is actually
57
76
        #             being tested
58
77
        self.network_info = utils.get_test_network_info(legacy_model=False)
72
91
    def _create_instance_in_the_db(self):
73
92
        values = {'name': 1,
74
93
                  'id': 1,
 
94
                  'uuid': "fake-uuid",
75
95
                  'project_id': self.project_id,
76
96
                  'user_id': self.user_id,
77
97
                  'image_ref': "1",
101
121
        self.assertEquals(len(instances), 1)
102
122
 
103
123
        # Get Nova record for VM
104
 
        vm_info = self.conn.get_info({'name': 1})
 
124
        vm_info = self.conn.get_info({'uuid': 'fake-uuid',
 
125
                                      'name': 1})
105
126
 
106
127
        # Get record for VM
107
128
        vms = vmwareapi_fake._get_objects("VirtualMachine")
116
137
        self.assertEquals(vm.get("summary.config.memorySizeMB"),
117
138
                          self.type_data['memory_mb'])
118
139
 
 
140
        self.assertEqual(
 
141
            vm.get("config.hardware.device")[2].device.obj_name,
 
142
            "ns0:VirtualE1000")
119
143
        # Check that the VM is running according to Nova
120
144
        self.assertEquals(vm_info['state'], power_state.RUNNING)
121
145
 
122
146
        # Check that the VM is running according to vSphere API.
123
147
        self.assertEquals(vm.get("runtime.powerState"), 'poweredOn')
124
148
 
 
149
        found_vm_uuid = False
 
150
        found_iface_id = False
 
151
        for c in vm.get("config.extraConfig"):
 
152
            if (c.key == "nvp.vm-uuid" and c.value == self.instance['uuid']):
 
153
                found_vm_uuid = True
 
154
            if (c.key == "nvp.iface-id.0" and c.value == "vif-xxx-yyy-zzz"):
 
155
                found_iface_id = True
 
156
 
 
157
        self.assertTrue(found_vm_uuid)
 
158
        self.assertTrue(found_iface_id)
 
159
 
125
160
    def _check_vm_info(self, info, pwr_state=power_state.RUNNING):
126
161
        """
127
162
        Check if the get_info returned values correspond to the instance
142
177
        instances = self.conn.list_instances()
143
178
        self.assertEquals(len(instances), 1)
144
179
 
145
 
    def test_list_interfaces(self):
146
 
        self._create_vm()
147
 
        interfaces = self.conn.list_interfaces(1)
148
 
        self.assertEquals(len(interfaces), 1)
149
 
        self.assertEquals(interfaces[0], 4000)
150
 
 
151
180
    def test_spawn(self):
152
181
        self._create_vm()
153
 
        info = self.conn.get_info({'name': 1})
 
182
        info = self.conn.get_info({'uuid': 'fake-uuid'})
154
183
        self._check_vm_info(info, power_state.RUNNING)
155
184
 
156
185
    def test_snapshot(self):
164
193
                  'expected_state': task_states.IMAGE_PENDING_UPLOAD}}]
165
194
        func_call_matcher = matchers.FunctionCallMatcher(expected_calls)
166
195
        self._create_vm()
167
 
        info = self.conn.get_info({'name': 1})
 
196
        info = self.conn.get_info({'uuid': 'fake-uuid'})
168
197
        self._check_vm_info(info, power_state.RUNNING)
169
198
        self.conn.snapshot(self.context, self.instance, "Test-Snapshot",
170
199
                           func_call_matcher.call)
171
 
        info = self.conn.get_info({'name': 1})
 
200
        info = self.conn.get_info({'uuid': 'fake-uuid'})
172
201
        self._check_vm_info(info, power_state.RUNNING)
173
202
        self.assertIsNone(func_call_matcher.match())
174
203
 
180
209
 
181
210
    def test_reboot(self):
182
211
        self._create_vm()
183
 
        info = self.conn.get_info({'name': 1})
184
 
        self._check_vm_info(info, power_state.RUNNING)
185
 
        reboot_type = "SOFT"
186
 
        self.conn.reboot(self.context, self.instance, self.network_info,
187
 
                         reboot_type)
188
 
        info = self.conn.get_info({'name': 1})
 
212
        info = self.conn.get_info({'name': 1, 'uuid': 'fake-uuid'})
 
213
        self._check_vm_info(info, power_state.RUNNING)
 
214
        reboot_type = "SOFT"
 
215
        self.conn.reboot(self.context, self.instance, self.network_info,
 
216
                         reboot_type)
 
217
        info = self.conn.get_info({'name': 1, 'uuid': 'fake-uuid'})
 
218
        self._check_vm_info(info, power_state.RUNNING)
 
219
 
 
220
    def test_reboot_with_uuid(self):
 
221
        """Test fall back to use name when can't find by uuid."""
 
222
        self._create_vm()
 
223
        info = self.conn.get_info({'name': 'fake-uuid', 'uuid': 'wrong-uuid'})
 
224
        self._check_vm_info(info, power_state.RUNNING)
 
225
        reboot_type = "SOFT"
 
226
        self.conn.reboot(self.context, self.instance, self.network_info,
 
227
                         reboot_type)
 
228
        info = self.conn.get_info({'name': 'fake-uuid', 'uuid': 'wrong-uuid'})
189
229
        self._check_vm_info(info, power_state.RUNNING)
190
230
 
191
231
    def test_reboot_non_existent(self):
196
236
 
197
237
    def test_reboot_not_poweredon(self):
198
238
        self._create_vm()
199
 
        info = self.conn.get_info({'name': 1})
 
239
        info = self.conn.get_info({'uuid': 'fake-uuid'})
200
240
        self._check_vm_info(info, power_state.RUNNING)
201
241
        self.conn.suspend(self.instance)
202
 
        info = self.conn.get_info({'name': 1})
 
242
        info = self.conn.get_info({'uuid': 'fake-uuid'})
203
243
        self._check_vm_info(info, power_state.SUSPENDED)
204
244
        self.assertRaises(exception.InstanceRebootFailure, self.conn.reboot,
205
245
                          self.context, self.instance, self.network_info,
207
247
 
208
248
    def test_suspend(self):
209
249
        self._create_vm()
210
 
        info = self.conn.get_info({'name': 1})
 
250
        info = self.conn.get_info({'uuid': "fake-uuid"})
211
251
        self._check_vm_info(info, power_state.RUNNING)
212
252
        self.conn.suspend(self.instance)
213
 
        info = self.conn.get_info({'name': 1})
 
253
        info = self.conn.get_info({'uuid': 'fake-uuid'})
214
254
        self._check_vm_info(info, power_state.SUSPENDED)
215
255
 
216
256
    def test_suspend_non_existent(self):
220
260
 
221
261
    def test_resume(self):
222
262
        self._create_vm()
223
 
        info = self.conn.get_info({'name': 1})
 
263
        info = self.conn.get_info({'uuid': 'fake-uuid'})
224
264
        self._check_vm_info(info, power_state.RUNNING)
225
265
        self.conn.suspend(self.instance)
226
 
        info = self.conn.get_info({'name': 1})
 
266
        info = self.conn.get_info({'uuid': 'fake-uuid'})
227
267
        self._check_vm_info(info, power_state.SUSPENDED)
228
268
        self.conn.resume(self.instance, self.network_info)
229
 
        info = self.conn.get_info({'name': 1})
 
269
        info = self.conn.get_info({'uuid': 'fake-uuid'})
230
270
        self._check_vm_info(info, power_state.RUNNING)
231
271
 
232
272
    def test_resume_non_existent(self):
236
276
 
237
277
    def test_resume_not_suspended(self):
238
278
        self._create_vm()
239
 
        info = self.conn.get_info({'name': 1})
 
279
        info = self.conn.get_info({'uuid': 'fake-uuid'})
240
280
        self._check_vm_info(info, power_state.RUNNING)
241
281
        self.assertRaises(exception.InstanceResumeFailure, self.conn.resume,
242
282
                          self.instance, self.network_info)
243
283
 
244
284
    def test_power_on(self):
245
285
        self._create_vm()
246
 
        info = self.conn.get_info({'name': 1})
 
286
        info = self.conn.get_info({'uuid': 'fake-uuid'})
247
287
        self._check_vm_info(info, power_state.RUNNING)
248
288
        self.conn.power_off(self.instance)
249
 
        info = self.conn.get_info({'name': 1})
 
289
        info = self.conn.get_info({'uuid': 'fake-uuid'})
250
290
        self._check_vm_info(info, power_state.SHUTDOWN)
251
 
        self.conn.power_on(self.instance)
252
 
        info = self.conn.get_info({'name': 1})
 
291
        self.conn.power_on(self.context, self.instance, self.network_info)
 
292
        info = self.conn.get_info({'uuid': 'fake-uuid'})
253
293
        self._check_vm_info(info, power_state.RUNNING)
254
294
 
255
295
    def test_power_on_non_existent(self):
256
296
        self._create_instance_in_the_db()
257
297
        self.assertRaises(exception.InstanceNotFound, self.conn.power_on,
258
 
                          self.instance)
 
298
                          self.context, self.instance, self.network_info)
259
299
 
260
300
    def test_power_off(self):
261
301
        self._create_vm()
262
 
        info = self.conn.get_info({'name': 1})
 
302
        info = self.conn.get_info({'uuid': 'fake-uuid'})
263
303
        self._check_vm_info(info, power_state.RUNNING)
264
304
        self.conn.power_off(self.instance)
265
 
        info = self.conn.get_info({'name': 1})
 
305
        info = self.conn.get_info({'uuid': 'fake-uuid'})
266
306
        self._check_vm_info(info, power_state.SHUTDOWN)
267
307
 
268
308
    def test_power_off_non_existent(self):
273
313
    def test_power_off_suspended(self):
274
314
        self._create_vm()
275
315
        self.conn.suspend(self.instance)
276
 
        info = self.conn.get_info({'name': 1})
 
316
        info = self.conn.get_info({'uuid': 'fake-uuid'})
277
317
        self._check_vm_info(info, power_state.SUSPENDED)
278
318
        self.assertRaises(exception.InstancePowerOffFailure,
279
319
                          self.conn.power_off, self.instance)
280
320
 
281
321
    def test_get_info(self):
282
322
        self._create_vm()
283
 
        info = self.conn.get_info({'name': 1})
 
323
        info = self.conn.get_info({'uuid': 'fake-uuid'})
284
324
        self._check_vm_info(info, power_state.RUNNING)
285
325
 
286
326
    def test_destroy(self):
287
327
        self._create_vm()
288
 
        info = self.conn.get_info({'name': 1})
 
328
        info = self.conn.get_info({'uuid': 'fake-uuid'})
289
329
        self._check_vm_info(info, power_state.RUNNING)
290
330
        instances = self.conn.list_instances()
291
331
        self.assertEquals(len(instances), 1)
308
348
        pass
309
349
 
310
350
    def test_get_console_output(self):
311
 
        pass
 
351
        vm_ref = fake_vm_ref()
 
352
        result = fake_http_resp()
 
353
        self._create_instance_in_the_db()
 
354
        self.mox.StubOutWithMock(vm_util, 'get_vm_ref_from_name')
 
355
        self.mox.StubOutWithMock(urllib2, 'urlopen')
 
356
        vm_util.get_vm_ref_from_name(mox.IgnoreArg(), self.instance['name']).\
 
357
        AndReturn(vm_ref)
 
358
        urllib2.urlopen(mox.IgnoreArg()).AndReturn(result)
 
359
 
 
360
        self.mox.ReplayAll()
 
361
        self.conn.get_console_output(self.instance)
 
362
 
 
363
    def test_diagnostics_non_existent_vm(self):
 
364
        self._create_instance_in_the_db()
 
365
        self.assertRaises(exception.InstanceNotFound,
 
366
                          self.conn.get_diagnostics,
 
367
                          self.instance)
 
368
 
 
369
    def test_get_console_pool_info(self):
 
370
        info = self.conn.get_console_pool_info("console_type")
 
371
        self.assertEquals(info['address'], 'test_url')
 
372
        self.assertEquals(info['username'], 'test_username')
 
373
        self.assertEquals(info['password'], 'test_pass')
 
374
 
 
375
    def test_get_vnc_console_non_existent(self):
 
376
        self._create_instance_in_the_db()
 
377
        self.assertRaises(exception.InstanceNotFound,
 
378
                          self.conn.get_vnc_console,
 
379
                          self.instance)
 
380
 
 
381
    def test_get_vnc_console(self):
 
382
        self._create_instance_in_the_db()
 
383
        self._create_vm()
 
384
        vnc_dict = self.conn.get_vnc_console(self.instance)
 
385
        self.assertEquals(vnc_dict['host'], "ha-host")
 
386
        self.assertEquals(vnc_dict['port'], 5910)
 
387
 
 
388
    def test_host_ip_addr(self):
 
389
        self.assertEquals(self.conn.get_host_ip_addr(), "test_url")
 
390
 
 
391
    def test_get_volume_connector(self):
 
392
 
 
393
        def fake_iqn(session, instance):
 
394
            return "iscsi-name"
 
395
 
 
396
        self._create_instance_in_the_db()
 
397
        self.stubs.Set(volume_util, "get_host_iqn", fake_iqn)
 
398
        connector_dict = self.conn.get_volume_connector(self.instance)
 
399
        self.assertEquals(connector_dict['ip'], "test_url")
 
400
        self.assertEquals(connector_dict['initiator'], "iscsi-name")
 
401
        self.assertEquals(connector_dict['host'], "test_url")
312
402
 
313
403
 
314
404
class VMwareAPIHostTestCase(test.TestCase):