|
| 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