Exception cleanup in scheduler
Fixes NoValidHost and willNotSchedule by moving them to exception.py Removed unneeded imports Change-Id: Ib9bb4b36d5e4c00667bd0b2d73137ba9eac5b3b0
This commit is contained in:
@@ -71,7 +71,7 @@ class DistributedScheduler(driver.Scheduler):
|
||||
NOTE: We're only focused on compute instances right now,
|
||||
so this method will always raise NoValidHost()."""
|
||||
msg = _("No host selection for %s defined." % topic)
|
||||
raise driver.NoValidHost(msg)
|
||||
raise exception.NoValidHost(reason=msg)
|
||||
|
||||
def schedule_run_instance(self, context, request_spec, *args, **kwargs):
|
||||
"""This method is called from nova.compute.api to provision
|
||||
@@ -103,7 +103,7 @@ class DistributedScheduler(driver.Scheduler):
|
||||
*args, **kwargs)
|
||||
|
||||
if not weighted_hosts:
|
||||
raise driver.NoValidHost(_('No hosts were available'))
|
||||
raise exception.NoValidHost(reason=_(""))
|
||||
|
||||
instances = []
|
||||
for num in xrange(num_instances):
|
||||
|
@@ -23,6 +23,7 @@ Simple Scheduler
|
||||
|
||||
from nova import db
|
||||
from nova import flags
|
||||
from nova import exception
|
||||
from nova.scheduler import driver
|
||||
from nova.scheduler import chance
|
||||
|
||||
@@ -51,7 +52,7 @@ class SimpleScheduler(chance.ChanceScheduler):
|
||||
if host and context.is_admin:
|
||||
service = db.service_get_by_args(elevated, host, 'nova-compute')
|
||||
if not self.service_is_up(service):
|
||||
raise driver.WillNotSchedule(_("Host %s is not alive") % host)
|
||||
raise exception.WillNotSchedule(host=host)
|
||||
return host
|
||||
|
||||
results = db.service_get_all_compute_sorted(elevated)
|
||||
@@ -61,12 +62,12 @@ class SimpleScheduler(chance.ChanceScheduler):
|
||||
for result in results:
|
||||
(service, instance_cores) = result
|
||||
if instance_cores + instance_opts['vcpus'] > FLAGS.max_cores:
|
||||
raise driver.NoValidHost(_("All hosts have too many cores"))
|
||||
msg = _("All hosts have too many cores")
|
||||
raise exception.NoValidHost(reason=msg)
|
||||
if self.service_is_up(service):
|
||||
return service['host']
|
||||
raise driver.NoValidHost(_("Scheduler was unable to locate a host"
|
||||
" for this request. Is the appropriate"
|
||||
" service running?"))
|
||||
msg = _("Is the appropriate service running?")
|
||||
raise exception.NoValidHost(reason=msg)
|
||||
|
||||
def schedule_run_instance(self, context, request_spec, *_args, **_kwargs):
|
||||
num_instances = request_spec.get('num_instances', 1)
|
||||
@@ -101,7 +102,7 @@ class SimpleScheduler(chance.ChanceScheduler):
|
||||
if host and context.is_admin:
|
||||
service = db.service_get_by_args(elevated, host, 'nova-volume')
|
||||
if not self.service_is_up(service):
|
||||
raise driver.WillNotSchedule(_("Host %s not available") % host)
|
||||
raise exception.WillNotSchedule(host=host)
|
||||
driver.cast_to_volume_host(context, host, 'create_volume',
|
||||
volume_id=volume_id, **_kwargs)
|
||||
return None
|
||||
@@ -113,15 +114,14 @@ class SimpleScheduler(chance.ChanceScheduler):
|
||||
for result in results:
|
||||
(service, volume_gigabytes) = result
|
||||
if volume_gigabytes + volume_ref['size'] > FLAGS.max_gigabytes:
|
||||
raise driver.NoValidHost(_("All hosts have too many "
|
||||
"gigabytes"))
|
||||
msg = _("All hosts have too many gigabytes")
|
||||
raise exception.NoValidHost(reason=msg)
|
||||
if self.service_is_up(service):
|
||||
driver.cast_to_volume_host(context, service['host'],
|
||||
'create_volume', volume_id=volume_id, **_kwargs)
|
||||
return None
|
||||
raise driver.NoValidHost(_("Scheduler was unable to locate a host"
|
||||
" for this request. Is the appropriate"
|
||||
" service running?"))
|
||||
msg = _("Is the appropriate service running?")
|
||||
raise exception.NoValidHost(reason=msg)
|
||||
|
||||
def schedule_set_network_host(self, context, *_args, **_kwargs):
|
||||
"""Picks a host that is up and has the fewest networks."""
|
||||
@@ -131,11 +131,11 @@ class SimpleScheduler(chance.ChanceScheduler):
|
||||
for result in results:
|
||||
(service, instance_count) = result
|
||||
if instance_count >= FLAGS.max_networks:
|
||||
raise driver.NoValidHost(_("All hosts have too many networks"))
|
||||
msg = _("All hosts have too many networks")
|
||||
raise exception.NoValidHost(reason=msg)
|
||||
if self.service_is_up(service):
|
||||
driver.cast_to_network_host(context, service['host'],
|
||||
'set_network_host', **_kwargs)
|
||||
return None
|
||||
raise driver.NoValidHost(_("Scheduler was unable to locate a host"
|
||||
" for this request. Is the appropriate"
|
||||
" service running?"))
|
||||
msg = _("Is the appropriate service running?")
|
||||
raise exception.NoValidHost(reason=msg)
|
||||
|
@@ -25,6 +25,7 @@ from nova import flags
|
||||
from nova import log as logging
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
from nova import exception
|
||||
from nova.scheduler import driver
|
||||
from nova.scheduler import simple
|
||||
from nova.vsa.api import VsaState
|
||||
@@ -173,7 +174,7 @@ class VsaScheduler(simple.SimpleScheduler):
|
||||
selected_hosts,
|
||||
unique)
|
||||
if host is None:
|
||||
raise driver.WillNotSchedule(_("No available hosts"))
|
||||
raise exception.NoValidHost(reason=_(""))
|
||||
|
||||
return (host, qos_cap)
|
||||
|
||||
@@ -216,7 +217,7 @@ class VsaScheduler(simple.SimpleScheduler):
|
||||
service = db.service_get_by_args(context.elevated(), host,
|
||||
'nova-volume')
|
||||
if not self.service_is_up(service):
|
||||
raise driver.WillNotSchedule(_("Host %s not available") % host)
|
||||
raise exception.WillNotSchedule(host=host)
|
||||
|
||||
return host
|
||||
else:
|
||||
|
@@ -25,7 +25,6 @@ from nova import exception
|
||||
from nova import rpc
|
||||
from nova import test
|
||||
from nova.compute import api as compute_api
|
||||
from nova.scheduler import driver
|
||||
from nova.scheduler import distributed_scheduler
|
||||
from nova.scheduler import least_cost
|
||||
from nova.scheduler import zone_manager
|
||||
@@ -120,7 +119,7 @@ class DistributedSchedulerTestCase(test.TestCase):
|
||||
|
||||
fake_context = context.RequestContext('user', 'project')
|
||||
request_spec = dict(instance_type=dict(memory_mb=1, local_gb=1))
|
||||
self.assertRaises(driver.NoValidHost, sched.schedule_run_instance,
|
||||
self.assertRaises(exception.NoValidHost, sched.schedule_run_instance,
|
||||
fake_context, request_spec)
|
||||
|
||||
def test_run_instance_with_blob_hint(self):
|
||||
@@ -189,7 +188,7 @@ class DistributedSchedulerTestCase(test.TestCase):
|
||||
|
||||
fake_context = context.RequestContext('user', 'project')
|
||||
|
||||
self.assertRaises(driver.NoValidHost, sched.schedule_run_instance,
|
||||
self.assertRaises(exception.NoValidHost, sched.schedule_run_instance,
|
||||
fake_context, {})
|
||||
self.assertTrue(self.was_admin)
|
||||
|
||||
|
@@ -28,7 +28,6 @@ from nova import utils
|
||||
from nova.volume import volume_types
|
||||
|
||||
from nova.scheduler import vsa as vsa_sched
|
||||
from nova.scheduler import driver
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
LOG = logging.getLogger('nova.tests.scheduler.vsa')
|
||||
@@ -274,7 +273,7 @@ class VsaSchedulerTestCase(test.TestCase):
|
||||
drive_type_num=5,
|
||||
init_num_drives=1)
|
||||
request_spec = self._get_vol_creation_request(num_vols=1, drive_ix=6)
|
||||
self.assertRaises(driver.WillNotSchedule,
|
||||
self.assertRaises(exception.NoValidHost,
|
||||
self.sched.schedule_create_volumes,
|
||||
self.context,
|
||||
request_spec,
|
||||
@@ -291,7 +290,7 @@ class VsaSchedulerTestCase(test.TestCase):
|
||||
prev = self._generate_default_service_states()
|
||||
request_spec = self._get_vol_creation_request(num_vols=3, drive_ix=0)
|
||||
|
||||
self.assertRaises(driver.WillNotSchedule,
|
||||
self.assertRaises(exception.NoValidHost,
|
||||
self.sched.schedule_create_volumes,
|
||||
self.context,
|
||||
request_spec,
|
||||
@@ -314,7 +313,7 @@ class VsaSchedulerTestCase(test.TestCase):
|
||||
self.service_states = new_states
|
||||
request_spec = self._get_vol_creation_request(num_vols=1, drive_ix=0)
|
||||
|
||||
self.assertRaises(driver.WillNotSchedule,
|
||||
self.assertRaises(exception.NoValidHost,
|
||||
self.sched.schedule_create_volumes,
|
||||
self.context,
|
||||
request_spec,
|
||||
@@ -365,7 +364,7 @@ class VsaSchedulerTestCase(test.TestCase):
|
||||
availability_zone=None)
|
||||
self._print_service_states()
|
||||
|
||||
self.assertRaises(driver.WillNotSchedule,
|
||||
self.assertRaises(exception.NoValidHost,
|
||||
self.sched.schedule_create_volumes,
|
||||
self.context,
|
||||
new_request,
|
||||
@@ -393,7 +392,7 @@ class VsaSchedulerTestCase(test.TestCase):
|
||||
self.stubs.Set(self.sched,
|
||||
'service_is_up', self._fake_service_is_up_False)
|
||||
|
||||
self.assertRaises(driver.WillNotSchedule,
|
||||
self.assertRaises(exception.WillNotSchedule,
|
||||
self.sched.schedule_create_volumes,
|
||||
self.context,
|
||||
request_spec,
|
||||
@@ -483,7 +482,7 @@ class VsaSchedulerTestCase(test.TestCase):
|
||||
global_volume = {}
|
||||
global_volume['volume_type_id'] = None
|
||||
|
||||
self.assertRaises(driver.NoValidHost,
|
||||
self.assertRaises(exception.NoValidHost,
|
||||
self.sched.schedule_create_volume,
|
||||
self.context,
|
||||
123,
|
||||
|
@@ -19,11 +19,7 @@
|
||||
Tests For misc util methods used with compute.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import context
|
||||
from nova import test
|
||||
|
Reference in New Issue
Block a user