diff --git a/etc/sahara/sahara.conf.sample b/etc/sahara/sahara.conf.sample index 58eadf07..1344d55d 100644 --- a/etc/sahara/sahara.conf.sample +++ b/etc/sahara/sahara.conf.sample @@ -444,6 +444,9 @@ # trust for Swift object access. (list value) #proxy_user_role_names = Member +# Disables event log feature. (boolean value) +#disable_event_log = false + [cinder] diff --git a/sahara/config.py b/sahara/config.py index 21b7a543..b1e95806 100644 --- a/sahara/config.py +++ b/sahara/config.py @@ -127,6 +127,7 @@ def list_opts(): from sahara.service.edp import job_utils from sahara.service import periodic from sahara.service import volumes + from sahara.utils import cluster_progress_ops as cpo from sahara.utils.openstack import heat from sahara.utils.openstack import neutron from sahara.utils.openstack import nova @@ -148,7 +149,8 @@ def list_opts(): job_utils.opts, periodic.periodic_opts, volumes.opts, - proxy.opts)), + proxy.opts, + cpo.event_log_opts)), (api.conductor_group.name, itertools.chain(api.conductor_opts)), (cinder.cinder_group.name, diff --git a/sahara/tests/unit/utils/test_cluster_progress_ops.py b/sahara/tests/unit/utils/test_cluster_progress_ops.py index 10b8d3d0..d5c83577 100644 --- a/sahara/tests/unit/utils/test_cluster_progress_ops.py +++ b/sahara/tests/unit/utils/test_cluster_progress_ops.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import mock import uuid from sahara import conductor @@ -26,6 +27,7 @@ class FakeInstance(object): def __init__(self): self.id = uuid.uuid4() self.name = uuid.uuid4() + self.cluster_id = uuid.uuid4() class ClusterProgressOpsTest(base.SaharaWithDbTestCase): @@ -158,3 +160,23 @@ class ClusterProgressOpsTest(base.SaharaWithDbTestCase): None, instance.id, instance.name, None) with context.InstanceInfoManager(info): tg.spawn("make_checks", self._make_checks, info) + + @cpo.event_wrapper(True) + def _do_nothing(self): + pass + + @mock.patch('sahara.utils.cluster_progress_ops._find_in_args') + @mock.patch('sahara.utils.general.check_cluster_exists') + def test_event_wrapper(self, p_check_cluster_exists, p_find): + self.override_config("disable_event_log", True) + self._do_nothing() + + self.assertEqual(0, p_find.call_count) + + self.override_config("disable_event_log", False) + p_find.return_value = FakeInstance() + p_check_cluster_exists.return_value = False + self._do_nothing() + + self.assertEqual(1, p_find.call_count) + self.assertEqual(1, p_check_cluster_exists.call_count) diff --git a/sahara/utils/cluster_progress_ops.py b/sahara/utils/cluster_progress_ops.py index 991eb969..f95fcdb5 100644 --- a/sahara/utils/cluster_progress_ops.py +++ b/sahara/utils/cluster_progress_ops.py @@ -15,6 +15,7 @@ import functools +from oslo_config import cfg from oslo_utils import excutils from oslo_utils import timeutils import six @@ -25,6 +26,16 @@ from sahara import context from sahara.utils import general as g conductor = c.API +CONF = cfg.CONF + +event_log_opts = [ + cfg.BoolOpt('disable_event_log', + default=False, + help="Disables event log feature.") +] + + +CONF.register_opts(event_log_opts) def add_successful_event(instance): @@ -56,7 +67,7 @@ def add_fail_event(instance, exception): def add_provisioning_step(cluster_id, step_name, total): - if not g.check_cluster_exists(cluster_id): + if CONF.disable_event_log or not g.check_cluster_exists(cluster_id): return update_provisioning_steps(cluster_id) @@ -69,7 +80,7 @@ def add_provisioning_step(cluster_id, step_name, total): def get_current_provisioning_step(cluster_id): - if not g.check_cluster_exists(cluster_id): + if CONF.disable_event_log or not g.check_cluster_exists(cluster_id): return None update_provisioning_steps(cluster_id) @@ -85,7 +96,7 @@ def get_current_provisioning_step(cluster_id): def update_provisioning_steps(cluster_id): - if not g.check_cluster_exists(cluster_id): + if CONF.disable_event_log or not g.check_cluster_exists(cluster_id): return ctx = context.ctx() @@ -127,7 +138,7 @@ def update_provisioning_steps(cluster_id): def get_cluster_events(cluster_id, provision_step=None): - if not g.check_cluster_exists(cluster_id): + if CONF.disable_event_log or not g.check_cluster_exists(cluster_id): return [] update_provisioning_steps(cluster_id) if provision_step: @@ -161,6 +172,8 @@ def event_wrapper(mark_successful_on_exit, **spec): def decorator(func): @functools.wraps(func) def handler(*args, **kwargs): + if CONF.disable_event_log: + return func(*args, **kwargs) step_name = spec.get('step', None) instance = _find_in_args(spec, *args, **kwargs) cluster_id = instance.cluster_id