forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_overcommit.py
More file actions
458 lines (403 loc) · 16.8 KB
/
test_overcommit.py
File metadata and controls
458 lines (403 loc) · 16.8 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
# 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.
""" test for feature "CPU and MEM OVERCOMMIT"
"""
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.lib.base import (Account,
Capacities,
Cluster,
Configurations,
FAILED,
Host,
PASS,
ServiceOffering,
time,
VirtualMachine,)
from marvin.lib.utils import cleanup_resources, validateList
from marvin.lib.common import (get_zone,
get_domain,
get_template)
from marvin.sshClient import SshClient
from nose.plugins.attrib import attr
def ssh_xen_host(password, ipaddr, instance_name):
"""Ssh into xen host and get vm mem details"""
mem = []
sshClient = SshClient(
ipaddr,
22,
"root",
password
)
command = "xe vm-list params=all name-label=%s" % instance_name
vm_detail = sshClient.execute(command)
max_str = vm_detail[17].split(":")
min_str = vm_detail[20].split(":")
max = int(max_str[1])
min = int(min_str[1])
mem.append(max)
mem.append(min)
return mem
def ssh_kvm_host(password, ipaddr, instance_name):
"""Ssh into kvm host and get vm mem details"""
mem = []
sshClient = SshClient(
ipaddr,
22,
"root",
password
)
command = "virsh dominfo %s" % instance_name
vm_detail = sshClient.execute(command)
max = vm_detail[7].split()
min = vm_detail[8].split()
mem.append(int(max[2]))
mem.append(int(min[2]))
return mem
def capacity_parser(capacity):
cpu = []
mem = []
cpu.append(capacity[0].capacitytotal)
cpu.append(capacity[0].capacityused)
cpu.append(capacity[0].percentused)
mem.append(capacity[1].capacitytotal)
mem.append(capacity[1].capacityused)
mem.append(capacity[1].percentused)
return cpu, mem
class Overcommit (cloudstackTestCase):
@classmethod
def setUpClass(cls):
testClient = super(Overcommit, cls).getClsTestClient()
cls.apiclient = testClient.getApiClient()
cls.testdata = testClient.getParsedTestDataConfig()
# Get Zone,Domain and templates
cls.domain = get_domain(cls.apiclient)
cls.zone = get_zone(cls.apiclient)
cls.testdata["mode"] = cls.zone.networktype
cls.testdata["configurableData"]["password"] = "xenroot"
cls.hypervisor = testClient.getHypervisorInfo()
cls.template = get_template(
cls.apiclient,
cls.zone.id,
cls.testdata["ostype"])
cls.testdata["template"]["ostypeid"] = cls.template.ostypeid
list_conf = Configurations.list(cls.apiclient,
name="capacity.check.period"
)
cls.wait_time = 5 + int(list_conf[0].value) / 1000
if cls.template == FAILED:
cls.fail(
"get_template() failed to return template with description \
%s" %
cls.testdata["ostype"])
cls._cleanup = []
try:
cls.account = Account.create(cls.apiclient,
cls.testdata["account"],
domainid=cls.domain.id
)
cls._cleanup.append(cls.account)
cls.service_offering = ServiceOffering.create(
cls.apiclient,
cls.testdata["service_offerings"]["small"])
cls._cleanup.append(cls.service_offering)
cls.deployVmResponse = VirtualMachine.create(
cls.apiclient,
services=cls.testdata["virtual_machine"],
accountid=cls.account.name,
domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id,
templateid=cls.template.id,
zoneid=cls.zone.id,
)
except Exception as e:
cls.tearDownClass()
raise e
return
@classmethod
def tearDownClass(cls):
try:
cleanup_resources(cls.apiclient, cls._cleanup)
except Exception as e:
raise Exception("Warning:Exception during cleanup: %s" % e)
@attr(
tags=[
"simulator",
"devcloud",
"basic",
"advanced"],
required_hardware="false")
def test_01_cluster_settings(self):
"""change cpu/mem.overprovisioning.factor at cluster level and
verify the change """
listHost = Host.list(self.apiclient,
id=self.deployVmResponse.hostid
)
self.assertEqual(
validateList(listHost)[0],
PASS,
"check list host response for host id %s" %
self.deployVmResponse.hostid)
Configurations.update(self.apiclient,
clusterid=listHost[0].clusterid,
name="mem.overprovisioning.factor",
value=2)
Configurations.update(self.apiclient,
clusterid=listHost[0].clusterid,
name="cpu.overprovisioning.factor",
value=3)
list_cluster = Cluster.list(self.apiclient,
id=listHost[0].clusterid)
self.assertEqual(
validateList(list_cluster)[0],
PASS,
"check list cluster response for cluster id %s" %
listHost[0].clusterid)
self.assertEqual(int(list_cluster[0].cpuovercommitratio),
3,
"check the cpu overcommit value at cluster level ")
self.assertEqual(int(list_cluster[0].memoryovercommitratio),
2,
"check memory overcommit value at cluster level")
Configurations.update(self.apiclient,
clusterid=listHost[0].clusterid,
name="mem.overprovisioning.factor",
value=1)
Configurations.update(self.apiclient,
clusterid=listHost[0].clusterid,
name="cpu.overprovisioning.factor",
value=1)
list_cluster1 = Cluster.list(self.apiclient,
id=listHost[0].clusterid)
self.assertEqual(
validateList(list_cluster1)[0],
PASS,
"check the list cluster response for id %s" %
listHost[0].clusterid)
self.assertEqual(int(list_cluster1[0].cpuovercommitratio),
1,
"check the cpu overcommit value at cluster level ")
self.assertEqual(int(list_cluster1[0].memoryovercommitratio),
1,
"check memory overcommit value at cluster level")
@attr(
tags=["simulator",
"devcloud",
"basic",
"advanced"],
required_hardware="true")
def test_02_Overcommit_factor(self):
"""change mem.overprovisioning.factor and verify vm memory """
listHost = Host.list(self.apiclient,
id=self.deployVmResponse.hostid
)
self.assertEqual(
validateList(listHost)[0],
PASS,
"check list host for host id %s" %
self.deployVmResponse.hostid)
if listHost[0].hypervisor.lower() not in ['kvm', 'xenserver']:
self.skipTest(
"Skiping test because of not supported hypervisor type %s" %
listHost[0].hypervisor)
Configurations.update(self.apiclient,
clusterid=listHost[0].clusterid,
name="mem.overprovisioning.factor",
value=1)
self.deployVmResponse.stop(self.apiclient)
self.deployVmResponse.start(self.apiclient)
if listHost[0].hypervisor.lower() == 'xenserver':
k = ssh_xen_host(
self.testdata["configurableData"]["password"],
listHost[0].ipaddress,
self.deployVmResponse.instancename)
elif listHost[0].hypervisor.lower() == 'kvm':
k = ssh_kvm_host(
self.testdata["configurableData"]["password"],
listHost[0].ipaddress,
self.deployVmResponse.instancename)
self.assertEqual(k[0],
k[1],
"Check static max ,min on host for overcommit 1 ")
Configurations.update(self.apiclient,
clusterid=listHost[0].clusterid,
name="mem.overprovisioning.factor",
value=2)
self.deployVmResponse.stop(self.apiclient)
self.deployVmResponse.start(self.apiclient)
if listHost[0].hypervisor.lower() == 'xenserver':
k1 = ssh_xen_host(
self.testdata["configurableData"]["password"],
listHost[0].ipaddress,
self.deployVmResponse.instancename)
elif listHost[0].hypervisor.lower() == 'kvm':
time.sleep(200)
k1 = ssh_kvm_host(
self.testdata["configurableData"]["password"],
listHost[0].ipaddress,
self.deployVmResponse.instancename)
self.assertEqual(k1[0],
2 * k1[1],
"Check static max ,min on host for overcommit 2")
@attr(
tags=[
"simulator",
"devcloud",
"basic",
"advanced"],
required_hardware="false")
def test_03_cluste_capacity_check(self):
"""change cpu/mem.overprovisioning.factor at cluster level and
verify cluster capacity """
listHost = Host.list(self.apiclient,
id=self.deployVmResponse.hostid
)
self.assertEqual(
validateList(listHost)[0],
PASS,
"check list host for host id %s" %
self.deployVmResponse.hostid)
Configurations.update(self.apiclient,
clusterid=listHost[0].clusterid,
name="mem.overprovisioning.factor",
value=1)
Configurations.update(self.apiclient,
clusterid=listHost[0].clusterid,
name="cpu.overprovisioning.factor",
value=1)
time.sleep(self.wait_time)
capacity = Capacities.list(self.apiclient,
clusterid=listHost[0].clusterid)
self.assertEqual(
validateList(capacity)[0],
PASS,
"check list capacity response for cluster id %s" %
listHost[0].clusterid)
cpu, mem = capacity_parser(capacity)
Configurations.update(self.apiclient,
clusterid=listHost[0].clusterid,
name="mem.overprovisioning.factor",
value=2)
Configurations.update(self.apiclient,
clusterid=listHost[0].clusterid,
name="cpu.overprovisioning.factor",
value=2)
time.sleep(self.wait_time)
capacity1 = Capacities.list(self.apiclient,
clusterid=listHost[0].clusterid)
self.assertEqual(
validateList(capacity1)[0],
PASS,
"check list capacity response for cluster id %s" %
listHost[0].clusterid)
cpu1, mem1 = capacity_parser(capacity1)
self.assertEqual(2 * cpu[0],
cpu1[0],
"check total capacity ")
self.assertEqual(2 * cpu[1],
cpu1[1],
"check capacity used")
self.assertEqual(cpu[2],
cpu1[2],
"check capacity % used")
self.assertEqual(2 * mem[0],
mem1[0],
"check mem total capacity ")
self.assertEqual(2 * mem[1],
mem1[1],
"check mem capacity used")
self.assertEqual(mem[2],
mem1[2],
"check mem capacity % used")
@attr(
tags=[
"simulator",
"devcloud",
"basic",
"advanced"],
required_hardware="false")
def test_04_zone_capacity_check(self):
"""change cpu/mem.overprovisioning.factor at cluster level for
all cluster in a zone and verify capacity at zone level """
list_cluster = Cluster.list(self.apiclient,
zoneid=self.zone.id)
self.assertEqual(
validateList(list_cluster)[0],
PASS,
"check list cluster response for zone id %s" %
self.zone.id)
k = len(list_cluster)
for id in xrange(k):
Configurations.update(self.apiclient,
clusterid=list_cluster[id].id,
name="mem.overprovisioning.factor",
value=1)
Configurations.update(self.apiclient,
clusterid=list_cluster[id].id,
name="cpu.overprovisioning.factor",
value=1)
time.sleep(self.wait_time)
capacity = Capacities.list(self.apiclient,
zoneid=self.zone.id)
self.assertEqual(
validateList(capacity)[0],
PASS,
"check list capacity response for zone id %s" %
self.zone.id)
cpu, mem = capacity_parser(capacity)
for id in xrange(k):
Configurations.update(self.apiclient,
clusterid=list_cluster[id].id,
name="mem.overprovisioning.factor",
value=2)
Configurations.update(self.apiclient,
clusterid=list_cluster[id].id,
name="cpu.overprovisioning.factor",
value=2)
time.sleep(self.wait_time)
capacity1 = Capacities.list(self.apiclient,
zoneid=self.zone.id)
self.assertEqual(validateList(capacity1)[0],
PASS,
"check list capacity for zone id %s" % self.zone.id)
cpu1, mem1 = capacity_parser(capacity1)
self.assertEqual(2 * cpu[0],
cpu1[0],
"check total capacity ")
self.assertEqual(2 * cpu[1],
cpu1[1],
"check capacity used")
self.assertEqual(cpu[2],
cpu1[2],
"check capacity % used")
self.assertEqual(2 * mem[0],
mem1[0],
"check mem total capacity ")
self.assertEqual(2 * mem[1],
mem1[1],
"check mem capacity used")
self.assertEqual(mem[2],
mem1[2],
"check mem capacity % used")
for id in xrange(k):
Configurations.update(self.apiclient,
clusterid=list_cluster[id].id,
name="mem.overprovisioning.factor",
value=1)
Configurations.update(self.apiclient,
clusterid=list_cluster[id].id,
name="cpu.overprovisioning.factor",
value=1)