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:
@@ -863,3 +863,11 @@ class InsufficientFreeMemory(NovaException):
|
||||
|
||||
class CouldNotFetchMetrics(NovaException):
|
||||
message = _("Could not fetch bandwidth/cpu/disk metrics for this host.")
|
||||
|
||||
|
||||
class NoValidHost(NovaException):
|
||||
message = _("No valid host was found. %(reason)s")
|
||||
|
||||
|
||||
class WillNotSchedule(NovaException):
|
||||
message = _("Host %(host)s is not up or doesn't exist.")
|
||||
|
||||
@@ -23,6 +23,7 @@ Chance (Random) Scheduler implementation
|
||||
|
||||
import random
|
||||
|
||||
from nova import exception
|
||||
from nova.scheduler import driver
|
||||
|
||||
|
||||
@@ -35,9 +36,8 @@ class ChanceScheduler(driver.Scheduler):
|
||||
elevated = context.elevated()
|
||||
hosts = self.hosts_up(elevated, topic)
|
||||
if not hosts:
|
||||
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)
|
||||
return hosts[int(random.random() * len(hosts))]
|
||||
|
||||
def schedule(self, context, topic, method, *_args, **kwargs):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -115,16 +115,6 @@ def encode_instance(instance, local=True):
|
||||
return instance
|
||||
|
||||
|
||||
class NoValidHost(exception.Error):
|
||||
"""There is no valid host for the command."""
|
||||
pass
|
||||
|
||||
|
||||
class WillNotSchedule(exception.Error):
|
||||
"""The specified host is not up or doesn't exist."""
|
||||
pass
|
||||
|
||||
|
||||
class Scheduler(object):
|
||||
"""The base class that all Scheduler clases should inherit from."""
|
||||
|
||||
@@ -421,7 +411,7 @@ class Scheduler(object):
|
||||
raise exception.MigrationError(reason=reason % locals())
|
||||
|
||||
def _get_compute_info(self, context, host, key):
|
||||
"""get compute node's infomation specified by key
|
||||
"""get compute node's information specified by key
|
||||
|
||||
:param context: security context
|
||||
:param host: hostname(must be compute node)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -444,7 +444,7 @@ class SimpleDriverTestCase(test.TestCase):
|
||||
'cast_to_compute_host', _fake_cast_to_compute_host)
|
||||
|
||||
request_spec = _create_request_spec(availability_zone='nova:host1')
|
||||
self.assertRaises(driver.WillNotSchedule,
|
||||
self.assertRaises(exception.WillNotSchedule,
|
||||
self.scheduler.driver.schedule_run_instance,
|
||||
self.context,
|
||||
request_spec)
|
||||
@@ -523,7 +523,7 @@ class SimpleDriverTestCase(test.TestCase):
|
||||
compute1.start()
|
||||
request_spec = _create_request_spec(availability_zone='zone2')
|
||||
try:
|
||||
self.assertRaises(driver.NoValidHost,
|
||||
self.assertRaises(exception.NoValidHost,
|
||||
self.scheduler.driver.schedule_run_instance,
|
||||
self.context,
|
||||
request_spec)
|
||||
@@ -540,7 +540,7 @@ class SimpleDriverTestCase(test.TestCase):
|
||||
# uses 'nova' for zone
|
||||
volume_id = _create_volume()
|
||||
try:
|
||||
self.assertRaises(driver.NoValidHost,
|
||||
self.assertRaises(exception.NoValidHost,
|
||||
self.scheduler.driver.schedule_create_volume,
|
||||
self.context,
|
||||
volume_id)
|
||||
@@ -570,7 +570,7 @@ class SimpleDriverTestCase(test.TestCase):
|
||||
compute2.run_instance(self.context, instance_id)
|
||||
instance_ids2.append(instance_id)
|
||||
request_spec = _create_request_spec()
|
||||
self.assertRaises(driver.NoValidHost,
|
||||
self.assertRaises(exception.NoValidHost,
|
||||
self.scheduler.driver.schedule_run_instance,
|
||||
self.context,
|
||||
request_spec)
|
||||
@@ -694,7 +694,7 @@ class SimpleDriverTestCase(test.TestCase):
|
||||
past = now - delta
|
||||
db.service_update(self.context, s1['id'], {'updated_at': past})
|
||||
request_spec = _create_request_spec(availability_zone='nova:host1')
|
||||
self.assertRaises(driver.WillNotSchedule,
|
||||
self.assertRaises(exception.WillNotSchedule,
|
||||
self.scheduler.driver.schedule_run_instance,
|
||||
self.context,
|
||||
request_spec)
|
||||
@@ -749,7 +749,7 @@ class SimpleDriverTestCase(test.TestCase):
|
||||
|
||||
request_spec = _create_request_spec()
|
||||
|
||||
self.assertRaises(driver.NoValidHost,
|
||||
self.assertRaises(exception.NoValidHost,
|
||||
self.scheduler.driver.schedule_run_instance,
|
||||
self.context,
|
||||
request_spec)
|
||||
@@ -795,7 +795,7 @@ class SimpleDriverTestCase(test.TestCase):
|
||||
volume2.create_volume(self.context, volume_id)
|
||||
volume_ids2.append(volume_id)
|
||||
volume_id = _create_volume()
|
||||
self.assertRaises(driver.NoValidHost,
|
||||
self.assertRaises(exception.NoValidHost,
|
||||
self.scheduler.driver.schedule_create_volume,
|
||||
self.context,
|
||||
volume_id)
|
||||
@@ -929,7 +929,7 @@ class SimpleDriverTestCase(test.TestCase):
|
||||
db.service_destroy(self.context, s_ref['id'])
|
||||
|
||||
def test_live_migration_dest_check_service_same_host(self):
|
||||
"""Confirms exceptioin raises in case dest and src is same host."""
|
||||
"""Confirms exception raises in case dest and src is same host."""
|
||||
instance_id = _create_instance()['id']
|
||||
i_ref = db.instance_get(self.context, instance_id)
|
||||
s_ref = self._create_compute_service(host=i_ref['host'])
|
||||
|
||||
@@ -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