Allow to use "run" method only if the runner is enabled
Checking for "_enabled" attriture in Runner class and its subclasses didn't happen everywhere it's needed. This commit simplified this check and does it in every needed place. TrivialFix Change-Id: Ib901e8f26cb870d6fbf08b557467bca6427de217
This commit is contained in:
parent
52b2028585
commit
eaf75d9bd9
|
@ -10,6 +10,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import functools
|
||||||
import itertools
|
import itertools
|
||||||
import json
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
|
@ -41,6 +42,16 @@ CONF.import_group('marathon', 'kolla_mesos.config.marathon')
|
||||||
CONF.import_group('chronos', 'kolla_mesos.config.chronos')
|
CONF.import_group('chronos', 'kolla_mesos.config.chronos')
|
||||||
|
|
||||||
|
|
||||||
|
def execute_if_enabled(f):
|
||||||
|
"""Decorator for executing methods only if runner is enabled."""
|
||||||
|
@functools.wraps(f)
|
||||||
|
def wrapper(self, *args, **kwargs):
|
||||||
|
if not self._enabled:
|
||||||
|
return
|
||||||
|
return f(self, *args, **kwargs)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class File(object):
|
class File(object):
|
||||||
def __init__(self, conf, name, service_name):
|
def __init__(self, conf, name, service_name):
|
||||||
self._conf = conf
|
self._conf = conf
|
||||||
|
@ -139,9 +150,8 @@ class Runner(object):
|
||||||
for key in self._conf.get('commands', []):
|
for key in self._conf.get('commands', []):
|
||||||
yield key, self._conf['commands'][key]
|
yield key, self._conf['commands'][key]
|
||||||
|
|
||||||
|
@execute_if_enabled
|
||||||
def write_to_zookeeper(self, zk, base_node):
|
def write_to_zookeeper(self, zk, base_node):
|
||||||
if not self._enabled:
|
|
||||||
return
|
|
||||||
for cmd_name, cmd_conf in self._list_commands():
|
for cmd_name, cmd_conf in self._list_commands():
|
||||||
cmd = Command(cmd_conf, cmd_name, self._conf['name'])
|
cmd = Command(cmd_conf, cmd_name, self._conf['name'])
|
||||||
cmd.write_to_zookeeper(zk, base_node)
|
cmd.write_to_zookeeper(zk, base_node)
|
||||||
|
@ -156,10 +166,9 @@ class Runner(object):
|
||||||
def _apply_service_def(self, app_def):
|
def _apply_service_def(self, app_def):
|
||||||
"""Apply the specifics from the service definition."""
|
"""Apply the specifics from the service definition."""
|
||||||
|
|
||||||
|
@execute_if_enabled
|
||||||
def generate_deployment_files(self, kolla_config, jinja_vars,
|
def generate_deployment_files(self, kolla_config, jinja_vars,
|
||||||
temp_dir=None):
|
temp_dir=None):
|
||||||
if not self._enabled:
|
|
||||||
return
|
|
||||||
_, proj, service = self._conf['name'].split('/')
|
_, proj, service = self._conf['name'].split('/')
|
||||||
values = {
|
values = {
|
||||||
'service_name': self._conf['name'],
|
'service_name': self._conf['name'],
|
||||||
|
@ -305,6 +314,7 @@ class MarathonApp(Runner):
|
||||||
app_def[opt] = utils.dict_update(app_def.get(opt),
|
app_def[opt] = utils.dict_update(app_def.get(opt),
|
||||||
self._conf['service'][opt])
|
self._conf['service'][opt])
|
||||||
|
|
||||||
|
@execute_if_enabled
|
||||||
def run(self):
|
def run(self):
|
||||||
self._client().add_app(self.app_def)
|
self._client().add_app(self.app_def)
|
||||||
LOG.info('Marathon app "%s" is started' %
|
LOG.info('Marathon app "%s" is started' %
|
||||||
|
@ -391,6 +401,7 @@ class ChronosTask(Runner):
|
||||||
return
|
return
|
||||||
chronos_env.append({"name": key, "value": value})
|
chronos_env.append({"name": key, "value": value})
|
||||||
|
|
||||||
|
@execute_if_enabled
|
||||||
def run(self):
|
def run(self):
|
||||||
self._client().add_job(self.app_def)
|
self._client().add_job(self.app_def)
|
||||||
LOG.info('Chronos job "%s" is started' %
|
LOG.info('Chronos job "%s" is started' %
|
||||||
|
|
Loading…
Reference in New Issue