self.app = self.loader.load_app(name)
self.host = getattr(CONF, '%s_listen' % name, "0.0.0.0")
self.port = getattr(CONF, '%s_listen_port' % name, 0)
- self.workers = getattr(CONF, '%s_workers' % name,
- processutils.get_worker_count())
+ self.workers = (getattr(CONF, '%s_workers' % name, None) or
+ processutils.get_worker_count())
+ if self.workers and self.workers < 1:
+ worker_name = '%s_workers' % name
+ msg = (_("%(worker_name)s value of %(workers)d is invalid, "
+ "must be greater than 0.") %
+ {'worker_name': worker_name,
+ 'workers': self.workers})
+ raise exception.InvalidInput(msg)
setup_profiler(name, self.host)
- if self.workers < 1:
- LOG.warn(_("Value of config option %(name)s_workers must be "
- "integer greater than 1. Input value ignored.") %
- {'name': name})
- # Reset workers to default
- self.workers = processutils.get_worker_count()
self.server = wsgi.Server(name,
self.app,
host=self.host,
from cinder import db
from cinder import exception
from cinder import manager
+from cinder.openstack.common import processutils
from cinder import service
from cinder import test
from cinder import wsgi
self.assertEqual(test_service.server._pool.size,
1000)
+ def test_workers_set_default(self):
+ test_service = service.WSGIService("osapi_volume")
+ self.assertEqual(test_service.workers, processutils.get_worker_count())
+
+ def test_workers_set_good_user_setting(self):
+ CONF.set_override('osapi_volume_workers', 8)
+ test_service = service.WSGIService("osapi_volume")
+ self.assertEqual(test_service.workers, 8)
+
+ def test_workers_set_zero_user_setting(self):
+ CONF.set_override('osapi_volume_workers', 0)
+ test_service = service.WSGIService("osapi_volume")
+ # If a value less than 1 is used, defaults to number of procs available
+ self.assertEqual(test_service.workers, processutils.get_worker_count())
+
+ def test_workers_set_negative_user_setting(self):
+ CONF.set_override('osapi_volume_workers', -1)
+ self.assertRaises(exception.InvalidInput,
+ service.WSGIService,
+ "osapi_volume")
+
class OSCompatibilityTestCase(test.TestCase):
def _test_service_launcher(self, fake_os):