Merge "Remove unused event_get methods"

changes/33/441333/1
Jenkins 6 years ago committed by Gerrit Code Review
commit ab267e763a

@ -826,20 +826,6 @@ def user_creds_delete(context, user_creds_id):
context.session.delete(creds)
def event_get(context, event_id):
result = context.session.query(models.Event).get(event_id)
return result
def event_get_all(context):
stacks = soft_delete_aware_query(context, models.Stack)
stack_ids = [stack.id for stack in stacks]
results = context.session.query(
models.Event
).filter(models.Event.stack_id.in_(stack_ids)).all()
return results
def event_get_all_by_tenant(context, limit=None, marker=None,
sort_keys=None, sort_dir=None, filters=None):
query = context.session.query(models.Event)

@ -67,16 +67,6 @@ class Event(
self._resource_properties = rpd_obj.data or {}
return self._resource_properties
@classmethod
def get_by_id(cls, context, event_id):
db_event = db_api.event_get(context, event_id)
return cls._from_db_object(context, cls(context), db_event)
@classmethod
def get_all(cls, context):
return [cls._from_db_object(context, cls(), db_event)
for db_event in db_api.event_get_all(context)]
@classmethod
def get_all_by_tenant(cls, context, **kwargs):
return [cls._from_db_object(context, cls(), db_event)

@ -936,27 +936,6 @@ class SqlAlchemyTest(common.HeatTestCase):
self.m.VerifyAll()
def test_event_get_all(self):
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
self._mock_create(self.m)
self.m.ReplayAll()
[s.create() for s in stacks]
[s._persist_state() for s in stacks]
self.m.UnsetStubs()
events = db_api.event_get_all(self.ctx)
self.assertEqual(12, len(events))
self._mock_delete(self.m)
self.m.ReplayAll()
stacks[0].delete()
events = db_api.event_get_all(self.ctx)
self.assertEqual(8, len(events))
self.m.VerifyAll()
def test_user_creds_password(self):
self.ctx.trust_id = None
self.ctx.region_name = 'RegionOne'
@ -2193,8 +2172,8 @@ class DBAPIStackTest(common.HeatTestCase):
ctx, tmpl_files[s].files_id))
self.assertIsNotNone(db_api.resource_get(
ctx, resources[s].id))
self.assertIsNotNone(db_api.event_get(
ctx, events[s].id))
self.assertIsNotNone(ctx.session.query(
models.Event).get(events[s].id))
self.assertIsNotNone(ctx.session.query(
models.ResourcePropertiesData).filter_by(
id=resources[s].rsrc_prop_data.id).first())
@ -2215,7 +2194,8 @@ class DBAPIStackTest(common.HeatTestCase):
self.assertEqual([],
db_api.event_get_all_by_stack(ctx,
stacks[s].id))
self.assertIsNone(db_api.event_get(ctx, events[s].id))
self.assertIsNone(ctx.session.query(
models.Event).get(events[s].id))
self.assertIsNone(ctx.session.query(
models.ResourcePropertiesData).filter_by(
id=resources[s].rsrc_prop_data.id).first())
@ -2715,10 +2695,10 @@ class DBAPIEventTest(common.HeatTestCase):
self.template = create_raw_template(self.ctx)
self.user_creds = create_user_creds(self.ctx)
def test_event_create_get(self):
def test_event_create(self):
stack = create_stack(self.ctx, self.template, self.user_creds)
event = create_event(self.ctx, stack_id=stack.id)
ret_event = db_api.event_get(self.ctx, event.id)
ret_event = self.ctx.session.query(models.Event).get(event.id)
self.assertIsNotNone(ret_event)
self.assertEqual(stack.id, ret_event.stack_id)
self.assertEqual('create', ret_event.resource_action)
@ -2728,26 +2708,6 @@ class DBAPIEventTest(common.HeatTestCase):
self.assertEqual('create_complete', ret_event.resource_status_reason)
self.assertEqual({'foo2': 'ev_bar'}, ret_event.rsrc_prop_data.data)
def test_event_get_all(self):
self.stack1 = create_stack(self.ctx, self.template, self.user_creds,
tenant='tenant1')
self.stack2 = create_stack(self.ctx, self.template, self.user_creds,
tenant='tenant2')
values = [
{'stack_id': self.stack1.id, 'resource_name': 'res1'},
{'stack_id': self.stack1.id, 'resource_name': 'res2'},
{'stack_id': self.stack2.id, 'resource_name': 'res3'},
]
[create_event(self.ctx, **val) for val in values]
events = db_api.event_get_all(self.ctx)
self.assertEqual(3, len(events))
stack_ids = [event.stack_id for event in events]
res_names = [event.resource_name for event in events]
[(self.assertIn(val['stack_id'], stack_ids),
self.assertIn(val['resource_name'], res_names)) for val in values]
def test_event_get_all_by_tenant(self):
self.stack1 = create_stack(self.ctx, self.template, self.user_creds,
tenant='tenant1')

