Merge "Add option to disable event log"
This commit is contained in:
commit
60c633ce2b
@ -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]
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
@ -58,7 +69,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)
|
||||
@ -71,7 +82,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)
|
||||
@ -87,7 +98,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()
|
||||
@ -129,7 +140,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:
|
||||
@ -163,6 +174,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
|
||||
|
Loading…
Reference in New Issue
Block a user