forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_host_high_availability.py
More file actions
862 lines (736 loc) · 29.5 KB
/
Copy pathtest_host_high_availability.py
File metadata and controls
862 lines (736 loc) · 29.5 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
""" P1 tests for dedicated Host high availability
"""
#Import Local Modules
from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import cloudstackTestCase
import unittest
from marvin.cloudstackAPI import (migrateVirtualMachine,
prepareHostForMaintenance,
cancelHostMaintenance)
from marvin.lib.utils import cleanup_resources
from marvin.lib.base import (Account,
VirtualMachine,
ServiceOffering,
Cluster,
Host,
Configurations)
from marvin.lib.common import (get_zone,
get_domain,
get_template,
list_hosts,
list_virtual_machines,
list_service_offering)
import time
class Services:
""" Dedicated host HA test cases """
def __init__(self):
self.services = {
"account": {
"email": "test@test.com",
"firstname": "HA",
"lastname": "HA",
"username": "HA",
# Random characters are appended for unique
# username
"password": "password",
},
"service_offering_with_ha": {
"name": "Tiny Instance With HA Enabled",
"displaytext": "Tiny Instance",
"cpunumber": 1,
"cpuspeed": 100, # in MHz
"memory": 128, # In MBs
},
"service_offering_without_ha": {
"name": "Tiny Instance Without HA",
"displaytext": "Tiny Instance",
"cpunumber": 1,
"cpuspeed": 100, # in MHz
"memory": 128, # In MBs
},
"virtual_machine": {
"displayname": "VM",
"username": "root",
"password": "password",
"ssh_port": 22,
"hypervisor": 'XenServer',
# Hypervisor type should be same as
# hypervisor type of cluster
"privateport": 22,
"publicport": 22,
"protocol": 'TCP',
},
"ostype": 'CentOS 5.3 (64-bit)',
"timeout": 100,
}
class TestHostHighAvailability(cloudstackTestCase):
""" Dedicated host HA test cases """
@classmethod
def setUpClass(cls):
cls.testClient = super(TestHostHighAvailability, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient()
cls.services = Services().services
# Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
cls.template = get_template(
cls.api_client,
cls.zone.id,
cls.services["ostype"]
)
cls.hypervisor = cls.testClient.getHypervisorInfo()
if cls.hypervisor.lower() in ['lxc']:
raise unittest.SkipTest("Template creation from root volume is not supported in LXC")
clusterWithSufficientHosts = None
clusters = Cluster.list(cls.api_client, zoneid=cls.zone.id)
for cluster in clusters:
cls.hosts = Host.list(cls.api_client, clusterid=cluster.id, type="Routing")
if len(cls.hosts) >= 3:
clusterWithSufficientHosts = cluster
break
if clusterWithSufficientHosts is None:
raise unittest.SkipTest("No Cluster with 3 hosts found")
configs = Configurations.list(
cls.api_client,
name='ha.tag'
)
assert isinstance(configs, list), "Config list not\
retrieved for ha.tag"
if configs[0].value != "ha":
raise unittest.SkipTest("Please set the global config\
value for ha.tag as 'ha'")
Host.update(cls.api_client, id=cls.hosts[2].id, hosttags="ha")
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["virtual_machine"]["template"] = cls.template.id
cls.service_offering_with_ha = ServiceOffering.create(
cls.api_client,
cls.services["service_offering_with_ha"],
offerha=True
)
cls.service_offering_without_ha = ServiceOffering.create(
cls.api_client,
cls.services["service_offering_without_ha"],
offerha=False
)
cls._cleanup = [
cls.service_offering_with_ha,
cls.service_offering_without_ha,
]
return
@classmethod
def tearDownClass(cls):
try:
# Remove the host from HA
Host.update(cls.api_client, id=cls.hosts[2].id, hosttags="")
#Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
self.account = Account.create(
self.apiclient,
self.services["account"],
admin=True,
domainid=self.domain.id
)
self.cleanup = [self.account]
return
def tearDown(self):
try:
#Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(configuration="ha.tag")
@attr(tags=["advanced", "advancedns", "sg", "basic", "eip", "simulator"])
def test_01_vm_deployment_with_compute_offering_with_ha_enabled(self):
""" Test VM deployments (Create HA enabled Compute Service Offering and VM) """
# Steps,
#1. Create a Compute service offering with the 'Offer HA' option selected.
#2. Create a Guest VM with the compute service offering created above.
# Validations,
#1. Ensure that the offering is created and that in the UI the 'Offer HA' field is enabled (Yes)
#The listServiceOffering API should list 'offerha' as true.
#2. Select the newly created VM and ensure that the Compute offering field value lists the compute service offering that was selected.
# Also, check that the HA Enabled field is enabled 'Yes'.
#list and validate above created service offering with Ha enabled
list_service_response = list_service_offering(
self.apiclient,
id=self.service_offering_with_ha.id
)
self.assertEqual(
isinstance(list_service_response, list),
True,
"listServiceOfferings returned invalid object in response."
)
self.assertNotEqual(
len(list_service_response),
0,
"listServiceOfferings returned empty list."
)
self.assertEqual(
list_service_response[0].offerha,
True,
"The service offering is not HA enabled"
)
#create virtual machine with the service offering with Ha enabled
virtual_machine = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_with_ha.id
)
vms = VirtualMachine.list(
self.apiclient,
id=virtual_machine.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"listVirtualMachines returned invalid object in response."
)
self.assertNotEqual(
len(vms),
0,
"listVirtualMachines returned empty list."
)
self.debug("Deployed VM on host: %s" % vms[0].hostid)
self.assertEqual(
vms[0].haenable,
True,
"VM not created with HA enable tag"
)
@attr(configuration="ha.tag")
@attr(tags=["advanced", "advancedns", "sg", "basic", "eip", "simulator", "multihost"])
def test_02_no_vm_creation_on_host_with_haenabled(self):
""" Verify you can not create new VMs on hosts with an ha.tag """
# Steps,
#1. Fresh install CS (Bonita) that supports this feature
#2. Create Basic zone, pod, cluster, add 3 hosts to cluster (host1, host2, host3), secondary & primary Storage
#3. When adding host3, assign the HA host tag.
#4. You should already have a compute service offering with HA already create from above. If not, create one for HA.
#5. Create VMs with the service offering with and without the HA tag
# Validations,
#Check to make sure the newly created VM is not on any HA enabled hosts
#The VM should be created only on host1 or host2 and never host3 (HA enabled)
#create and verify virtual machine with HA enabled service offering
virtual_machine_with_ha = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_with_ha.id
)
vms = VirtualMachine.list(
self.apiclient,
id=virtual_machine_with_ha.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"listVirtualMachines returned invalid object in response."
)
self.assertNotEqual(
len(vms),
0,
"listVirtualMachines returned empty list."
)
vm = vms[0]
self.debug("Deployed VM on host: %s" % vm.hostid)
#validate the virtual machine created is host Ha enabled
list_hosts_response = list_hosts(
self.apiclient,
id=vm.hostid
)
self.assertEqual(
isinstance(list_hosts_response, list),
True,
"listHosts returned invalid object in response."
)
self.assertNotEqual(
len(list_hosts_response),
0,
"listHosts retuned empty list in response."
)
self.assertEqual(
list_hosts_response[0].hahost,
False,
"VM created on HA enabled host."
)
#create and verify virtual machine with Ha disabled service offering
virtual_machine_without_ha = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_without_ha.id
)
vms = VirtualMachine.list(
self.apiclient,
id=virtual_machine_without_ha.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"listVirtualMachines returned invalid object in response."
)
self.assertNotEqual(
len(vms),
0,
"listVirtualMachines returned empty list."
)
vm = vms[0]
self.debug("Deployed VM on host: %s" % vm.hostid)
#verify that the virtual machine created on the host is Ha disabled
list_hosts_response = list_hosts(
self.apiclient,
id=vm.hostid
)
self.assertEqual(
isinstance(list_hosts_response, list),
True,
"listHosts returned invalid object in response."
)
self.assertNotEqual(
len(list_hosts_response),
0,
"listHosts returned empty list."
)
host = list_hosts_response[0]
self.assertEqual(
host.hahost,
False,
"VM migrated to HA enabled host."
)
@attr(configuration="ha.tag")
@attr(tags=["advanced", "advancedns", "sg", "basic", "eip", "simulator", "multihost"])
def test_03_cant_migrate_vm_to_host_with_ha_positive(self):
""" Verify you can not migrate VMs to hosts with an ha.tag (positive) """
# Steps,
# 1. Create a Compute service offering with the 'Offer HA' option selected.
# 2. Create a Guest VM with the compute service offering created above.
# 3. Select the VM and migrate VM to another host. Choose a 'Suitable' host (i.e. host2)
# Validations
# The option from the 'Migrate instance to another host' dialog box' should list host3 as 'Not Suitable' for migration.
# Confirm that the VM is migrated to the 'Suitable' host you selected
# (i.e. host2)
# create and verify the virtual machine with HA enabled service
# offering
self.hypervisor = self.testClient.getHypervisorInfo()
if self.hypervisor.lower() in ['lxc']:
self.skipTest("vm migrate is not supported in %s" % self.hypervisor)
virtual_machine_with_ha = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_with_ha.id
)
vms = VirtualMachine.list(
self.apiclient,
id=virtual_machine_with_ha.id,
listall=True,
)
self.assertEqual(
isinstance(vms, list),
True,
"List VMs should return valid response for deployed VM"
)
self.assertNotEqual(
len(vms),
0,
"List VMs should return valid response for deployed VM"
)
vm = vms[0]
self.debug("Deployed VM on host: %s" % vm.hostid)
# Find out a Suitable host for VM migration
list_hosts_response = list_hosts(
self.apiclient,
virtualmachineid = vm.id
)
self.assertEqual(
isinstance(list_hosts_response, list),
True,
"The listHosts API returned the invalid list"
)
self.assertNotEqual(
len(list_hosts_response),
0,
"The listHosts returned nothing."
)
suitableHost = None
for host in list_hosts_response:
if host.suitableformigration and host.hostid != vm.hostid:
suitableHost = host
break
self.assertTrue(
suitableHost is not None,
"suitablehost should not be None")
# Migration of the VM to a suitable host
self.debug(
"Migrating VM-ID: %s to Host: %s" %
(vm.id, suitableHost.id))
cmd = migrateVirtualMachine.migrateVirtualMachineCmd()
cmd.hostid = suitableHost.id
cmd.virtualmachineid = vm.id
self.apiclient.migrateVirtualMachine(cmd)
# Verify that the VM migrated to a targeted Suitable host
list_vm_response = list_virtual_machines(
self.apiclient,
id=vm.id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"The listVirtualMachines returned the invalid list."
)
self.assertNotEqual(
list_vm_response,
None,
"The listVirtualMachines API returned nothing."
)
vm_response = list_vm_response[0]
self.assertEqual(
vm_response.id,
vm.id,
"The virtual machine id and the the virtual machine from listVirtualMachines is not matching."
)
self.assertEqual(
vm_response.hostid,
suitableHost.id,
"The VM is not migrated to targeted suitable host."
)
@attr(configuration="ha.tag")
@attr(tags=["advanced", "advancedns", "sg", "basic", "eip", "simulator", "multihost"])
def test_04_cant_migrate_vm_to_host_with_ha_negative(self):
""" Verify you can not migrate VMs to hosts with an ha.tag (negative) """
# Steps,
#1. Create a Compute service offering with the 'Offer HA' option selected.
#2. Create a Guest VM with the compute service offering created above.
#3. Select the VM and migrate VM to another host. Choose a 'Not Suitable' host.
# Validations,
#The option from the 'Migrate instance to another host' dialog box should list host3 as 'Not Suitable' for migration.
#By design, The Guest VM can STILL can be migrated to host3 if the admin chooses to do so.
#create and verify virtual machine with HA enabled service offering
self.hypervisor = self.testClient.getHypervisorInfo()
if self.hypervisor.lower() in ['lxc']:
self.skipTest("vm migrate is not supported in %s" % self.hypervisor)
virtual_machine_with_ha = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_with_ha.id
)
vms = VirtualMachine.list(
self.apiclient,
id=virtual_machine_with_ha.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"The listVirtualMachines returned invalid object in response."
)
self.assertNotEqual(
len(vms),
0,
"The listVirtualMachines returned empty response."
)
vm = vms[0]
self.debug("Deployed VM on host: %s" % vm.hostid)
#Find out Non-Suitable host for VM migration
list_hosts_response = list_hosts(
self.apiclient,
type="Routing"
)
self.assertEqual(
isinstance(list_hosts_response, list),
True,
"listHosts returned invalid object in response."
)
self.assertNotEqual(
len(list_hosts_response),
0,
"listHosts returned empty response."
)
notSuitableHost = None
for host in list_hosts_response:
if not host.suitableformigration and host.id != vm.hostid:
notSuitableHost = host
break
self.assertTrue(notSuitableHost is not None, "notsuitablehost should not be None")
#Migrate VM to Non-Suitable host
self.debug("Migrating VM-ID: %s to Host: %s" % (vm.id, notSuitableHost.id))
cmd = migrateVirtualMachine.migrateVirtualMachineCmd()
cmd.hostid = notSuitableHost.id
cmd.virtualmachineid = vm.id
self.apiclient.migrateVirtualMachine(cmd)
#Verify that the virtual machine got migrated to targeted Non-Suitable host
list_vm_response = list_virtual_machines(
self.apiclient,
id=vm.id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"listVirtualMachine returned invalid object in response."
)
self.assertNotEqual(
len(list_vm_response),
0,
"listVirtualMachines returned empty response."
)
self.assertEqual(
list_vm_response[0].id,
vm.id,
"Virtual machine id with the virtual machine from listVirtualMachine is not matching."
)
self.assertEqual(
list_vm_response[0].hostid,
notSuitableHost.id,
"The detination host id of migrated VM is not matching."
)
@attr(configuration="ha.tag")
@attr(speed="slow")
@attr(tags=["advanced", "advancedns", "sg", "basic", "eip", "simulator", "multihost"])
def test_05_no_vm_with_ha_gets_migrated_to_ha_host_in_live_migration(self):
""" Verify that none of the VMs with HA enabled migrate to an ha tagged host during live migration """
# Steps,
#1. Fresh install CS that supports this feature
#2. Create Basic zone, pod, cluster, add 3 hosts to cluster (host1, host2, host3), secondary & primary Storage
#3. When adding host3, assign the HA host tag.
#4. Create VMs with and without the Compute Service Offering with the HA tag.
#5. Note the VMs on host1 and whether any of the VMs have their 'HA enabled' flags enabled.
#6. Put host1 into maintenance mode.
# Validations,
#1. Make sure the VMs are created on either host1 or host2 and not on host3
#2. Putting host1 into maintenance mode should trigger a live migration. Make sure the VMs are not migrated to HA enabled host3.
# create and verify virtual machine with HA disabled service offering
self.hypervisor = self.testClient.getHypervisorInfo()
if self.hypervisor.lower() in ['lxc']:
self.skipTest("vm migrate is not supported in %s" % self.hypervisor)
virtual_machine_with_ha = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_with_ha.id
)
vms = VirtualMachine.list(
self.apiclient,
id=virtual_machine_with_ha.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"List VMs should return valid response for deployed VM"
)
self.assertNotEqual(
len(vms),
0,
"List VMs should return valid response for deployed VM"
)
vm_with_ha_enabled = vms[0]
#Verify the virtual machine got created on non HA host
list_hosts_response = list_hosts(
self.apiclient,
id=vm_with_ha_enabled.hostid
)
self.assertEqual(
isinstance(list_hosts_response, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
len(list_hosts_response),
0,
"Check Host is available"
)
self.assertEqual(
list_hosts_response[0].hahost,
False,
"The virtual machine is not ha enabled so check if VM is created on host which is also not ha enabled"
)
#put the Host in maintenance mode
self.debug("Enabling maintenance mode for host %s" % vm_with_ha_enabled.hostid)
cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
cmd.id = vm_with_ha_enabled.hostid
self.apiclient.prepareHostForMaintenance(cmd)
timeout = self.services["timeout"]
#verify the VM live migration happened to another running host
self.debug("Waiting for VM to come up")
time.sleep(timeout)
vms = VirtualMachine.list(
self.apiclient,
id=vm_with_ha_enabled.id,
listall=True,
)
self.assertEqual(
isinstance(vms, list),
True,
"List VMs should return valid response for deployed VM"
)
self.assertNotEqual(
len(vms),
0,
"List VMs should return valid response for deployed VM"
)
vm_with_ha_enabled1 = vms[0]
list_hosts_response = list_hosts(
self.apiclient,
id=vm_with_ha_enabled1.hostid
)
self.assertEqual(
isinstance(list_hosts_response, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
len(list_hosts_response),
0,
"Check Host is available"
)
self.assertEqual(
list_hosts_response[0].hahost,
False,
"The virtual machine is not ha enabled so check if VM is created on host which is also not ha enabled"
)
self.debug("Disabling the maintenance mode for host %s" % vm_with_ha_enabled.hostid)
cmd = cancelHostMaintenance.cancelHostMaintenanceCmd()
cmd.id = vm_with_ha_enabled.hostid
self.apiclient.cancelHostMaintenance(cmd)
@attr(configuration="ha.tag")
@attr(speed="slow")
@attr(tags=["advanced", "advancedns", "sg", "basic", "eip", "simulator", "multihost"])
def test_06_no_vm_without_ha_gets_migrated_to_ha_host_in_live_migration(self):
""" Verify that none of the VMs without HA enabled migrate to an ha tagged host during live migration """
# Steps,
#1. Fresh install CS that supports this feature
#2. Create Basic zone, pod, cluster, add 3 hosts to cluster (host1, host2, host3), secondary & primary Storage
#3. When adding host3, assign the HA host tag.
#4. Create VMs with and without the Compute Service Offering with the HA tag.
#5. Note the VMs on host1 and whether any of the VMs have their 'HA enabled' flags enabled.
#6. Put host1 into maintenance mode.
# Validations,
#1. Make sure the VMs are created on either host1 or host2 and not on host3
#2. Putting host1 into maintenance mode should trigger a live migration. Make sure the VMs are not migrated to HA enabled host3.
# create and verify virtual machine with HA disabled service offering
self.hypervisor = self.testClient.getHypervisorInfo()
if self.hypervisor.lower() in ['lxc']:
self.skipTest("vm migrate is not supported in %s" % self.hypervisor)
virtual_machine_without_ha = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_without_ha.id
)
vms = VirtualMachine.list(
self.apiclient,
id=virtual_machine_without_ha.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"List VMs should return valid response for deployed VM"
)
self.assertNotEqual(
len(vms),
0,
"List VMs should return valid response for deployed VM"
)
vm_with_ha_disabled = vms[0]
#Verify the virtual machine got created on non HA host
list_hosts_response = list_hosts(
self.apiclient,
id=vm_with_ha_disabled.hostid
)
self.assertEqual(
isinstance(list_hosts_response, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
len(list_hosts_response),
0,
"Check Host is available"
)
self.assertEqual(
list_hosts_response[0].hahost,
False,
"The virtual machine is not ha enabled so check if VM is created on host which is also not ha enabled"
)
#put the Host in maintenance mode
self.debug("Enabling maintenance mode for host %s" % vm_with_ha_disabled.hostid)
cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
cmd.id = vm_with_ha_disabled.hostid
self.apiclient.prepareHostForMaintenance(cmd)
timeout = self.services["timeout"]
#verify the VM live migration happened to another running host
self.debug("Waiting for VM to come up")
time.sleep(timeout)
vms = VirtualMachine.list(
self.apiclient,
id=vm_with_ha_disabled.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"List VMs should return valid response for deployed VM"
)
self.assertNotEqual(
len(vms),
0,
"List VMs should return valid response for deployed VM"
)
list_hosts_response = list_hosts(
self.apiclient,
id=vms[0].hostid
)
self.assertEqual(
isinstance(list_hosts_response, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
len(list_hosts_response),
0,
"Check Host is available"
)
self.assertEqual(
list_hosts_response[0].hahost,
False,
"The virtual machine is not ha enabled so check if VM is created on host which is also not ha enabled"
)
self.debug("Disabling the maintenance mode for host %s" % vm_with_ha_disabled.hostid)
cmd = cancelHostMaintenance.cancelHostMaintenanceCmd()
cmd.id = vm_with_ha_disabled.hostid
self.apiclient.cancelHostMaintenance(cmd)