@ -63,8 +63,9 @@ class FormatTest(common.HeatTestCase):
'z3455xyc-9f88-404d-a85b-5315293e67de',
res_properties, resource.name, resource.type(),
uuid='abc123yc-9f88-404d-a85b-531529456xyz')
event_id = ev.store()
return event_object.Event.get_by_id(self.context, event_id)
ev.store()
return event_object.Event.get_all_by_stack(self.context,
self.stack.id)[0]
def test_format_stack_resource(self):
self.stack.created_time = datetime(2015, 8, 3, 17, 5, 1)
@ -329,7 +330,8 @@ class FormatTest(common.HeatTestCase):
models.Event).filter_by(id=event.id).first()
db_obj.update({'resource_properties': {'legacy_k1': 'legacy_v1'}})
db_obj.save(self.stack.context.session)
event_legacy = event_object.Event.get_by_id(self.context, event.id)
event_legacy = event_object.Event.get_all_by_stack(self.context,
self.stack.id)[0]
formatted = api.format_event(event_legacy, self.stack.identifier())
self.assertEqual({'legacy_k1': 'legacy_v1'},
formatted[rpc_api.EVENT_RES_PROPERTIES])

@ -15,7 +15,6 @@ import mock
from oslo_config import cfg
import uuid
from heat.db.sqlalchemy import api as db_api
from heat.db.sqlalchemy import models
from heat.engine import event
from heat.engine import stack
@ -240,13 +239,13 @@ class EventTest(EventCommon):
# for test purposes, dress up the event to have the deprecated
# properties_data field populated
e_obj = db_api.event_get(self.resource.context, e.id)
e_obj = self.ctx.session.query(models.Event).get(e.id)
with self.ctx.session.begin():
e_obj['resource_properties'] = {'Time': 'not enough'}
e_obj['rsrc_prop_data'] = None
# verify the deprecated data gets loaded
ev = event_object.Event.get_by_id(self.ctx, e.id)
ev = event_object.Event.get_all_by_stack(self.ctx, self.stack.id)[0]
self.assertEqual({'Time': 'not enough'}, ev.resource_properties)
def test_event_object_resource_properties_data(self):
@ -262,8 +261,8 @@ class EventTest(EventCommon):
{'stack_id': self.stack.id,
'uuid': str(uuid.uuid4()),
'rsrc_prop_data_id': rpd_db_obj.id})
e_obj = event_object.Event().get_by_id(utils.dummy_context(),
e_obj.id)
e_obj = event_object.Event.get_all_by_stack(utils.dummy_context(),
self.stack.id)[0]
# properties data appears unencrypted to event object
self.assertEqual(data, e_obj.resource_properties)
@ -281,7 +280,8 @@ class EventEncryptedTest(EventCommon):
e.store()
# verify the resource_properties_data db data is encrypted
e_obj = event_object.Event.get_by_id(self.resource.context, e.id)
e_obj = event_object.Event.get_all_by_stack(self.resource.context,
self.stack.id)[0]
rpd_id = e_obj['rsrc_prop_data_id']
results = self.resource.context.session.query(
models.ResourcePropertiesData).filter_by(
@ -292,5 +292,6 @@ class EventEncryptedTest(EventCommon):
# verify encrypted data is decrypted when retrieved through
# heat object layer
ev = event_object.Event.get_by_id(self.ctx, e.id)
ev = event_object.Event.get_all_by_stack(self.ctx,
self.stack.id)[0]
self.assertEqual({'Foo': 'goo'}, ev.resource_properties)

Loading…
Cancel
Save