-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathtest_scale_vm.py
944 lines (825 loc) · 35.6 KB
/
test_scale_vm.py
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
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
# 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 Scaling up Vm
"""
# Import Local Modules
from marvin.codes import FAILED
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackAPI import scaleVirtualMachine
from marvin.lib.utils import cleanup_resources
from marvin.lib.base import (Account,
Host,
VirtualMachine,
ServiceOffering,
DiskOffering,
Template,
Configurations,
Volume)
from marvin.lib.common import (get_zone,
get_template,
get_test_template,
get_builtin_template_info,
get_domain)
from nose.plugins.attrib import attr
from marvin.sshClient import SshClient
import time
_multiprocess_shared_ = True
class TestScaleVm(cloudstackTestCase):
@classmethod
def setUpClass(cls):
testClient = super(TestScaleVm, cls).getClsTestClient()
cls.apiclient = testClient.getApiClient()
cls.services = testClient.getParsedTestDataConfig()
cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][0].__dict__["clusters"][0].__dict__["hosts"][
0].__dict__
cls._cleanup = []
cls.unsupportedHypervisor = False
cls.hypervisor = cls.testClient.getHypervisorInfo()
if cls.hypervisor.lower() in ('kvm', 'hyperv', 'lxc'):
cls.unsupportedHypervisor = True
return
# Get Zone, Domain and templates
cls.domain = get_domain(cls.apiclient)
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
cls.services['mode'] = cls.zone.networktype
if cls.hypervisor.lower() in ['simulator', 'vmware']:
cls.template = get_template(
cls.apiclient,
cls.zone.id,
cls.services["ostype"]
)
if cls.template == FAILED:
assert False, "get_template() failed to return template\
with description %s" % cls.services["ostype"]
cls.template = Template.update(
cls.template,
cls.apiclient,
isdynamicallyscalable='true'
)
else:
cls.template = get_test_template(
cls.apiclient,
cls.zone.id,
cls.hypervisor
)
if cls.template == FAILED:
assert False, "get_test_template() failed to return template\
with hypervisor %s" % cls.hypervisor
cls.template = Template.update(
cls.template,
cls.apiclient,
isdynamicallyscalable='true'
)
# Set Zones and disk offerings
cls.services["small"]["zoneid"] = cls.zone.id
cls.services["small"]["template"] = cls.template.id
# Create account, service offerings, vm.
cls.account = Account.create(
cls.apiclient,
cls.services["account"],
domainid=cls.domain.id
)
cls._cleanup.append(cls.account)
cls.small_offering = ServiceOffering.create(
cls.apiclient,
cls.services["service_offerings"]["small"]
)
cls._cleanup.append(cls.small_offering)
cls.big_offering = ServiceOffering.create(
cls.apiclient,
cls.services["service_offerings"]["big"]
)
cls._cleanup.append(cls.big_offering)
Configurations.update(
cls.apiclient,
name="enable.dynamic.scale.vm",
value="true"
)
cls.small_offering_dynamic_scaling_disabled = ServiceOffering.create(
cls.apiclient,
cls.services["service_offerings"]["small"],
dynamicscalingenabled=False
)
cls.big_offering_dynamic_scaling_disabled = ServiceOffering.create(
cls.apiclient,
cls.services["service_offerings"]["small"],
dynamicscalingenabled=False
)
cls._cleanup = [
cls.small_offering,
cls.big_offering,
cls.small_offering_dynamic_scaling_disabled,
cls.big_offering_dynamic_scaling_disabled,
cls.account
]
@classmethod
def tearDownClass(cls):
Configurations.update(
cls.apiclient,
name="enable.dynamic.scale.vm",
value="false"
)
Configurations.update(
cls.apiclient,
name="allow.diskOffering.change.during.scale.vm",
value="false"
)
super(TestScaleVm,cls).tearDownClass()
return
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
self.cleanup = []
self.services["disk_offering"]["disksize"] = 2
if self.unsupportedHypervisor:
self.skipTest("Skipping test because unsupported hypervisor\
%s" % self.hypervisor)
def tearDown(self):
# Clean up, terminate the created ISOs
super(TestScaleVm,self).tearDown()
return
def get_ssh_client(self, ip, username, password, retries=10):
""" Setup ssh client connection and return connection """
try:
ssh_client = SshClient(ip, 22, username, password, retries)
except Exception as e:
raise self.skipTest("Unable to create ssh connection: " % e)
self.assertIsNotNone(
ssh_client, "Failed to setup ssh connection to ip=%s" % ip)
return ssh_client
def is_host_xcpng8(self, hostname):
return type(hostname) == list and len(hostname) > 0 and 'XCP-ng 8' in hostname[0]
@attr(hypervisor="xenserver")
@attr(tags=["advanced", "basic"], required_hardware="false")
def test_01_scale_vm(self):
"""Test scale virtual machine
"""
# Validate the following
# Scale up the vm and see if it scales to the new svc offering and is
# finally in running state
# VirtualMachine should be updated to tell cloudstack
# it has PV tools
# available and successfully scaled. We will only mock
# that behaviour
# here but it is not expected in production since the VM
# scaling is not
# guaranteed until tools are installed, vm rebooted
# create a virtual machine
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.services["small"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.small_offering.id,
mode=self.services["mode"]
)
self.cleanup.append(self.virtual_machine)
# If hypervisor is Vmware, then check if
# the vmware tools are installed and the process is running
# Vmware tools are necessary for scale VM operation
if self.hypervisor.lower() == "vmware":
sshClient = self.virtual_machine.get_ssh_client()
result = str(
sshClient.execute("service vmware-tools status")).lower()
self.debug("and result is: %s" % result)
if "running" not in result:
self.skipTest("Skipping scale VM operation because\
VMware tools are not installed on the VM")
res = None
if self.hypervisor.lower() != 'simulator':
hostid = self.virtual_machine.hostid
host = Host.list(
self.apiclient,
zoneid=self.zone.id,
hostid=hostid,
type='Routing'
)[0]
try:
username = self.hostConfig["username"]
password = self.hostConfig["password"]
ssh_client = self.get_ssh_client(host.ipaddress, username, password)
res = ssh_client.execute("hostnamectl | grep 'Operating System' | cut -d':' -f2")
except Exception as e:
pass
if 'XenServer' in res[0]:
self.skipTest("Skipping test for XenServer as it's License does not allow scaling")
self.virtual_machine.update(
self.apiclient,
isdynamicallyscalable='true')
if self.is_host_xcpng8(res):
self.debug("Only scaling for CPU for XCP-ng 8")
offering_data = self.services["service_offerings"]["big"]
offering_data["cpunumber"] = 2
offering_data["memory"] = self.virtual_machine.memory
self.bigger_offering = ServiceOffering.create(
self.apiclient,
offering_data
)
self.cleanup.append(self.bigger_offering)
else:
self.bigger_offering = self.big_offering
self.debug("Scaling VM-ID: %s to service offering: %s and state %s" % (
self.virtual_machine.id,
self.bigger_offering.id,
self.virtual_machine.state
))
cmd = scaleVirtualMachine.scaleVirtualMachineCmd()
cmd.serviceofferingid = self.bigger_offering.id
cmd.id = self.virtual_machine.id
try:
self.apiclient.scaleVirtualMachine(cmd)
except Exception as e:
if "LicenceRestriction" in str(e):
self.skipTest("Your XenServer License does not allow scaling")
else:
self.fail("Scaling failed with the following exception: " + str(e))
list_vm_response = VirtualMachine.list(
self.apiclient,
id=self.virtual_machine.id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
list_vm_response,
None,
"Check virtual machine is in listVirtualMachines"
)
vm_response = list_vm_response[0]
self.assertEqual(
vm_response.id,
self.virtual_machine.id,
"Check virtual machine ID of scaled VM"
)
self.debug(
"Scaling VM-ID: %s from service offering: %s to new service\
offering %s and the response says %s" %
(self.virtual_machine.id,
self.virtual_machine.serviceofferingid,
self.bigger_offering.id,
vm_response.serviceofferingid))
self.assertEqual(
vm_response.serviceofferingid,
self.bigger_offering.id,
"Check service offering of the VM"
)
self.assertEqual(
vm_response.state,
'Running',
"Check the state of VM"
)
return
@attr(tags=["advanced", "basic"], required_hardware="false")
def test_02_scale_vm_negative_offering_disable_scaling(self):
"""Test scale virtual machine which is created from a service offering for which dynamicscalingenabled is false. Scaling operation should fail.
"""
# VirtualMachine should be updated to tell cloudstack
# it has PV tools
# available and successfully scaled. We will only mock
# that behaviour
# here but it is not expected in production since the VM
# scaling is not
# guaranteed until tools are installed, vm rebooted
# create a virtual machine which cannot be dynamically scalable
self.virtual_machine_with_service_offering_dynamic_scaling_disabled = VirtualMachine.create(
self.apiclient,
self.services["small"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.small_offering_dynamic_scaling_disabled.id,
mode=self.services["mode"]
)
self.cleanup.append(self.virtual_machine_with_service_offering_dynamic_scaling_disabled)
# If hypervisor is Vmware, then check if
# the vmware tools are installed and the process is running
# Vmware tools are necessary for scale VM operation
if self.hypervisor.lower() == "vmware":
sshClient = self.virtual_machine_with_service_offering_dynamic_scaling_disabled.get_ssh_client()
result = str(
sshClient.execute("service vmware-tools status")).lower()
self.debug("and result is: %s" % result)
if "running" not in result:
self.skipTest("Skipping scale VM operation because\
VMware tools are not installed on the VM")
list_vm_response = VirtualMachine.list(
self.apiclient,
id=self.virtual_machine_with_service_offering_dynamic_scaling_disabled.id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
list_vm_response,
None,
"Check virtual machine is in listVirtualMachines"
)
vm_response = list_vm_response[0]
self.assertEqual(
vm_response.id,
self.virtual_machine_with_service_offering_dynamic_scaling_disabled.id,
"Check virtual machine ID of scaled VM"
)
self.assertEqual(
vm_response.isdynamicallyscalable,
False,
"Check if VM is not dynamically scalable"
)
self.debug("Scaling VM-ID: %s to service offering: %s for which dynamic scaling is disabled and VM state %s" % (
self.virtual_machine_with_service_offering_dynamic_scaling_disabled.id,
self.big_offering_dynamic_scaling_disabled.id,
self.virtual_machine_with_service_offering_dynamic_scaling_disabled.state
))
cmd = scaleVirtualMachine.scaleVirtualMachineCmd()
cmd.serviceofferingid = self.big_offering_dynamic_scaling_disabled.id
cmd.id = self.virtual_machine_with_service_offering_dynamic_scaling_disabled.id
try:
self.apiclient.scaleVirtualMachine(cmd)
except Exception as e:
if "LicenceRestriction" in str(e):
self.skipTest("Your XenServer License does not allow scaling")
else:
pass
else:
self.fail("Expected an exception to be thrown, failing")
self.debug("Scaling VM-ID: %s to service offering: %s for which dynamic scaling is enabled and VM state %s" % (
self.virtual_machine_with_service_offering_dynamic_scaling_disabled.id,
self.big_offering.id,
self.virtual_machine_with_service_offering_dynamic_scaling_disabled.state
))
cmd = scaleVirtualMachine.scaleVirtualMachineCmd()
cmd.serviceofferingid = self.big_offering.id
cmd.id = self.virtual_machine_with_service_offering_dynamic_scaling_disabled.id
try:
self.apiclient.scaleVirtualMachine(cmd)
except Exception as e:
if "LicenceRestriction" in str(e):
self.skipTest("Your XenServer License does not allow scaling")
else:
pass
else:
self.fail("Expected an exception to be thrown, failing")
return
@attr(tags=["advanced", "basic"], required_hardware="false")
def test_03_scale_vm_negative_vm_disable_scaling(self):
"""Test scale virtual machine which is not dynamically scalable to a service offering. Scaling operation should fail.
"""
# Validate the following
# Scale up the vm which is not dynamically scalable and see if scaling operation fails
# VirtualMachine should be updated to tell cloudstack
# it has PV tools
# available and successfully scaled. We will only mock
# that behaviour
# here but it is not expected in production since the VM
# scaling is not
# guaranteed until tools are installed, vm rebooted
# create a virtual machine which cannot be dynamically scalable
self.virtual_machine_not_dynamically_scalable = VirtualMachine.create(
self.apiclient,
self.services["small"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.small_offering.id,
mode=self.services["mode"],
dynamicscalingenabled=False
)
self.cleanup.append(self.virtual_machine_not_dynamically_scalable)
# If hypervisor is Vmware, then check if
# the vmware tools are installed and the process is running
# Vmware tools are necessary for scale VM operation
if self.hypervisor.lower() == "vmware":
sshClient = self.virtual_machine_not_dynamically_scalable.get_ssh_client()
result = str(
sshClient.execute("service vmware-tools status")).lower()
self.debug("and result is: %s" % result)
if "running" not in result:
self.skipTest("Skipping scale VM operation because\
VMware tools are not installed on the VM")
list_vm_response = VirtualMachine.list(
self.apiclient,
id=self.virtual_machine_not_dynamically_scalable.id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
list_vm_response,
None,
"Check virtual machine is in listVirtualMachines"
)
vm_response = list_vm_response[0]
self.assertEqual(
vm_response.id,
self.virtual_machine_not_dynamically_scalable.id,
"Check virtual machine ID of scaled VM"
)
self.assertEqual(
vm_response.isdynamicallyscalable,
False,
"Check if VM is not dynamically scalable"
)
self.debug("Scaling VM-ID: %s to service offering: %s for which dynamic scaling is enabled and VM state %s" % (
self.virtual_machine_not_dynamically_scalable.id,
self.big_offering.id,
self.virtual_machine_not_dynamically_scalable.state
))
cmd = scaleVirtualMachine.scaleVirtualMachineCmd()
cmd.serviceofferingid = self.big_offering.id
cmd.id = self.virtual_machine_not_dynamically_scalable.id
try:
self.apiclient.scaleVirtualMachine(cmd)
except Exception as e:
if "LicenceRestriction" in str(e):
self.skipTest("Your XenServer License does not allow scaling")
else:
pass
else:
self.fail("Expected an exception to be thrown, failing")
return
@attr(hypervisor="xenserver")
@attr(tags=["advanced", "basic"], required_hardware="false")
def test_04_scale_vm_with_user_account(self):
"""Test scale virtual machine under useraccount
"""
# Validate the following
# Create a user Account and create a VM in it.
# Scale up the vm and see if it scales to the new svc offering
# Create an user account
self.userAccount = Account.create(
self.apiclient,
self.services["account"],
admin=False,
domainid=self.domain.id
)
self.cleanup.append(self.userAccount)
# Create user api client of the user account
self.userapiclient = self.testClient.getUserApiClient(
UserName=self.userAccount.name,
DomainName=self.userAccount.domain
)
# create a virtual machine
self.virtual_machine_in_user_account = VirtualMachine.create(
self.userapiclient,
self.services["small"],
accountid=self.userAccount.name,
domainid=self.userAccount.domainid,
serviceofferingid=self.small_offering.id,
mode=self.services["mode"]
)
if self.hypervisor.lower() == "vmware":
sshClient = self.virtual_machine_in_user_account.get_ssh_client()
result = str(
sshClient.execute("service vmware-tools status")).lower()
self.debug("and result is: %s" % result)
if "running" not in result:
self.skipTest("Skipping scale VM operation because\
VMware tools are not installed on the VM")
res = None
if self.hypervisor.lower() != 'simulator':
list_vm_response = VirtualMachine.list(
self.apiclient,
id=self.virtual_machine_in_user_account.id
)[0]
hostid = list_vm_response.hostid
host = Host.list(
self.apiclient,
zoneid=self.zone.id,
hostid=hostid,
type='Routing'
)[0]
try:
username = self.hostConfig["username"]
password = self.hostConfig["password"]
ssh_client = self.get_ssh_client(host.ipaddress, username, password)
res = ssh_client.execute("hostnamectl | grep 'Operating System' | cut -d':' -f2")
except Exception as e:
pass
if 'XenServer' in res[0]:
self.skipTest("Skipping test for XenServer as it's License does not allow scaling")
self.virtual_machine_in_user_account.update(
self.userapiclient,
isdynamicallyscalable='true')
if self.is_host_xcpng8(res):
self.debug("Only scaling for CPU for XCP-ng 8")
offering_data = self.services["service_offerings"]["big"]
offering_data["cpunumber"] = 2
offering_data["memory"] = self.virtual_machine_in_user_account.memory
self.bigger_offering = ServiceOffering.create(
self.apiclient,
offering_data
)
self.cleanup.append(self.bigger_offering)
else:
self.bigger_offering = self.big_offering
self.debug("Scaling VM-ID: %s to service offering: %s and state %s" % (
self.virtual_machine_in_user_account.id,
self.bigger_offering.id,
self.virtual_machine_in_user_account.state
))
cmd = scaleVirtualMachine.scaleVirtualMachineCmd()
cmd.serviceofferingid = self.bigger_offering.id
cmd.id = self.virtual_machine_in_user_account.id
try:
self.userapiclient.scaleVirtualMachine(cmd)
except Exception as e:
if "LicenceRestriction" in str(e):
self.skipTest("Your XenServer License does not allow scaling")
else:
self.fail("Scaling failed with the following exception: " + str(e))
list_vm_response = VirtualMachine.list(
self.userapiclient,
id=self.virtual_machine_in_user_account.id
)
vm_response = list_vm_response[0]
self.debug(
"Scaling VM-ID: %s from service offering: %s to new service\
offering %s and the response says %s" %
(self.virtual_machine_in_user_account.id,
self.virtual_machine_in_user_account.serviceofferingid,
self.bigger_offering.id,
vm_response.serviceofferingid))
self.assertEqual(
vm_response.serviceofferingid,
self.bigger_offering.id,
"Check service offering of the VM"
)
self.assertEqual(
vm_response.state,
'Running',
"Check the state of VM"
)
return
@attr(hypervisor="xenserver")
@attr(tags=["advanced", "basic"], required_hardware="false")
def test_05_scale_vm_dont_allow_disk_offering_change(self):
"""Test scale virtual machine with disk offering changes
"""
# Validate the following two cases
# 1
# create serviceoffering1 with diskoffering1
# create serviceoffering2 with diskoffering2
# create a VM with serviceoffering1
# Scale up the vm to serviceoffering2
# Check disk offering of root volume to be diskoffering1 since setting allow.diskOffering.change.during.scale.vm is false
# 2
# create serviceoffering3 with diskoffering3
# update setting allow.diskOffering.change.during.scale.vm to true
# scale up the VM to serviceoffering3
# Check disk offering of root volume to be diskoffering3 since setting allow.diskOffering.change.during.scale.vm is true
builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
self.services["template_2"]["url"] = builtin_info[0]
self.services["template_2"]["hypervisor"] = builtin_info[1]
self.services["template_2"]["format"] = builtin_info[2]
try:
template = Template.register(self.apiclient,
self.services["template_2"],
zoneid=self.zone.id,
account=self.account.name,
domainid=self.account.domainid,
hypervisor=self.hypervisor
)
template.download(self.apiclient)
except Exception as e:
self.fail("Failed to register template: %s" % e)
time.sleep(120)
template = Template.update(
template,
self.apiclient,
isdynamicallyscalable='true'
)
templates = Template.list(self.apiclient,
templatefilter= \
self.services["template_2"]["templatefilter"],
id=template.id,
)
template = templates[0]
disk_offering = self.services["disk_offering"]
disk_offering["disksize"] = 25
disk_offering["name"] = "Disk Offering 1"
self.disk_offering1 = DiskOffering.create(
self.apiclient,
disk_offering,
)
self._cleanup.append(self.disk_offering1)
offering_data = {
'displaytext': 'ServiceOffering1WithDiskOffering1',
'cpuspeed': 500,
'cpunumber': 1,
'name': 'ServiceOffering1WithDiskOffering1',
'memory': 512,
'diskofferingid': self.disk_offering1.id
}
self.ServiceOffering1WithDiskOffering1 = ServiceOffering.create(
self.apiclient,
offering_data,
)
self._cleanup.append(self.ServiceOffering1WithDiskOffering1)
# create a virtual machine
self.virtual_machine_test = VirtualMachine.create(
self.apiclient,
self.services["small"],
templateid=template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.ServiceOffering1WithDiskOffering1.id,
mode=self.services["mode"]
)
if self.hypervisor.lower() == "vmware":
sshClient = self.virtual_machine_test.get_ssh_client()
result = str(
sshClient.execute("service vmware-tools status")).lower()
self.debug("and result is: %s" % result)
if "running" not in result:
self.skipTest("Skipping scale VM operation because\
VMware tools are not installed on the VM")
res = None
if self.hypervisor.lower() != 'simulator':
hostid = self.virtual_machine_test.hostid
host = Host.list(
self.apiclient,
zoneid=self.zone.id,
hostid=hostid,
type='Routing'
)[0]
try:
username = self.hostConfig["username"]
password = self.hostConfig["password"]
ssh_client = self.get_ssh_client(host.ipaddress, username, password)
res = ssh_client.execute("hostnamectl | grep 'Operating System' | cut -d':' -f2")
except Exception as e:
pass
if 'XenServer' in res[0]:
self.skipTest("Skipping test for XenServer as it's License does not allow scaling")
self.virtual_machine_test.update(
self.apiclient,
isdynamicallyscalable='true')
disk_offering2 = self.services["disk_offering"]
disk_offering2["name"] = "Disk Offering 2"
self.disk_offering2 = DiskOffering.create(
self.apiclient,
disk_offering2,
)
self._cleanup.append(self.disk_offering2)
offering_data = {
'displaytext': 'ServiceOffering2WithDiskOffering2',
'cpuspeed': 1000,
'cpunumber': 2,
'name': 'ServiceOffering2WithDiskOffering2',
'memory': 1024,
'diskofferingid': self.disk_offering2.id
}
if self.is_host_xcpng8(res):
self.debug("Only scaling for CPU for XCP-ng 8")
offering_data["memory"] = self.virtual_machine_test.memory
self.ServiceOffering2WithDiskOffering2 = ServiceOffering.create(
self.apiclient,
offering_data,
)
self._cleanup.append(self.ServiceOffering2WithDiskOffering2)
self.debug("Scaling VM-ID: %s to service offering: %s and state %s" % (
self.virtual_machine_test.id,
self.ServiceOffering2WithDiskOffering2.id,
self.virtual_machine_test.state
))
cmd = scaleVirtualMachine.scaleVirtualMachineCmd()
cmd.serviceofferingid = self.ServiceOffering2WithDiskOffering2.id
cmd.id = self.virtual_machine_test.id
try:
self.apiclient.scaleVirtualMachine(cmd)
except Exception as e:
if "LicenceRestriction" in str(e):
self.skipTest("Your XenServer License does not allow scaling")
else:
self.fail("Scaling failed with the following exception: " + str(e))
list_vm_response = VirtualMachine.list(
self.apiclient,
id=self.virtual_machine_test.id
)
vm_response = list_vm_response[0]
self.debug(
"Scaling VM-ID: %s from service offering: %s to new service\
offering %s and the response says %s" %
(self.virtual_machine_test.id,
self.virtual_machine_test.serviceofferingid,
self.ServiceOffering2WithDiskOffering2.id,
vm_response.serviceofferingid))
vm_response = list_vm_response[0]
self.assertEqual(
vm_response.serviceofferingid,
self.ServiceOffering2WithDiskOffering2.id,
"Check service offering of the VM"
)
volume_response = Volume.list(
self.apiclient,
virtualmachineid=self.virtual_machine_test.id,
listall=True
)[0]
self.assertEqual(
volume_response.diskofferingid,
self.disk_offering1.id,
"Check disk offering of the VM, this should not change since allow.diskOffering.change.during.scale.vm is false"
)
# Do same scale vm operation with allow.diskOffering.change.during.scale.vm value to true
if self.hypervisor.lower() in ['simulator']:
self.debug("Simulator doesn't support changing disk offering, volume resize")
return
disk_offering_data = self.services["disk_offering"]
disk_offering_data["name"] = "Disk Offering 3"
if self.hypervisor.lower() in ['xenserver']:
self.debug("For hypervisor %s, do not resize volume and just change try to change the disk offering")
volume_response = Volume.list(
self.apiclient,
virtualmachineid=self.virtual_machine_test.id,
listall=True
)[0]
disk_offering_data["disksize"] = int(volume_response.size / (1024 ** 3))
self.disk_offering3 = DiskOffering.create(
self.apiclient,
disk_offering_data,
)
self._cleanup.append(self.disk_offering3)
offering_data = {
'displaytext': 'ServiceOffering3WithDiskOffering3',
'cpuspeed': 1500,
'cpunumber': 2,
'name': 'ServiceOffering3WithDiskOffering3',
'memory': 1024,
'diskofferingid': self.disk_offering3.id
}
if self.is_host_xcpng8(res):
self.debug("Only scaling for CPU for XCP-ng 8")
offering_data["memory"] = vm_response.memory
self.ServiceOffering3WithDiskOffering3 = ServiceOffering.create(
self.apiclient,
offering_data,
)
self._cleanup.append(self.ServiceOffering3WithDiskOffering3)
Configurations.update(
self.apiclient,
name="allow.diskOffering.change.during.scale.vm",
value="true"
)
time.sleep(30)
self.debug("Scaling VM-ID: %s to service offering: %s and state %s" % (
self.virtual_machine_test.id,
self.ServiceOffering3WithDiskOffering3.id,
self.virtual_machine_test.state
))
cmd = scaleVirtualMachine.scaleVirtualMachineCmd()
cmd.serviceofferingid = self.ServiceOffering3WithDiskOffering3.id
cmd.id = self.virtual_machine_test.id
try:
self.apiclient.scaleVirtualMachine(cmd)
except Exception as e:
if "LicenceRestriction" in str(e):
self.skipTest("Your XenServer License does not allow scaling")
else:
self.fail("Scaling failed with the following exception: " + str(e))
list_vm_response = VirtualMachine.list(
self.apiclient,
id=self.virtual_machine_test.id
)
vm_response = list_vm_response[0]
self.debug(
"Scaling VM-ID: %s from service offering: %s to new service\
offering %s and the response says %s" %
(self.virtual_machine_test.id,
self.virtual_machine_test.serviceofferingid,
self.ServiceOffering3WithDiskOffering3.id,
vm_response.serviceofferingid))
self.assertEqual(
vm_response.serviceofferingid,
self.ServiceOffering3WithDiskOffering3.id,
"Check service offering of the VM"
)
volume_response = Volume.list(
self.apiclient,
virtualmachineid=self.virtual_machine_test.id,
listall=True
)[0]
self.debug("After scaling 3: Volume disk offering %s and disk offering 3: %s" % (volume_response.diskofferingid, self.disk_offering3.id))
self.assertEqual(
volume_response.diskofferingid,
self.disk_offering3.id,
"Check disk offering of the VM, this should change since allow.diskOffering.change.during.scale.vm is true"
)
return