use worker from neutron-lib

neutron-lib 1.6 is out and among other things contains the rehomed
NeutronWorker class; now named BaseWorker in neutron-lib. This patch
updates references to use the lib version.

Since there's only 1 other consumer of these changes [1], this
patch depends on it so that it's free to merge after the single
consumer is updated.

[1] http://codesearch.openstack.org/?q=from%20neutron%20import%20worker

NeutronLibImpact

Change-Id: Id6bd414ae90119bf527bcaca6b88cc33ff79f685
Depends-On: Ifc0ecf6d5d3d4f8c406caad233d3648646724b12
This commit is contained in:
Boden R 2017-05-11 15:00:08 -06:00
parent dfcfbc0aac
commit b65d881792
5 changed files with 15 additions and 60 deletions

View File

@ -980,10 +980,10 @@ class MechanismDriver(object):
pass
def get_workers(self):
"""Get any NeutronWorker instances that should have their own process
"""Get any worker instances that should have their own process
Any driver that needs to run processes separate from the API or RPC
workers, can return a sequence of NeutronWorker instances.
workers, can return a sequence of worker instances.
"""
return ()

View File

@ -22,6 +22,7 @@ from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from neutron_lib import context
from neutron_lib.plugins import directory
from neutron_lib import worker as neutron_worker
from oslo_concurrency import processutils
from oslo_config import cfg
from oslo_log import log as logging
@ -37,7 +38,6 @@ from neutron.common import profiler
from neutron.common import rpc as n_rpc
from neutron.conf import service
from neutron.db import api as session
from neutron import worker as neutron_worker
from neutron import wsgi
@ -94,7 +94,7 @@ def serve_wsgi(cls):
return service
class RpcWorker(neutron_worker.NeutronWorker):
class RpcWorker(neutron_worker.BaseWorker):
"""Wraps a worker to be handled by ProcessLauncher"""
start_listeners_method = 'start_rpc_listeners'
@ -197,7 +197,7 @@ def _get_plugins_workers():
]
class AllServicesNeutronWorker(neutron_worker.NeutronWorker):
class AllServicesNeutronWorker(neutron_worker.BaseWorker):
def __init__(self, services, worker_process_count=1):
super(AllServicesNeutronWorker, self).__init__(worker_process_count)
self._services = services

View File

@ -21,6 +21,7 @@ import traceback
import httplib2
import mock
from neutron_lib import worker as neutron_worker
from oslo_config import cfg
import psutil
@ -28,7 +29,6 @@ from neutron.common import utils
from neutron import manager
from neutron import service
from neutron.tests import base
from neutron import worker as neutron_worker
from neutron import wsgi
@ -273,7 +273,7 @@ class TestPluginWorker(TestNeutronServer):
plugin_workers_launcher.wait()
def test_start(self):
class FakeWorker(neutron_worker.NeutronWorker):
class FakeWorker(neutron_worker.BaseWorker):
def start(self):
pass

View File

@ -10,11 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from neutron_lib import worker
from oslo_service import loopingcall
from oslo_service import service
class WorkerSupportServiceMixin(object):
@ -28,12 +25,13 @@ class WorkerSupportServiceMixin(object):
return self.__workers
def get_workers(self):
"""Returns a collection NeutronWorker instances needed by this service
"""Returns a collection neutron_lib.worker.BaseWorker instances
needed by this service
"""
return list(self._workers)
def add_worker(self, worker):
"""Adds NeutronWorker needed for this service
"""Adds neutron_lib.worker.BaseWorker needed for this service
If a object needs to define workers thread/processes outside of API/RPC
workers then it will call this method to register worker. Should be
@ -42,57 +40,14 @@ class WorkerSupportServiceMixin(object):
self._workers.append(worker)
def add_workers(self, workers):
"""Adds NeutronWorker list needed for this service
"""Adds neutron_lib.worker.BaseWorker list needed for this service
The same as add_worker but adds a list of workers
"""
self._workers.extend(workers)
class NeutronWorker(service.ServiceBase):
"""Partial implementation of the ServiceBase ABC
Subclasses will still need to add the other abstract methods defined in
service.ServiceBase. See oslo_service for more details.
If a plugin needs to handle synchronization with the Neutron database and
do this only once instead of in every API worker, for instance, it would
define a NeutronWorker class and the plugin would have get_workers return
an array of NeutronWorker instances. For example:
class MyPlugin(...):
def get_workers(self):
return [MyPluginWorker()]
class MyPluginWorker(NeutronWorker):
def start(self):
super(MyPluginWorker, self).start()
do_sync()
"""
# default class value for case when super().__init__ is not called
_worker_process_count = 1
def __init__(self, worker_process_count=_worker_process_count):
"""
Initialize worker
:param worker_process_count: Defines how many processes to spawn for
worker:
0 - spawn 1 new worker thread,
1..N - spawn N new worker processes
"""
self._worker_process_count = worker_process_count
@property
def worker_process_count(self):
return self._worker_process_count
def start(self):
if self.worker_process_count > 0:
registry.notify(resources.PROCESS, events.AFTER_INIT, self.start)
class PeriodicWorker(NeutronWorker):
class PeriodicWorker(worker.BaseWorker):
"""A worker that runs a function at a fixed interval."""
def __init__(self, check_func, interval, initial_delay):

View File

@ -24,6 +24,7 @@ import time
import eventlet.wsgi
from neutron_lib import context
from neutron_lib import exceptions as exception
from neutron_lib import worker as neutron_worker
from oslo_config import cfg
import oslo_i18n
from oslo_log import log as logging
@ -43,7 +44,6 @@ from neutron.common import config
from neutron.common import exceptions as n_exc
from neutron.conf import wsgi as wsgi_config
from neutron.db import api
from neutron import worker as neutron_worker
CONF = cfg.CONF
wsgi_config.register_socket_opts()
@ -59,7 +59,7 @@ def encode_body(body):
return encodeutils.to_utf8(body)
class WorkerService(neutron_worker.NeutronWorker):
class WorkerService(neutron_worker.BaseWorker):
"""Wraps a worker to be handled by ProcessLauncher"""
def __init__(self, service, application, disable_ssl=False,
worker_process_count=0):