summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael H Wilson <geekinutah@gmail.com>2012-10-16 15:47:52 -0600
committerMichael H Wilson <geekinutah@gmail.com>2012-10-25 23:51:48 -0600
commit0bf28bec6097d128aa439b288b249fafcac7dbc0 (patch)
tree348bde399a5efd964741470af9264195899c228e
parent5d677e204c99fbcf86e0c721ad2fd327a03c35c2 (diff)
downloadnova-0bf28bec6097d128aa439b288b249fafcac7dbc0.tar.gz
nova-0bf28bec6097d128aa439b288b249fafcac7dbc0.tar.xz
nova-0bf28bec6097d128aa439b288b249fafcac7dbc0.zip
Fix hardcoded topic strings with constants.
Replace hardcoded topic strings like 'volume' or 'compute' with config constants like FLAGS.volume_topic, etc. See bug #1057831 and bug #1061628. Change-Id: I817ecc3cbe3245b51a0c047be58d17edfec8a838
-rwxr-xr-xbin/nova-cert3
-rwxr-xr-xbin/nova-compute4
-rwxr-xr-xbin/nova-console4
-rwxr-xr-xbin/nova-consoleauth5
-rwxr-xr-xbin/nova-network4
-rwxr-xr-xbin/nova-scheduler4
-rwxr-xr-xbin/nova-volume4
-rw-r--r--nova/api/openstack/compute/contrib/instance_usage_audit_log.py2
-rw-r--r--nova/db/sqlalchemy/api.py9
-rw-r--r--nova/scheduler/chance.py6
-rw-r--r--nova/scheduler/driver.py8
-rw-r--r--nova/scheduler/filter_scheduler.py11
-rw-r--r--nova/scheduler/filters/compute_filter.py4
-rw-r--r--nova/scheduler/filters/core_filter.py2
-rw-r--r--nova/scheduler/host_manager.py2
-rw-r--r--nova/service.py3
16 files changed, 46 insertions, 29 deletions
diff --git a/bin/nova-cert b/bin/nova-cert
index 81189492a..ebdd0e0b9 100755
--- a/bin/nova-cert
+++ b/bin/nova-cert
@@ -39,8 +39,9 @@ from nova import utils
if __name__ == '__main__':
flags.parse_args(sys.argv)
+ FLAGS = flags.FLAGS
logging.setup("nova")
utils.monkey_patch()
- server = service.Service.create(binary='nova-cert')
+ server = service.Service.create(binary='nova-cert', topic=FLAGS.cert_topic)
service.serve(server)
service.wait()
diff --git a/bin/nova-compute b/bin/nova-compute
index 0a8432b1e..2a2a0013a 100755
--- a/bin/nova-compute
+++ b/bin/nova-compute
@@ -41,8 +41,10 @@ from nova import utils
if __name__ == '__main__':
flags.parse_args(sys.argv)
+ FLAGS = flags.FLAGS
logging.setup('nova')
utils.monkey_patch()
- server = service.Service.create(binary='nova-compute')
+ server = service.Service.create(binary='nova-compute',
+ topic=FLAGS.compute_topic)
service.serve(server)
service.wait()
diff --git a/bin/nova-console b/bin/nova-console
index 97b152930..f664040b7 100755
--- a/bin/nova-console
+++ b/bin/nova-console
@@ -39,7 +39,9 @@ from nova import service
if __name__ == '__main__':
flags.parse_args(sys.argv)
+ FLAGS = flags.FLAGS
logging.setup("nova")
- server = service.Service.create(binary='nova-console')
+ server = service.Service.create(binary='nova-console',
+ topic=FLAGS.console_topic)
service.serve(server)
service.wait()
diff --git a/bin/nova-consoleauth b/bin/nova-consoleauth
index f8277daf6..58ecd37b3 100755
--- a/bin/nova-consoleauth
+++ b/bin/nova-consoleauth
@@ -39,8 +39,9 @@ from nova import service
if __name__ == "__main__":
flags.parse_args(sys.argv)
+ FLAGS = flags.FLAGS
logging.setup("nova")
-
- server = service.Service.create(binary='nova-consoleauth')
+ server = service.Service.create(binary='nova-consoleauth',
+ topic=FLAGS.consoleauth_topic)
service.serve(server)
service.wait()
diff --git a/bin/nova-network b/bin/nova-network
index ca9a97551..36343bb73 100755
--- a/bin/nova-network
+++ b/bin/nova-network
@@ -41,8 +41,10 @@ from nova import utils
if __name__ == '__main__':
flags.parse_args(sys.argv)
+ FLAGS = flags.FLAGS
logging.setup("nova")
utils.monkey_patch()
- server = service.Service.create(binary='nova-network')
+ server = service.Service.create(binary='nova-network',
+ topic=FLAGS.network_topic)
service.serve(server)
service.wait()
diff --git a/bin/nova-scheduler b/bin/nova-scheduler
index e100156df..64dadb9e4 100755
--- a/bin/nova-scheduler
+++ b/bin/nova-scheduler
@@ -43,8 +43,10 @@ from nova import utils
if __name__ == '__main__':
flags.parse_args(sys.argv)
+ FLAGS = flags.FLAGS
logging.setup("nova")
utils.monkey_patch()
- server = service.Service.create(binary='nova-scheduler')
+ server = service.Service.create(binary='nova-scheduler',
+ topic=FLAGS.scheduler_topic)
service.serve(server)
service.wait()
diff --git a/bin/nova-volume b/bin/nova-volume
index 2c10c99f5..602b332b7 100755
--- a/bin/nova-volume
+++ b/bin/nova-volume
@@ -41,8 +41,10 @@ from nova import utils
if __name__ == '__main__':
flags.parse_args(sys.argv)
+ FLAGS = flags.FLAGS
logging.setup("nova")
utils.monkey_patch()
- server = service.Service.create(binary='nova-volume')
+ server = service.Service.create(binary='nova-volume',
+ topic=FLAGS.volume_topic)
service.serve(server)
service.wait()
diff --git a/nova/api/openstack/compute/contrib/instance_usage_audit_log.py b/nova/api/openstack/compute/contrib/instance_usage_audit_log.py
index 1331c0a93..4547bbd01 100644
--- a/nova/api/openstack/compute/contrib/instance_usage_audit_log.py
+++ b/nova/api/openstack/compute/contrib/instance_usage_audit_log.py
@@ -82,7 +82,7 @@ class InstanceUsageAuditLogController(object):
# We do this this way to include disabled compute services,
# which can have instances on them. (mdragon)
services = [svc for svc in db.service_get_all(context)
- if svc['topic'] == 'compute']
+ if svc['topic'] == FLAGS.compute_topic]
hosts = set(serv['host'] for serv in services)
seen_hosts = set()
done_hosts = set()
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 0946d0b19..2e390a2ff 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -331,7 +331,8 @@ def service_destroy(context, service_id):
service_ref = service_get(context, service_id, session=session)
service_ref.delete(session=session)
- if service_ref.topic == 'compute' and service_ref.compute_node:
+ if (service_ref.topic == FLAGS.compute_topic and
+ service_ref.compute_node):
for c in service_ref.compute_node:
c.delete(session=session)
@@ -387,7 +388,7 @@ def service_get_all_compute_by_host(context, host):
result = model_query(context, models.Service, read_deleted="no").\
options(joinedload('compute_node')).\
filter_by(host=host).\
- filter_by(topic="compute").\
+ filter_by(topic=FLAGS.compute_topic).\
all()
if not result:
@@ -420,7 +421,7 @@ def service_get_all_compute_sorted(context):
# (SELECT host, SUM(instances.vcpus) AS instance_cores
# FROM instances GROUP BY host) AS inst_cores
# ON services.host = inst_cores.host
- topic = 'compute'
+ topic = FLAGS.compute_topic
label = 'instance_cores'
subq = model_query(context, models.Instance.host,
func.sum(models.Instance.vcpus).label(label),
@@ -438,7 +439,7 @@ def service_get_all_compute_sorted(context):
def service_get_all_volume_sorted(context):
session = get_session()
with session.begin():
- topic = 'volume'
+ topic = FLAGS.volume_topic
label = 'volume_gigabytes'
subq = model_query(context, models.Volume.host,
func.sum(models.Volume.size).label(label),
diff --git a/nova/scheduler/chance.py b/nova/scheduler/chance.py
index 65806d4d5..e0f351a78 100644
--- a/nova/scheduler/chance.py
+++ b/nova/scheduler/chance.py
@@ -65,8 +65,8 @@ class ChanceScheduler(driver.Scheduler):
for num, instance_uuid in enumerate(instance_uuids):
request_spec['instance_properties']['launch_index'] = num
try:
- host = self._schedule(context, 'compute', request_spec,
- filter_properties)
+ host = self._schedule(context, FLAGS.compute_topic,
+ request_spec, filter_properties)
updated_instance = driver.instance_update_db(context,
instance_uuid)
self.compute_rpcapi.run_instance(context,
@@ -88,7 +88,7 @@ class ChanceScheduler(driver.Scheduler):
filter_properties, instance, instance_type,
reservations):
"""Select a target for resize."""
- host = self._schedule(context, 'compute', request_spec,
+ host = self._schedule(context, FLAGS.compute_topic, request_spec,
filter_properties)
self.compute_rpcapi.prep_resize(context, image, instance,
instance_type, host, reservations)
diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py
index 2c2f95e2d..5cbe925c5 100644
--- a/nova/scheduler/driver.py
+++ b/nova/scheduler/driver.py
@@ -96,7 +96,7 @@ def cast_to_volume_host(context, host, method, **kwargs):
db.volume_update(context, volume_id,
{'host': host, 'scheduled_at': now})
rpc.cast(context,
- rpc.queue_get_for(context, 'volume', host),
+ rpc.queue_get_for(context, FLAGS.volume_topic, host),
{"method": method, "args": kwargs})
LOG.debug(_("Casted '%(method)s' to volume '%(host)s'") % locals())
@@ -119,7 +119,7 @@ def cast_to_compute_host(context, host, method, **kwargs):
instance_update_db(context, instance_uuid)
rpc.cast(context,
- rpc.queue_get_for(context, 'compute', host),
+ rpc.queue_get_for(context, FLAGS.compute_topic, host),
{"method": method, "args": kwargs})
LOG.debug(_("Casted '%(method)s' to compute '%(host)s'") % locals())
@@ -128,8 +128,8 @@ def cast_to_host(context, topic, host, method, **kwargs):
"""Generic cast to host"""
topic_mapping = {
- "compute": cast_to_compute_host,
- "volume": cast_to_volume_host}
+ FLAGS.compute_topic: cast_to_compute_host,
+ FLAGS.volume_topic: cast_to_volume_host}
func = topic_mapping.get(topic)
if func:
diff --git a/nova/scheduler/filter_scheduler.py b/nova/scheduler/filter_scheduler.py
index 7b13ab215..789f252b0 100644
--- a/nova/scheduler/filter_scheduler.py
+++ b/nova/scheduler/filter_scheduler.py
@@ -69,8 +69,9 @@ class FilterScheduler(driver.Scheduler):
notifier.notify(context, notifier.publisher_id("scheduler"),
'scheduler.run_instance.start', notifier.INFO, payload)
- weighted_hosts = self._schedule(context, "compute", request_spec,
- filter_properties, instance_uuids)
+ weighted_hosts = self._schedule(context, FLAGS.compute_topic,
+ request_spec, filter_properties,
+ instance_uuids)
# NOTE(comstud): Make sure we do not pass this through. It
# contains an instance of RpcContext that cannot be serialized.
@@ -115,7 +116,7 @@ class FilterScheduler(driver.Scheduler):
the prep_resize operation to it.
"""
- hosts = self._schedule(context, 'compute', request_spec,
+ hosts = self._schedule(context, FLAGS.compute_topic, request_spec,
filter_properties, [instance['uuid']])
if not hosts:
raise exception.NoValidHost(reason="")
@@ -219,7 +220,7 @@ class FilterScheduler(driver.Scheduler):
ordered by their fitness.
"""
elevated = context.elevated()
- if topic != "compute":
+ if topic != FLAGS.compute_topic:
msg = _("Scheduler only understands Compute nodes (for now)")
raise NotImplementedError(msg)
@@ -299,7 +300,7 @@ class FilterScheduler(driver.Scheduler):
"""
if topic is None:
# Schedulers only support compute right now.
- topic = "compute"
+ topic = FLAGS.compute_topic
if topic in self.cost_function_cache:
return self.cost_function_cache[topic]
diff --git a/nova/scheduler/filters/compute_filter.py b/nova/scheduler/filters/compute_filter.py
index 2d7c898d6..4af71c7b4 100644
--- a/nova/scheduler/filters/compute_filter.py
+++ b/nova/scheduler/filters/compute_filter.py
@@ -13,10 +13,12 @@
# License for the specific language governing permissions and limitations
# under the License.
+from nova import flags
from nova.openstack.common import log as logging
from nova.scheduler import filters
from nova import utils
+FLAGS = flags.FLAGS
LOG = logging.getLogger(__name__)
@@ -27,7 +29,7 @@ class ComputeFilter(filters.BaseHostFilter):
def host_passes(self, host_state, filter_properties):
"""Returns True for only active compute nodes"""
instance_type = filter_properties.get('instance_type')
- if host_state.topic != 'compute' or not instance_type:
+ if host_state.topic != FLAGS.compute_topic or not instance_type:
return True
capabilities = host_state.capabilities
service = host_state.service
diff --git a/nova/scheduler/filters/core_filter.py b/nova/scheduler/filters/core_filter.py
index 98b0930d9..0c4a67dcc 100644
--- a/nova/scheduler/filters/core_filter.py
+++ b/nova/scheduler/filters/core_filter.py
@@ -37,7 +37,7 @@ class CoreFilter(filters.BaseHostFilter):
def host_passes(self, host_state, filter_properties):
"""Return True if host has sufficient CPU cores."""
instance_type = filter_properties.get('instance_type')
- if host_state.topic != 'compute' or not instance_type:
+ if host_state.topic != FLAGS.compute_topic or not instance_type:
return True
if not host_state.vcpus_total:
diff --git a/nova/scheduler/host_manager.py b/nova/scheduler/host_manager.py
index 7ae7a64b8..4727c4706 100644
--- a/nova/scheduler/host_manager.py
+++ b/nova/scheduler/host_manager.py
@@ -337,7 +337,7 @@ class HostManager(object):
with the instance (in case the InstanceType changed since the
instance was created)."""
- if topic != 'compute':
+ if topic != FLAGS.compute_topic:
raise NotImplementedError(_(
"host_manager only implemented for 'compute'"))
diff --git a/nova/service.py b/nova/service.py
index 6f350c635..caff1672a 100644
--- a/nova/service.py
+++ b/nova/service.py
@@ -479,7 +479,8 @@ class Service(object):
if not topic:
topic = binary.rpartition('nova-')[2]
if not manager:
- manager = FLAGS.get('%s_manager' % topic, None)
+ manager = FLAGS.get('%s_manager' %
+ binary.rpartition('nova-')[2], None)
if report_interval is None:
report_interval = FLAGS.report_interval
if periodic_interval is None: