From 3e34e875426b5df92d3c045aac48e2db0ad1d173 Mon Sep 17 00:00:00 2001 From: vagrant Date: Tue, 18 Feb 2014 07:14:11 +0000 Subject: [PATCH 1/6] Revert cmd/compute.py and service.py --- nova/cmd/compute.py | 13 ++----------- nova/service.py | 10 ++++++---- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/nova/cmd/compute.py b/nova/cmd/compute.py index 169b753c76a..ad7bab4a295 100644 --- a/nova/cmd/compute.py +++ b/nova/cmd/compute.py @@ -34,9 +34,7 @@ from nova import utils CONF = cfg.CONF -CONF.import_opt('host', 'nova.netconf') CONF.import_opt('compute_topic', 'nova.compute.rpcapi') -CONF.import_opt('compute_processes', 'nova.compute.simulator') CONF.import_opt('use_local', 'nova.conductor.api', group='conductor') @@ -65,15 +63,8 @@ def main(): objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI() - for i in xrange(CONF.compute_processes): - if i > 0: - host = '%s-%s' % (CONF.host, str(i)) - else: - host = CONF.host - - server = service.Service.create(binary='nova-compute', + server = service.Service.create(binary='nova-compute', topic=CONF.compute_topic, - host=host, db_allowed=False) - service.serve(server) + service.serve(server) service.wait() diff --git a/nova/service.py b/nova/service.py index ec2b1f3b184..421811fe949 100644 --- a/nova/service.py +++ b/nova/service.py @@ -383,14 +383,16 @@ def process_launcher(): # NOTE(vish): the global launcher is to maintain the existing # functionality of calling service.serve + # service.wait -_launcher = [] +_launcher = None def serve(server, workers=None): global _launcher - _launcher.append(service.launch(server, workers=workers)) + if _launcher: + raise RuntimeError(_('serve() can only be called once')) + + _launcher = service.launch(server, workers=workers) def wait(): - for service in _launcher: - service.wait() + _launcher.wait() From 61e491f3b7b615dc006d209081277941b50b9ef4 Mon Sep 17 00:00:00 2001 From: Deen Liu Date: Wed, 26 Feb 2014 21:23:55 -0500 Subject: [PATCH 2/6] Add stand-alone app. --- nova/simulator/config.py | 30 +++++++++++++++++++++++++ nova/simulator/simulator.py | 44 +++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 nova/simulator/config.py create mode 100644 nova/simulator/simulator.py diff --git a/nova/simulator/config.py b/nova/simulator/config.py new file mode 100644 index 00000000000..ded063d78cb --- /dev/null +++ b/nova/simulator/config.py @@ -0,0 +1,30 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012, Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Nova-compute simulator for stress testing. +""" + +from oslo.config import cfg + +simulator_opts = [ + cfg.IntOpt('compute_processes', + default=1, + help='the number of compute services to simulate'), +] + +CONF = cfg.CONF +CONF.register_opts(simulator_opts) diff --git a/nova/simulator/simulator.py b/nova/simulator/simulator.py new file mode 100644 index 00000000000..16921b938b0 --- /dev/null +++ b/nova/simulator/simulator.py @@ -0,0 +1,44 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Starter script for Simulator.""" +import sys + +from oslo.config import cfg + +from nova import config +from nova import objects +from nova.openstack.common import log as logging +from nova import service +from nova import utils + +CONF = cfg.CONF +CONF.import_opt('host', 'nova.netconf') +CONF.import_opt('compute_topic', 'nova.compute.rpcapi') + +if __name__ == '__main__': + config.parse_args(sys.argv) + logging.setup('nova') + utils.monkey_patch() + server = service.Service.create(binary='nova-compute', + topic=CONF.compute_topic, + host='123', + db_allowed=False) + service.serve(server) + service.wait() + From a1e41c1917dfffba27140ab0c853c20e604a009a Mon Sep 17 00:00:00 2001 From: vagrant Date: Wed, 23 Apr 2014 04:25:21 +0000 Subject: [PATCH 3/6] Fix bugs in simulator app. Able to start multipe nova-comput processes. --- nova/{simulator => cmd}/simulator.py | 31 +++++++++++++++++++++++++--- nova/service.py | 2 +- nova/simulator/config.py | 2 +- nova/simulator/simulator | 24 +++++++++++++++++++++ nova/simulator/start.py | 11 ++++++++++ 5 files changed, 65 insertions(+), 5 deletions(-) rename nova/{simulator => cmd}/simulator.py (60%) create mode 100644 nova/simulator/simulator create mode 100644 nova/simulator/start.py diff --git a/nova/simulator/simulator.py b/nova/cmd/simulator.py similarity index 60% rename from nova/simulator/simulator.py rename to nova/cmd/simulator.py index 16921b938b0..a40c296b8e8 100644 --- a/nova/simulator/simulator.py +++ b/nova/cmd/simulator.py @@ -18,26 +18,51 @@ """Starter script for Simulator.""" import sys +import traceback from oslo.config import cfg +from nova.conductor import rpcapi as conductor_rpcapi from nova import config +import nova.db.api +from nova import exception from nova import objects +from nova.objects import base as objects_base from nova.openstack.common import log as logging from nova import service from nova import utils CONF = cfg.CONF -CONF.import_opt('host', 'nova.netconf') CONF.import_opt('compute_topic', 'nova.compute.rpcapi') +CONF.import_opt('use_local', 'nova.conductor.api', group='conductor') -if __name__ == '__main__': +def block_db_access(): + class NoDB(object): + def __getattr__(self, attr): + return self + + def __call__(self, *args, **kwargs): + stacktrace = "".join(traceback.format_stack()) + LOG = logging.getLogger('nova.compute') + LOG.error('No db access allowed in nova-compute: %s', stacktrace) + raise exception.DBNotAllowed('nova-compute') + + nova.db.api.IMPL = NoDB() + +def main(host): + objects.register_all() config.parse_args(sys.argv) logging.setup('nova') utils.monkey_patch() + + if not CONF.conductor.use_local: + block_db_access() + objects_base.NovaObject.indirection_api = \ + conductor_rpcapi.ConductorAPI() + server = service.Service.create(binary='nova-compute', topic=CONF.compute_topic, - host='123', + host=host, db_allowed=False) service.serve(server) service.wait() diff --git a/nova/service.py b/nova/service.py index 421811fe949..60bd6403d6d 100644 --- a/nova/service.py +++ b/nova/service.py @@ -390,7 +390,7 @@ def serve(server, workers=None): global _launcher if _launcher: raise RuntimeError(_('serve() can only be called once')) - + _launcher = service.launch(server, workers=workers) diff --git a/nova/simulator/config.py b/nova/simulator/config.py index ded063d78cb..ab1083274cc 100644 --- a/nova/simulator/config.py +++ b/nova/simulator/config.py @@ -22,7 +22,7 @@ simulator_opts = [ cfg.IntOpt('compute_processes', - default=1, + default=20, help='the number of compute services to simulate'), ] diff --git a/nova/simulator/simulator b/nova/simulator/simulator new file mode 100644 index 00000000000..784bece5e83 --- /dev/null +++ b/nova/simulator/simulator @@ -0,0 +1,24 @@ +#!/usr/bin/python + +import start +from oslo.config import cfg +from multiprocessing import Process + +CONF = cfg.CONF +CONF.import_opt('compute_processes', 'nova.compute.simulator') + +if __name__ == "__main__": + workers = [] + for i in xrange(10): + host = '%s-%s' % (CONF.host, str(i + 1)) + p = Process(target=start.start, args=(host, )) + p.start() + workers.append(p) + + try: + for worker in workers: + worker.join() + except KeyboardInterrupt: + for worker in workers: + worker.terminate() + worker.join() \ No newline at end of file diff --git a/nova/simulator/start.py b/nova/simulator/start.py new file mode 100644 index 00000000000..40b43142cca --- /dev/null +++ b/nova/simulator/start.py @@ -0,0 +1,11 @@ +#!/usr/bin/python + +import sys +from nova.cmd.simulator import main + +def start(host): + main(host) + sys.exit() + +if __name__ == "__main__": + start('i do nothing') \ No newline at end of file From ce80463e17246240702f968f2de7288f8578c555 Mon Sep 17 00:00:00 2001 From: liudeen Date: Wed, 23 Apr 2014 04:43:57 +0000 Subject: [PATCH 4/6] Fix bugs in simulator app. Able to start multipe nova-comput processes. --- nova/{simulator => cmd}/simulator.py | 31 +++++++++++++++++++++++++--- nova/service.py | 2 +- nova/simulator/config.py | 2 +- nova/simulator/simulator | 24 +++++++++++++++++++++ nova/simulator/start.py | 11 ++++++++++ 5 files changed, 65 insertions(+), 5 deletions(-) rename nova/{simulator => cmd}/simulator.py (60%) create mode 100644 nova/simulator/simulator create mode 100644 nova/simulator/start.py diff --git a/nova/simulator/simulator.py b/nova/cmd/simulator.py similarity index 60% rename from nova/simulator/simulator.py rename to nova/cmd/simulator.py index 16921b938b0..a40c296b8e8 100644 --- a/nova/simulator/simulator.py +++ b/nova/cmd/simulator.py @@ -18,26 +18,51 @@ """Starter script for Simulator.""" import sys +import traceback from oslo.config import cfg +from nova.conductor import rpcapi as conductor_rpcapi from nova import config +import nova.db.api +from nova import exception from nova import objects +from nova.objects import base as objects_base from nova.openstack.common import log as logging from nova import service from nova import utils CONF = cfg.CONF -CONF.import_opt('host', 'nova.netconf') CONF.import_opt('compute_topic', 'nova.compute.rpcapi') +CONF.import_opt('use_local', 'nova.conductor.api', group='conductor') -if __name__ == '__main__': +def block_db_access(): + class NoDB(object): + def __getattr__(self, attr): + return self + + def __call__(self, *args, **kwargs): + stacktrace = "".join(traceback.format_stack()) + LOG = logging.getLogger('nova.compute') + LOG.error('No db access allowed in nova-compute: %s', stacktrace) + raise exception.DBNotAllowed('nova-compute') + + nova.db.api.IMPL = NoDB() + +def main(host): + objects.register_all() config.parse_args(sys.argv) logging.setup('nova') utils.monkey_patch() + + if not CONF.conductor.use_local: + block_db_access() + objects_base.NovaObject.indirection_api = \ + conductor_rpcapi.ConductorAPI() + server = service.Service.create(binary='nova-compute', topic=CONF.compute_topic, - host='123', + host=host, db_allowed=False) service.serve(server) service.wait() diff --git a/nova/service.py b/nova/service.py index 421811fe949..60bd6403d6d 100644 --- a/nova/service.py +++ b/nova/service.py @@ -390,7 +390,7 @@ def serve(server, workers=None): global _launcher if _launcher: raise RuntimeError(_('serve() can only be called once')) - + _launcher = service.launch(server, workers=workers) diff --git a/nova/simulator/config.py b/nova/simulator/config.py index ded063d78cb..ab1083274cc 100644 --- a/nova/simulator/config.py +++ b/nova/simulator/config.py @@ -22,7 +22,7 @@ simulator_opts = [ cfg.IntOpt('compute_processes', - default=1, + default=20, help='the number of compute services to simulate'), ] diff --git a/nova/simulator/simulator b/nova/simulator/simulator new file mode 100644 index 00000000000..784bece5e83 --- /dev/null +++ b/nova/simulator/simulator @@ -0,0 +1,24 @@ +#!/usr/bin/python + +import start +from oslo.config import cfg +from multiprocessing import Process + +CONF = cfg.CONF +CONF.import_opt('compute_processes', 'nova.compute.simulator') + +if __name__ == "__main__": + workers = [] + for i in xrange(10): + host = '%s-%s' % (CONF.host, str(i + 1)) + p = Process(target=start.start, args=(host, )) + p.start() + workers.append(p) + + try: + for worker in workers: + worker.join() + except KeyboardInterrupt: + for worker in workers: + worker.terminate() + worker.join() \ No newline at end of file diff --git a/nova/simulator/start.py b/nova/simulator/start.py new file mode 100644 index 00000000000..40b43142cca --- /dev/null +++ b/nova/simulator/start.py @@ -0,0 +1,11 @@ +#!/usr/bin/python + +import sys +from nova.cmd.simulator import main + +def start(host): + main(host) + sys.exit() + +if __name__ == "__main__": + start('i do nothing') \ No newline at end of file From 5d299c3d5dd547905c5cf44c889e097053601caf Mon Sep 17 00:00:00 2001 From: Deen Liu Date: Mon, 28 Apr 2014 23:37:21 -0400 Subject: [PATCH 5/6] Add support /etc/nova/nova.conf file. --- nova/simulator/simulator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/simulator/simulator b/nova/simulator/simulator index 784bece5e83..f96455e6b14 100644 --- a/nova/simulator/simulator +++ b/nova/simulator/simulator @@ -9,7 +9,7 @@ CONF.import_opt('compute_processes', 'nova.compute.simulator') if __name__ == "__main__": workers = [] - for i in xrange(10): + for i in xrange(CONF.compute_processes): host = '%s-%s' % (CONF.host, str(i + 1)) p = Process(target=start.start, args=(host, )) p.start() From a298c3ddf331fa8bdc5c01816ec9740ebf2c044c Mon Sep 17 00:00:00 2001 From: Deen Liu Date: Mon, 28 Apr 2014 23:44:42 -0400 Subject: [PATCH 6/6] Fix simulator script. --- nova/simulator/simulator | 4 ---- 1 file changed, 4 deletions(-) diff --git a/nova/simulator/simulator b/nova/simulator/simulator index 2532b47fe43..f96455e6b14 100644 --- a/nova/simulator/simulator +++ b/nova/simulator/simulator @@ -9,11 +9,7 @@ CONF.import_opt('compute_processes', 'nova.compute.simulator') if __name__ == "__main__": workers = [] -<<<<<<< HEAD for i in xrange(CONF.compute_processes): -======= - for i in xrange(10): ->>>>>>> a1e41c1917dfffba27140ab0c853c20e604a009a host = '%s-%s' % (CONF.host, str(i + 1)) p = Process(target=start.start, args=(host, )) p.start()