Finish quota refactor.
Finishes quota refactoring by making use of the new quota infrastructure. Partially implements blueprint quota-refactor (the final piece is to remove the old quota architecture). This change is fairly substantial. To make it easier to review, it has been broken up into 3 parts. This is the second part. Change-Id: I1c8b43198f0d44e9e13a45575361aa043fd0639e
This commit is contained in:
@@ -105,6 +105,8 @@ flags.DECLARE('vpn_start', 'nova.network.manager')
|
||||
flags.DECLARE('default_floating_pool', 'nova.network.manager')
|
||||
flags.DECLARE('public_interface', 'nova.network.linux_net')
|
||||
|
||||
QUOTAS = quota.QUOTAS
|
||||
|
||||
|
||||
# Decorators for actions
|
||||
def args(*args, **kwargs):
|
||||
@@ -493,11 +495,11 @@ class ProjectCommands(object):
|
||||
db.quota_update(ctxt, project_id, key, value)
|
||||
except exception.ProjectQuotaNotFound:
|
||||
db.quota_create(ctxt, project_id, key, value)
|
||||
project_quota = quota.get_project_quotas(ctxt, project_id)
|
||||
project_quota = QUOTAS.get_project_quotas(ctxt, project_id)
|
||||
for key, value in project_quota.iteritems():
|
||||
if value is None:
|
||||
value = 'unlimited'
|
||||
print '%s: %s' % (key, value)
|
||||
if value['limit'] < 0 or value['limit'] is None:
|
||||
value['limit'] = 'unlimited'
|
||||
print '%s: %s' % (key, value['limit'])
|
||||
|
||||
@args('--project', dest="project_id", metavar='<Project name>',
|
||||
help='Project name')
|
||||
|
@@ -41,14 +41,15 @@ class SchedulerAPI(nova.rpc.proxy.RpcProxy):
|
||||
|
||||
def run_instance(self, ctxt, topic, request_spec, admin_password,
|
||||
injected_files, requested_networks, is_first_time,
|
||||
filter_properties, call=True):
|
||||
filter_properties, reservations, call=True):
|
||||
rpc_method = self.call if call else self.cast
|
||||
return rpc_method(ctxt, self.make_msg('run_instance', topic=topic,
|
||||
request_spec=request_spec, admin_password=admin_password,
|
||||
injected_files=injected_files,
|
||||
requested_networks=requested_networks,
|
||||
is_first_time=is_first_time,
|
||||
filter_properties=filter_properties))
|
||||
filter_properties=filter_properties,
|
||||
reservations=reservations))
|
||||
|
||||
def prep_resize(self, ctxt, topic, instance_uuid, instance_type_id, image,
|
||||
update_db, request_spec, filter_properties):
|
||||
|
@@ -91,7 +91,8 @@ class SimpleScheduler(chance.ChanceScheduler):
|
||||
msg = _("Is the appropriate service running?")
|
||||
raise exception.NoValidHost(reason=msg)
|
||||
|
||||
def schedule_run_instance(self, context, request_spec, *_args, **_kwargs):
|
||||
def schedule_run_instance(self, context, request_spec, reservations,
|
||||
*_args, **_kwargs):
|
||||
num_instances = request_spec.get('num_instances', 1)
|
||||
instances = []
|
||||
for num in xrange(num_instances):
|
||||
@@ -99,7 +100,7 @@ class SimpleScheduler(chance.ChanceScheduler):
|
||||
request_spec['instance_properties'], *_args, **_kwargs)
|
||||
request_spec['instance_properties']['launch_index'] = num
|
||||
instance_ref = self.create_instance_db_entry(context,
|
||||
request_spec)
|
||||
request_spec, reservations)
|
||||
driver.cast_to_compute_host(context, host, 'run_instance',
|
||||
instance_uuid=instance_ref['uuid'], **_kwargs)
|
||||
instances.append(driver.encode_instance(instance_ref))
|
||||
|
@@ -68,14 +68,16 @@ class SchedulerRpcAPITestCase(test.TestCase):
|
||||
topic='fake_topic', request_spec='fake_request_spec',
|
||||
admin_password='pw', injected_files='fake_injected_files',
|
||||
requested_networks='fake_requested_networks',
|
||||
is_first_time=True, filter_properties='fake_filter_properties')
|
||||
is_first_time=True, filter_properties='fake_filter_properties',
|
||||
reservations=None)
|
||||
|
||||
def test_run_instance_cast(self):
|
||||
self._test_scheduler_api('run_instance', rpc_method='cast',
|
||||
topic='fake_topic', request_spec='fake_request_spec',
|
||||
admin_password='pw', injected_files='fake_injected_files',
|
||||
requested_networks='fake_requested_networks',
|
||||
is_first_time=True, filter_properties='fake_filter_properties')
|
||||
is_first_time=True, filter_properties='fake_filter_properties',
|
||||
reservations=None)
|
||||
|
||||
def test_prep_resize(self):
|
||||
self._test_scheduler_api('prep_resize', rpc_method='cast',
|
||||
|
@@ -32,10 +32,12 @@ from nova import log as logging
|
||||
from nova.notifier import test_notifier
|
||||
from nova.openstack.common import importutils
|
||||
import nova.policy
|
||||
from nova import quota
|
||||
from nova import rpc
|
||||
from nova import test
|
||||
import nova.volume.api
|
||||
|
||||
QUOTAS = quota.QUOTAS
|
||||
FLAGS = flags.FLAGS
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@@ -90,6 +92,20 @@ class VolumeTestCase(test.TestCase):
|
||||
|
||||
def test_create_delete_volume(self):
|
||||
"""Test volume can be created and deleted."""
|
||||
# Need to stub out reserve, commit, and rollback
|
||||
def fake_reserve(context, expire=None, **deltas):
|
||||
return ["RESERVATION"]
|
||||
|
||||
def fake_commit(context, reservations):
|
||||
pass
|
||||
|
||||
def fake_rollback(context, reservations):
|
||||
pass
|
||||
|
||||
self.stubs.Set(QUOTAS, "reserve", fake_reserve)
|
||||
self.stubs.Set(QUOTAS, "commit", fake_commit)
|
||||
self.stubs.Set(QUOTAS, "rollback", fake_rollback)
|
||||
|
||||
volume = self._create_volume()
|
||||
volume_id = volume['id']
|
||||
self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
|
||||
|
Reference in New Issue
Block a user