Skip to content

Commit 9667154

Browse files
SudharmaJainRohit Yadav
authored andcommitted
CLOUDSTACK-9567 Difference in the api call outputs for CAPACITY_TYPE_CPU = 1
(cherry picked from commit 732be53) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 77fb2c9 commit 9667154

2 files changed

Lines changed: 114 additions & 4 deletions

File tree

engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
139139

140140
private static final String LIST_CAPACITY_GROUP_BY_CAPACITY_PART1=
141141
"SELECT sum(capacity.used_capacity), sum(capacity.reserved_capacity),"
142-
+ " (case capacity_type when 1 then (sum(total_capacity) * CAST((select value from `cloud`.`cluster_details` where cluster_details.name= 'cpuOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id) AS DECIMAL (10,4))) "
143-
+ "when '0' then (sum(total_capacity) * CAST((select value from `cloud`.`cluster_details` where cluster_details.name= 'memoryOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id) AS DECIMAL(10,4)))else sum(total_capacity) end),"
144-
+ "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / ( case capacity_type when 1 then (sum(total_capacity) * CAST((select value from `cloud`.`cluster_details` where cluster_details.name= 'cpuOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id) AS DECIMAL(10,4))) "
145-
+ "when '0' then (sum(total_capacity) * CAST((select value from `cloud`.`cluster_details` where cluster_details.name= 'memoryOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id) AS DECIMAL(10,4))) else sum(total_capacity) end)) percent,"
142+
+ " (case capacity_type when 1 then sum(total_capacity * CAST((select value from `cloud`.`cluster_details` where cluster_details.name= 'cpuOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id) AS DECIMAL (10,4))) "
143+
+ "when '0' then sum(total_capacity * CAST((select value from `cloud`.`cluster_details` where cluster_details.name= 'memoryOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id) AS DECIMAL(10,4)))else sum(total_capacity) end),"
144+
+ "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / ( case capacity_type when 1 then sum(total_capacity * CAST((select value from `cloud`.`cluster_details` where cluster_details.name= 'cpuOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id) AS DECIMAL(10,4))) "
145+
+ "when '0' then sum(total_capacity * CAST((select value from `cloud`.`cluster_details` where cluster_details.name= 'memoryOvercommitRatio' AND cluster_details.cluster_id=capacity.cluster_id) AS DECIMAL(10,4))) else sum(total_capacity) end)) percent,"
146146
+ "capacity.capacity_type, capacity.data_center_id, pod_id, cluster_id FROM `cloud`.`op_host_capacity` capacity WHERE total_capacity > 0 AND data_center_id is not null AND capacity_state='Enabled' ";
147147

148148
private static final String LIST_CAPACITY_GROUP_BY_CAPACITY_PART2 = " GROUP BY capacity_type";
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
""" test for listPods
19+
"""
20+
21+
from nose.plugins.attrib import attr
22+
from marvin.cloudstackTestCase import cloudstackTestCase, unittest
23+
from marvin.lib.utils import (cleanup_resources)
24+
from marvin.lib.base import (Pod, Cluster, Capacities)
25+
from marvin.cloudstackAPI import (updateConfiguration)
26+
27+
28+
class TestListPod(cloudstackTestCase):
29+
@classmethod
30+
def setUpClass(cls):
31+
super(TestListPod, cls)
32+
33+
def setUp(self):
34+
self.apiclient = self.testClient.getApiClient()
35+
36+
# build cleanup list
37+
self.cleanup = []
38+
39+
def tearDown(self):
40+
try:
41+
cleanup_resources(self.apiclient, self.cleanup)
42+
except Exception as e:
43+
self.debug("Warning! Exception in tearDown: %s" % e)
44+
45+
@attr(tags=["advanced", "basic"], required_hardware="false")
46+
def test_list_pod_with_overcommit(self):
47+
"""Test List Pod Api with cluster CPU and Memory OverProvisioning
48+
"""
49+
50+
podlist = Pod.list(self.apiclient)
51+
52+
for pod in podlist:
53+
clusterlist = Cluster.list(self.apiclient, podid=pod.id)
54+
if len(clusterlist) > 1:
55+
56+
updateCpuOvercommitCmd = updateConfiguration.updateConfigurationCmd()
57+
updateCpuOvercommitCmd.clusterid = clusterlist[0].id
58+
updateCpuOvercommitCmd.name="cpu.overprovisioning.factor"
59+
60+
if clusterlist[0].cpuovercommitratio == clusterlist[1].cpuovercommitratio and clusterlist[0].cpuovercommitratio == "1.0":
61+
cpuovercommit = "1.0"
62+
updateCpuOvercommitCmd.value="2.0"
63+
self.apiclient.updateConfiguration(updateCpuOvercommitCmd)
64+
65+
elif clusterlist[0].cpuovercommitratio != clusterlist[1].cpuovercommitratio:
66+
cpuovercommit = clusterlist[0].cpuovercommitratio
67+
68+
else:
69+
cpuovercommit = clusterlist[0].cpuovercommitratio
70+
updateCpuOvercommitCmd.value="1.0"
71+
self.apiclient.updateConfiguration(updateCpuOvercommitCmd)
72+
73+
updateMemoryOvercommitCmd = updateConfiguration.updateConfigurationCmd()
74+
updateMemoryOvercommitCmd.clusterid = clusterlist[0].id
75+
updateMemoryOvercommitCmd.name="mem.overprovisioning.factor"
76+
77+
if clusterlist[0].memoryovercommitratio == clusterlist[1].memoryovercommitratio and clusterlist[0].memoryovercommitratio == "1.0":
78+
memoryovercommit = "1.0"
79+
updateMemoryOvercommitCmd.value="2.0"
80+
self.apiclient.updateConfiguration(updateMemoryOvercommitCmd)
81+
82+
elif clusterlist[0].memoryovercommitratio != clusterlist[1].memoryovercommitratio:
83+
memoryovercommit = clusterlist[0].memoryovercommitratio
84+
85+
else:
86+
memoryovercommit = clusterlist[0].memoryovercommitratio
87+
updateMemoryOvercommitCmd.value="1.0"
88+
self.apiclient.updateConfiguration(updateMemoryOvercommitCmd)
89+
90+
podWithCap = Pod.list(self.apiclient, id=pod.id, showcapacities=True)
91+
cpucapacity = Capacities.list(self.apiclient, podid=pod.id, type=1)
92+
memorycapacity = Capacities.list(self.apiclient, podid=pod.id, type=0)
93+
94+
updateCpuOvercommitCmd.value = cpuovercommit
95+
updateMemoryOvercommitCmd.value = memoryovercommit
96+
97+
self.apiclient.updateConfiguration(updateCpuOvercommitCmd)
98+
self.apiclient.updateConfiguration(updateMemoryOvercommitCmd)
99+
100+
self.assertEqual(
101+
[cap for cap in podWithCap[0].capacity if cap.type == 1][0].capacitytotal,
102+
cpucapacity[0].capacitytotal,
103+
"listPods api returns wrong CPU capacity "
104+
)
105+
106+
self.assertEqual(
107+
[cap for cap in podWithCap[0].capacity if cap.type == 0][0].capacitytotal,
108+
memorycapacity[0].capacitytotal,
109+
"listPods api returns wrong memory capacity"
110+
)

0 commit comments

Comments
 (0)