]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
Fix for bug 883310
authorMandell Degerness <mdegerne@gmail.com>
Fri, 3 Feb 2012 00:01:29 +0000 (00:01 +0000)
committerMandell Degerness <mdegerne@gmail.com>
Fri, 3 Feb 2012 00:01:29 +0000 (00:01 +0000)
Don't throw exception when flavor has vcpus=0 or memory_mb=0

Change-Id: I6f12cf06a569b491f537880afe37f2cf516be2d2

nova/quota.py
nova/tests/test_quota.py

index 95fa317d531e007c62b08d8c51fccd56c57e0a54..d29ba685d28257d3bb7dae4689bfecd464e9be94 100644 (file)
@@ -110,9 +110,13 @@ def allowed_instances(context, requested_instances, instance_type):
     allowed_cores = _get_request_allotment(requested_cores, used_cores,
                                            quota['cores'])
     allowed_ram = _get_request_allotment(requested_ram, used_ram, quota['ram'])
-    allowed_instances = min(allowed_instances,
-                            allowed_cores // instance_type['vcpus'],
-                            allowed_ram // instance_type['memory_mb'])
+    if instance_type['vcpus']:
+        allowed_instances = min(allowed_instances,
+                                allowed_cores // instance_type['vcpus'])
+    if instance_type['memory_mb']:
+        allowed_instances = min(allowed_instances,
+                                allowed_ram // instance_type['memory_mb'])
+
     return min(requested_instances, allowed_instances)
 
 
index 3c267b8b019beea180fcf5540984d5d749bedb37..8ed38cc928d8a65edf6332030c1e745f33963d31 100644 (file)
@@ -97,9 +97,19 @@ class QuotaTestCase(test.TestCase):
                 dict(memory_mb=4096, vcpus=2, root_gb=40, flavorid=3),
             'm1.large': dict(memory_mb=8192, vcpus=4, root_gb=80, flavorid=4),
             'm1.xlarge':
-                dict(memory_mb=16384, vcpus=8, root_gb=160, flavorid=5)}
+                dict(memory_mb=16384, vcpus=8, root_gb=160, flavorid=5),
+            'm1.nocpu': dict(memory_mb=512, vcpus=0, root_gb=0, flavorid=6),
+            'm1.nomem': dict(memory_mb=0, vcpus=1, root_gb=0, flavorid=7)}
         return instance_types[name]
 
+    def test_quota_no_mem_no_cpu(self):
+        num_instances = quota.allowed_instances(self.context, 100,
+            self._get_instance_type('m1.nocpu'))
+        self.assertEqual(num_instances, 2)
+        num_instances = quota.allowed_instances(self.context, 100,
+            self._get_instance_type('m1.nomem'))
+        self.assertEqual(num_instances, 2)
+
     def test_quota_overrides(self):
         """Make sure overriding a projects quotas works"""
         num_instances = quota.allowed_instances(self.context, 100,