summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-06-15 01:44:18 +0000
committerGerrit Code Review <review@openstack.org>2013-06-15 01:44:18 +0000
commit898c260e84a4e3c002d9feacbc43293361185e6f (patch)
tree69c242105e479d2218722073f4e533a4230e0582 /nova
parentd23ef2ab59b1cadb5df32c997dab2054177bc622 (diff)
parent90453d5c60e7a9d023c916ad257c03f47a4e4031 (diff)
Merge "Fix quota checks while resizing up by admin"
Diffstat (limited to 'nova')
-rw-r--r--nova/compute/api.py13
-rw-r--r--nova/tests/compute/test_compute.py34
2 files changed, 43 insertions, 4 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 001342822..1e24e8ce5 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -2023,8 +2023,10 @@ class API(base.Base):
old_instance_type, 1, -1)
@staticmethod
- def _reserve_quota_delta(context, deltas):
- return QUOTAS.reserve(context, **deltas) if deltas else None
+ def _reserve_quota_delta(context, deltas, project_id=None):
+ if not deltas:
+ return
+ return QUOTAS.reserve(context, project_id=project_id, **deltas)
@wrap_check_policy
@check_instance_lock
@@ -2080,7 +2082,9 @@ class API(base.Base):
deltas = self._upsize_quota_delta(context, new_instance_type,
current_instance_type)
try:
- reservations = self._reserve_quota_delta(context, deltas)
+ reservations = self._reserve_quota_delta(context, deltas,
+ project_id=instance[
+ 'project_id'])
except exception.OverQuota as exc:
quotas = exc.kwargs['quotas']
usages = exc.kwargs['usages']
@@ -2126,7 +2130,8 @@ class API(base.Base):
# With cells, the best we can do right now is commit the reservations
# immediately...
if CONF.cells.enable and reservations:
- QUOTAS.commit(context, reservations)
+ QUOTAS.commit(context, reservations,
+ project_id=instance['project_id'])
reservations = []
args = {
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index be332beb0..f39230ce7 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -6749,6 +6749,40 @@ class ComputeAPITestCase(BaseTestCase):
flavors.destroy(name)
self.compute.terminate_instance(self.context, instance=instance)
+ def test_resize_by_admin_for_tenant_with_sufficient_quota(self):
+ user_project_id = 'user'
+ instance = self._create_fake_instance({'project_id': user_project_id})
+ self.context.is_admin = True
+ db.quota_create(self.context, self.context.project_id, 'ram', 0)
+ instance = db.instance_get_by_uuid(self.context, instance['uuid'])
+ instance = jsonutils.to_primitive(instance)
+ self.compute.run_instance(self.context, instance=instance)
+ name = 'test_resize_with_big_mem'
+ flavor_id = 11
+ flavors.create(name, 1024, 1, 0, ephemeral_gb=0, flavorid=flavor_id,
+ swap=0, rxtx_factor=1.0, is_public=True)
+ deltas = {'ram': 512}
+ reservations = ['reservation_id']
+
+ self.mox.StubOutWithMock(self.compute_api, '_reserve_quota_delta')
+
+ self.compute_api._reserve_quota_delta(self.context,
+ deltas,
+ project_id=user_project_id). \
+ AndReturn(reservations)
+
+ CONF.cells.enable = True
+ self.mox.StubOutWithMock(nova.quota.QUOTAS, 'commit')
+ nova.quota.QUOTAS.commit(self.context, reservations,
+ project_id=user_project_id)
+ self.mox.ReplayAll()
+
+ self.compute_api.resize(self.context, instance, flavor_id)
+
+ flavors.destroy(name)
+ db.quota_destroy_all_by_project(self.context, self.context.project_id)
+ self.compute.terminate_instance(self.context, instance=instance)
+
def test_resize_revert_deleted_flavor_fails(self):
orig_name = 'test_resize_revert_orig_flavor'
orig_flavorid = 11