Fixes StackWatchService to use objects in place of db
Fixes StackWatchService to use Stack and WatchRule objects in places of db api. Implements blueprint versioned-objects Change-Id: I4f364ef90e4ca58065e974cd9d400d785d465daa
This commit is contained in:
parent
795b4dd610
commit
970ac9fac1
@ -17,9 +17,10 @@ from oslo_utils import timeutils
|
|||||||
from heat.common import context
|
from heat.common import context
|
||||||
from heat.common.i18n import _LE
|
from heat.common.i18n import _LE
|
||||||
from heat.common.i18n import _LW
|
from heat.common.i18n import _LW
|
||||||
from heat.db import api as db_api
|
|
||||||
from heat.engine import stack
|
from heat.engine import stack
|
||||||
from heat.engine import watchrule
|
from heat.engine import watchrule
|
||||||
|
from heat.objects import stack as stack_object
|
||||||
|
from heat.objects import watch_rule as watch_rule_object
|
||||||
from heat.rpc import api as rpc_api
|
from heat.rpc import api as rpc_api
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -32,19 +33,21 @@ class StackWatch(object):
|
|||||||
def start_watch_task(self, stack_id, cnxt):
|
def start_watch_task(self, stack_id, cnxt):
|
||||||
|
|
||||||
def stack_has_a_watchrule(sid):
|
def stack_has_a_watchrule(sid):
|
||||||
wrs = db_api.watch_rule_get_all_by_stack(cnxt, sid)
|
wrs = watch_rule_object.WatchRule.get_all_by_stack(cnxt, sid)
|
||||||
|
|
||||||
now = timeutils.utcnow()
|
now = timeutils.utcnow()
|
||||||
start_watch_thread = False
|
start_watch_thread = False
|
||||||
for wr in wrs:
|
for wr in wrs:
|
||||||
# reset the last_evaluated so we don't fire off alarms when
|
# reset the last_evaluated so we don't fire off alarms when
|
||||||
# the engine has not been running.
|
# the engine has not been running.
|
||||||
db_api.watch_rule_update(cnxt, wr.id, {'last_evaluated': now})
|
watch_rule_object.WatchRule.update_by_id(
|
||||||
|
cnxt, wr.id,
|
||||||
|
{'last_evaluated': now})
|
||||||
|
|
||||||
if wr.state != rpc_api.WATCH_STATE_CEILOMETER_CONTROLLED:
|
if wr.state != rpc_api.WATCH_STATE_CEILOMETER_CONTROLLED:
|
||||||
start_watch_thread = True
|
start_watch_thread = True
|
||||||
|
|
||||||
children = db_api.stack_get_all_by_owner_id(cnxt, sid)
|
children = stack_object.Stack.get_all_by_owner_id(cnxt, sid)
|
||||||
for child in children:
|
for child in children:
|
||||||
if stack_has_a_watchrule(child.id):
|
if stack_has_a_watchrule(child.id):
|
||||||
start_watch_thread = True
|
start_watch_thread = True
|
||||||
@ -63,8 +66,10 @@ class StackWatch(object):
|
|||||||
# scoping otherwise we fail to retrieve the stack
|
# scoping otherwise we fail to retrieve the stack
|
||||||
LOG.debug("Periodic watcher task for stack %s" % sid)
|
LOG.debug("Periodic watcher task for stack %s" % sid)
|
||||||
admin_context = context.get_admin_context()
|
admin_context = context.get_admin_context()
|
||||||
db_stack = db_api.stack_get(admin_context, sid, tenant_safe=False,
|
db_stack = stack_object.Stack.get_by_id(admin_context,
|
||||||
eager_load=True)
|
sid,
|
||||||
|
tenant_safe=False,
|
||||||
|
eager_load=True)
|
||||||
if not db_stack:
|
if not db_stack:
|
||||||
LOG.error(_LE("Unable to retrieve stack %s for periodic task"),
|
LOG.error(_LE("Unable to retrieve stack %s for periodic task"),
|
||||||
sid)
|
sid)
|
||||||
@ -73,13 +78,14 @@ class StackWatch(object):
|
|||||||
use_stored_context=True)
|
use_stored_context=True)
|
||||||
|
|
||||||
# recurse into any nested stacks.
|
# recurse into any nested stacks.
|
||||||
children = db_api.stack_get_all_by_owner_id(admin_context, sid)
|
children = stack_object.Stack.get_all_by_owner_id(admin_context, sid)
|
||||||
for child in children:
|
for child in children:
|
||||||
self.check_stack_watches(child.id)
|
self.check_stack_watches(child.id)
|
||||||
|
|
||||||
# Get all watchrules for this stack and evaluate them
|
# Get all watchrules for this stack and evaluate them
|
||||||
try:
|
try:
|
||||||
wrs = db_api.watch_rule_get_all_by_stack(admin_context, sid)
|
wrs = watch_rule_object.WatchRule.get_all_by_stack(admin_context,
|
||||||
|
sid)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.warn(_LW('periodic_task db error watch rule removed? %(ex)s'),
|
LOG.warn(_LW('periodic_task db error watch rule removed? %(ex)s'),
|
||||||
ex)
|
ex)
|
||||||
|
@ -27,10 +27,12 @@ class StackServiceWatcherTest(common.HeatTestCase):
|
|||||||
self.ctx = utils.dummy_context(tenant_id='stack_service_test_tenant')
|
self.ctx = utils.dummy_context(tenant_id='stack_service_test_tenant')
|
||||||
self.patch('heat.engine.service.warnings')
|
self.patch('heat.engine.service.warnings')
|
||||||
|
|
||||||
@mock.patch.object(service_stack_watch.db_api, 'stack_get_all_by_owner_id')
|
@mock.patch.object(service_stack_watch.stack_object.Stack,
|
||||||
@mock.patch.object(service_stack_watch.db_api,
|
'get_all_by_owner_id')
|
||||||
'watch_rule_get_all_by_stack')
|
@mock.patch.object(service_stack_watch.watch_rule_object.WatchRule,
|
||||||
@mock.patch.object(service_stack_watch.db_api, 'watch_rule_update')
|
'get_all_by_stack')
|
||||||
|
@mock.patch.object(service_stack_watch.watch_rule_object.WatchRule,
|
||||||
|
'update_by_id')
|
||||||
def test_periodic_watch_task_not_created(self, watch_rule_update,
|
def test_periodic_watch_task_not_created(self, watch_rule_update,
|
||||||
watch_rule_get_all_by_stack,
|
watch_rule_get_all_by_stack,
|
||||||
stack_get_all_by_owner_id):
|
stack_get_all_by_owner_id):
|
||||||
@ -47,10 +49,12 @@ class StackServiceWatcherTest(common.HeatTestCase):
|
|||||||
# assert that add_timer is NOT called.
|
# assert that add_timer is NOT called.
|
||||||
self.assertEqual([], tg.add_timer.call_args_list)
|
self.assertEqual([], tg.add_timer.call_args_list)
|
||||||
|
|
||||||
@mock.patch.object(service_stack_watch.db_api, 'stack_get_all_by_owner_id')
|
@mock.patch.object(service_stack_watch.stack_object.Stack,
|
||||||
@mock.patch.object(service_stack_watch.db_api,
|
'get_all_by_owner_id')
|
||||||
'watch_rule_get_all_by_stack')
|
@mock.patch.object(service_stack_watch.watch_rule_object.WatchRule,
|
||||||
@mock.patch.object(service_stack_watch.db_api, 'watch_rule_update')
|
'get_all_by_stack')
|
||||||
|
@mock.patch.object(service_stack_watch.watch_rule_object.WatchRule,
|
||||||
|
'update_by_id')
|
||||||
def test_periodic_watch_task_created(self, watch_rule_update,
|
def test_periodic_watch_task_created(self, watch_rule_update,
|
||||||
watch_rule_get_all_by_stack,
|
watch_rule_get_all_by_stack,
|
||||||
stack_get_all_by_owner_id):
|
stack_get_all_by_owner_id):
|
||||||
@ -73,10 +77,12 @@ class StackServiceWatcherTest(common.HeatTestCase):
|
|||||||
sid=stack_id)],
|
sid=stack_id)],
|
||||||
tg.add_timer.call_args_list)
|
tg.add_timer.call_args_list)
|
||||||
|
|
||||||
@mock.patch.object(service_stack_watch.db_api, 'stack_get_all_by_owner_id')
|
@mock.patch.object(service_stack_watch.stack_object.Stack,
|
||||||
@mock.patch.object(service_stack_watch.db_api,
|
'get_all_by_owner_id')
|
||||||
'watch_rule_get_all_by_stack')
|
@mock.patch.object(service_stack_watch.watch_rule_object.WatchRule,
|
||||||
@mock.patch.object(service_stack_watch.db_api, 'watch_rule_update')
|
'get_all_by_stack')
|
||||||
|
@mock.patch.object(service_stack_watch.watch_rule_object.WatchRule,
|
||||||
|
'update_by_id')
|
||||||
def test_periodic_watch_task_created_nested(self, watch_rule_update,
|
def test_periodic_watch_task_created_nested(self, watch_rule_update,
|
||||||
watch_rule_get_all_by_stack,
|
watch_rule_get_all_by_stack,
|
||||||
stack_get_all_by_owner_id):
|
stack_get_all_by_owner_id):
|
||||||
|
Loading…
Reference in New Issue
Block a user