Modify the load order of manage.py

In zun.cmd.compute.py
Existing process:
1. Import the zun.compute.manager.py file
2. Load configuration item
3. Start the service
So if you use a timer like this:

    @periodic_task.periodic_task(run_immediately=True,
        spacing=CONF.detection_interval)
    def delete_unused_containers(self, context):

Modify the CONF.detection_interval will not take effect,
it is always using the default value

Change-Id: Ia3ca548690f67c010db20a675ae33df240868349
Closes-Bug: #1755095
This commit is contained in:
JiWei 2018-03-12 22:57:36 +08:00 committed by Hongbin Lu
parent c8028f9aae
commit ad4bae52d4
5 changed files with 16 additions and 16 deletions

View File

@ -20,7 +20,6 @@ from oslo_service import service
from zun.common import rpc_service
from zun.common import service as zun_service
from zun.compute import manager as compute_manager
import zun.conf
CONF = zun.conf.CONF
@ -35,6 +34,7 @@ def main():
CONF.import_opt('topic', 'zun.conf.compute', group='compute')
from zun.compute import manager as compute_manager
endpoints = [
compute_manager.Manager(),
]

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import functools
import copy
from eventlet.green import threading
from oslo_context import context
@ -185,3 +187,12 @@ def set_ctx(new_ctx):
if new_ctx:
setattr(_CTX_STORE, _CTX_KEY, new_ctx)
setattr(context._request_store, 'context', new_ctx)
def set_context(func):
@functools.wraps(func)
def handler(self, ctx):
if ctx is None:
ctx = get_admin_context(all_projects=True)
func(self, ctx)
return handler

View File

@ -22,7 +22,6 @@ from oslo_utils import importutils
from zun.common import context
from zun.common import profiler
from zun.common import rpc
from zun.compute import manager as compute_manager
import zun.conf
from zun.objects import base as objects_base
from zun.servicegroup import zun_service_periodic as servicegroup
@ -62,7 +61,7 @@ class Service(service.Service):
def start(self):
servicegroup.setup(CONF, self.binary, self.tg)
for endpoint in self.endpoints:
if isinstance(endpoint, compute_manager.Manager):
if hasattr(endpoint, 'init_containers'):
endpoint.init_containers(
context.get_admin_context(all_projects=True))
self.tg.add_dynamic_timer(

View File

@ -14,7 +14,6 @@
import itertools
import functools
import six
import time
@ -42,15 +41,6 @@ CONF = zun.conf.CONF
LOG = logging.getLogger(__name__)
def set_context(func):
@functools.wraps(func)
def handler(self, ctx):
if ctx is None:
ctx = context.get_admin_context(all_projects=True)
func(self, ctx)
return handler
class Manager(periodic_task.PeriodicTasks):
"""Manages the running containers."""
@ -918,7 +908,7 @@ class Manager(periodic_task.PeriodicTasks):
@periodic_task.periodic_task(spacing=CONF.sync_container_state_interval,
run_immediately=True)
@set_context
@context.set_context
def sync_container_state(self, ctx):
LOG.debug('Start syncing container states.')

View File

@ -15,7 +15,7 @@
from oslo_log import log
from oslo_service import periodic_task
from zun.compute import manager
from zun.common import context
from zun import objects
@ -35,7 +35,7 @@ class ZunServicePeriodicTasks(periodic_task.PeriodicTasks):
super(ZunServicePeriodicTasks, self).__init__(conf)
@periodic_task.periodic_task(run_immediately=True)
@manager.set_context
@context.set_context
def update_zun_service(self, ctx):
LOG.debug('Update zun_service')
if self.zun_service_ref is None: