]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
heat : db API add watch_rule_get_by_name
authorSteven Hardy <shardy@redhat.com>
Fri, 12 Oct 2012 16:18:11 +0000 (17:18 +0100)
committerSteven Hardy <shardy@redhat.com>
Fri, 12 Oct 2012 16:20:48 +0000 (17:20 +0100)
Add watch_rule_get_by_name, and move the previous
watch_rule_get to look up rule by ID, which is consistent
with the other api calls.  Lookup by id is required for
WatchRule rework

Ref #217

Change-Id: I4b5d08ffcd31b6b522c65edd0a202e8cf5a367b8
Signed-off-by: Steven Hardy <shardy@redhat.com>
heat/db/api.py
heat/db/sqlalchemy/api.py
heat/engine/manager.py
heat/tests/test_engine_manager.py

index e00dc71e99bf40df1013625461ee41b03ba78247..6724bd1b88136555b7bd75c848baaa73d68d2f4f 100644 (file)
@@ -143,8 +143,12 @@ def event_create(context, values):
     return IMPL.event_create(context, values)
 
 
-def watch_rule_get(context, watch_rule_name):
-    return IMPL.watch_rule_get(context, watch_rule_name)
+def watch_rule_get(context, watch_rule_id):
+    return IMPL.watch_rule_get(context, watch_rule_id)
+
+
+def watch_rule_get_by_name(context, watch_rule_name):
+    return IMPL.watch_rule_get_by_name(context, watch_rule_name)
 
 
 def watch_rule_get_all(context):
index c0249b390f8970fa47c03eab07d0da6fbb10385a..ee6a9356494844b0fa94e9425e6c34aaf2488ee5 100644 (file)
@@ -258,7 +258,13 @@ def event_create(context, values):
     return event_ref
 
 
-def watch_rule_get(context, watch_rule_name):
+def watch_rule_get(context, watch_rule_id):
+    result = model_query(context, models.WatchRule).\
+                        filter_by(id=watch_rule_id).first()
+    return result
+
+
+def watch_rule_get_by_name(context, watch_rule_name):
     result = model_query(context, models.WatchRule).\
                         filter_by(name=watch_rule_name).first()
     return result
index f4589bf8bc463c11b68f9bbc12f4ff70ccbec6dc..92fc1fe32bc0ce9a6f9fbe8f764de60d325f89e4 100644 (file)
@@ -454,7 +454,7 @@ class EngineManager(manager.Manager):
         This could be used by CloudWatch and WaitConditions
         and treat HA service events like any other CloudWatch.
         '''
-        wr = db_api.watch_rule_get(None, watch_name)
+        wr = db_api.watch_rule_get_by_name(None, watch_name)
         if wr is None:
             logger.warn('NoSuch watch:%s' % (watch_name))
             return ['NoSuch Watch Rule', None]
@@ -483,7 +483,7 @@ class EngineManager(manager.Manager):
         '''
         if watch_name:
             try:
-                wr = db_api.watch_rule_get(context, watch_name)
+                wr = db_api.watch_rule_get_by_name(context, watch_name)
             except Exception as ex:
                 logger.warn('show_watch (%s) db error %s' %
                             (watch_name, str(ex)))
@@ -538,7 +538,7 @@ class EngineManager(manager.Manager):
 
         if watch_name:
             try:
-                wr = db_api.watch_rule_get(context, watch_name)
+                wr = db_api.watch_rule_get_by_name(context, watch_name)
             except Exception as ex:
                 logger.warn('show_watch (%s) db error %s' %
                             (watch_name, str(ex)))
index 4ffaa89508e30ae7712659e5e7325f3c0c155e41..60a738693e8bb7fa2ca18236dfcf727d01f0ee23 100644 (file)
@@ -621,7 +621,7 @@ class stackManagerTest(unittest.TestCase):
     def test_show_watch_metric(self):
         # Get one of the  watch rules created in test_show_watch
         # And add a metric datapoint
-        watch = db_api.watch_rule_get(self.ctx, "HttpFailureAlarm")
+        watch = db_api.watch_rule_get_by_name(self.ctx, "HttpFailureAlarm")
         self.assertNotEqual(watch, None)
         values = {'watch_rule_id': watch.id,
                   'data': {